Common menu items
Common menu items are drawn for all right click menus, so the same function won't need to be added multiple times to different menus.
This commit is contained in:
parent
049e27c559
commit
03f33af437
|
@ -6,30 +6,48 @@ gtk = ocarina.gtk
|
|||
Menu = gtk.Menu
|
||||
MenuItem = gtk.MenuItem
|
||||
|
||||
lib_items = []
|
||||
plist_items = []
|
||||
common_items = []
|
||||
lib_items = []
|
||||
plist_items = []
|
||||
|
||||
def add_menu_item(items, text, func):
|
||||
items.append( (text, func) )
|
||||
items.sort()
|
||||
|
||||
def add_common_menu_item(text, func):
|
||||
add_menu_item(common_items, text, func)
|
||||
|
||||
def add_lib_menu_item(text, func):
|
||||
add_menu_item(lib_items, text, func)
|
||||
|
||||
def add_plist_menu_item(text, func):
|
||||
add_menu_item(plist_items, text, func)
|
||||
|
||||
def make_menu_item(text, func):
|
||||
item = MenuItem(text)
|
||||
item.connect("activate", func)
|
||||
item.show()
|
||||
return item
|
||||
|
||||
def make_menu(items, button, time):
|
||||
if len(items) == 0:
|
||||
return
|
||||
show = False
|
||||
if len(items) > 0:
|
||||
show = True
|
||||
menu = Menu()
|
||||
|
||||
if len(common_items) > 0:
|
||||
show = True
|
||||
for (text, func) in common_items:
|
||||
menu.append(make_menu_item(text, func))
|
||||
if len(items) > 0:
|
||||
div = MenuItem()
|
||||
div.show()
|
||||
menu.append(div)
|
||||
|
||||
for (text, func) in items:
|
||||
item = MenuItem(text)
|
||||
item.connect("activate", func)
|
||||
item.show()
|
||||
menu.append(item)
|
||||
menu.popup(None, None, None, button, time)
|
||||
menu.append(make_menu_item(text, func))
|
||||
if show == True:
|
||||
menu.popup(None, None, None, button, time)
|
||||
|
||||
def make_lib_menu(button, time):
|
||||
make_menu(lib_items, button, time)
|
||||
|
|
Loading…
Reference in New Issue