41 |
def item_index(self, item): |
def item_index(self, item): |
42 |
"""Return the index of item in the menu. |
"""Return the index of item in the menu. |
43 |
|
|
44 |
|
The item parameter may be the name of a non-menu entry or the |
45 |
|
name of a menu or a menu itself. |
46 |
|
|
47 |
Return None it item is not found. |
Return None it item is not found. |
48 |
""" |
""" |
49 |
try: |
for i in range(len(self.items)): |
50 |
return self.items.index(item) |
temp = self.items[i] |
51 |
except ValueError: |
if temp == item: |
52 |
return None |
# this case takes care of item being the name of an |
53 |
|
# entry or a menu. |
54 |
|
return i |
55 |
|
elif isinstance(temp, Menu) and temp.name == item: |
56 |
|
# item is the name of a menu |
57 |
|
return i |
58 |
|
# Didn't find the item so return None |
59 |
|
return None |
60 |
|
|
61 |
def find_menu(self, name): |
def find_menu(self, name): |
62 |
"""Return the submenu named name or None if no such item exists""" |
"""Return the submenu named name or None if no such item exists""" |
69 |
"""Insert a menu item. |
"""Insert a menu item. |
70 |
|
|
71 |
Parameters: |
Parameters: |
72 |
|
|
73 |
item -- the menu item to insert must be either a string with |
item -- the menu item to insert must be either a string with |
74 |
the command's name or a Menu instance. |
the command's name or a Menu instance. |
75 |
|
|
76 |
menu -- (optional) the submenu to insert into. It should be a |
menu -- (optional) the submenu to insert into. It should be a |
77 |
sequence of menu names. |
sequence of menu names. |
78 |
|
|
79 |
after -- (optional) insert the new item after this one. after |
after -- (optional) insert the new item after this one. after |
80 |
should be the name of a command. |
should be the name of a command. |
81 |
""" |
""" |
94 |
idx = None |
idx = None |
95 |
|
|
96 |
if idx is not None: |
if idx is not None: |
97 |
self.items.insert(idx + 1, item) |
self.items.insert(idx + 1, item) |
98 |
else: |
else: |
99 |
self.items.append(item) |
self.items.append(item) |
100 |
|
|
110 |
name -- the (internal) name of the menu |
name -- the (internal) name of the menu |
111 |
|
|
112 |
title -- the (possibly localized) title |
title -- the (possibly localized) title |
113 |
|
|
114 |
menu -- (optional) the submenu to insert into. It should be a |
menu -- (optional) the submenu to insert into. It should be a |
115 |
sequence of menu names. |
sequence of menu names. |
116 |
|
|
117 |
after -- (optional) insert the new item after this one. after |
after -- (optional) insert the new item after this one. after |
118 |
should be the name of a command. |
should be the name of a command. |
119 |
""" |
""" |
124 |
def SetItems(self, items): |
def SetItems(self, items): |
125 |
"""Replace the contents of the menu by items.""" |
"""Replace the contents of the menu by items.""" |
126 |
self.items = items |
self.items = items |
|
|
|