Reference on a WindowXMLDialog control always fails
#1
Hi there,

after searching hours on the internet, I still don't get it. I found posts that seemed to match my current problem but after having a closer look the problems they had mostly had to deal with wrong xml implementation. They also had relating messages in the log, which I don't have.

What I try to do:

Creating an WindowXMLDialog in an video addon => Done, will be displayed properly, "lorem ipsum" is autoscrolling, window looks as wished
Changing the content of an control element to make things more dynamic => Ends up in control is non-existent, makes me mad Big Grin

However, heres the xml of my guitest addon:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<window>
    <defaultcontrol always="true">11</defaultcontrol>
    <coordinates>
        <system>1</system>
        <left>10</left>
        <top>10</top>
    </coordinates>
    <include>dialogeffect</include>
    <controls>
        <control type="image">
            <left>0</left>
            <top>0</top>
            <width>1270</width>
            <height>700</height>
            <texture border="40">DialogBack.png</texture>
        </control>
        <control type="image">
            <description>Dialog Header image</description>
            <left>40</left>
            <top>16</top>
            <width>1270</width>
            <height>40</height>
            <texture>dialogheader.png</texture>
        </control>
        <control type="label" id="1">
            <description>header label</description>
            <left>40</left>
            <top>20</top>
            <width>1270</width>
            <height>30</height>
            <font>font13_title</font>
            <label>Details zum Film</label>
            <align>center</align>
            <aligny>center</aligny>
            <textcolor>selected</textcolor>
            <shadowcolor>black</shadowcolor>
        </control>
        <control type="button">
            <description>Close Window button</description>
            <left>1190</left>
            <top>15</top>
            <width>64</width>
            <height>32</height>
            <label>-</label>
            <font>-</font>
            <onclick>PreviousMenu</onclick>
            <texturefocus>DialogCloseButton-focus.png</texturefocus>
            <texturenofocus>DialogCloseButton.png</texturenofocus>
            <onleft>10</onleft>
            <onright>10</onright>
            <onup>10</onup>
            <ondown>10</ondown>
            <visible>system.getbool(input.enablemouse)</visible>
        </control>
        <control type="textbox" id="9988">
            <description>moviedescription</description>
            <left>30</left>
            <top>60</top>
            <width>1200</width>
            <height>100</height>
            <align>left</align>
            <label>This is a textbox with autoscroll[CR][CR]Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</label>
            <font>font13</font>
            <autoscroll time="3000" delay="4000" repeat="5000">true</autoscroll>
        </control>
    </controls>
</window>

Here is the default.py implementation:
Code:
# -*- coding: utf-8 -*-
#------------------------------------------------------------
# Movie4k
# Version 1.0.2
#------------------------------------------------------------
# License: GPL (http://www.gnu.org/licenses/gpl-3.0.html)
#------------------------------------------------------------

import xbmc
import xbmcplugin
import xbmcaddon
import xbmcgui

import os
import sys
import datetime
import urlparse
import urllib2

#get actioncodes from https://github.com/xbmc/xbmc/blob/master/xbmc/guilib/Key.h
ACTION_PREVIOUS_MENU = 10
ACTION_SELEC_ITEM = 7
# Eleement IDs
MY_DESCRIPTION = 9988

# Plugin Info
ADDON_ID = 'plugin.video.guitest2'
REAL_SETTINGS = xbmcaddon.Addon(id=ADDON_ID)
ADDON_ID = REAL_SETTINGS.getAddonInfo('id')
ADDON_NAME = REAL_SETTINGS.getAddonInfo('name')
ADDON_PATH = REAL_SETTINGS.getAddonInfo('path')
ADDON_VERSION = REAL_SETTINGS.getAddonInfo('version')
xbmc.log(ADDON_ID +' '+ ADDON_NAME +' '+ ADDON_PATH +' '+ ADDON_VERSION)
SkinMasterPath = os.path.join(ADDON_PATH, 'skins' ) + '/'
MySkinPath = (os.path.join(SkinMasterPath, '720p')) + '/'
MySkin = 'mygui.xml'

class MyFirstWinXML(xbmcgui.WindowXMLDialog):
    def __new__(cls):
        return super(MyFirstWinXML, cls).__new__(cls, "mygui.xml", ADDON_PATH)

    def __init__(self):
        super(MyFirstWinXML, self).__init__()
        
    def mySetLabelText(self, MyText):
        self.getControl(MY_DESCRIPTION).setLabel(MyText)

xbmc.log("MySkin is: " + MySkin)
mydisplay=MyFirstWinXML()
mydisplay.mySetLabelText("Text is now differen[CR]The quick brown fox jumps over the lazy dog![CR]The quick brown fox jumps over the lazy dog!")
mydisplay.doModal()

Here is the result in the xbmc log:
Code:
19:10:57 T:140092425709312  NOTICE: MySkin is: mygui.xml
19:10:57 T:140092425709312   ERROR: EXCEPTION: Non-Existent Control 9988
19:10:57 T:140092425709312   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.RuntimeError'>
                                            Error Contents: Non-Existent Control 9988
                                            Traceback (most recent call last):
                                              File "/home/kbox/.xbmc/addons/plugin.video.guitest2/default.py", line 50, in <module>
                                                mydisplay.mySetLabelText("Text is now differen[CR]The quick brown fox jumps over the lazy dog![CR]The quick brown fox jumps over the lazy dog!")
                                              File "/home/kbox/.xbmc/addons/plugin.video.guitest2/default.py", line 46, in mySetLabelText
                                                self.getControl(MY_DESCRIPTION).setLabel(MyText)
                                            RuntimeError: Non-Existent Control 9988
                                            -->End of Python script error report<--

As said I have no errors saying the xml is not valid or anything else. I hope someone can help me finding out why i cannot reference the textbox element of the xml. Hopefully its just a stupid mistake by myselt Smile

Thanks for any hint
Reply
#2
you first have to do .doModal(), and then .getControl().
Donate: https://kodi.tv/contribute/donate (foundation), 146Gr48FqHM7TPB9q33HHv6uWpgQqdz1yk (BTC personal)
Estuary: Kodis new default skin - ExtendedInfo Script - KodiDevKit
Reply
#3
Hi phil65 and thanks for your reply,

I can remember that I tried this yesterday due I could imagine that elements are not present until .doModal(). But the problem here is, that if I do a .doModal() the XML defined values will be presented and the code stops until the window is closed. So it will never reach my dynamic data setter.

Code:
mydisplay.doModal()
mydisplay.mySetLabelText("Text is now differen[CR]The quick brown fox jumps over the lazy dog![CR]The quick brown fox jumps over the lazy dog!") # This line will only be reached if window is closed

How can I make it happen that I can initiate external values to my popup window and then display it? Can I create an instance of mydisplay that contains the control elements for referencing?

I could imagine the way to do so is quite different to my approach. I just want do be able to change values on the WindowXMLDialog from python code either on initiation or while its displayed.

Thanks
Reply
#4
put that getControl() stuff in onInit(). if you want to pass some values there then use parameters when creating the windowxml instance.
this here should help:
http://kodi.wiki/view/WindowXML
Donate: https://kodi.tv/contribute/donate (foundation), 146Gr48FqHM7TPB9q33HHv6uWpgQqdz1yk (BTC personal)
Estuary: Kodis new default skin - ExtendedInfo Script - KodiDevKit
Reply
#5
Thank you so much phil65 !!!

now I finally got this working by using this code (of course there is a lot more in it than I really needed => Dummy module):

Code:
# -*- coding: utf-8 -*-
#------------------------------------------------------------
# Version 1.0.2
#------------------------------------------------------------
# License: GPL (http://www.gnu.org/licenses/gpl-3.0.html)
#------------------------------------------------------------

import xbmc
import xbmcplugin
import xbmcaddon
import xbmcgui

import os
import sys
import datetime
import urlparse
import urllib2

#get actioncodes from https://github.com/xbmc/xbmc/blob/master/xbmc/guilib/Key.h
ACTION_PREVIOUS_MENU = 10
ACTION_SELEC_ITEM = 7
# Eleement IDs
MY_DESCRIPTION = 9988

# Plugin Info
ADDON_ID = 'plugin.video.guitest2'
REAL_SETTINGS = xbmcaddon.Addon(id=ADDON_ID)
ADDON_ID = REAL_SETTINGS.getAddonInfo('id')
ADDON_NAME = REAL_SETTINGS.getAddonInfo('name')
ADDON_PATH = REAL_SETTINGS.getAddonInfo('path')
ADDON_VERSION = REAL_SETTINGS.getAddonInfo('version')
xbmc.log(ADDON_ID +' '+ ADDON_NAME +' '+ ADDON_PATH +' '+ ADDON_VERSION)
SkinMasterPath = os.path.join(ADDON_PATH, 'skins' ) + '/'
MySkinPath = (os.path.join(SkinMasterPath, '720p')) + '/'
MySkin = 'mygui.xml'

class MyFirstWinXML(xbmcgui.WindowXMLDialog):
    def __new__(cls):
        return super(MyFirstWinXML, cls).__new__(cls, "mygui.xml", ADDON_PATH)

    def __init__(self):
        super(MyFirstWinXML, self).__init__()
        
    def onInit(self):
      self.getControl(MY_DESCRIPTION).setText(self.myText)
      pass
        
    def mySetLabelText(self, MyText):
        self.myText = MyText

xbmc.log("MySkin is: " + MySkin)
mydisplay=MyFirstWinXML()
mydisplay.mySetLabelText("Text is now differen[CR]The quick brown fox jumps over the lazy dog![CR]The quick brown fox jumps over the lazy dog!")
mydisplay.doModal()

"Lorem ipsum" will be overwritten on initialization by the "lazy dog". So using this base I should be able to fully create dialogs filled with dynamic data Cool

Hope this will be useful for others as well due the site You're linked me to is well known, but does not really tell how to startup with an addon that comes with custom dialogs.

If I got more familiar with the technique, I consider writing a corresponding wiki page so others will be able to startup with an addon skeleton Smile

Regards
Reply

Logout Mark Read Team Forum Stats Members Help
Reference on a WindowXMLDialog control always fails0