ocarina: Added random button

I also added code for creating toggle buttons easily.
This commit is contained in:
Bryan Schumaker 2011-04-21 08:14:21 -04:00
parent 86bac243d2
commit f8c64e0f78
3 changed files with 31 additions and 17 deletions

View File

@ -8,11 +8,19 @@ SIZE = gtk.ICON_SIZE_MENU
def on_click(button, func):
func()
def on_toggle(button, func):
func(button.get_active())
def stock_image(stock_item):
img = gtk.image_new_from_stock(stock_item, SIZE)
img.show()
return img
def file_image(file):
img = gtk.image_new_from_file(file)
img.show()
return img
def make_text(text):
lbl = gtk.Label(text)
lbl.show()
@ -33,6 +41,22 @@ def make_button(stock_item, func, tooltip, show):
b.set_tooltip_text(tooltip)
return b
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)
if show == True:
b.show()
return b
def make_toggle(img_file, func, tooltip, is_active, show):
b = toggle_button(func, is_active, show)
img = file_image(img_file)
b.add(img)
b.set_tooltip_text(tooltip)
return b
def rewind_button(show):
return make_button(gtk.STOCK_MEDIA_REWIND, controls.seek_backward, "Rewind", show)
@ -57,3 +81,6 @@ def goto_button(goto_func, show):
def clear_button(clear_func, show):
return make_button(gtk.STOCK_CLEAR, clear_func, "Clear Current Source", show)
def random_button(is_active, show):
return make_toggle("images/random.png", controls.set_rand, "Random", is_active, show)

View File

@ -1,6 +1,7 @@
# Bryan Schumaker (11/25/2010)
import gtk
import libsaria
from ocarina.body import button
import entry
@ -25,8 +26,9 @@ def add_button(name, button):
header_body.pack_start(button, False, False)
header_body.pack_start(entry.entry)
add_button( "GOTO", button.goto_button(goto_func, True))
add_button("CLEAR", button.clear_button(clear_func, True))
add_button( "GOTO", button.goto_button(goto_func, True))
add_button( "CLEAR", button.clear_button(clear_func, True))
add_button("RANDOM", button.random_button(libsaria.prefs.get_pref("libsaria.random"), True))
#import ocarina
#from ocarina.components import button

View File

@ -48,13 +48,6 @@ class SaveButton(Button):
if loc != None:
export.save_playlist(loc)
class ClearButton(Button):
def __init__(self):
Button.__init__(self, gtk.STOCK_CLEAR, "Clear Current Source")
def clicked(self, button):
from ocarina import body
body.cur_page_reset()
class ExportButton(Button):
def __init__(self):
Button.__init__(self, gtk.STOCK_CONVERT, "Export Library")
@ -162,11 +155,3 @@ class DislikeButton(ToggleButton):
if status == True:
status = None
LS.controls.set_like(status)
class RandomButton(ToggleButton):
def __init__(self):
ToggleButton.__init__(self, "images/random.png", "Random")
self.set_active(prefs.get_pref("libsaria.random"))
def toggle(self, button):
LS.controls.set_rand(self.get_active())