ocarina/trunk/src/GuiObjects/controlPanel.py

95 lines
2.5 KiB
Python

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)
event = gtk.EventBox()
event.add(pbar)
vbox.pack_start(event,True,False,0)
#vbox.pack_start(pbar,True,False,0)
self.pack_start(vbox,True,True,0)
event.connect("button_release_event",self.pbarclick,pbar)
event.show()
vbox.show()
pbar.show()
gobject.timeout_add(1000,self.updatePBar,pbar)
def pbarclick(self,widgit,data,pbar):
if data.button == 1:
prcnt = float(data.x) / float(pbar.get_allocation()[2])
self.data.song.seek(int(prcnt * self.data.song.info.duration * 1000000000))
#print float(data.x)/float(pbar.get_allocation()[0])
# 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):
if self.data.song and (self.data.song.playing == False):
return True
try:
(success,time) = self.data.song.curTime()
except:
success = False
if success == True:
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