182 lines
4.3 KiB
Python
182 lines
4.3 KiB
Python
# Bryan Schumaker (8/22/2010)
|
|
|
|
import ocarina
|
|
gtk = ocarina.gtk
|
|
libsaria = ocarina.libsaria
|
|
button = None
|
|
|
|
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.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=False, fill=False):
|
|
self.contents.pack_start(widget, expand, fill)
|
|
|
|
|
|
class FilterBar(Bar):
|
|
def __init__(self):
|
|
Bar.__init__(self, False)
|
|
global button
|
|
global libsaria
|
|
|
|
self.pack(button.OpenButton())
|
|
|
|
|
|
class InfoBar(Bar):
|
|
def __init__(self, up_button):
|
|
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())
|
|
self.pack(button.UpButton(up_button))
|
|
|
|
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))
|
|
|
|
|
|
class ControlTab(gtk.Label):
|
|
def __init__(self, stock, func):
|
|
gtk.Label.__init__(self)
|
|
self.img = gtk.Image()
|
|
self.img.set_from_stock(stock, gtk.ICON_SIZE_MENU)
|
|
self.set_text("You should never see this text")
|
|
self.show()
|
|
self.img.show()
|
|
self.img.connect("button_press_event", self.clicked)
|
|
self.func = func
|
|
def is_control_tab(self):
|
|
return True
|
|
def hide(self, arg=None):
|
|
gtk.Label.hide(self)
|
|
def show(self, arg=None):
|
|
gtk.Label.show(self)
|
|
def clicked(self, *args):
|
|
print args
|
|
|
|
class CloseTab(ControlTab):
|
|
def __init__(self, close):
|
|
ControlTab.__init__(self,gtk.STOCK_REMOVE, close)
|
|
|
|
class PlayTab(ControlTab):
|
|
def __init__(self):
|
|
ControlTab.__init__(self, gtk.STOCK_MEDIA_PLAY, self.play)
|
|
libsaria.event.invite("POSTPLAY", self.hide)
|
|
libsaria.event.invite("POSTPAUSE", self.show)
|
|
libsaria.event.invite("POSTSTOP", self.show)
|
|
def play(self):
|
|
libsaria.music.play()
|
|
|
|
class PauseTab(ControlTab):
|
|
def __init__(self):
|
|
ControlTab.__init__(self, gtk.STOCK_MEDIA_PAUSE, self.pause)
|
|
libsaria.event.invite("POSTPLAY", self.show)
|
|
libsaria.event.invite("POSTPAUSE", self.hide)
|
|
libsaria.event.invite("POSTSTOP", self.hide)
|
|
self.hide()
|
|
def pause(self):
|
|
libsaria.music.pause()
|
|
|
|
|
|
class InfoTab(gtk.Notebook):
|
|
def __init__(self, down_button):
|
|
gtk.Notebook.__init__(self)
|
|
self.add_control_tab(CloseTab(down_button))
|
|
self.add_control_tab(PlayTab())
|
|
self.add_control_tab(PauseTab())
|
|
self.down_button = down_button
|
|
self.cur_page = 0
|
|
self.connect("switch_page", self.switched_pages)
|
|
|
|
def add_control_tab(self, contents):
|
|
self.append_page(contents, contents.img)
|
|
self.set_tab_label_packing(contents, False, False, gtk.PACK_END)
|
|
|
|
def add_controls(self, controls):
|
|
self.append_page(controls.page, controls)
|
|
self.set_tab_label_packing(controls.page, False, False, gtk.PACK_END)
|
|
|
|
def add_page(self, content, label):
|
|
self.prepend_page(content, label)
|
|
self.set_current_page(0)
|
|
|
|
def switched_pages(self, notebook, page, page_num):
|
|
new_page = self.get_nth_page(page_num)
|
|
if isinstance(new_page, ControlTab):
|
|
new_page.func()
|
|
self.stop_emission("switch-page")
|
|
else:
|
|
self.cur_page = page_num
|
|
return True
|
|
|
|
|
|
class TwoWayPane(InfoBar):
|
|
def __init__(self):
|
|
InfoBar.__init__(self, self.up_button)
|
|
self.bar = self.contents
|
|
self.tab = InfoTab(self.down_button)
|
|
self.pack_start(self.tab)
|
|
|
|
|
|
def up_button(self):
|
|
self.bar.hide()
|
|
self.tab.show()
|
|
|
|
def down_button(self):
|
|
self.bar.show()
|
|
self.tab.hide()
|
|
|
|
|
|
def init():
|
|
global info
|
|
global filter
|
|
global button
|
|
|
|
import button
|
|
info = TwoWayPane()
|
|
filter = FilterBar()
|
|
add_info_page("Test", gtk.Label("test label!"))
|
|
|
|
def get_info():
|
|
global info
|
|
return info
|
|
|
|
def get_filter():
|
|
global filter
|
|
return filter
|
|
|
|
def add_info_page(label, content):
|
|
global info
|
|
if label.__class__ == str:
|
|
label = gtk.Label(label)
|
|
label.show()
|
|
content.show()
|
|
info.tab.add_page(content, label)
|
|
|