PDA

View Full Version : self.getControl - TypeError:Non-Existent Control


fjskmdl
2009-07-22, 14:50
I want to set the label text of a control when i display the window.
I use the following code:

ctrl = self.getControl(5)

But this gives me this error:
TypeError:Non-Existent Control 5

in my windowxml file i have a label control with id="5":

<control type="label" id="5">
<animation effect="slide" start="600,0" end="0,0" time="200">WindowOpen</animation>
<animation effect="slide" start="0,0" end="600,0" time="200">WindowClose</animation>
<description>Feed Label</description>
<width>427</width>
<posx>244</posx>
<posy>70</posy>
<align>center</align>
<aligny>center</aligny>
<label>Feeds loading...</label>
<font>font13</font>
<textcolor>FFFFFFFF</textcolor>
</control>

Does anyone know why this does not work.

I am trying to show an info dialog when pressing a listitem, so i use windowxml to create a custom dialog (dialog.yesno, dialog.ok is not good for me, no multiple lines)
Is this the right way?

thanks in advance

jmarshall
2009-07-23, 01:00
Perhaps you're requesting the control prior to it being setup?

fjskmdl
2009-07-23, 11:14
I don't think that is the case.
Here is the full code of my problem. Hopefully someone can help me with this :)

import os
import pickle
import sys
import traceback
import xbmcgui
import xbmc
import random
import string
import re

class YouTubeGUI(xbmcgui.WindowXML):
id_obj = ''
def setObj(self,val):
self.id_obj = val
ctrl = self.getControl(5)
pass
def onInit(self):
pass


base_path = os.getcwd()

w = YouTubeGUI("details.xml", base_path, "DefaultSkin")
w.setObj(1)
w.doModal()
del w

jmarshall
2009-07-23, 12:16
The control isn't created until doModal() is called would be my guess. I'm sure one of the more experienced scripters can confirm this. You should do any such processing in the onInit callback.

Cheers,
Jonathan

fjskmdl
2009-07-23, 13:24
second try:


class YouTubeGUI(xbmcgui.WindowXML):
def onInit(self):
ctrl = xbmcgui.getControl(1)
ctrl.setLabel = "david"
print "ja"
pass
def testfunctie():
ctrl = xbmcgui.getControl(1)
ctrl.setLabel = "david"
print "ja2"

base_path = os.getcwd()

w = YouTubeGUI("testje.xml", base_path, "DefaultSkin")
#w.setObj(1)
w.doModal()
w.testfunctie()
del w


neither print "ja" or print "ja2" is being executed...

Is there someone who can give me a working example of this:

Showing listitems, when clicking a listitem show a dialog (with labels and textboxes (multiple lines) + yes no button.
On cancel return to list.

This is what i am trying to do. I need getControl to set the textbox value/ labels etc

thanks

fjskmdl
2009-07-24, 19:59
i finally got it working using the code below:

class MyFirstWinXML(xbmcgui.WindowXMLDialog):
def __init__(self,strXMLname, strFallbackPath, strDefaultName, forceFallback):
# Changing the three varibles passed won't change, anything
# Doing strXMLname = "bah.xml" will not change anything.
# don't put GUI sensitive stuff here (as the xml hasn't been read yet
# Idea to initialize your variables here
pass

def onInit(self):
# Put your List Populating code/ and GUI startup stuff here
pass

def onAction(self, action):
# Same as normal python Windows.
if action == ACTION_PREVIOUS_MENU:
self.close()
def onClick(self, controlID):
"""
Notice: onClick not onControl
Notice: it gives the ID of the control not the control object
"""
pass

def onFocus(self, controlID):
pass

base_path = os.getcwd()

tbd = MyFirstWinXML("details.xml", base_path, "DefaultSkin", 0)
tbd.doModal()
del tdb


But i still have the following problem. I cannot close the window. This is what the xbmc.log says about the onAction def:

ERROR: Exception in python script's onAction