I now add buttons to the info tabs using an action widget.
This commit is contained in:
parent
ab29b2cb2b
commit
42dbdd2736
|
@ -0,0 +1,9 @@
|
|||
# Bryan Schumaker (10/4/2010)
|
||||
|
||||
import ocarina
|
||||
gtk = ocarina.gtk
|
||||
|
||||
class FilterEntry(gtk.Entry):
|
||||
def __init__(self):
|
||||
gtk.Entry.__init__(self)
|
||||
self.show()
|
|
@ -4,6 +4,7 @@ import ocarina
|
|||
gtk = ocarina.gtk
|
||||
libsaria = ocarina.libsaria
|
||||
button = None
|
||||
entry = None
|
||||
|
||||
lib_get_cur_id = libsaria.collection.lib_get_cur_id
|
||||
lib_get_attr = libsaria.collection.lib_get_attr
|
||||
|
@ -34,8 +35,10 @@ class FilterBar(Bar):
|
|||
def __init__(self):
|
||||
Bar.__init__(self, False)
|
||||
global button
|
||||
global libsaria
|
||||
global entry
|
||||
#global libsaria
|
||||
|
||||
self.pack(entry.FilterEntry(), True, True)
|
||||
self.pack(button.OpenButton())
|
||||
|
||||
|
||||
|
@ -61,79 +64,28 @@ class InfoBar(Bar):
|
|||
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())
|
||||
|
||||
hbox = gtk.HBox()
|
||||
hbox.show()
|
||||
hbox.pack_start(button.PlayButton())
|
||||
hbox.pack_start(button.PauseButton())
|
||||
hbox.pack_start(button.DownButton(down_button))
|
||||
self.set_action_widget(hbox, gtk.PACK_END)
|
||||
|
||||
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
|
||||
self.cur_page = page_num
|
||||
|
||||
|
||||
class TwoWayPane(InfoBar):
|
||||
|
@ -142,7 +94,6 @@ class TwoWayPane(InfoBar):
|
|||
self.bar = self.contents
|
||||
self.tab = InfoTab(self.down_button)
|
||||
self.pack_start(self.tab)
|
||||
|
||||
|
||||
def up_button(self):
|
||||
self.bar.hide()
|
||||
|
@ -157,8 +108,11 @@ def init():
|
|||
global info
|
||||
global filter
|
||||
global button
|
||||
global entry
|
||||
|
||||
import button
|
||||
import entry
|
||||
|
||||
info = TwoWayPane()
|
||||
filter = FilterBar()
|
||||
add_info_page("Test", gtk.Label("test label!"))
|
||||
|
|
Loading…
Reference in New Issue