comparison urwid_satext/sat_widgets.py @ 79:33677d99ebdf

addMenu allows to add a new category without adding an item
author souliane <souliane@mailoo.org>
date Mon, 07 Apr 2014 19:58:13 +0200
parents 56c02f4731f9
children 2d66ac0f4d75
comparison
equal deleted inserted replaced
78:56c02f4731f9 79:33677d99ebdf
758 if key == shortcut: 758 if key == shortcut:
759 category, item, callback = self.shortcuts[shortcut] 759 category, item, callback = self.shortcuts[shortcut]
760 callback((category, item)) 760 callback((category, item))
761 return key 761 return key
762 762
763 def addMenu(self, category, item, callback, shortcut=None): 763 def addMenu(self, category, item=None, callback=None, shortcut=None):
764 """Add a menu item, create the category if new 764 """Create the category if new and add a menu item (if item is not None).
765
765 @param category: category of the menu (e.g. File/Edit) 766 @param category: category of the menu (e.g. File/Edit)
766 @param item: menu item (e.g. new/close/about) 767 @param item: menu item (e.g. new/close/about)
767 @callback: method to call when item is selected""" 768 @callback: method to call when item is selected"""
768 if not category in self.menu.keys(): 769 if not category in self.menu.keys():
769 self.menu_keys.append(category) 770 self.menu_keys.append(category)
770 self.menu[category] = [] 771 self.menu[category] = []
771 button = CustomButton(('menubar',category), self.onCategoryClick, 772 button = CustomButton(('menubar',category), self.onCategoryClick,
772 left_border = ('menubar',"[ "), 773 left_border = ('menubar',"[ "),
773 right_border = ('menubar'," ]")) 774 right_border = ('menubar'," ]"))
774 self._w.base_widget.addWidget(button,button.getSize()) 775 self._w.base_widget.addWidget(button,button.getSize())
776 if not item:
777 return
775 self.menu[category].append((item, callback)) 778 self.menu[category].append((item, callback))
776 if shortcut: 779 if shortcut:
777 assert(shortcut not in self.shortcuts.keys()) 780 assert(shortcut not in self.shortcuts.keys())
778 self.shortcuts[shortcut] = (category, item, callback) 781 self.shortcuts[shortcut] = (category, item, callback)
779 782