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

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

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

revision 238 by bh, Wed Jul 24 10:19:46 2002 UTC revision 281 by bh, Mon Aug 26 18:16:36 2002 UTC
# Line 193  class MainWindow(wxFrame): Line 193  class MainWindow(wxFrame):
193              else:              else:
194                  print "Unknown command %s" % name                  print "Unknown command %s" % name
195    
196        def Context(self):
197            """Return the context object for a command invoked from this window
198            """
199            return Context(self.application, self.application.Session(), self)
200    
201      def invoke_command(self, event):      def invoke_command(self, event):
202          name = self.id_to_name.get(event.GetId())          name = self.id_to_name.get(event.GetId())
203          if name is not None:          if name is not None:
204              command = registry.Command(name)              command = registry.Command(name)
205              context = Context(self.application, self.application.Session(),              command.Execute(self.Context())
                               self)  
             command.Execute(context)  
206          else:          else:
207              print "Unknown command ID %d" % event.GetId()              print "Unknown command ID %d" % event.GetId()
208    
209      def update_command_ui(self, event):      def update_command_ui(self, event):
210          #print "update_command_ui", self.id_to_name[event.GetId()]          #print "update_command_ui", self.id_to_name[event.GetId()]
211          context = Context(self.application, self.application.Session(), self)          context = self.Context()
212          command = registry.Command(self.id_to_name[event.GetId()])          command = registry.Command(self.id_to_name[event.GetId()])
213          if command is not None:          if command is not None:
214              event.Enable(command.Sensitive(context))              event.Enable(command.Sensitive(context))
# Line 435  class MainWindow(wxFrame): Line 438  class MainWindow(wxFrame):
438              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
439              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
440              if dialog is None:              if dialog is None:
441                  dialog = tableview.TableFrame(self, self.interactor, name,                  dialog = tableview.LayerTableFrame(self, self.interactor, name,
442                                                "Table: %s" % layer.Title(),                                                     "Table: %s" % layer.Title(),
443                                                layer, table)                                                     layer, table)
444                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
445                  dialog.Show(true)                  dialog.Show(true)
446              else:              else:
# Line 511  def _method_command(name, title, method, Line 514  def _method_command(name, title, method,
514                           helptext = helptext, icon = icon,                           helptext = helptext, icon = icon,
515                           sensitive = sensitive))                           sensitive = sensitive))
516    
517    def make_check_current_tool(toolname):
518        """Return a function that tests if the currently active tool is toolname
519    
520        The returned function can be called with the context and returns
521        true iff the currently active tool's name is toolname. It's directly
522        usable as the 'checked' callback of a command.
523        """
524        def check_current_tool(context, name=toolname):
525            return context.mainwindow.canvas.CurrentTool() == name
526        return check_current_tool
527    
528  def _tool_command(name, title, method, toolname, helptext = "",  def _tool_command(name, title, method, toolname, helptext = "",
529                    icon = ""):                    icon = ""):
530      """Add a tool command"""      """Add a tool command"""
     def check_current_tool(context, name=toolname):  
         return context.mainwindow.canvas.CurrentTool() == name  
531      registry.Add(Command(name, title, call_method, args=(method,),      registry.Add(Command(name, title, call_method, args=(method,),
532                           helptext = helptext, icon = icon,                           helptext = helptext, icon = icon,
533                           checked = check_current_tool))                           checked = make_check_current_tool(toolname)))
534    
535  def _has_selected_layer(context):  def _has_selected_layer(context):
536      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
537      return context.mainwindow.has_selected_layer()      return context.mainwindow.has_selected_layer()
538    
539    def _has_tree_window_shown(context):
540        """Return true if the tree window is shown"""
541        return context.mainwindow.get_open_dialog("session_tree") is None
542    
543  # File menu  # File menu
544  _method_command("new_session", "&New Session", "NewSession")  _method_command("new_session", "&New Session", "NewSession")
545  _method_command("open_session", "&Open Session", "OpenSession")  _method_command("open_session", "&Open Session", "OpenSession")
546  _method_command("save_session", "&Save Session", "SaveSession")  _method_command("save_session", "&Save Session", "SaveSession")
547  _method_command("save_session_as", "Save Session &As", "SaveSessionAs")  _method_command("save_session_as", "Save Session &As", "SaveSessionAs")
548  _method_command("show_session_tree", "Show Session &Tree", "ShowSessionTree")  _method_command("show_session_tree", "Show Session &Tree", "ShowSessionTree",
549                    sensitive = _has_tree_window_shown)
550  _method_command("exit", "&Exit", "Exit")  _method_command("exit", "&Exit", "Exit")
551    
552  # Help menu  # Help menu

Legend:
Removed from v.238  
changed lines
  Added in v.281

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26