2004-11-15, 12:55
hi community,
first of all i want to thank everyone developing xbmc.
i am really new to python (never written something in it), but i started to write a little script. at a specified time an action will be executed. this can be starting/stopping of the playlist or a shutdown. i'm using a thread which compares the alarmtime with the current time.
if i started the thread and closed the window, the script runs in the background. my question is: how do i bring a running script to the foreground?
and it seems like a running thread in the background can't be stopped. when i try to rerun the script it says (stopping) but the thread is running and running... (this is maybe a feature request...)
here are some code snippets:
first of all i want to thank everyone developing xbmc.
i am really new to python (never written something in it), but i started to write a little script. at a specified time an action will be executed. this can be starting/stopping of the playlist or a shutdown. i'm using a thread which compares the alarmtime with the current time.
if i started the thread and closed the window, the script runs in the background. my question is: how do i bring a running script to the foreground?
and it seems like a running thread in the background can't be stopped. when i try to rerun the script it says (stopping) but the thread is running and running... (this is maybe a feature request...)
here are some code snippets:
Quote: def oncontrol(self, control):
# if closebutton is pressed close
if control == self.abortbutton:
self.close()
# if startbutton is pressed
elif control == self.startbutton:
d = datetime.datetime.now()
d = d.replace(hour=int(self.timelist.getselecteditem().getlabel()[0:2]),minute=int(self.timelist.getselecteditem().getlabel()[3:5]),second=0,microsecond=0)
if self.dodialogyesno("at "+d.ctime()," do "+actions[self.actionlist.getselectedposition()],"the current time: "+datetime.datetime.now().ctime()):
c = countdown(d, self.actionlist.getselectedposition())
c.start()
self.close()
c.join()
# depending on action do something, see actions
if c.action == 0:
print "play!"
player = xbmc.player()
player.play()
if c.action == 1:
print "stop!"
player = xbmc.player()
player.stop()
if c.action == 2:
print "shutdown!"
xbmc.shutdown()
class countdown(threading.thread):
"a simple thread comparing datetime objects"
checkstep = 2 # interval of the checking (seconds)
action = 0
def (self, alarm, action):
# executing the constructor of thread
threading.thread.(self)
# type test
if alarm. != datetime.datetime:
raise typeerror
self.alarm = alarm
self.action = action
def run(self):
# if the alarm is before now sleep and check again
while datetime.datetime.now() < self.alarm:
time.sleep(self.checkstep)