118 lines
2.7 KiB
Python
118 lines
2.7 KiB
Python
#! /usr/bin/python
|
|
|
|
__author__="bjschuma"
|
|
__date__ ="$Mar 14, 2010 11:13:03 PM$"
|
|
|
|
import gtk
|
|
import ocarina
|
|
import guibuilder
|
|
from ct import call
|
|
|
|
class Button(gtk.Button):
|
|
def __init__(self,attrs,cmd):
|
|
gtk.Button.__init__(self)
|
|
self.command = ""
|
|
hidden = False
|
|
relief = gtk.RELIEF_NORMAL
|
|
for a in attrs:
|
|
if a == "cmd":
|
|
self.command = attrs[a]
|
|
elif a == "text":
|
|
self.set_label(attrs[a])
|
|
elif a == "show":
|
|
ocarina.events.invite(attrs[a],self.show)
|
|
elif a == "hide":
|
|
ocarina.events.invite(attrs[a],self.hide)
|
|
elif a=="hidden" and attrs[a].lower()=="true":
|
|
hidden = True
|
|
elif a=="relief":
|
|
if attrs[a] == "none":
|
|
relief = gtk.RELIEF_NONE
|
|
elif attrs[a] == "half":
|
|
relief = gtk.RELIEF_HALF
|
|
elif a=="stock" and attrs[a]=="true":
|
|
self.set_use_stock(True)
|
|
|
|
self.set_relief(relief)
|
|
self.connect("clicked",self.clicked)
|
|
if hidden==False:
|
|
self.show()
|
|
|
|
|
|
def clicked(self,button):
|
|
cmd.run(self.command)
|
|
|
|
|
|
|
|
class ButtonImage(gtk.Button):
|
|
def __init__(self,attrs,stock):
|
|
gtk.Button.__init__(self)
|
|
size = gtk.ICON_SIZE_BUTTON
|
|
show = None
|
|
hide = None
|
|
shownow = True
|
|
relief = gtk.RELIEF_NORMAL
|
|
self.func = None
|
|
for a in attrs:
|
|
if a=="size":
|
|
if attrs[a] == "large":
|
|
size = gtk.ICON_SIZE_DIALOG
|
|
elif a=="show":
|
|
show = attrs[a]
|
|
elif a=="hide":
|
|
hide = attrs[a]
|
|
elif a=="shownow" and attrs[a]=="false":
|
|
shownow = False
|
|
elif a=="func":
|
|
self.func = attrs[a]
|
|
elif a=="relief":
|
|
if attrs[a] == "none":
|
|
relief = gtk.RELIEF_NONE
|
|
elif attrs[a] == "half":
|
|
relief = gtk.RELIEF_HALF
|
|
|
|
img = gtk.image_new_from_stock(stock,size)
|
|
img.show()
|
|
self.add( img )
|
|
|
|
if shownow==True:
|
|
self.show()
|
|
|
|
if hide!=None:
|
|
ocarina.events.invite(hide, self.hide)
|
|
if show!=None:
|
|
ocarina.events.invite(show, self.show)
|
|
self.set_relief(relief)
|
|
self.connect("clicked",self.onclick)
|
|
|
|
def onclick(self,button):
|
|
if self.func != None:
|
|
self.func()
|
|
|
|
|
|
|
|
def make_button(attrs):return Button(attrs)
|
|
|
|
def make_buttonplay(attrs):
|
|
attrs["show"] = ocarina.events.OCARINA_PAUSE
|
|
attrs["hide"] = ocarina.events.OCARINA_PLAY
|
|
attrs["func"] = call.play
|
|
attrs["shownow"] = str( call.playing() ).lower()
|
|
return ButtonImage(attrs,gtk.STOCK_MEDIA_PLAY)
|
|
|
|
def make_buttonpause(attrs):
|
|
attrs["show"] = ocarina.events.OCARINA_PLAY
|
|
attrs["hide"] = ocarina.events.OCARINA_PAUSE
|
|
attrs["func"] = call.pause
|
|
attrs["shownow"] = str( call.playing() ).lower()
|
|
return ButtonImage(attrs,gtk.STOCK_MEDIA_PAUSE)
|
|
|
|
def make_buttonstop(attrs):
|
|
attrs["func"] = call.stop
|
|
return ButtonImage(attrs,gtk.STOCK_MEDIA_STOP)
|
|
|
|
|
|
guibuilder.parts["button"] = make_button
|
|
guibuilder.parts["button-play"] = make_buttonplay
|
|
guibuilder.parts["button-pause"] = make_buttonpause
|
|
guibuilder.parts["button-stop"] = make_buttonstop |