[Thuban-commits] r2873 - in trunk/thuban: . Thuban/UI

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Apr 4 12:38:55 CEST 2009


Author: dpinte
Date: 2009-04-04 12:38:54 +0200 (Sat, 04 Apr 2009)
New Revision: 2873

Modified:
   trunk/thuban/ChangeLog
   trunk/thuban/Thuban/UI/mainwindow.py
Log:
2009-04-04 Didrik Pinte <dpinte at dipole-consulting.com>

  * Thuban/UI/mainwindow.py : completed command methods by allowing to remove 
    from menu and toolbar



Modified: trunk/thuban/ChangeLog
===================================================================
--- trunk/thuban/ChangeLog	2009-03-30 10:03:02 UTC (rev 2872)
+++ trunk/thuban/ChangeLog	2009-04-04 10:38:54 UTC (rev 2873)
@@ -1,3 +1,8 @@
+2009-04-04 Didrik Pinte <dpinte at dipole-consulting.com>
+
+  * Thuban/UI/mainwindow.py : completed command methods by allowing to remove
+    from menu and toolbar
+
 2009-03-30 Didrik Pinte <dpinte at dipole-consulting.com>
 
    * Thuban/version.py : resetted to svn release (thanks to Bernhard check)

Modified: trunk/thuban/Thuban/UI/mainwindow.py
===================================================================
--- trunk/thuban/Thuban/UI/mainwindow.py	2009-03-30 10:03:02 UTC (rev 2872)
+++ trunk/thuban/Thuban/UI/mainwindow.py	2009-04-04 10:38:54 UTC (rev 2873)
@@ -106,7 +106,7 @@
 
         # creat the menubar from the main_menu description
         self.SetMenuBar(self.build_menu_bar(main_menu))
-
+        
         # Similarly, create the toolbar from main_toolbar
         toolbar = self.build_toolbar(main_toolbar)
         # call Realize to make sure that the tools appear.
@@ -197,6 +197,13 @@
             if command.IsDynamic():
                 self.Bind(wx.EVT_UPDATE_UI, self.update_command_ui, id=ID)
 
+    def unbind_command_events(self, command, ID):
+        """Unbind the necessary events for the given command and ID"""
+        if self.events_bound.has_key(ID):
+            self.Unbind(wx.EVT_MENU, self.invoke_command, id=ID)
+            if command.IsDynamic():
+                self.Unbind(wx.EVT_UPDATE_UI, self.update_command_ui, id=ID)
+
     def build_menu_bar(self, menudesc):
         """Build and return the menu bar from the menu description"""
         menu_bar = wx.MenuBar()
@@ -266,6 +273,17 @@
             else:
                 print _("Unknown command %s") % name
 
+    def remove_menu_command(self, menu, name):
+        if name is None:
+            return
+        else:
+            command = registry.Command(name)
+            if command is not None:
+                assert isinstance(menu, wx.Menu)
+                ID = self.get_id(name)
+                menu.Remove(ID)
+                self.unbind_command_events(command, ID)
+
     def add_toolbar_command(self, toolbar, name):
         """Add the command with name name to the toolbar toolbar.
 
@@ -291,6 +309,19 @@
             else:
                 print _("Unknown command %s") % name
 
+    def remove_toolbar_command(self, toolbar, name):
+        """Remove the command with name name from the toolbar
+        """
+        if name is None:
+            return
+        else:
+            command = registry.Command(name)
+            if command is not None:
+                ID = self.get_id(name)
+                assert isinstance(toolbar, wx.ToolBar)
+                toolbar.RemoveTool(ID)
+                self.unbind_command_events(command, ID)             
+                
     def Context(self):
         """Return the context object for a command invoked from this window
         """



More information about the Thuban-commits mailing list