From 2f562bcc81ff0cd4d09e3aecc15319efff961660 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Mon, 30 Aug 2010 17:57:08 -0400 Subject: [PATCH] Buttons Added a button class, and attached play/pause buttons to the bottom of the window. --- libsaria/__init__.py | 1 + libsaria/collection/__init__.py | 12 +++++- ocarina/button.py | 46 +++++++++++++++++++++++ ocarina/info.py | 65 ++++++++++++++++++++++----------- ocarina/tabs.py | 2 - 5 files changed, 102 insertions(+), 24 deletions(-) create mode 100644 ocarina/button.py diff --git a/libsaria/__init__.py b/libsaria/__init__.py index ee7e8f79..77a5b421 100644 --- a/libsaria/__init__.py +++ b/libsaria/__init__.py @@ -36,6 +36,7 @@ def startup(): global plugin import music import plugin + event.start("PRESTART") music.init() plugin.load_all() diff --git a/libsaria/collection/__init__.py b/libsaria/collection/__init__.py index d5842f9f..00a8cb26 100644 --- a/libsaria/collection/__init__.py +++ b/libsaria/collection/__init__.py @@ -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 + diff --git a/ocarina/button.py b/ocarina/button.py new file mode 100644 index 00000000..248c3b45 --- /dev/null +++ b/ocarina/button.py @@ -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() diff --git a/ocarina/info.py b/ocarina/info.py index 35c60a8c..aa5b6684 100644 --- a/ocarina/info.py +++ b/ocarina/info.py @@ -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 diff --git a/ocarina/tabs.py b/ocarina/tabs.py index b28b85cd..9e3e2108 100644 --- a/ocarina/tabs.py +++ b/ocarina/tabs.py @@ -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: