ocarina: Call toggle buttons without toggling enabled

I disable the toggle callback, call a function, and then reconnect the
callback.
This commit is contained in:
Bryan Schumaker 2011-04-24 09:47:05 -04:00
parent 55730d3dbf
commit 97af3d50e4
2 changed files with 10 additions and 13 deletions

View File

@ -44,9 +44,12 @@ def make_button(stock_item, func, tooltip, show):
def toggle_connect(button, func):
button.t_id = button.connect("toggled", on_toggle, func)
button.t_func = func
def toggle_unconnect(button):
def toggle_call_unconnected(button, func, *args):
button.disconnect(button.t_id)
func(*args)
toggle_connect(button, button.t_func)
def toggle_button(func, is_active, show):
b = gtk.ToggleButton()
@ -121,9 +124,6 @@ def 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:
@ -132,6 +132,3 @@ def set_dislike(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)

View File

@ -64,12 +64,12 @@ def set_art(path):
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_like1(like):
LIKE.set_active(like == True)
DISLIKE.set_active(like == False)
def _on_like0(like):
button.toggle_call_unconnected(DISLIKE, _on_like1, like)
button.toggle_call_unconnected(LIKE, _on_like0, like)
def on_load(title, artist, album, year, lenstr, count):
TITLE.set_text(title)