Right click menus
I have started a system to create a right click menu on the fly and show it. Currently, it only works for the library. This will be used to populate the playlist and probably many other things (like plugins!)
This commit is contained in:
parent
48d0af571c
commit
02fe6dc8ba
|
@ -59,4 +59,6 @@ def lib_is_visible(text):
|
|||
global library
|
||||
return library.is_visible(text)
|
||||
|
||||
def add_to_playlist(lib_id):
|
||||
print lib_id
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ def set_badfiles():
|
|||
|
||||
class Library(collection.Collection):
|
||||
def __init__(self):
|
||||
collection.Collection.__init__(self, "DLTree_test")
|
||||
collection.Collection.__init__(self, "library.dl_tree")
|
||||
|
||||
def scan(self, path):
|
||||
print "Library scanning %s" % path
|
||||
|
@ -55,3 +55,4 @@ class Library(collection.Collection):
|
|||
self.insert_allocate(split_root + [file], ref)
|
||||
except UnicodeEncodeError:
|
||||
pass
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import ocarina
|
||||
import list
|
||||
|
||||
import menu
|
||||
|
||||
libsaria = ocarina.libsaria
|
||||
from libsaria import collection
|
||||
|
@ -16,6 +16,7 @@ class Actions:
|
|||
self.mouse_motion = None
|
||||
self.selected_row = None
|
||||
self.refilter = None
|
||||
self.show_rc_menu = None
|
||||
|
||||
|
||||
class Collection(gtk.ScrolledWindow):
|
||||
|
@ -56,6 +57,9 @@ class Collection(gtk.ScrolledWindow):
|
|||
string = self.mouse_motion(list_row)
|
||||
list.set_value(list_iter, len(list_row)-1, "Played: %s"%string)
|
||||
|
||||
def add_selected_to_playlist(self):
|
||||
self.list.for_each_selected(collection.add_to_playlist)
|
||||
|
||||
|
||||
class Library(Collection):
|
||||
def __init__(self):
|
||||
|
@ -63,10 +67,14 @@ class Library(Collection):
|
|||
actions.mouse_motion = self.mouse_motion
|
||||
actions.selected_row = self.select_row
|
||||
actions.refilter = self.refilter
|
||||
actions.show_rc_menu = self.show_rc_menu
|
||||
|
||||
Collection.__init__(self, actions)
|
||||
libsaria.event.invite("POSTSTART", self.populate, bg=True)
|
||||
libsaria.event.invite("POSTNEWSOURCE", self.refresh, bg=True)
|
||||
|
||||
menu.add_lib_menu_item("Add to playlist", self.add_selected_to_playlist)
|
||||
|
||||
def populate(self):
|
||||
import datetime
|
||||
before = datetime.datetime.now()
|
||||
|
@ -84,6 +92,9 @@ class Library(Collection):
|
|||
def select_row(self, row):
|
||||
collection.lib_play_id(row[0])
|
||||
|
||||
def show_rc_menu(self, button, time):
|
||||
menu.make_lib_menu(button, time)
|
||||
|
||||
def filter(self, text):
|
||||
collection.lib_filter(text)
|
||||
self.list.refilter()
|
||||
|
|
|
@ -37,18 +37,25 @@ class List(gtk.TreeView):
|
|||
self.filter_model.set_visible_func(actions.refilter)
|
||||
self.refilter = self.filter_model.refilter
|
||||
|
||||
self.sel = self.get_selection()
|
||||
self.sel.set_mode(gtk.SELECTION_MULTIPLE)
|
||||
|
||||
self.connect("row-activated", self.row_activated)
|
||||
self.connect("button-release-event", self.button_clicked)
|
||||
|
||||
self.set_model(self.filter_model)
|
||||
self.show_all()
|
||||
|
||||
def button_clicked(self, widget, event):
|
||||
if event.button == 3:
|
||||
self.actions.show_rc_menu(event.button, event.time)
|
||||
|
||||
def row_activated(self, widget, path, column):
|
||||
list = self.filter_model
|
||||
iter = list.get_iter(path)
|
||||
row = list[iter]
|
||||
self.actions.selected_row(row)
|
||||
|
||||
|
||||
def freeze(self):
|
||||
self.set_model(None)
|
||||
self.freeze_child_notify()
|
||||
|
@ -60,3 +67,9 @@ class List(gtk.TreeView):
|
|||
def clear(self):
|
||||
self.list.clear()
|
||||
|
||||
def for_each_selected(self, func):
|
||||
filter = self.filter_model
|
||||
for iter in self.sel.get_selected_rows()[1]:
|
||||
func(filter[iter][0])
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# Bryan Schumaker
|
||||
|
||||
import ocarina
|
||||
|
||||
gtk = ocarina.gtk
|
||||
Menu = gtk.Menu
|
||||
MenuItem = gtk.MenuItem
|
||||
|
||||
lib_items = []
|
||||
|
||||
def add_lib_menu_item(text, func):
|
||||
lib_items.append( (text, func) )
|
||||
lib_items.sort()
|
||||
|
||||
|
||||
def make_lib_menu(button, time):
|
||||
menu = Menu()
|
||||
for (text, func) in lib_items:
|
||||
item = MenuItem(text)
|
||||
item.connect("activate", lambda x: func())
|
||||
item.show()
|
||||
menu.append(item)
|
||||
menu.popup(None, None, None, button, time)
|
Loading…
Reference in New Issue