166 lines
3.9 KiB
Python
166 lines
3.9 KiB
Python
# Bryan Schumaker (8/26/2010)
|
|
|
|
import ocarina
|
|
import image
|
|
LS = ocarina.libsaria
|
|
gtk = ocarina.gtk
|
|
prefs = LS.prefs
|
|
|
|
|
|
class Button(gtk.Button):
|
|
def __init__(self, stock, size=gtk.ICON_SIZE_MENU, func=None, show=True):
|
|
gtk.Button.__init__(self)
|
|
self.func = func
|
|
img = gtk.image_new_from_stock(stock, size)
|
|
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)
|
|
|
|
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)
|
|
LS.event.invite("POSTPLAY", self.hide)
|
|
LS.event.invite("POSTPAUSE", self.show)
|
|
LS.event.invite("POSTSTOP", self.show)
|
|
def clicked(self, button):
|
|
LS.audio.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, show=False)
|
|
LS.event.invite("POSTPLAY", self.show)
|
|
LS.event.invite("POSTPAUSE", self.hide)
|
|
LS.event.invite("POSTSTOP", self.hide)
|
|
def clicked(self, button):
|
|
LS.audio.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)
|
|
def clicked(self, button):
|
|
LS.audio.stop()
|
|
|
|
|
|
class NextButton(Button):
|
|
def __init__(self):
|
|
Button.__init__(self, gtk.STOCK_MEDIA_NEXT)
|
|
def clicked(self, button):
|
|
LS.sources.plist_next()
|
|
|
|
|
|
class ForwardButton(Button):
|
|
def __init__(self):
|
|
Button.__init__(self, gtk.STOCK_MEDIA_FORWARD)
|
|
def clicked(self, button):
|
|
LS.audio.seek_sec(5)
|
|
|
|
|
|
class RewindButton(Button):
|
|
def __init__(self):
|
|
Button.__init__(self, gtk.STOCK_MEDIA_REWIND)
|
|
def clicked(self, button):
|
|
LS.audio.seek_sec(-5)
|
|
|
|
class OpenButton(Button):
|
|
def __init__(self):
|
|
Button.__init__(self, gtk.STOCK_OPEN, gtk.ICON_SIZE_BUTTON)
|
|
def clicked(self, button):
|
|
from ocarina import fsselect
|
|
fsselect.run_chooser2(LS.data.universal_open)
|
|
|
|
class ClearButton(Button):
|
|
def __init__(self):
|
|
Button.__init__(self, gtk.STOCK_CLEAR, gtk.ICON_SIZE_BUTTON)
|
|
def clicked(self, button):
|
|
from ocarina import tabs
|
|
tabs.reset_current_page()
|
|
|
|
class ExportButton(Button):
|
|
def __init__(self):
|
|
Button.__init__(self, gtk.STOCK_CONVERT, gtk.ICON_SIZE_BUTTON)
|
|
def clicked(self, button):
|
|
from libsaria import backup
|
|
backup.backup()
|
|
|
|
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["random"])
|
|
self.set_relief(gtk.RELIEF_NONE)
|
|
self.connect("toggled", self.toggle)
|
|
self.show()
|
|
|
|
def toggle(self, button):
|
|
LS.sources.toggle_rand()
|
|
|
|
|
|
class UpButton(Button):
|
|
def __init__(self, callback):
|
|
Button.__init__(self, gtk.STOCK_ADD)
|
|
self.callback = callback
|
|
def clicked(self, button):
|
|
self.callback()
|
|
|
|
class DownButton(Button):
|
|
def __init__(self, callback):
|
|
Button.__init__(self, gtk.STOCK_REMOVE)
|
|
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["volume"])
|
|
self.resize()
|
|
|
|
self.connect("value-changed", self.changed)
|
|
LS.event.invite("POSTSETVOLUME", self.set_slider)
|
|
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_BUTTON)
|
|
|
|
def changed(self, widget, value):
|
|
LS.audio.set_volume(value)
|
|
widget.resize()
|