864f64cc84
Now they are created right before the buttons are. This makes it so I can return buttons that do exactly what I want every time.
93 lines
2.2 KiB
Python
93 lines
2.2 KiB
Python
# Bryan Schumaker (2 / 20 / 2011)
|
|
|
|
import gtk
|
|
from libsaria import controls
|
|
|
|
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()
|
|
return lbl
|
|
|
|
def default_button(func, show):
|
|
b = gtk.Button()
|
|
b.set_relief(gtk.RELIEF_NONE)
|
|
b.connect("clicked", on_click, func)
|
|
if show == True:
|
|
b.show()
|
|
return b
|
|
|
|
def make_button(stock_item, func, tooltip, show):
|
|
b = default_button(func, show)
|
|
img = stock_image(stock_item)
|
|
b.add(img)
|
|
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)
|
|
|
|
def forward_button(show):
|
|
return make_button(gtk.STOCK_MEDIA_FORWARD, controls.seek_forward, "Fast Forward", show)
|
|
|
|
def play_button(show):
|
|
return make_button(gtk.STOCK_MEDIA_PLAY, controls.play, "Play", show)
|
|
|
|
def pause_button(show):
|
|
return make_button(gtk.STOCK_MEDIA_PAUSE, controls.pause, "Pause", show)
|
|
|
|
def stop_button(show):
|
|
return make_button(gtk.STOCK_MEDIA_STOP, controls.stop, "Stop", show)
|
|
|
|
def next_button(show):
|
|
return make_button(gtk.STOCK_MEDIA_NEXT, controls.next, "Next", show)
|
|
|
|
def goto_button(show):
|
|
def goto_func():
|
|
from ocarina import body
|
|
body.cur_page_goto()
|
|
return make_button(gtk.STOCK_JUMP_TO, goto_func, "Go To Current Song", show)
|
|
|
|
def clear_button(show):
|
|
def clear_func():
|
|
from ocarina import body
|
|
body.cur_page_clear()
|
|
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)
|