Changing controls from a thread
#1
my problem is;

unless i init a controllabel with the same text that a thread is set to update, the thread fails to update the text?

Quote:import xbmc, xbmcgui

import time
from threading import thread

global th

try: emulating = xbmcgui.emulating
except: emulating = false

#######################################################################################################################
class main(xbmcgui.window):
def (self):
if emulating: xbmcgui.window.(self)

# do you init stuff
#example set a label to display a clock - time.strftime("%h:%m:%s",time.localtime())
self.clock = xbmcgui.controllabel(100,100,280,30,time.strftime("%h:%m:%s",time.localtime()),'font12','0xffffffff')
self.addcontrol(self.clock)
# and when you want you can launch the thread :
global th
th=cyclingthread(self)
th.start()
#you tell the thread to start and it will do the rest... your script can go on
#....
#be sure to launch the thread after seting you control if those control are used by the thread

#other def here....


def onaction(self,action):
if action == action_back: #when you quit your script, you need to stop the thread
global th
th.stop() #call the stop function of our thread
self.close()
else:
pass

#######################################################################################################################
class cyclingthread(thread):
def (self,motherclass):
print "cyclingthread()"
thread.(self)
self.mother=motherclass #self.mother will be the same as 'self' in the main class

def run(self):
print "run()"
self.running=1
while self.running:
self.mother.clock.setlabel(time.strftime("%h:%m:%s",time.localtime()))
time.sleep(1)

def stop( self ):
print "stop()"
self.running = 0
self.join()


#----------------------
#execution
debut = main()
debut.domodal()
th.stop()#close the updater thread
del debut

the above code works, but if you set the controllabel to be anything but a date/time formated string *of the same format* the thread fails to cause the labels text to change.

ie change the format on line 18 to %h%s it stops working.
or change it from a date format to a fixed string "ab:cd:ef" it also stops.

does anyone know the reason behind this ?

cheers.
Reply

Logout Mark Read Team Forum Stats Members Help
Changing controls from a thread0