From ee38160d8c1c916be5bb4d4b0beb2124b6f6ae97 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Thu, 28 May 2009 00:41:37 +0000 Subject: [PATCH] Add more command line commands git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@3 1daee41c-8060-4895-b1f0-2197c00d777a --- trunk/Makefile | 6 ++++++ trunk/cline.py | 16 ++++++++++++++-- trunk/ocarina.py | 37 ++++++++++++++++++++++++++++--------- trunk/song.py | 8 +++----- 4 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 trunk/Makefile diff --git a/trunk/Makefile b/trunk/Makefile new file mode 100644 index 00000000..73b3e71f --- /dev/null +++ b/trunk/Makefile @@ -0,0 +1,6 @@ + +open: + geany *.py & + +clean: + rm -rf *.pyc diff --git a/trunk/cline.py b/trunk/cline.py index 2f524ccf..524c3606 100644 --- a/trunk/cline.py +++ b/trunk/cline.py @@ -1,6 +1,17 @@ import threading import curses +################################################################################ +# Command line class, will run in its own thread # +# Does not contain any actual commands, this just takes user input # +# Commands must be registered before they can be used # +# When registering a command: pass the key, a poiner to the function, and # +# a help message # +# This does have a built-in help function, which displays the help messages # +# for registered commands. The help function can be overridden if needed # +################################################################################ + + class CLine(threading.Thread): # Initialize ncurses stuff def __init__(self): @@ -102,8 +113,9 @@ class CLine(threading.Thread): self.printLine(line) self.advanceLine() self.prompt() - + + # Print a single line on the screen def printLine(self,line): (y,x) = self.stdscr.getyx() self.advanceLine() @@ -118,7 +130,7 @@ class CLine(threading.Thread): self.cmnds[command]=(func,help) - + # Scan through keys and print help messages def printHelp(self): lines = [] keys = self.cmnds.keys() diff --git a/trunk/ocarina.py b/trunk/ocarina.py index 74eeab43..bef013c5 100644 --- a/trunk/ocarina.py +++ b/trunk/ocarina.py @@ -18,7 +18,7 @@ class main: self.commands.printLines(lines) self.song = Song(argv[0],self.quit,self.commands.printLines) - self.song.play() + #self.song.play() # Start main loop as a thread so we can get bus calls and use command line gobject.threads_init() @@ -26,38 +26,57 @@ class main: thread.start_new_thread(mainloop.run,()) + # Quit program def quit(self): self.commands.quit() print "Quitting..." sys.exit(0) + # Register commands for use in command line def registerCmnds(self): self.commands.register("quit",self.quit,"Exit ocarina") self.commands.register("exit",self.quit,"Exit ocarina") - self.commands.register("foo",self.foo,"a test function") self.commands.register("play",self.play,"Play current song") self.commands.register("pause",self.pause,"Pause current song") self.commands.register("time",self.time,"Display running time") + self.commands.register("info",self.info,"Display detailed info about current song") + self.commands.register("this",self.this,"Display basic info about current song") - def foo(self): - self.commands.printLine("foo...") - - + # Begin playback def play(self): self.song.play() - + # Pause music def pause(self): self.song.pause() - + # Show running time info def time(self): cur = self.song.curTime() tot = self.song.length self.commands.printLine(cur.toStr()+" / "+tot.toStr()) - + + # Show detailed song info + def info(self): + # Return if no tags found + if self.song.taglist == None: + self.commands.printLine("Could not find any tags") + return + for tag in self.song.taglist.keys(): + self.commands.printLine(tag+": "+str(self.song.taglist[tag])) + + # Show basic song info + def this(self): + # Return if no tags found + if self.song.taglist == None: + self.commands.printLine("Could not find any tags") + return + fields = ["title","artist","track-number","track-count","album"] + for field in fields: + if (field in self.song.taglist.keys()) == True: + self.commands.printLine(field+": "+str(self.song.taglist[field])) if __name__=='__main__':main(sys.argv[1:]) diff --git a/trunk/song.py b/trunk/song.py index dbdc8f7e..95ee83d3 100644 --- a/trunk/song.py +++ b/trunk/song.py @@ -27,6 +27,7 @@ class Song(): # Initialize stuff for finding duration self.time_format = gst.Format(gst.FORMAT_TIME) self.length = None + self.taglist = None # Called on bus messages @@ -42,10 +43,7 @@ class Song(): #print "Error: %s" % err, debug self.quit() elif t == gst.MESSAGE_TAG: - #print "Tags:" - # Probably should convert this to some other data structure - # For easier use later - taglist = message.parse_tag() + self.taglist = message.parse_tag() return @@ -54,7 +52,7 @@ class Song(): self.player.set_state(gst.STATE_PLAYING) # Start main loop and find duration (if this hasn't been done yet) if self.length == None: - time.sleep(0.2) + time.sleep(0.5) self.duration()