Add more command line commands

git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@3 1daee41c-8060-4895-b1f0-2197c00d777a
This commit is contained in:
bjschuma 2009-05-28 00:41:37 +00:00
parent ed7469a646
commit ee38160d8c
4 changed files with 51 additions and 16 deletions

6
trunk/Makefile Normal file
View File

@ -0,0 +1,6 @@
open:
geany *.py &
clean:
rm -rf *.pyc

View File

@ -1,6 +1,17 @@
import threading import threading
import curses 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): class CLine(threading.Thread):
# Initialize ncurses stuff # Initialize ncurses stuff
def __init__(self): def __init__(self):
@ -102,8 +113,9 @@ class CLine(threading.Thread):
self.printLine(line) self.printLine(line)
self.advanceLine() self.advanceLine()
self.prompt() self.prompt()
# Print a single line on the screen
def printLine(self,line): def printLine(self,line):
(y,x) = self.stdscr.getyx() (y,x) = self.stdscr.getyx()
self.advanceLine() self.advanceLine()
@ -118,7 +130,7 @@ class CLine(threading.Thread):
self.cmnds[command]=(func,help) self.cmnds[command]=(func,help)
# Scan through keys and print help messages
def printHelp(self): def printHelp(self):
lines = [] lines = []
keys = self.cmnds.keys() keys = self.cmnds.keys()

View File

@ -18,7 +18,7 @@ class main:
self.commands.printLines(lines) self.commands.printLines(lines)
self.song = Song(argv[0],self.quit,self.commands.printLines) 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 # Start main loop as a thread so we can get bus calls and use command line
gobject.threads_init() gobject.threads_init()
@ -26,38 +26,57 @@ class main:
thread.start_new_thread(mainloop.run,()) thread.start_new_thread(mainloop.run,())
# Quit program
def quit(self): def quit(self):
self.commands.quit() self.commands.quit()
print "Quitting..." print "Quitting..."
sys.exit(0) sys.exit(0)
# Register commands for use in command line
def registerCmnds(self): def registerCmnds(self):
self.commands.register("quit",self.quit,"Exit ocarina") self.commands.register("quit",self.quit,"Exit ocarina")
self.commands.register("exit",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("play",self.play,"Play current song")
self.commands.register("pause",self.pause,"Pause current song") self.commands.register("pause",self.pause,"Pause current song")
self.commands.register("time",self.time,"Display running time") 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): # Begin playback
self.commands.printLine("foo...")
def play(self): def play(self):
self.song.play() self.song.play()
# Pause music
def pause(self): def pause(self):
self.song.pause() self.song.pause()
# Show running time info
def time(self): def time(self):
cur = self.song.curTime() cur = self.song.curTime()
tot = self.song.length tot = self.song.length
self.commands.printLine(cur.toStr()+" / "+tot.toStr()) 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:]) if __name__=='__main__':main(sys.argv[1:])

View File

@ -27,6 +27,7 @@ class Song():
# Initialize stuff for finding duration # Initialize stuff for finding duration
self.time_format = gst.Format(gst.FORMAT_TIME) self.time_format = gst.Format(gst.FORMAT_TIME)
self.length = None self.length = None
self.taglist = None
# Called on bus messages # Called on bus messages
@ -42,10 +43,7 @@ class Song():
#print "Error: %s" % err, debug #print "Error: %s" % err, debug
self.quit() self.quit()
elif t == gst.MESSAGE_TAG: elif t == gst.MESSAGE_TAG:
#print "Tags:" self.taglist = message.parse_tag()
# Probably should convert this to some other data structure
# For easier use later
taglist = message.parse_tag()
return return
@ -54,7 +52,7 @@ class Song():
self.player.set_state(gst.STATE_PLAYING) self.player.set_state(gst.STATE_PLAYING)
# Start main loop and find duration (if this hasn't been done yet) # Start main loop and find duration (if this hasn't been done yet)
if self.length == None: if self.length == None:
time.sleep(0.2) time.sleep(0.5)
self.duration() self.duration()