import os import gobject import pygtk pygtk.require('2.0') import gtk from button import Button from image import Image from check import CheckButton class ControlPanel(gtk.HBox): def __init__(self,data,plist): gtk.HBox.__init__(self,False,0) self.pauseImg = Image(os.path.join("images","pause.png")) self.data = data self.next = plist.next self.pack_start(CheckButton("Random",self.toggleRand,self.data.random),False,False,0) self.makeProgressBar() (self.nextImg,self.nextBtn) = self.makeButton("next","next.png",None,self.next) (self.stopImg,self.stopBtn) = self.makeButton("stop","stop.png",None,self.stop) (self.playImg,self.plauseBtn) = self.makeButton("plause","play.png",None,self.plause) self.show() # Everything for making and adding a button def makeButton(self,name,img,text,func): image = None if img: image = Image(os.path.join("images",img)) button = Button(name,image,text,func) self.pack_end(button,False,False,0) return (image,button) # Make the progress bar, and set updates def makeProgressBar(self): vbox = gtk.VBox() pbar = gtk.ProgressBar() pbar.set_fraction(0) vbox.pack_start(pbar,True,False,0) self.pack_start(vbox,True,True,0) vbox.show() pbar.show() gobject.timeout_add(100,self.updatePBar,pbar) # Play/Pause function def plause(self,widgit,data): self.data.song.plause() self.changeImg() # Stop function def stop(self,widgit,data): self.data.song.stop() self.changeImg() # Change the image on the play button def changeImg(self): self.plauseBtn.set_image(self.playImg) if self.data.song.playing == True: self.plauseBtn.set_image(self.pauseImg) self.plauseBtn.show() # Update time/progress of the progress bar def updatePBar(self,pbar): try: (success,time) = self.data.song.curTime() except: success = False if success == True: time = time/1000000000 pbar.set_fraction(float(time)/self.data.song.info.duration) pbar.set_text(self.data.song.info.fixTime(time) + " / " + self.data.song.info.length) return True def toggleRand(self,widgit): self.data.random = not self.data.random