From a519ad62abe31c18c427317bab447cdaa1795683 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Fri, 22 Apr 2011 17:30:56 -0400 Subject: [PATCH] ocarina: Added like and dislike buttons --- ocarina/body/button.py | 31 ++++++++++++++++++++++++++++++- ocarina/body/footer/__init__.py | 3 +++ ocarina/body/footer/nowplaying.py | 19 +++++++++++++++++++ ocarina/callbacks.py | 4 ++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/ocarina/body/button.py b/ocarina/body/button.py index 366334fa..62bc6185 100644 --- a/ocarina/body/button.py +++ b/ocarina/body/button.py @@ -41,11 +41,17 @@ def make_button(stock_item, func, tooltip, show): b.set_tooltip_text(tooltip) return b +def toggle_connect(button, func): + button.t_id = button.connect("toggled", on_toggle, func) + +def toggle_unconnect(button): + button.disconnect(button.t_id) + def toggle_button(func, is_active, show): b = gtk.ToggleButton() b.set_relief(gtk.RELIEF_NONE) b.set_active(is_active) - b.connect("toggled", on_toggle, func) + toggle_connect(b, func) if show == True: b.show() return b @@ -102,3 +108,26 @@ def clear_button(show): def random_button(is_active, show): return make_toggle("images/random.png", controls.set_rand, "Random", is_active, show) + +def set_like(like): + if like == False: + like = None + controls.set_like(like) + +def like_button(show): + return make_toggle("images/thumbs_up.png", set_like, "I like this", False, show) + +def like_button_reconnect(like_button): + toggle_connect(like_button, set_like) + +def set_dislike(like): + like = not like + if like == True: + like = None + controls.set_like(like) + +def dislike_button(show): + return make_toggle("images/thumbs_down.png", set_dislike, "I don't like this", False, show) + +def dislike_button_reconnect(dislike_button): + toggle_connect(dislike_button, set_dislike) diff --git a/ocarina/body/footer/__init__.py b/ocarina/body/footer/__init__.py index 98e60026..da71b5e0 100644 --- a/ocarina/body/footer/__init__.py +++ b/ocarina/body/footer/__init__.py @@ -42,6 +42,9 @@ def on_load(): tiny.on_load() detailed.on_load() +def on_like(): + detailed.nowplaying.on_like() + #import gtk #import pango #import ocarina diff --git a/ocarina/body/footer/nowplaying.py b/ocarina/body/footer/nowplaying.py index 94db415c..ca2e1203 100644 --- a/ocarina/body/footer/nowplaying.py +++ b/ocarina/body/footer/nowplaying.py @@ -1,6 +1,8 @@ # Bryan Schumaker (4 / 21 / 2011) import gtk +from libsaria import controls +from ocarina.body import button page = gtk.HBox(False, 5) label = gtk.Label("Now Playing") @@ -34,9 +36,25 @@ pack_label(attr_box, LENGTH) pack_label(attr_box, COUNT) page.pack_start(attr_box) +LIKE = button.like_button(True) +DISLIKE = button.dislike_button(True) +buttons = gtk.HBox(True) +buttons.pack_start( LIKE, False, False) +buttons.pack_start(DISLIKE, False, False) +page.pack_start(buttons, False) + page.show_all() label.show() +def on_like(): + like = controls.get_like() + button.toggle_unconnect(LIKE) + button.toggle_unconnect(DISLIKE) + LIKE.set_active(like == True) + DISLIKE.set_active(like == False) + button.like_button_reconnect(LIKE) + button.dislike_button_reconnect(DISLIKE) + def on_load(title, artist, album, year, lenstr, count): TITLE.set_text(title) ARTIST.set_text("by %s" % artist) @@ -44,3 +62,4 @@ def on_load(title, artist, album, year, lenstr, count): YEAR.set_text("Year: %s" % year) LENGTH.set_text("Length: %s" % lenstr) COUNT.set_text("Play count: %s" % count) + on_like() diff --git a/ocarina/callbacks.py b/ocarina/callbacks.py index 166c6c6a..b6004fce 100644 --- a/ocarina/callbacks.py +++ b/ocarina/callbacks.py @@ -24,3 +24,7 @@ def on_load(*args): queue.refresh() body.cur_page_goto() invite("POSTLOAD", on_load) + +def on_like(*args): + footer.on_like() +invite("POSTSETLIKE", on_like)