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() # Pause after current track pafter = gtk.MenuItem(label="Pause After Current Track") pafter.connect("activate",self.ops.afterTrack,"pafter") pafter.show() pback.append(pafter) # Quit after current track qafter = gtk.MenuItem(label="Quit After Current Track") qafter.connect("activate",self.ops.afterTrack,"qafter") qafter.show() pback.append(qafter) 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