ocarina/ocarina/components/button.py

230 lines
5.8 KiB
Python

# Bryan Schumaker (8/26/2010)
import ocarina
import image
LS = ocarina.libsaria
gtk = ocarina.gtk
prefs = LS.prefs
invite = LS.event.invite
class Button(gtk.Button):
def __init__(self, stock, tooltip, func=None, show=True):
gtk.Button.__init__(self)
self.func = func
img = gtk.image_new_from_stock(stock, gtk.ICON_SIZE_MENU)
img.show()
self.add(img)
self.set_relief(gtk.RELIEF_NONE)
self.click_id = self.connect("clicked", self.clicked)
if show == True:
Button.show(self)
self.set_alignment(0,0)
self.set_tooltip_text(tooltip)
def clicked(self, button):
self.func()
def show(self, *args):
gtk.Button.show(self)
def hide(self, *args):
gtk.Button.hide(self)
class PlayButton(Button):
def __init__(self):
Button.__init__(self, gtk.STOCK_MEDIA_PLAY, "Play")
invite("POSTPLAY", self.hide)
invite("POSTPAUSE", self.show)
invite("POSTSTOP", self.show)
def clicked(self, button):
LS.controls.play()
def hide(self, playing):
if playing == True:
Button.hide(self)
def show(self, paused):
if paused == True:
Button.show(self)
class PauseButton(Button):
def __init__(self):
Button.__init__(self, gtk.STOCK_MEDIA_PAUSE, "Pause", show=False)
invite("POSTPLAY", self.show)
invite("POSTPAUSE", self.hide)
invite("POSTSTOP", self.hide)
def clicked(self, button):
LS.controls.pause()
def hide(self, paused):
if paused == True:
Button.hide(self)
def show(self, playing):
if playing == True:
Button.show(self)
class StopButton(Button):
def __init__(self):
Button.__init__(self, gtk.STOCK_MEDIA_STOP, "Stop")
def clicked(self, button):
LS.controls.stop()
class NextButton(Button):
def __init__(self):
Button.__init__(self, gtk.STOCK_MEDIA_NEXT, "Next")
def clicked(self, button):
LS.controls.next()
class ForwardButton(Button):
def __init__(self):
Button.__init__(self, gtk.STOCK_MEDIA_FORWARD, "Skip Forward")
def clicked(self, button):
LS.controls.seek_forward()
class RewindButton(Button):
def __init__(self):
Button.__init__(self, gtk.STOCK_MEDIA_REWIND, "Skip Backward")
def clicked(self, button):
LS.controls.seek_backward()
class OpenButton(Button):
def __init__(self):
Button.__init__(self, gtk.STOCK_OPEN, "Open Anything")
def clicked(self, button):
from ocarina import fsselect
fsselect.run_chooser2(LS.path.files.universal_open)
class ClearButton(Button):
def __init__(self):
Button.__init__(self, gtk.STOCK_CLEAR, "Clear Current Source")
def clicked(self, button):
from ocarina import body
body.cur_page_reset()
class ExportButton(Button):
def __init__(self):
Button.__init__(self, gtk.STOCK_CONVERT, "Export Library")
def clicked(self, button):
from libsaria.path import backup
backup.backup()
class GotoButton(Button):
def __init__(self):
Button.__init__(self, gtk.STOCK_JUMP_TO, "Go To Current Song")
def clicked(self, button):
from ocarina import body
body.cur_page_goto()
class UpdateButton(Button):
def __init__(self):
Button.__init__(self, gtk.STOCK_REFRESH, "Update Library")
def clicked(self, button):
LS.sources.library.update_bg()
class RandomButton(gtk.ToggleButton):
def __init__(self):
gtk.ToggleButton.__init__(self)
img = gtk.image_new_from_file("images/random.png")
img.show()
self.add(img)
self.set_active(prefs.get_pref("libsaria.random"))
self.set_relief(gtk.RELIEF_NONE)
self.connect("toggled", self.toggle)
self.set_tooltip_text("Random")
self.show()
def toggle(self, button):
LS.controls.toggle_rand()
class UpButton(Button):
def __init__(self, callback):
Button.__init__(self, gtk.STOCK_GO_UP, "Show More Information")
self.callback = callback
def clicked(self, button):
self.callback()
class DownButton(Button):
def __init__(self, callback):
Button.__init__(self, gtk.STOCK_GO_DOWN, "Show Less Information")
self.callback = callback
def clicked(self, button):
self.callback()
class VolumeButton(gtk.VolumeButton):
def __init__(self):
gtk.VolumeButton.__init__(self)
self.set_relief(gtk.RELIEF_NONE)
adj = self.get_adjustment()
adj.set_page_increment(0.05)
self.set_value(prefs.get_pref("libsaria.audio.volume"))
self.resize()
self.connect("value-changed", self.changed)
invite("POSTSETVOLUME", self.set_slider)
self.set_tooltip_text("Change Volume")
self.show()
def set_slider(self, prcnt):
self.set_value(prcnt)
def resize(self):
image = self.get_children()[0]
icon = image.get_icon_name()[0]
image.set_from_icon_name(icon, gtk.ICON_SIZE_MENU)
def changed(self, widget, value):
LS.controls.set_volume(value)
widget.resize()
class LikeButton(gtk.ToggleButton):
def __init__(self):
gtk.ToggleButton.__init__(self)
img = gtk.image_new_from_file("images/thumbs_up.png")
img.show()
self.add(img)
self.set_active(liked==True)
self.set_relief(gtk.RELIEF_NONE)
self.t_id = self.connect("toggled", self.toggle)
invite("POSTLOAD", self.set_status)
invite("POSTSETLIKE", self.set_status)
self.show()
def set_status(self, *args):
print "setting status..."
self.disconnect(self.t_id)
self.set_active(LS.controls.get_like() == True)
self.t_id = self.connect("toggled", self.toggle)
def toggle(self, button):
status = self.get_active()
if status == False:
status = None
LS.controls.set_like(status)
class DislikeButton(gtk.ToggleButton):
def __init__(self):
gtk.ToggleButton.__init__(self)
img = gtk.image_new_from_file("images/thumbs_down.png")
img.show()
self.add(img)
self.set_active(liked==False)
self.set_relief(gtk.RELIEF_NONE)
self.t_id = self.connect("toggled", self.toggle)
invite("POSTLOAD", self.set_status)
invite("POSTSETLIKE", self.set_status)
self.show()
def set_status(self, *args):
self.disconnect(self.t_id)
self.set_active(LS.controls.get_like() == False)
self.t_id = self.connect("toggled", self.toggle)
def toggle(self, button):
status = not self.get_active()
if status == True:
status = None
LS.controls.set_like(status)