Mercurial > vixm
changeset 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 | b34cc91f003d |
children | 50745af6a63b |
files | vixm/ui.py |
diffstat | 1 files changed, 55 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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,) +