Kodi Community Forum

Full Version: add controls - xbmcgui.ControlGroup?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to group some controls to a ControlGroup, so I can display and hide them.
How do I do this?
thanks

Code:
import xbmc, xbmcplugin, xbmcgui, xbmc, xbmcaddon

class TestWindow(xbmcgui.WindowDialog):
    def __init__(self):
        background = xbmcgui.ControlImage(120, 40, 1040, 600, 'ContentPanel.png')
        self.addControl(background)
        
        self.btnClose = xbmcgui.ControlButton(1083, 54, 64, 32, '', noFocusTexture='DialogCloseButton.png', focusTexture='DialogCloseButton-focus.png')
        self.addControl(self.btnClose)
        
        # I want to group these controls in grpinfo =============================
        #===========================================================
        self.grpinfo = xbmcgui.ControlGroup(400, 70, 520, 400)
        self.addControl(self.grpinfo)
        
        self.lbl_0 = xbmcgui.ControlLabel(414, 110, 157, 40, 'Hello World 0', alignment=0x00000001)
        self.addControl(self.lbl_0)

        self.lbl_1 = xbmcgui.ControlLabel(414, 150, 157, 40, 'Hello World 1', alignment=0x00000001)
        self.addControl(self.lbl_1)
        #===========================================================
        #===========================================================
        
        self.btnHide = xbmcgui.ControlButton(310, 580, 160, 40, 'Hide group', alignment=0x00000006, font='font12')
        self.addControl(self.btnHide)
        
        self.btnView = xbmcgui.ControlButton(560, 580, 160, 40, 'View group', alignment=0x00000006, font='font12')
        self.addControl(self.btnView)
        
    def onControl(self, control):
        if control == self.btnClose:
            self.close()
            
        if control == self.btnHide:
            self.grpinfo.setVisible(False)
            
        if control == self.btnView:
            self.grpinfo.setVisible(True)
            
addon_url = sys.argv[0]
addon_id = int(sys.argv[1])
paramstring = sys.argv[2]
if paramstring == '?test=true':
    window = TestWindow()
    window.doModal()
else:
    tester = xbmcgui.ListItem('Window test')
    url = addon_url + '?test=true'
    xbmcplugin.addDirectoryItem(addon_id, url, tester, isFolder=False)
    xbmcplugin.endOfDirectory(addon_id)
i don't think you can...
as far as i can see the xbmcgui.ControlGroup class is pretty useless.
besides creating one, no other methods are implemented.
And what is the correct way to group components?
if you use the xbmcgui.WindowDialog class, there is none.

i would recommend to use the xbmcgui.WindowXMLDialog class instead and handle group controls in your skin xml file.
(2017-01-29, 22:15)antrrax Wrote: [ -> ]And what is the correct way to group components?

From Python perspective, there are no built-in facilities. You can either deal with controls one by one, or write some custom wrapper to deal them as a group (in your case, apply setVisible method).

Another alternative is to use a XML-based UI.
I'm facing the same issue. I wanted to create a custom control to use in a grouplist control.

I had envisaged defining several different layouts as python classes with various controls (labels, butttons, images) grouped in a ControlGroup.

These custom controlgroups would then be created dynamically via a loop in my python code and added to the grouplist. Depending on the particular criteria, the loop would add different classes to the grouplist.

I'm not sure if I can do this in xml because I need different layouts for different conditions and I don't think (unless someone tells me otherwise) I can use a group control with buttons etc in a list control.

Are there any options available to me?
Ah. Actually looks like you can't access grouplist via python anyway. I'll need to be more creative...
I left the grouplist. The solution I used was this one:

Code:
    def __init__(self):
        # Label de informações
        self.lblstr = ['Título original:', 'País de Origem:', 'Emissora:', 'Situação:', 'Lançamento:', 'Gênero:', 'Nota TMDB:', 'Fim da temp:']
        self.ctlLabel = []
        self.ctlLabelInfo = []
        
        self.info_gap = 0
        for i in range(len(self.lblstr)):
            poxY = 80 + self.info_gap

            self.ctlLabel.append(xbmcgui.ControlLabel(414, poxY, 157, 40, self.lblstr[i], alignment=0x00000001))
            self.addControl(self.ctlLabel[i])

            self.ctlLabelInfo.append(xbmcgui.ControlLabel(585, poxY, 543, 40, ''))
            self.addControl(self.ctlLabelInfo[i])

            self.info_gap += 40
        #------------

    def addSerieInfo(self, listInfo):
        for i in range(len(listInfo)):
            if i == 0:
                self.ctlLabelInfo[i].setLabel('[COLOR gold]' + listInfo[i] + '[/COLOR]')
                
            elif i == len(listInfo)-1:
                self.ctlLabelInfo[i].setLabel('[COLOR blue]' + listInfo[i] + '[/COLOR]')
                
            else:
                self.ctlLabelInfo[i].setLabel(listInfo[i])

    def onControl(self, control):
        if control == self.lstBtn[5]:
            if self.lstBtn[5].getLabel() == 'Elenco' :
                for i in range(len(self.ctlLabel)):
                    if i > 0 :
                        self.ctlLabelInfo[i].setVisible(False)
                        self.ctlLabel[i].setVisible(False)

Image

Image
Thanks. What's the class that this code belongs to?
What I'd like to do is create some "widgets" (essentially a group of controls that i can add to a grouplist).

While I could define the layout of such a control in xml, I don't think there's a way to let me reuse that layout multiple times.

The alternative is to use a list control as i can define the itemlayout in xml but I don't think that you can use buttons on a list item.
This is all my add-on code:
All code is inside a single file 'addon.py' - [kodi 16]
It's a little messy, I do not know if you'll understand.

http://www.mediafire.com/file/qqblbzfnte...esplay.zip

Look for this class:
'Class winInfos (xbmcgui.WindowDialog):'

The function
'def getinfo (url, title):'
calls the class
OK. A WindowDialog isn't going to work for my needs. I'll keep playing around.
Maybe I was overthinking this. Easiest way may just be to have a separate control outside of the list and then have it look up the active item when the button is clicked.

I've got a basic idea working so I'll go with that for now.