From 3a2da685612b0697cc1d018f0c9ef8744fb3943f Mon Sep 17 00:00:00 2001 From: bjschuma Date: Fri, 5 Jun 2009 16:51:18 +0000 Subject: [PATCH] Can select dir to scan for library. Can quit after current track git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@19 1daee41c-8060-4895-b1f0-2197c00d777a --- trunk/library.py | 2 +- trunk/ocarina.py | 103 ++----------------------- trunk/operations.py | 15 +++- trunk/song.py | 5 ++ trunk/window.py | 183 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 210 insertions(+), 98 deletions(-) create mode 100644 trunk/window.py diff --git a/trunk/library.py b/trunk/library.py index e1366883..b31e4724 100644 --- a/trunk/library.py +++ b/trunk/library.py @@ -31,7 +31,7 @@ class Library(): #self.prnt(["Directory not found: "+dir]) print "Directory not found: %s" % dir return - self.prnt(["Scanning: "+self.data.path]) + print "Scanning: "+self.data.path self.traverse("") num = len(self.data.files) #self.prnt(["Found "+str(num)+" files!"]) diff --git a/trunk/ocarina.py b/trunk/ocarina.py index 01284ff8..21bdd959 100644 --- a/trunk/ocarina.py +++ b/trunk/ocarina.py @@ -13,6 +13,7 @@ from library import Library from operations import Operations from playlist import Playlist from songInfo import SongInfo +from window import Window #gtk.gdk.threads_init() gobject.threads_init() @@ -20,8 +21,7 @@ gobject.threads_init() class main: def __init__(self,argv): - self.ops = Operations() - self.makeWindow() + self.ops = Operations(self.quit) self.library = Library() self.plist = Playlist() @@ -29,11 +29,9 @@ 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) + window = Window(self.quit,self.ops) + self.ops.setInfo = window.changeInfo + self.ops.resetInfo = window.resetInfo song = None # If we were given a song as input, check that it exists and begin playback @@ -53,104 +51,17 @@ class main: self.ops.song = song self.ops.next("","") - #gobject.idle_add(self.markProgress,self.pbar,"progress") - # Call gtk main gtk.main() - # Make the main window - def makeWindow(self): - # Make window - self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) - self.window.set_title("Ocarina") - self.window.connect("delete_event",self.delete_event) - self.window.set_border_width(0) - 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) - self.thisButton = self.makeButton("thisButton",None,"This",self.ops.this) - self.infoButton = self.makeButton("infoButton",None,"Info",self.ops.info) - # Add buttons to window - self.inside.pack_start(self.playButton,False,False,0) - self.inside.pack_start(self.pauseButton,False,False,0) - 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) - self.pbar.show() - # Update the progress bar every 100 ms - gobject.timeout_add(100,self.ops.markProgress,self.pbar,"progress") - 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.show() - - self.control.show() - self.window.show() - - # Called before exiting - def delete_event(self,widget,event,data=None): + # Eventually replace "delete_event" with this + def quit(self,widget,event,data=None): print "Quitting..." self.library.dump() gtk.main_quit() return False - # Use this to make a button - # Give the name, image path, text, and callback function - def makeButton(self,name,path,text,func): - button = gtk.Button() - box = gtk.HBox(False,0) - box.set_border_width(0) - if path != None: - image = gtk.Image() - image.set_from_file(path) - image.show() - box.pack_start(image,False,False,0) - if text != None: - label = gtk.Label(text) - label.show() - box.pack_start(label,False,False,0) - box.show() - button.add(box) - button.connect("clicked",func,name) - button.show() - return button - - - def scanLib(self,dir): - if dir == "": - print "Please include a library directory" - return - self.library.scan(dir) - if __name__=='__main__':main(sys.argv[1:]) diff --git a/trunk/operations.py b/trunk/operations.py index b0cad781..94bc6fd6 100644 --- a/trunk/operations.py +++ b/trunk/operations.py @@ -2,10 +2,12 @@ from song import Song # Use to define various operations class Operations: - def __init__(self): + def __init__(self,exit): self.song = None self.plist = None self.library = None + self.exit = exit + self.quitAfter = False # Begin playback @@ -22,11 +24,17 @@ class Operations: self.song.pause() + def afterTrack(self,widget,data): + if data=="qafter": + self.quitAfter = True + # Advance to the next song def next(self,widget,data): # Close open songs if self.song != None: self.song.close() + if self.quitAfter == True: + self.exit(None,None) # Get next song index = self.plist.next() if index > -1: @@ -34,6 +42,7 @@ class Operations: info = self.library.data.files[index] self.song = Song(info,self.next) if index > -2: + self.song.setInfo = self.setInfo self.song.play() @@ -79,3 +88,7 @@ class Operations: # Toggle random def random(self,widget,data): self.plist.random = not self.plist.random + + + def scanLib(self,dir): + self.library.scan(dir) diff --git a/trunk/song.py b/trunk/song.py index 027fc021..c4e5a1d9 100644 --- a/trunk/song.py +++ b/trunk/song.py @@ -13,6 +13,8 @@ class Song(): #self.prnt=prnt self.info = info self.info.tags = dict() + self.setInfo = None + self.getNext = None # initialize player pipeline self.player = gst.Pipeline("player") bin = gst.element_factory_make("playbin",None) @@ -46,12 +48,15 @@ class Song(): #if self.prnt != None: # self.prnt(["Error: "+ str(err) + " " +str(debug)]) print "Error: %s" % err, debug + print "Trying next song" + self.getNext(None,None) #if self.quit != None: # self.quit("") elif t == gst.MESSAGE_TAG: tags = message.parse_tag() for tag in tags.keys(): self.info.tags[tag] = tags[tag] + self.setInfo(tags) #self.taglist = message.parse_tag() return diff --git a/trunk/window.py b/trunk/window.py new file mode 100644 index 00000000..cd2bc372 --- /dev/null +++ b/trunk/window.py @@ -0,0 +1,183 @@ +import gobject +import pygtk +pygtk.require('2.0') +import gtk + + +class Window(gtk.Window): + def __init__(self,onQuit,ops): + gtk.Window.__init__(self,gtk.WINDOW_TOPLEVEL) + print "Making window!" + self.ops = ops + self.tooltip = gtk.Tooltips() + self.tagLabels = dict() + self.set_title("Ocarina") + # Call quit function when closed + self.connect("delete_event",onQuit) + self.set_icon_from_file("images/ocarina.png") + + self.mainLayout = gtk.VBox(False,0) + self.add(self.mainLayout) + self.mainLayout.show() + + self.makeMenuBar() + self.makeInfoPane() + self.makeControls() + self.show() + + + # Make initial info pane + def makeInfoPane(self): + info = gtk.Frame("Current Song:") + box = gtk.VBox(False,0) + info.add(box) + self.tagLabels["title"] = self.makeLabel("Title: ?",box) + self.tagLabels["artist"] = self.makeLabel("Artist: ?",box) + self.tagLabels["album"] = self.makeLabel("Album: ?",box) + box.show() + info.show() + self.mainLayout.add(info) + + + # Set up a new label, add to container + # Goes into a HBox so that it is left justified + def makeLabel(self,text,container): + box = gtk.HBox(False,0) + label = gtk.Label(text) + self.tooltip.set_tip(label,text,tip_private=None) + label.set_max_width_chars(35) + label.show() + box.pack_start(label,False,False,0) + box.show() + container.pack_start(box,False,False,0) + return label + + + # Change label info + def changeInfo(self,tags): + keys = tags.keys() + labels = self.tagLabels.keys() + for key in keys: + if (key in labels) == True: + str = key.title()+": "+tags[key] + self.tagLabels[key].set_label(str) + self.tooltip.set_tip(self.tagLabels[key],str,tip_private=None) + self.tagLabels[key].show() + + + # Reset label info + def resetInfo(self): + labels = self.tagLabels.keys() + for key in labels: + self.tagLabels[key].set_label(key.title()+": ?") + self.tooltip.set_tip(self.tagLabels[key],key.title()+": ?") + self.tagLabels[key].show() + + # Use to make play/pause/next/etc buttons + def makeControls(self): + #controls = gtk.VBox(False,0) + topRow = gtk.HBox(False,0) + # Make top row buttons + self.makeButton("play","images/play.png",None,self.ops.play,topRow) + self.makeButton("pause","images/pause.png",None,self.ops.pause,topRow) + self.makeButton("next","images/next.png",None,self.ops.next,topRow) + self.makeButton("this",None,"This",self.ops.this,topRow) + self.makeButton("info",None,"Info",self.ops.info,topRow) + + test = gtk.VBox(False,0) + self.makeCheck("Random",self.ops.random,self.ops.plist.random,True,topRow) + topRow.show() + self.mainLayout.pack_start(topRow,False,False,0) + # Make progress bar, add below top row + pbar = gtk.ProgressBar() + pbar.set_fraction(0) + gobject.timeout_add(1000,self.ops.markProgress,pbar,"progress") + pbar.show() + self.mainLayout.pack_start(pbar,False,False,0) + # Show completed controls + #controls.show() + #self.add(controls) + + + # Make buttons and add to container + # Path is to an image + # Text is label text + # Func is callback function + def makeButton(self,name,path,text,func,container): + button = gtk.Button() + box = gtk.HBox(False,0) + box.set_border_width(0) + if path != None: + image = gtk.Image() + image.set_from_file(path) + image.show() + box.pack_start(image,False,False,0) + if text != None: + label = gtk.Label(text) + label.show() + box.pack_start(label,False,False,0) + box.show() + button.add(box) + button.connect("clicked",func,name) + button.show() + container.pack_start(button,False,False,0) + return button + + + # Make a checkbox and add to container + # Active is variable to check, status is value it has to mark as active + def makeCheck(self,name,func,active,status,container): + check = gtk.CheckButton(label=name) + if active == status: + check.set_active(1) + check.connect("toggled",func,name) + check.show() + container.pack_start(check,False,False,0) + return check + + + def makeMenuBar(self): + # Make menu bar + bar = gtk.MenuBar() + # This is the dropdown selections + # Make a new library option + library = gtk.MenuItem("Library") + lib = gtk.Menu() + newLib = gtk.MenuItem(label="New Library") + newLib.connect_object("activate",self.selectDir,self.ops.scanLib) + newLib.show() + lib.append(newLib) + # This shows in the toolbar + library.set_submenu(lib) + library.show() + bar.append(library) + + # Make playback option + playback = gtk.MenuItem("Playback") + pback = gtk.Menu() + safter = gtk.MenuItem(label="Quit After Current Track") + safter.connect("activate",self.ops.afterTrack,"qafter") + safter.show() + pback.append(safter) + playback.set_submenu(pback) + playback.show() + bar.append(playback) + # Add to main layout + bar.show() + self.mainLayout.pack_start(bar,False,False,0) + + + def selectDir(self,func): + dirsel = gtk.FileChooserDialog(None,action=gtk.FILE_CHOOSER_ACTION_OPEN,buttons =(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) + dirsel.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER) + response = dirsel.run() + if response == gtk.RESPONSE_OK: + #print dirsel.get_filename(),'selected' + func(dirsel.get_filename()) + dirsel.hide() + #if response == gtk.RESPONSE_CANCEL: + # dirsel.hide() + #elif response == gtk.RESPONSE_OK: + # print module.get_filename(),'selected' + #else: + # print response