comparison vixm/ui.py @ 5:187453f856a7

Added a ex-like interface supporting a goto line syntax to enqueue a song and ':list [listid]' and ':quit'
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Fri, 18 Aug 2006 20:26:11 -0400
parents dd00b69169c6
children 50745af6a63b
comparison
equal deleted inserted replaced
4:b34cc91f003d 5:187453f856a7
1 # all the user interface related bits 1 # all the user interface related bits
2 2
3 import time 3 import time, sys
4 from threading import Thread 4 from threading import Thread
5 import xmms 5 import xmms
6 6
7 import playlist, song 7 import playlist, song
8 8
22 for i in range(0,listlength): 22 for i in range(0,listlength):
23 s = song.song(i) 23 s = song.song(i)
24 lists[playlist.LIST_DEFAULT].enqueue(s) 24 lists[playlist.LIST_DEFAULT].enqueue(s)
25 25
26 print "Instanciating ui thread..." 26 print "Instanciating ui thread..."
27 ui = uiThread() 27 ui = uiThread(lists)
28 ui.start() 28 ui.start()
29 29
30 while True: 30 while not ui.shutdown:
31 print "Checking for xmms events"
32 time.sleep(1) 31 time.sleep(1)
33 32
34 class uiThread(Thread): 33 class uiThread(Thread):
35 """ This is the main ui thread class, it does all the magic 34 """ This is the main ui thread class, it does all the magic
36 necessary to have a vi-like interface """ 35 necessary to have a vi-like interface """
37 def __init__(self): 36 def __init__(self, lists):
38 Thread.__init__(self) 37 Thread.__init__(self)
39 38
39 self.lists = lists
40 self.shutdown = False
41
42 def __enqueue(self, id):
43 s = self.lists[playlist.LIST_DEFAULT][id]
44 print "Enqueuing song: %d. %s (%d)" % (id, s["title"], s["time"])
45 self.lists[playlist.LIST_PRIO].enqueue(s)
46
47 def __cmd(self, txt):
48 parts = txt.split()
49 cmd = parts[0]
50
51 if cmd == "quit":
52 self.shutdown = True
53 elif cmd == "list":
54 i = 1
55
56 if len(parts) > 1:
57 try:
58 listid = int(parts[1])
59 if listid < 0 or listid >= len(self.lists):
60 raise ValueError
61 except:
62 print "Invalid list number"
63 return
64 else:
65 listid = playlist.LIST_PRIO
66
67 for s in self.lists[listid]:
68 print "%d. %s (%d)" % (i, s["title"], s["time"])
69 i += 1
70 else:
71 print "Invalid command \"%s\"" % (cmd,)
72
40 def run(self): 73 def run(self):
41 while True: 74 while not self.shutdown:
42 print "Checking for ui events" 75 tmp = sys.stdin.readline().strip()
43 time.sleep(1) 76
77 if tmp.startswith(":"):
78 # ':NNN'
79 try:
80 id = int(tmp[1:])
81 except:
82 self.__cmd(tmp[1:])
83 continue
84 self.__enqueue(id)
44 85
86 elif tmp.startswith("/"):
87 # '/ABC'
88 print "Searching not yet implemented"
89 else:
90 print "Unable to parse command \"%s\"" % (tmp,)
91