/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/menu.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/menu.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 235 by bh, Tue Jul 16 15:25:24 2002 UTC revision 236 by bh, Tue Jul 23 16:53:14 2002 UTC
# Line 41  class Menu: Line 41  class Menu:
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"""
# Line 59  class Menu: Line 69  class Menu:
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          """          """
# Line 84  class Menu: Line 94  class Menu:
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    
# Line 100  class Menu: Line 110  class Menu:
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          """          """
# Line 114  class Menu: Line 124  class Menu:
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
           

Legend:
Removed from v.235  
changed lines
  Added in v.236

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26