Buttons
Added a button class, and attached play/pause buttons to the bottom of the window.
This commit is contained in:
parent
4d41cbfc30
commit
2f562bcc81
|
@ -36,6 +36,7 @@ def startup():
|
|||
global plugin
|
||||
import music
|
||||
import plugin
|
||||
|
||||
event.start("PRESTART")
|
||||
music.init()
|
||||
plugin.load_all()
|
||||
|
|
|
@ -16,6 +16,8 @@ QUEUE = 2
|
|||
import collection
|
||||
library = collection.Collection()
|
||||
|
||||
cur_lib_id = -1
|
||||
|
||||
def new_source(path, bg=True):
|
||||
global library
|
||||
path = expand(path)
|
||||
|
@ -30,11 +32,19 @@ def walk_library():
|
|||
|
||||
def lib_get_attr(id, attr):
|
||||
global library
|
||||
return library.get_attr(id, attr)
|
||||
if id >= 0:
|
||||
return library.get_attr(id, attr)
|
||||
return None
|
||||
|
||||
def lib_play_id(id):
|
||||
global cur_lib_id
|
||||
cur_lib_id = id
|
||||
filepath = lib_get_attr(id, "filepath")
|
||||
libsaria.music.load(filepath)
|
||||
libsaria.music.play()
|
||||
|
||||
def lib_get_cur_id():
|
||||
global cur_lib_id
|
||||
return cur_lib_id
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
# Bryan Schumaker (8/26/2010)
|
||||
|
||||
import ocarina
|
||||
LS = ocarina.libsaria
|
||||
gtk = ocarina.gtk
|
||||
|
||||
class Button(gtk.Button):
|
||||
def __init__(self, stock, 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:
|
||||
self.show()
|
||||
|
||||
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.music.play()
|
||||
|
||||
|
||||
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.music.pause()
|
|
@ -1,46 +1,69 @@
|
|||
# Bryan Schumaker (8/22/2010)
|
||||
|
||||
import ocarina
|
||||
gtk = ocarina.gtk
|
||||
gtk = ocarina.gtk
|
||||
libsaria = ocarina.libsaria
|
||||
button = None
|
||||
|
||||
class Filter(gtk.VBox):
|
||||
def __init__(self):
|
||||
lib_get_cur_id = libsaria.collection.lib_get_cur_id
|
||||
lib_get_attr = libsaria.collection.lib_get_attr
|
||||
|
||||
filter = None
|
||||
info = None
|
||||
|
||||
class Bar(gtk.VBox):
|
||||
def __init__(self, sep_on_top):
|
||||
gtk.VBox.__init__(self)
|
||||
self.show()
|
||||
self.sep = gtk.HSeparator()
|
||||
self.sep.show()
|
||||
self.filter_box = gtk.HBox()
|
||||
self.pack_start(self.filter_box)
|
||||
self.filter_box.show()
|
||||
self.pack_start(self.sep)
|
||||
self.contents = gtk.HBox()
|
||||
self.contents.show()
|
||||
if sep_on_top == True:
|
||||
self.pack_start(self.sep)
|
||||
self.pack_start(self.contents)
|
||||
else:
|
||||
self.pack_start(self.contents)
|
||||
self.pack_start(self.sep)
|
||||
|
||||
def pack(self, widget, expand=True, fill=True):
|
||||
self.filter_box.pack_start(widget, expand, fill)
|
||||
def pack(self, widget, expand=False, fill=False):
|
||||
self.contents.pack_start(widget, expand, fill)
|
||||
|
||||
|
||||
class Info(gtk.VBox):
|
||||
class InfoBar(Bar):
|
||||
def __init__(self):
|
||||
gtk.VBox.__init__(self)
|
||||
self.show()
|
||||
self.sep = gtk.HSeparator()
|
||||
self.sep.show()
|
||||
self.pack_start(self.sep)
|
||||
Bar.__init__(self, True)
|
||||
global button
|
||||
global libsaria
|
||||
|
||||
self.title = gtk.Label("Ocarina 4.1")
|
||||
self.title.show()
|
||||
self.pack(self.title, True, True)
|
||||
self.pack(button.PlayButton())
|
||||
self.pack(button.PauseButton())
|
||||
|
||||
filter = Filter()
|
||||
info = Info()
|
||||
libsaria.event.invite("POSTLOAD", self.change_title)
|
||||
|
||||
def change_title(self, filepath):
|
||||
id = libsaria.collection.lib_get_cur_id()
|
||||
title = lib_get_attr(id, "title")
|
||||
artist = libsaria.collection.lib_get_attr(id, "artist")
|
||||
self.title.set_text("%s by %s" % (title,artist))
|
||||
|
||||
|
||||
def init():
|
||||
global info
|
||||
global filter
|
||||
label = gtk.Label("Bottom label")
|
||||
label.show()
|
||||
info.pack_start(label)
|
||||
global button
|
||||
|
||||
import button
|
||||
info = InfoBar()
|
||||
filter = Bar(False)
|
||||
|
||||
label2 = gtk.Label("Top label")
|
||||
label2.show()
|
||||
filter.pack(label2)
|
||||
filter.pack(label2, True, True)
|
||||
|
||||
|
||||
def get_info():
|
||||
global info
|
||||
|
|
|
@ -19,13 +19,11 @@ class TabPage(gtk.VBox):
|
|||
def __init__(self, content):
|
||||
gtk.VBox.__init__(self)
|
||||
self.content = content
|
||||
#self.pack_end(content, True, True, 0)
|
||||
self.show()
|
||||
|
||||
def visible(self):
|
||||
global bottom
|
||||
global top
|
||||
print top, bottom
|
||||
if top is not None:
|
||||
self.pack_start(top, False, False)
|
||||
if self.content is not None:
|
||||
|
|
Loading…
Reference in New Issue