import gobject import pango import pygtk pygtk.require('2.0') import gtk import thread from kiwi.ui.objectlist import Column, ObjectList from GuiObjects.menuItem import MenuItem from GuiObjects.libView import LibView class Window(gtk.Window): #def __init__(self,onQuit,ops,song): def __init__(self,onQuit,options,data): gtk.Window.__init__(self,gtk.WINDOW_TOPLEVEL) self.data = data self.options = options if self.options.verbose == True: print "Making window!" self.resize(self.data.size[0],self.data.size[1]) self.set_title("Ocarina") self.connect("delete_event",onQuit) self.set_icon_from_file("images/ocarina.png") self.mainLayout = gtk.VBox(False,0) self.add(self.mainLayout) self.makeMenuBar() self.makeContentPane() ''' self.song = song self.ops = ops self.tree = None 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.makeList() self.makeControls() self.maximize() ''' self.mainLayout.show() self.show() # Make initial info pane def makeInfoPane(self): self.infoFrame = gtk.Frame("Current Song:") box = gtk.VBox(False,0) self.infoFrame.add(box) attr = pango.AttrList() attr.insert(pango.AttrSize(12000, 0, -1)) self.tagLabels["title"] = self.makeLabel("Title: ?",box,attr) self.tagLabels["artist"] = self.makeLabel("Artist: ?",box,attr) self.tagLabels["album"] = self.makeLabel("Album: ?",box,attr) box.show() self.infoFrame.show() #self.mainLayout.add(self.infoFrame) self.mainLayout.pack_start(self.infoFrame,False,False,0) # Set up a new label, add to container # Goes into a HBox so that it is left justified def makeLabel(self,text,container,attr): box = gtk.HBox(False,0) label = gtk.Label(text) s = label.get_style().copy() self.tooltip.set_tip(label,text,tip_private=None) #label.set_max_width_chars(35) label.set_attributes(attr) 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() def changeFrameTitle(self,label): self.infoFrame.set_label(label+"Current Track:") # 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() def makeList(self): title = Column('title') title.expand = True title.searchable = True artist = Column('artist') artist.expand = True artist.searchable = True album = Column('album') album.expand = True album.searchable = True count = Column('count') count.expand = True #count.searchable = True length = Column('length') length.expand = True #length.searchable = True self.list = ObjectList([title,artist,album,count,length]) for num in self.ops.plist.list: #print self.ops.plist.translate(num) self.list.append(self.ops.plist.translate(num)) #self.list.append(num) self.list.sort_by_attribute('artist') self.list.connect("row-activated",self.ops.plist.selectSong,"clicked",self.list) self.list.show() self.mainLayout.add(self.list) ''' # Make scrolled window, add to window scroll = gtk.ScrolledWindow() scroll.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) #self.mainLayout.pack_start(scroll,False,False,0) self.mainLayout.add(scroll) # Make and populate list self.list = gtk.ListStore(int,str,str,str,int) for num in self.ops.plist.list: self.list.append(self.ops.plist.translate(num)) # Make treeview from list if self.tree: self.tree = None self.tree = gtk.TreeView(self.list) cell = gtk.CellRendererText() cols = ["Id","Title","Artist","Album","Count"] for i in range(len(cols)): col = gtk.TreeViewColumn(cols[i],cell) col.add_attribute(cell,'text',i) col.set_resizable(True) col.set_sort_column_id(i) self.tree.append_column(col) self.tree.connect("row-activated",self.ops.plist.selectSong,"clicked",self.list) self.tree.connect("button_press_event",self.ops.click,"clicked",self.list,self.tree.get_selection()) self.tree.set_grid_lines(True) scroll.add(self.tree) self.tree.columns_autosize() self.tree.show() scroll.show() #self.gotoCurSong() ''' def gotoCurSong(self): #return if len(self.list) == 0: return #print self.list[0][0] #print len(self.list) selrow = 0 row = 0 for i in range(len(self.list)): #print i if self.list[i].id == self.ops.plist.curSong: if i > 10: selrow = i - 10 row = i break self.list.select(self.list[row],True) #selrow = self.ops.plist.curSong - 10 #if selrow < 0: # selrow = 0 #print selrow,row #self.tree.scroll_to_cell(selrow,None,True,0,0) #treesel = self.tree.get_selection() #treesel.select_path(row) # Use to make play/pause/next/etc buttons def makeControls(self): #controls = gtk.VBox(False,0) row = gtk.HBox(False,0) topRow = gtk.HBox(False,0) # Make top row buttons #self.makeButton("play","images/play.png",None,self.ops.play,topRow) self.makeButton("play","images/play.png",None,self.song.play,topRow) #self.makeButton("pause","images/pause.png",None,self.ops.pause,topRow) self.makeButton("pause","images/pause.png",None,self.song.pause,topRow) self.makeButton("stop","images/stop.png",None,self.ops.stop,topRow) self.makeButton("next","images/next.png",None,self.ops.next,topRow) self.makeButton("info",None,"Info",self.ops.info,topRow) #self.makeButton("plist",None,"Plist",self.ops.plist.showWindow,topRow) test = gtk.VBox(False,0) self.makeCheck("Random",self.ops.random,self.ops.plist.random,True,topRow) topRow.show() row.pack_end(topRow,False,False,0) row.show() #self.mainLayout.pack_start(topRow,False,False,0) self.mainLayout.pack_start(row,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 # Used to make the top row menu bar def makeMenuBar(self): # Make a menu bar bar = gtk.MenuBar() # This is the dropdown selections # Make a new library option newLib = MenuItem("New Library",self.selectDir,"ScanLib",self.data.library.scan,None) library = MenuItem("Library",None,None,None,[newLib]) bar.append(library) # Replace first 'None' with after track functions pafter = MenuItem("Pause After Current Track",None,"pafter",self.changeFrameTitle,None) qafter = MenuItem("Quit After Current Track",None,"qafter",self.changeFrameTitle,None) playback = MenuItem("Playback",None,None,None,[pafter,qafter]) bar.append(playback) bar.show() self.mainLayout.pack_start(bar,False,False,0) # Used to select a directory def selectDir(self,widgit,data,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 = None response = dirsel.run() file = "" if response == gtk.RESPONSE_OK: file = dirsel.get_filename() dirsel.hide() dirsel.destroy() dirsel = None #thread.start_new_thread(func,(data,file)) func(data,file) def makeContentPane(self): self.contentPane = gtk.HBox(False,0) self.divider = gtk.HPaned() self.divider.set_position(self.data.divider) self.contentPane.add(self.divider) self.divider.show() libview = LibView(self.data.library) libview.show() self.divider.add1(libview) tracks = gtk.TreeStore(str) for file in self.data.library.files: tracks.append(None,[file.title]) trackview = gtk.TreeView(tracks) title = gtk.TreeViewColumn('filename') trackview.append_column(title) cell = gtk.CellRendererText() title.pack_start(cell,True) title.add_attribute(cell,'text',0) trackview.set_rules_hint(True) trackview.show() trackscroll = gtk.ScrolledWindow() trackscroll.add(trackview) trackscroll.show() self.divider.add2(trackscroll) self.contentPane.show() self.mainLayout.add(self.contentPane)