9 |
|
|
10 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
11 |
|
|
12 |
|
from Thuban import _ |
13 |
|
|
14 |
class Menu: |
class Menu: |
15 |
|
|
42 |
def item_index(self, item): |
def item_index(self, item): |
43 |
"""Return the index of item in the menu. |
"""Return the index of item in the menu. |
44 |
|
|
45 |
The item parameter may be the name of a non-menu entry or the |
item -- may be the name of a non-menu entry or the |
46 |
name of a menu or a menu itself. |
name of a menu or a menu itself. |
47 |
|
|
48 |
Return None it item is not found. |
Return None it item is not found. |
49 |
""" |
""" |
87 |
submenu_index.InsertItem(item, menu = menu[1:], after = after) |
submenu_index.InsertItem(item, menu = menu[1:], after = after) |
88 |
else: |
else: |
89 |
# the submenu doesn't exist yet. Raise an error. |
# the submenu doesn't exist yet. Raise an error. |
90 |
raise KeyError("Submenu %s doesn't exist" % menu[0]) |
raise KeyError(_("Submenu %s doesn't exist") % menu[0]) |
91 |
else: |
else: |
92 |
if after is not None: |
if after is not None: |
93 |
idx = self.item_index(after) |
idx = self.item_index(after) |
99 |
else: |
else: |
100 |
self.items.append(item) |
self.items.append(item) |
101 |
|
|
102 |
def InsertSeparator(self): |
def InsertSeparator(self, after = None): |
103 |
"""Insert a separator""" |
"""Insert a separator |
104 |
self.InsertItem(None) |
|
105 |
|
after -- (optional) insert the separator after this one. after |
106 |
|
should be the name of a command. |
107 |
|
""" |
108 |
|
self.InsertItem(None, after = after) |
109 |
|
|
110 |
def InsertMenu(self, name, title, menu = (), after = None): |
def InsertMenu(self, name, title, menu = (), after = None): |
111 |
"""Insert and return a new menu. |
"""Insert and return a new menu. |
126 |
self.InsertItem(newmenu, menu = menu, after = after) |
self.InsertItem(newmenu, menu = menu, after = after) |
127 |
return newmenu |
return newmenu |
128 |
|
|
129 |
|
def FindOrInsertMenu(self, name, title, menu = (), after = None): |
130 |
|
""" |
131 |
|
Find the menu with the specified name. If found, return it. |
132 |
|
Else insert the menu as specified and return it. |
133 |
|
|
134 |
|
Parameters: See InsertMenu(). |
135 |
|
""" |
136 |
|
|
137 |
|
m = self.find_menu(name) |
138 |
|
if m is None: |
139 |
|
m = self.InsertMenu(name, title, menu, after) |
140 |
|
return m |
141 |
|
|
142 |
|
|
143 |
def SetItems(self, items): |
def SetItems(self, items): |
144 |
"""Replace the contents of the menu by items.""" |
"""Replace the contents of the menu by items.""" |
145 |
self.items = items |
self.items = items |
146 |
|
|
147 |
|
def RemoveItem(self, item): |
148 |
|
"""Remove an item from the menu. |
149 |
|
|
150 |
|
item -- the (internal) name of the item. |
151 |
|
""" |
152 |
|
i = self.item_index(item) |
153 |
|
if i is not None: |
154 |
|
self.items.pop(i) |