Mercurial > vixm
view 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 |
line wrap: on
line source
# all the user interface related bits import time, sys from threading import Thread import xmms import playlist, song def run(): """ this is where we start execution """ # first, let's create the two playlists print "Creating playlists..." lists = {} lists[playlist.LIST_PRIO] = playlist.playlist() lists[playlist.LIST_DEFAULT] = playlist.playlist(allowrandom=True) # read in the info for all the songs in XMMS's playlist print "Loading songs from XMMS's playlist..." songs = [] listlength = xmms.control.get_playlist_length() for i in range(0,listlength): s = song.song(i) lists[playlist.LIST_DEFAULT].enqueue(s) print "Instanciating ui thread..." ui = uiThread(lists) ui.start() 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, 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 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,)