# HG changeset patch # User Josef "Jeff" Sipek # Date 1155947171 14400 # Node ID 187453f856a7c4755bcc4b62f891ef65961b09a1 # Parent b34cc91f003deab4cead1084389fb72eaf54796b Added a ex-like interface supporting a goto line syntax to enqueue a song and ':list [listid]' and ':quit' diff -r b34cc91f003d -r 187453f856a7 vixm/ui.py --- a/vixm/ui.py Sat Aug 12 21:04:45 2006 -0400 +++ b/vixm/ui.py Fri Aug 18 20:26:11 2006 -0400 @@ -1,6 +1,6 @@ # all the user interface related bits -import time +import time, sys from threading import Thread import xmms @@ -24,21 +24,68 @@ lists[playlist.LIST_DEFAULT].enqueue(s) print "Instanciating ui thread..." - ui = uiThread() + ui = uiThread(lists) ui.start() - while True: - print "Checking for xmms events" + while not ui.shutdown: time.sleep(1) class uiThread(Thread): """ This is the main ui thread class, it does all the magic necessary to have a vi-like interface """ - def __init__(self): + def __init__(self, lists): Thread.__init__(self) + self.lists = lists + self.shutdown = False + + def __enqueue(self, id): + s = self.lists[playlist.LIST_DEFAULT][id] + print "Enqueuing song: %d. %s (%d)" % (id, s["title"], s["time"]) + self.lists[playlist.LIST_PRIO].enqueue(s) + + def __cmd(self, txt): + parts = txt.split() + cmd = parts[0] + + if cmd == "quit": + self.shutdown = True + elif cmd == "list": + i = 1 + + if len(parts) > 1: + try: + listid = int(parts[1]) + if listid < 0 or listid >= len(self.lists): + raise ValueError + except: + print "Invalid list number" + return + else: + listid = playlist.LIST_PRIO + + for s in self.lists[listid]: + print "%d. %s (%d)" % (i, s["title"], s["time"]) + i += 1 + else: + print "Invalid command \"%s\"" % (cmd,) + def run(self): - while True: - print "Checking for ui events" - time.sleep(1) + while not self.shutdown: + tmp = sys.stdin.readline().strip() + + if tmp.startswith(":"): + # ':NNN' + try: + id = int(tmp[1:]) + except: + self.__cmd(tmp[1:]) + continue + self.__enqueue(id) + elif tmp.startswith("/"): + # '/ABC' + print "Searching not yet implemented" + else: + print "Unable to parse command \"%s\"" % (tmp,) +