Kodi Community Forum
How do i end a script if there is no user input - Printable Version

+- Kodi Community Forum (http://forum.kodi.tv)
+-- Forum: Development (/forumdisplay.php?fid=32)
+--- Forum: Python Add-on Development (/forumdisplay.php?fid=26)
+--- Thread: How do i end a script if there is no user input (/showthread.php?tid=9457)



- Zeosstud - 2005-01-26 22:35

i have managed to put together a script that will goto my playlist directory, get a list of all the playlists, then allow me to choose one, it then load, shuffles and plays.  here is what i need it to do now.  if there is no user input for say 10 seconds i want it to select the default playlist, load, shuffle and play it.  could someone suggest how to accomplish this.
below is the script just as i have it running on my xbox currently.  i know there is alot of excess code in this, it will be cleaned up soon.

import os, xbmc, xbmcgui
try: emulating = xbmcgui.emulating
except: emulating = false

#get actioncodes from keymap.xml
action_previous_menu = 10

class myclass(xbmcgui.window):
def (self):
if emulating: xbmcgui.window.(self)
self.addcontrol(xbmcgui.controlimage(0,0,720,480, "q:\\scripts\\background.gif"))
self.stractioninfo = xbmcgui.controllabel(100, 200, 200, 200, "", "font13", "0xffff00ff")
self.addcontrol(self.stractioninfo)
self.stractioninfo.setlabel("push back to quit, or select an item from the list and push a")

# make the list
self.list = xbmcgui.controllist(300, 250, 200, 200)
self.addcontrol(self.list)

#define playlist directory here
               path = 'q:\\albums\\playlists\\'
list = os.listdir(path)
intcount = len(list)
for a in list :
                   self.list.additem(a)
               
self.setfocus(self.list)

               #select playlist
               #playlist = getrandomplaylist(path)

def onaction(self, action):
if action == action_previous_menu:
self.close()

def oncontrol(self, control):
if control == self.list:
item = self.list.getselecteditem()
#self.message("you selected : " + item.getlabel())
path1 = 'q:\\albums\\playlists\\'
xbmc.playlist(0).load(path1+item.getlabel())
xbmc.playlist(0).shuffle()
xbmc.player().play()
self.close()

def message(self, message):
dialog = xbmcgui.dialog()
dialog.ok(" my message title", message)

mydisplay = myclass()
mydisplay.domodal()
del mydisplay


- solexalex - 2005-01-27 00:26

you have to create a thread class
Quote:from threading import thread
class thread(thread):
def (self,time_out):
thread.(self)
self.time_out=time_out
def run(self):
self.running=1
while self.running:
time.sleep(self.time_out)

def stop( self ):
self.running = 0
self.join()
this is not complete... you'll have to set tome things in the run def to make it working the way you want

thne, you'll have to create the thread class
Quote:th = thread(10) #1 is the time out you want in secs, so you'll have to count in the run def in the thread
th.start()
th.join()

then you'll have to make something to reset your counter each time a control event is detected (oncontrol) or action (onaction)

hope these can help


- Zeosstud - 2005-01-27 00:39

thanks for the reply, trying to figure out how to implement your solutions now. if anyone has any code examples they want to share, please let me know. struggleing to perfect this little script.

zeosstud


- solexalex - 2005-01-27 01:35

you can check my wakeup script
it is an alarm to wake you up if you can keep your xbox on
it wakes you up with the sound of your choice, stream, radio, tv, video...

check for the correct thread in this board