/[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 187 by bh, Tue May 28 12:38:17 2002 UTC revision 374 by jan, Mon Jan 27 14:20:02 2003 UTC
# Line 9  Line 9 
9    
10  __version__ = "$Revision$"  __version__ = "$Revision$"
11    
12    from Thuban import _
13    
14  class Menu:  class Menu:
15    
# Line 41  class Menu: Line 42  class Menu:
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
46            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          """          """
50          try:          for i in range(len(self.items)):
51              return self.items.index(item)              temp = self.items[i]
52          except ValueError:              if temp == item:
53              return None                  # this case takes care of item being the name of an
54                    # entry or a menu.
55                    return i
56                elif isinstance(temp, Menu) and temp.name == item:
57                    # item is the name of a menu
58                    return i
59            # Didn't find the item so return None
60            return None
61    
62      def find_menu(self, name):      def find_menu(self, name):
63          """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 70  class Menu:
70          """Insert a menu item.          """Insert a menu item.
71    
72          Parameters:          Parameters:
73            
74           item -- the menu item to insert must be either a string with           item -- the menu item to insert must be either a string with
75                  the command's name or a Menu instance.                  the command's name or a Menu instance.
76            
77           menu -- (optional) the submenu to insert into. It should be a           menu -- (optional) the submenu to insert into. It should be a
78                  sequence of menu names.                  sequence of menu names.
79            
80           after -- (optional) insert the new item after this one. after           after -- (optional) insert the new item after this one. after
81                   should be the name of a command.                   should be the name of a command.
82          """          """
# Line 76  class Menu: Line 87  class Menu:
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)
# Line 84  class Menu: Line 95  class Menu:
95                  idx = None                  idx = None
96    
97              if idx is not None:              if idx is not None:
98                  self.items.insert(idx + 1, item)                  self.items.insert(idx + 1, item)
99              else:              else:
100                  self.items.append(item)                  self.items.append(item)
101    
# Line 100  class Menu: Line 111  class Menu:
111           name -- the (internal) name of the menu           name -- the (internal) name of the menu
112    
113           title -- the (possibly localized) title           title -- the (possibly localized) title
114            
115           menu -- (optional) the submenu to insert into. It should be a           menu -- (optional) the submenu to insert into. It should be a
116                  sequence of menu names.                  sequence of menu names.
117            
118           after -- (optional) insert the new item after this one. after           after -- (optional) insert the new item after this one. after
119                   should be the name of a command.                   should be the name of a command.
120          """          """
121          newmenu = Menu(name, title)          newmenu = Menu(name, title)
122          self.InsertItem(newmenu, menu = menu, after = after)          self.InsertItem(newmenu, menu = menu, after = after)
123          return newmenu          return newmenu
124    
125        def SetItems(self, items):
126            """Replace the contents of the menu by items."""
127            self.items = items

Legend:
Removed from v.187  
changed lines
  Added in v.374

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26