Play / Pause / Close tabs
I am using tabs in the info pane to act as buttons when the pane is expanded. Eventually I want to move this over to an action widget, but pygtk doesn't support action widgets for notebooks yet. Hopefully this will be fixed by the next release.
This commit is contained in:
parent
4a5085d973
commit
6609e48d5c
|
@ -3,11 +3,11 @@
|
|||
__all__ = ["collection"]
|
||||
|
||||
import libsaria
|
||||
#import tagpy
|
||||
import tagpy
|
||||
call = libsaria.event.call
|
||||
exists = libsaria.path.exists
|
||||
expand = libsaria.path.expand
|
||||
#FileRef = tagpy.FileRef
|
||||
FileRef = tagpy.FileRef
|
||||
|
||||
LIBRARY = 0
|
||||
PLAYLIST = 1
|
||||
|
|
|
@ -38,6 +38,8 @@ def universal_open(file):
|
|||
global plugin
|
||||
split = file.rsplit('.', 1)
|
||||
ext = split[len(split)-1]
|
||||
if path.is_dir(file):
|
||||
print "Is a dir! Scan it!"
|
||||
# Install and start a plugin
|
||||
if ext == "py":
|
||||
if plugin == None:
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import os
|
||||
|
||||
exists = os.path.exists
|
||||
is_dir = os.path.isdir
|
||||
expand = os.path.expanduser
|
||||
splitext = os.path.splitext
|
||||
join = os.path.join
|
||||
|
|
|
@ -16,6 +16,7 @@ class Button(gtk.Button):
|
|||
self.click_id = self.connect("clicked", self.clicked)
|
||||
if show == True:
|
||||
self.show()
|
||||
self.set_alignment(0,0)
|
||||
|
||||
def clicked(self, button):
|
||||
self.func()
|
||||
|
@ -54,3 +55,18 @@ class OpenButton(Button):
|
|||
from ocarina import fsselect
|
||||
fsselect.run_chooser2(LS.data.universal_open)
|
||||
print "OpenButton clicked"
|
||||
|
||||
|
||||
class UpButton(Button):
|
||||
def __init__(self, callback):
|
||||
Button.__init__(self, gtk.STOCK_ADD)
|
||||
self.callback = callback
|
||||
def clicked(self, button):
|
||||
self.callback()
|
||||
|
||||
class DownButton(Button):
|
||||
def __init__(self, callback):
|
||||
Button.__init__(self, gtk.STOCK_REMOVE)
|
||||
self.callback = callback
|
||||
def clicked(self, button):
|
||||
self.callback()
|
||||
|
|
|
@ -39,8 +39,9 @@ def make_chooser2(title, callback):
|
|||
|
||||
size = close_button.size_request()
|
||||
open_button.set_size_request(size[0], size[1])
|
||||
close_button.connect("clicked", hide_chooser)
|
||||
chooser_widget.connect("file-activated", select_path, callback)
|
||||
open_button.connect("clicked", select_path, callback)
|
||||
close_button.connect("clicked", hide_chooser)
|
||||
|
||||
chooser_window.add(chooser_box)
|
||||
chooser_window.resize(800, 600)
|
||||
|
@ -50,19 +51,18 @@ def hide_chooser(button):
|
|||
global chooser_window
|
||||
chooser_window.hide()
|
||||
|
||||
def select_path(button, callback):
|
||||
def select_path(widget, callback):
|
||||
global chooser_widget
|
||||
global chooser_window
|
||||
chooser_window.hide()
|
||||
callback( chooser_widget.get_uri() )
|
||||
uri = chooser_widget.get_uri()
|
||||
if uri[:7] == "file://":
|
||||
uri = uri[7:]
|
||||
callback(uri)
|
||||
|
||||
def run_chooser2(callback):
|
||||
make_chooser2("title", callback)
|
||||
|
||||
def response(*args):
|
||||
print "here?"
|
||||
print args
|
||||
|
||||
|
||||
def run_chooser(chooser):
|
||||
file = None
|
||||
|
|
109
ocarina/info.py
109
ocarina/info.py
|
@ -40,7 +40,7 @@ class FilterBar(Bar):
|
|||
|
||||
|
||||
class InfoBar(Bar):
|
||||
def __init__(self):
|
||||
def __init__(self, up_button):
|
||||
Bar.__init__(self, True)
|
||||
global button
|
||||
global libsaria
|
||||
|
@ -50,6 +50,7 @@ class InfoBar(Bar):
|
|||
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)
|
||||
|
||||
|
@ -60,21 +61,121 @@ 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())
|
||||
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 = InfoBar()
|
||||
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)
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ libsaria = ocarina.libsaria
|
|||
gtk = ocarina.gtk
|
||||
Label = gtk.Label
|
||||
|
||||
|
||||
tabs = None
|
||||
contents = dict()
|
||||
cur_page = 0
|
||||
|
|
Loading…
Reference in New Issue