Kodi Community Forum
combo box or spin control usage - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: combo box or spin control usage (/showthread.php?tid=200179)



combo box or spin control usage - ianuk2005 - 2014-07-18

Hi,

I can't figure out how to use the default spin controls and cannot find any option for a combo box. Can anyone point me in the right direction to usage, I have created a spincontrolex in the skin but have no obvious way of populating it's data. The regular spincontrol only seem's to be usable for textboxes/list scrolling and not as an option selection in the documentation.

Code:
<control type="spincontrolex" id="1000">
              <description>My first settings spin control</description>
              <posx>0</posx>
              <posy>0</posy>
              <width>250</width>
              <height>200</height>
              <visible>true</visible>
              <colordiffuse>FFFFFFFF</colordiffuse>
              <label>test</label>
              <font>font12</font>
              <textcolor>FFFFFFFF</textcolor>
              <disabledcolor>80FFFFFF</disabledcolor>
              <onup>2</onup>
              <ondown>3</ondown>
              <onleft>1</onleft>
              <onright>1</onright>
        </control>

Code:
//code fails doesn't get a control
def onInit(self):      
        spincontrol = self.getControl(1000);
        return;



RE: combo box or spin control usage - jmarshall - 2014-07-19

It may well be that a spincontrolex is not supported in the plugin. A normal spincontrol should do the trick though.

Once you've got the control, add the labels you want to it etc.


RE: combo box or spin control usage - ianuk2005 - 2014-07-19

How do you add anything to a spin control though it doesn't seem to be in the documentation of how to say for example add a list of 10 text items for it to toggle through.


RE: combo box or spin control usage - ianuk2005 - 2014-07-20

ok i'm at a total loss with this one still, I tried a normal spin control in the skin e.g.

Code:
<control type="spincontrol" id="14">
              <description>My first spin control</description>
              <posx>80</posx>
              <posy>60</posy>    
              <visible>true</visible>
              <colordiffuse>FFFFFFFF</colordiffuse>
              <subtype>text</subtype>
              <font>font12</font>
              <textcolor>FFFFFFFF</textcolor>
              <disabledcolor>80FFFFFF</disabledcolor>
              <onup>2</onup>
              <ondown>3</ondown>
              <onleft>1</onleft>
              <onright>1</onright>
        </control>

Code:
def onInit(self):      
        spincontrol = self.getControl(14);
        self.setFocus(spincontrol)
        return;

This also fails, there also appears to be no examples of correct usage in skins as they all use spincontrolex in confluence but never assign data within the skin. The python doc's don't seem to have any real support for the spin control.

If the spin controls are indeed totally unusable for addons is there any good alternative for presenting a selectable set of data?


RE: combo box or spin control usage - ianuk2005 - 2014-07-20

ended up implementing my own using buttons and a label. Here's the class and an example usage if anyones interested:

Class:
Code:
'''
Created on 19 Jul 2014

@author: Ian
'''
class SpinControlOption(object):
    '''
    classdocs
    '''

    options = [];
    upBtn = None;
    downBtn = None;
    label = None;
    window = None;
    selectedIndex = 0;
    
    def __init__(self, window, upId, downId, labelId, options):
        self.options = options;
        self.window = window;
        
        self.upBtn = window.getControl(upId);
        self.downBtn = window.getControl(downId);
        self.label = window.getControl(labelId);
        
        self.setSelected();
        
        return;
    
    def setSelected(self):
        length = self.options.__len__();
        if self.selectedIndex < 0:
            self.selectedIndex = 0;
        if self.selectedIndex > length - 1:
            self.selectedIndex = length - 1;
            
        self.label.setLabel(self.options[self.selectedIndex]);
        return;
    
    def forwardInput(self, actionid):
        if actionid == 7:
            focusedItem = self.window.getFocus();
            
            if focusedItem == self.upBtn:
                self.selectedIndex -= 1;
                self.setSelected();
                
            if focusedItem == self.downBtn:
                self.selectedIndex += 1;
                self.setSelected();
                
        return;
    
    def getSelectedOption(self):
        return self.options[self.selectedIndex];

skin xml:
Code:
control type="group" id="1000">
            <control type="button" id="1001">
                <description>Value Button</description>
                <left>300</left>
                <top>10</top>
                <width>20</width>
                <height>20</height>
                <font>font13</font>
                <aligny>center</aligny>
                <invalidcolor>invalid</invalidcolor>
                <texturefocus>toggledown-focus.png</texturefocus>
                <texturenofocus>toggledown.png</texturenofocus>
                <label>-</label>
                <onup>9001</onup>
                <onleft>1001</onleft>
                <onright>1002</onright>
                <ondown>9000</ondown>
            </control>
            <control type="button" id="1002">
                <description>Value Button</description>
                <left>325</left>
                <top>10</top>
                <width>20</width>
                <height>20</height>
                <font>font13</font>
                <aligny>center</aligny>
                <invalidcolor>invalid</invalidcolor>
                <texturefocus>toggleup-focus.png</texturefocus>
                <texturenofocus>toggleup.png</texturenofocus>
                <label>-</label>
                <onup>9001</onup>
                <onleft>1001</onleft>
                <onright>1002</onright>
                <ondown>9000</ondown>
            </control>
            <control type="label" id="1003">
                <description>Rule Field label</description>
                <width>300</width>
                <height>40</height>
                <font>font13</font>
                <label>Options go here</label>
                <align>left</align>
                <aligny>center</aligny>
                <textcolor>white</textcolor>
                <shadowcolor>black</shadowcolor>
            </control>
        </control>

window class:
Code:
'''
Created on 15 Jul 2014

@author: Ian
'''

import xbmcgui;
import xbmcaddon;
from resources.lib.xbmctools.xbmcactions import XbmcActions
from resources.lib.superepg.views.spincontroloption import SpinControlOption

class LiveChannleEditor(xbmcgui.WindowXML):
    '''
    classdocs
    '''
    inputForwardControls = [];
    
    def __new__(cls):
        ADDON = xbmcaddon.Addon(id = 'script.service.superepg')
        return super(LiveChannleEditor, cls).__new__(cls, 'livechanneleditor.xml', ADDON.getAddonInfo('path'));

    def __init__(self):
        super(LiveChannleEditor, self).__init__();
        
        
    def onInit(self):      
        spincontrol = self.getControl(1001);
        
        self.inputForwardControls = [];
        spincontrolOption = SpinControlOption(self, 1002, 1001, 1003, ["example", "example2", "example3"]);
        self.inputForwardControls.insert(0, spincontrolOption)
        
        self.setFocus(spincontrol)
        return;
    
    def onAction(self, action):
        if action.getId() == XbmcActions.KEY_NAV_BACK:
            self.close()

        for control in self.inputForwardControls:
            control.forwardInput(action.getId());
        return;



RE: combo box or spin control usage - jmarshall - 2014-07-20

A nice workaround Smile


RE: combo box or spin control usage - ianuk2005 - 2014-07-20

(2014-07-20, 01:32)jmarshall Wrote: A nice workaround Smile

I cannot find any info on using the built in controls for this for an addon so I think it's quicker to just make a basic class and share on here. It's a bit hacky and basic but it works and is re-usable =)