From 93f2dacf836868962ba2c160a8efb5da7947d5ea Mon Sep 17 00:00:00 2001 From: bjschuma Date: Thu, 4 Jun 2009 23:35:03 +0000 Subject: [PATCH] Removed command line class git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@18 1daee41c-8060-4895-b1f0-2197c00d777a --- trunk/cline.py | 150 -------------------------------------------- trunk/ocarina | 2 +- trunk/ocarina.py | 56 +++++++---------- trunk/operations.py | 5 ++ trunk/playlist.py | 8 ++- 5 files changed, 34 insertions(+), 187 deletions(-) delete mode 100644 trunk/cline.py diff --git a/trunk/cline.py b/trunk/cline.py deleted file mode 100644 index 1e5fe958..00000000 --- a/trunk/cline.py +++ /dev/null @@ -1,150 +0,0 @@ -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): - threading.Thread.__init__(self) - self.stdscr = curses.initscr() - self.maxSize = self.stdscr.getmaxyx() - curses.cbreak() - curses.noecho() - self.stdscr.keypad(1) - self.input = "" - self.pos = (0,0) # REMEMBER: (y,x) - self.start() - self.cmnds = dict() - - - # Reverse ncurses stuff (returns screen to normal) - # THIS MUST BE CALLED BEFORE EXITING!!! - def quit(self): - curses.nocbreak() - curses.echo() - self.stdscr.keypad(0) - curses.endwin() - - - # Print the prompt - def prompt(self): - (y,x) = self.stdscr.getyx() - self.stdscr.addstr(y,0,">>> ") - self.stdscr.refresh() - - - # Run the command line - def run(self): - try: - self.prompt() - while(True): - # Enter key pressed - c = self.stdscr.getch() - if c==10: - self.enter() - elif c==127: - self.backspace() - else: - self.input+=curses.keyname(c) - self.changeline() - finally: - self.quit() - - - # Enter key pressed - # Returns true if we keep going - def enter(self): - args = self.input.strip().split(' ',1) - self.input = args[0].lower() - input = "" - if len(args) > 1: - input = args[1].strip() - #self.printLine(self.input+"\t"+input) - #self.input = self.input.strip().lower() - if self.input=="": - return - elif self.input in self.cmnds.keys(): - self.cmnds[self.input][0](input) - self.advanceLine() - self.prompt() - self.input = "" - elif self.input == "help": - self.printHelp() - self.input = "" - - - # Backspace key pressed - def backspace(self): - (y,x) = self.stdscr.getyx() - if self.input != "": - self.stdscr.move(y,x-1) - self.stdscr.delch() - self.input=self.input[0:len(self.input)-1] - - - # Advance cursor to next line - def advanceLine(self): - (y,x) = self.stdscr.getyx() - if y==self.maxSize[0]-1: - self.stdscr.move(0,0) - self.stdscr.deleteln() - else: - y+=1 - self.stdscr.move(y,0) - - - # Change the current line to reflect self.input - def changeline(self): - (y,x) = self.stdscr.getyx() - self.stdscr.deleteln() - self.stdscr.move(y,0) - self.prompt() - self.stdscr.addstr(self.input) - - - # Print lines to the screen - def printLines(self,lines): - #self.advanceLine() - for line in lines: - 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() - (y,x) = self.stdscr.getyx() - if len(line) > (self.maxSize[1]-1): - self.stdscr.addstr(line[0:(self.maxSize[1]-1)]) - self.printLine(line[self.maxSize[1]-1:len(line)]) - else: - self.stdscr.addstr(line) - #self.stdscr.move(y+1,x) - self.stdscr.refresh() - - - # Associate a command with a function - def register(self,command,func,help): - self.cmnds[command]=(func,help) - - - # Scan through keys and print help messages - def printHelp(self): - lines = [] - keys = self.cmnds.keys() - keys.sort() - for cmnd in keys: - lines+=[cmnd+"\t"+self.cmnds[cmnd][1]] - self.printLines(lines) diff --git a/trunk/ocarina b/trunk/ocarina index 0e1fb77e..e7287eda 100755 --- a/trunk/ocarina +++ b/trunk/ocarina @@ -1,2 +1,2 @@ #!/bin/bash -`which python` ocarina.py $? +`which python` ocarina.py $@ diff --git a/trunk/ocarina.py b/trunk/ocarina.py index 791a7d49..01284ff8 100644 --- a/trunk/ocarina.py +++ b/trunk/ocarina.py @@ -29,6 +29,12 @@ class main: self.ops.plist = self.plist self.ops.library = self.library + #self.ops.plist.random = True + if self.ops.plist.random==True: + # Toggle random status because set_active toggles it back + self.ops.random(None,None) + self.randomButton.set_active(1) + song = None # If we were given a song as input, check that it exists and begin playback if len(argv) > 0: @@ -49,7 +55,6 @@ class main: #gobject.idle_add(self.markProgress,self.pbar,"progress") - # Call gtk main gtk.main() @@ -64,9 +69,21 @@ class main: self.window.set_icon_from_file("images/ocarina.png") # Make a control box for buttons self.control = gtk.VBox(False,0) + + self.infoFrame = gtk.Frame("Song Info Goes Here") + infoLabel = gtk.Label("test") + self.infoFrame.add(infoLabel) + infoLabel.show() + self.infoFrame.show() + + self.inside = gtk.HBox(False,0) self.window.add(self.control) # Make buttons + self.randomButton = gtk.CheckButton(label="Random") + self.randomButton.connect("toggled",self.ops.random,"randomButton") + # Start with random enabled + self.randomButton.show() self.playButton = self.makeButton("playButton","images/play.png",None,self.ops.play) self.pauseButton = self.makeButton("pauseButton","images/pause.png",None,self.ops.pause) self.nextButton = self.makeButton("nextButton","images/next.png",None,self.ops.next) @@ -78,8 +95,10 @@ class main: self.inside.pack_start(self.nextButton,False,False,0) self.inside.pack_start(self.thisButton,False,False,0) self.inside.pack_start(self.infoButton,False,False,0) + self.inside.pack_start(self.randomButton,False,False,0) self.inside.show() # Top row + self.control.pack_start(self.infoFrame,False,False,0) self.control.pack_start(self.inside,False,False,0) self.pbar = gtk.ProgressBar() self.pbar.set_fraction(0) @@ -89,9 +108,9 @@ class main: self.control.pack_start(self.pbar,False,False,0) # Tray - self.statusIcon = gtk.StatusIcon() - self.statusIcon.set_from_file("images/ocarina.png") - self.statusIcon.set_tooltip("Ocarina") + #self.statusIcon = gtk.StatusIcon() + #self.statusIcon.set_from_file("images/ocarina.png") + #self.statusIcon.set_tooltip("Ocarina") #self.statusIcon.show() self.control.show() @@ -127,31 +146,6 @@ class main: return button - # Show running time info - #def time(self,unused): - # if self.song == None: - # return - # cur = self.song.curTime() - # tot = self.song.info.length - # self.commands.printLine(cur.toStr()+" / "+tot.toStr()) - - - # Show basic song info - #def this(self,unused): - #def this(self,widget,data): - # # Return if no song found - # if self.song == None: - # return - # # Return if no tags found - # if self.song.info.tags == None: - # print "Could not find any tags" - # return - # fields = ["title","artist","track-number","track-count","album"] - # for field in fields: - # if (field in self.song.info.tags.keys()) == True: - # print field+":",self.song.info.tags[field] - - def scanLib(self,dir): if dir == "": print "Please include a library directory" @@ -159,8 +153,4 @@ class main: self.library.scan(dir) - def random(self,unused): - self.plist.random = not self.plist.random - - if __name__=='__main__':main(sys.argv[1:]) diff --git a/trunk/operations.py b/trunk/operations.py index 7b80c0e7..b0cad781 100644 --- a/trunk/operations.py +++ b/trunk/operations.py @@ -74,3 +74,8 @@ class Operations: for tag in self.song.info.tags.keys(): print tag+":",self.song.info.tags[tag] print self.song.info.filename + + + # Toggle random + def random(self,widget,data): + self.plist.random = not self.plist.random diff --git a/trunk/playlist.py b/trunk/playlist.py index 4f18e2b9..f6a7c1ed 100644 --- a/trunk/playlist.py +++ b/trunk/playlist.py @@ -29,10 +29,12 @@ class Playlist: return self.queue.get() if len(self.list) == 0: return -2 + if self.random==True: self.curSong = random.randint(0,len(self.list)-1) + else: + self.curSong += 1 + if self.curSong > len(self.list): + self.curSong = 0 song = self.list[self.curSong] - self.curSong += 1 - if self.curSong > len(self.list): - self.curSong = 0 return song