Kodi Community Forum

Full Version: controlId won't match
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I have problem matching controlIds (clicked_control == self.go_down_control). How come in Kodi v19 I'm getting diffrent value of controlId?, in Kodi v18 everything is working fine.

xml:
<control type="button" id="9000">
                <description>Navigate down</description>
                <posx>910</posx>
                <posy>905</posy>
                <width>80</width>
                <height>80</height>
                <texturefocus colordiffuse="button_focus">buttons/down.png</texturefocus>
                <texturenofocus>buttons/down.png</texturenofocus>
                <onup>9001</onup>
                <ondown>-</ondown>
                <onleft>9002</onleft>
                <onright>9002</onright>
            </control>

python:
NAV_DOWN_BUTTON = 9000

python:
def onInit(self):
        self.go_down_control = self.getControl(NAV_DOWN_BUTTON)

python:
    def onClick(self, controlId):
        deb('onClick controlId: %s' % controlId )
        clicked_control = self.getControl(controlId)

        if clicked_control == self.go_down_control:
            deb('SkinPicker godown control')
            self.showNextSkin()

Result

2020-02-19 17:36:05.555 T:15760  NOTICE: MTVGUIDE @ onClick clicked_control : <xbmcgui.ControlButton object at 0x0000024B41EEF480>
2020-02-19 17:36:05.555 T:15760  NOTICE: MTVGUIDE @ onClick self.go_down_control: <xbmcgui.ControlButton object at 0x0000024B3D9EB690>
no idea i'm afraid.. i always simply compare control id's. much easier imho.

python:

if controlId == NAV_DOWN_BUTTON:
    ...
(2020-02-19, 18:57)ronie Wrote: [ -> ]no idea i'm afraid.. i always simply compare control id's. much easier imho.

python:

if controlId == NAV_DOWN_BUTTON:
    ...

The problem is that they should match but they don't. When pressing controlid 9000 it should return self.go_down_control.
I just realized the issue has to do with floating point division, I'm not sure how to convert all my division integers.
(2020-02-25, 07:49)M89SE Wrote: [ -> ]I just realized the issue has to do with floating point division, I'm not sure how to convert all my division integers.

You can make Python2 division work like Python3 division by importing division from future.

https://docs.python.org/2/library/__future__.html

As a specific Kodi thing, you should require script.module.future to make sure it's available.

Alternatively, you can do integer division in Python3 (and Python2) by using // instead of /.  Here's a Stack Overflow thread that might help:

https://stackoverflow.com/questions/2958...n-division

I think the answer with 11 votes describes your situation.