Hi all,

I'm running on python version 2.6 for xbmc media application, but I'm having trouble with setLabel function.

When I run the code, it will update the value in the setLabel, but it will not allow me to update the values in the setLabel more than once.

Here it the code:

#DOWNLOAD THE XML SOURCE HERE
url = ADDON.getSetting('allchannels.url')
req = urllib2.Request(url)
response = urllib2.urlopen(req)
data = response.read()
response.close()
profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))
self.getControl(4202).setLabel("1%")


if os.path.exists(profilePath):
   profilePath = profilePath + 'source.db'
   con = database.connect(profilePath)
   cur = con.cursor()
   cur.execute('CREATE TABLE programs(channel TEXT, title TEXT, start_date TIMESTAMP, stop_date TIMESTAMP, description TEXT)')
   con.commit()
   con.close
   tv_elem = ElementTree.parse(StringIO.StringIO(data)).getroot()
   channels = OrderedDict()

   # Get the loaded data
   for channel in tv_elem.findall('channel'):
       channel_name = channel.find('display-name').text
       for program in channel.findall('programme'):
            title = program.find('title').text
            start_time = program.get("start")
            stop_time = program.get("stop")
            cur.execute("INSERT INTO programs(channel, title, start_date, stop_date)" + " VALUES(?, ?, ?, ?)", [channel_name, title, start_time, stop_time])
            con.commit()
            con.close
            secondsLeft = 20 * (100 - 10) / 100
            secondsLeft -= secondsLeft % 10

            self.getControl(4202).setLabel(str(secondsLeft)+"%")

Do you know how I can set the value in the setLabel function more than once?

Edited 2 Years Ago by mark103

It is possible that the GUI or whatever that setLabel uses, does not update the screen until the for loop finishes. We don't have enough info to help much further than that as the code is incomplete. Also, please post what you have done to debug this code. If you have added a print statement to show that setLabel is indeed called then the problem is possibly as stated above. If however setLabel is not even being called, then the problem is with one of the for loops.

@ZZucker: Thank you for your advise, do I need to use something like this?

self.getControl(4202).Update

or

self.getControl(4202).Refresh

I think it is
self.getControl(4202).SetLabel(str(secondsLeft)+"%")

Here is an example ...

# click on a wx.StaticText() label widget

import wx

class MyPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, wx.ID_ANY)
        self.label = wx.StaticText(self, wx.ID_ANY, 
            label="Oh My GOD", pos=(10, 10))
        self.label.SetBackgroundColour("yellow")
        # respond to the left mouse button click
        self.label.Bind(wx.EVT_LEFT_DOWN, self.onAction)

    def onAction(self, event):
        """ some action code, add a '!' with each click"""
        val = self.label.GetLabel()
        s = val + '!'
        self.label.SetLabel(s)


app = wx.App(0)
# create a frame, no parent, default ID, title, size
caption = "click on the label"
frame = wx.Frame(None, wx.ID_ANY, caption, size=(400, 110))
MyPanel(frame)
frame.Show(True)
app.MainLoop()

Edited 2 Years Ago by vegaseat

This article has been dead for over six months. Start a new discussion instead.