GUI Menu
#1
I am trying to write a xbmc addon that will rip movies or tv shows from a dvd/blu-ray using makemkv. The issue I am running in to, is I need a menu where you can select multiple items. See below for an example of the menu I need.

Code:
Select which titles you would like to rip:
Title 1   <---- Select this one
Title 2   <---- Select this one
Title 3
Title 4   <---- Select this one

[ Then they will click 'OK' ]

I hope I was clear in what I am trying to do. I have looked around the forums and documentation to find an answer, but no luck for me. lol

Any help would be great.

Thanks.
Reply
#2
Multiple choice dialog does exist in XBMC (see select languages for subs download dialog) but I'm not sure if it is accessible from addons. But honestly I'm not very familiar with XML skinning for addons. Maybe someone will help here.
But I'm familiar with Python-based UI controls, and the 1-st thing that comes to mind is to create a dialog with multiple RadioButtons and "OK" and "Cancel" Buttons at the bottom. The only potential problem here is that you will need a dialog with too many items (>10-20) that will not fit into the screen. Later I will provide you an example.
Reply
#3
Have a look at this thread: http://forum.kodi.tv/showthread.php?tid=170468

It's something that I've used in one of my addons. There's no xml involved, just uses a dialogselect object. It's not a perfect solution but it may help you do what you want.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#4
el_Paraguayo,

I think that is a very creative solution given the limitation of xbmc python menus. I might use that solution, however, I am very curious to see Roman_V_M's solution.


Thanks for the quick response everyone.
Reply
#5
After giving it some thoughts I dismiss my previous comments.

Below is an example of a proper multi-choice dialog created only in Python.
You will need 2 things:
My PyXBMCt framework (included in Gotham repo): http://forum.kodi.tv/showthread.php?tid=174859
A check icon, e.g. this: http://findicons.com/icon/62709/agt_acti...?id=269801
The icon needs to be placed in your addon root folder as "check.png". I will leave to you wrapping the code below into a proper Kodi addon structure. I guess you know what you are doing.

Code:
PHP Code:
import os
import xbmcgui
import xbmcaddon
import pyxbmct
.addonwindow as pyxbmct

_addon 
xbmcaddon.Addon()
_path _addon.getAddonInfo("path")
_check_icon os.path.join(_path"check.png"# Don't decode _path to utf-8!!!


class MultiChoiceDialog(pyxbmct.AddonDialogWindow):
    
def __init__(selftitle=""items=[]):
        
super(MultiChoiceDialogself).__init__(title)
        
self.setGeometry(45030044)
        
self.selected = []
        
self.set_controls()
        
self.connect_controls()
        
self.listing.addItems(items)
        
self.set_navigation()

    
def set_controls(self):
        
self.listing pyxbmct.List(_imageWidth=15)
        
self.placeControl(self.listing00rowspan=3columnspan=4)
        
self.ok_button pyxbmct.Button("OK")
        
self.placeControl(self.ok_button31)
        
self.cancel_button pyxbmct.Button("Cancel")
        
self.placeControl(self.cancel_button32)

    
def connect_controls(self):
        
self.connect(self.listingself.check_uncheck)
        
self.connect(self.ok_buttonself.ok)
        
self.connect(self.cancel_buttonself.close)

    
def set_navigation(self):
        
self.listing.controlUp(self.ok_button)
        
self.listing.controlDown(self.ok_button)
        
self.ok_button.setNavigation(self.listingself.listingself.cancel_buttonself.cancel_button)
        
self.cancel_button.setNavigation(self.listingself.listingself.ok_buttonself.ok_button)
        
self.setFocus(self.listing)


    
def check_uncheck(self):
        
list_item self.listing.getSelectedItem()
        if 
list_item.getLabel2() == "checked":
            
list_item.setIconImage("")
            
list_item.setLabel2("unchecked")
        else:
            
list_item.setIconImage(_check_icon)
            
list_item.setLabel2("checked")

    
def ok(self):
        for 
index in range(self.listing.size()):
            if 
self.listing.getListItem(index).getLabel2() == "checked":
                
self.selected.append(index)
        
super(MultiChoiceDialogself).close()

    
def close(self):
        
self.selected = []
        
super(MultiChoiceDialogself).close()

if 
__name__ == "__main__":
    
items = ["Item {0}".format(i) for i in range(111)]
    
dialog MultiChoiceDialog("Select items"items)
    
dialog.doModal()
    
xbmcgui.Dialog().notification("Finished""Selected: {0}".format(dialog.selected))
    
del dialog #You need to delete your instance when it is no longer needed
    #because underlying xbmcgui classes are not grabage-collected. 

If you've done everything OK, then you will get the following result:

Image

Items can be selected/deselected by clicking on them. Checked items are marked with "check" icons.

The list of checked items is accessed via selected property of MultiChoiceDialog class instance. Note that selected item indices start from 0, e.g [0, 3, 5].

This is only a proof of concept, and you can use this code and change it as you see fit.
Reply
#6
Wow, I am impressed with your find Roman_V_M. I have never heard of PyXBMCt. I look forward to learning and applying this to my code.

Thanks.
Reply
#7
You welcome.Smile BTW, I've slightly changed the code above in ok and cancel methods.
Reply
#8
I'd highly recommend using pyXBMCt if possible. It really is an excellent piece of work.

Unfortunately for me, Roman_V_M hadn't written the code at the time I wrote my earlier script!!
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#9
That worked great. The only issues I have is:

1. I would like the menu to be more dynamic. What if the movie title is really long.

2. Based on the image, how is the user suppose to know that you can scroll down?
Reply
#10
(2014-10-29, 21:28)edwardcode Wrote: That worked great. The only issues I have is:

1. I would like the menu to be more dynamic. What if the movie title is really long.

2. Based on the image, how is the user suppose to know that you can scroll down?

1. I'm not sure what you mean, but in ControlList currently selected item is auto-scrolled if it is too long. Also there is a FadeLabel control which provides auto-scrollable text label.

2. PyXBMCt is just an abstraction layer over xbmcgui classes, so its features are limited to those of underlying classes. Unfortunately, xbmcgui.CongrolList does not have a scroll-bar or another visual indicator for how many items it contains.
So you need to provide some visual hint yourself. This may be a simple text label, e.g. "Items selected: {0} of {1}", or some graphic hints.

As I understand, XML-based add-on UI provides more features, but for that you need to learn XML skinning as well.
Reply
#11
I have 2 more questions.

1. Is there a way I can have the row highlight when I select it instead of a check box? Not a big deal, I am just curious.

2. My out put will look like this for each item in the list: 'Title: %s, Chapters: %s, Length: %s, Size: %s'
What I would like to do is put each piece of information in its own column, and only have the title column be used for the selections. I am not sure how to do that.

At the very lease I would like to put a tab (\t) in between each section. Example below:

Code:
'Title: %s,\tChapters: %s,\tLength: %s,\tSize: %s'

When I do that command on the command line, it looks good. When I put that into your code it just put a single space where the (\t) is.

Thanks in advance.
Reply
#12
(2014-10-30, 19:22)edwardcode Wrote: I have 2 more questions.

1. Is there a way I can have the row highlight when I select it instead of a check box? Not a big deal, I am just curious.

2. My out put will look like this for each item in the list: 'Title: %s, Chapters: %s, Length: %s, Size: %s'
What I would like to do is put each piece of information in its own column, and only have the title column be used for the selections. I am not sure how to do that.

At the very lease I would like to put a tab (\t) in between each section. Example below:

Code:
'Title: %s,\tChapters: %s,\tLength: %s,\tSize: %s'

When I do that command on the command line, it looks good. When I put that into your code it just put a single space where the (\t) is.

Thanks in advance.


Unfortunately, xbmcgui Control classes have limited capabilities. So no to both of your questions.
If you need fancy UI, then you should consider XML-based (skinned) add-on UI.
Reply
#13
I have an other question. I have created a couple of menus in a separate py file, named menu.py, and each menu is in it's own class. I have my main python addon file, named default.py, and I import the menu.py. So what happens is xbmc calls default.py and pulls up a menu from menu.py. When you click 'ok' default.py does some more work and then runs another menu from menu.py. For each menu, when you click 'cancel' it sets a variable to 'cancel'. Then default.py will see that variable and exit the addon. The problem I am having is when I click the 'X' button on the top right of the dialog window, it will close the window but not set the variable to 'cancel' so my addon will continue down. How do I get a status or set a veritable when you click the 'x' button in the dialog window, so I can exit the addon?

I hope I was clear.

Thanks.
Reply
#14
(2014-11-11, 23:36)edwardcode Wrote: I have an other question. I have created a couple of menus in a separate py file, named menu.py, and each menu is in it's own class. I have my main python addon file, named default.py, and I import the menu.py. So what happens is xbmc calls default.py and pulls up a menu from menu.py. When you click 'ok' default.py does some more work and then runs another menu from menu.py. For each menu, when you click 'cancel' it sets a variable to 'cancel'. Then default.py will see that variable and exit the addon. The problem I am having is when I click the 'X' button on the top right of the dialog window, it will close the window but not set the variable to 'cancel' so my addon will continue down. How do I get a status or set a veritable when you click the 'x' button in the dialog window, so I can exit the addon?

I hope I was clear.

Thanks.

Without code examples your explanation is quite vague, but I'll risk to guess that you need to re-implement close() method in your class and add there your own code that resets your variables to default values. It was partially my fault because my code example had had the same logical bug, as I wrote it quickly, simply as a PoC, and not a "production" code. Now I've corrected the example above.
Reply
#15
That was not quite what I was talking about, but it gave me a good idea that worked. I just set a variable in the __init__ called self.status = 'cancel'. When you click 'ok' it will change self.status = 'ok'. This way no matter how you exit the menu it will default to 'cancel'.
Reply

Logout Mark Read Team Forum Stats Members Help
GUI Menu0