Mercurial > vixm
comparison vixm/control.py @ 12:b5370c42288b
Code refactoring & implemented help command
author | Josef "Jeff" Sipek <jeffpc@josefsipek.net> |
---|---|
date | Sat, 19 Aug 2006 20:18:57 -0400 |
parents | |
children | 2ecc611d198f |
comparison
equal
deleted
inserted
replaced
11:50584a5c300e | 12:b5370c42288b |
---|---|
1 import playlist, util | |
2 | |
3 def cmd_quit(ui, start, stop, args): | |
4 ui.shutdown = True | |
5 | |
6 def cmd_number(ui, start, stop, args): | |
7 do_list(ui, start, stop, True, args) | |
8 | |
9 def cmd_list(ui, start, stop, args): | |
10 do_list(ui, start, stop, False, args) | |
11 | |
12 def cmd_enqueue(ui, start, stop, args): | |
13 try: | |
14 id = int(args[0])-1 | |
15 | |
16 if (id < 0) or \ | |
17 (id >= len(ui.lists[playlist.LIST_DEFAULT])): | |
18 raise ValueError | |
19 | |
20 except ValueError: | |
21 print "Invalid song id" | |
22 return | |
23 | |
24 ui.enqueue(id) | |
25 | |
26 def cmd_dequeue(ui, start, stop, args): | |
27 print "not implemented yet" | |
28 | |
29 def cmd_help(ui, start, stop, args): | |
30 for c in args[0]: | |
31 print "\t%s" % (args[0][c][2],) | |
32 | |
33 def do_list(ui, start, stop, number, args): | |
34 # get the list id from the argument or default to | |
35 # LIST_PRIO | |
36 try: | |
37 if args[1]: | |
38 listid = int(args[1]) | |
39 else: | |
40 listid = playlist.LIST_PRIO | |
41 | |
42 if listid < 0 or listid >= len(ui.lists): | |
43 raise ValueError | |
44 except ValueError, e: | |
45 print "Invalid list number" | |
46 raise e | |
47 | |
48 max = len(ui.lists[listid]) | |
49 if not max: | |
50 return | |
51 | |
52 start = util.fixupint(start, max) | |
53 stop = util.fixupint(stop, max) | |
54 | |
55 # starting number should be less than the ending | |
56 # number, as well as positive; ending number should | |
57 # be less than or equal to the size of the playlist | |
58 if start > stop or \ | |
59 start < 1 or \ | |
60 stop > max: | |
61 raise ValueError | |
62 | |
63 i = 1 | |
64 pfx = "" | |
65 for s in ui.lists[listid]: | |
66 if i < start or i > stop: | |
67 i += 1 | |
68 continue | |
69 | |
70 if number: | |
71 pfx = "%d. " % (i,) | |
72 | |
73 print "%s%s (%s)" % (pfx, s["title"], | |
74 util.strtime(s["time"])) | |
75 i += 1 | |
76 |