/[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 363 by jonathan, Mon Jan 27 11:40:13 2003 UTC revision 512 by jonathan, Tue Mar 11 16:32:39 2003 UTC
# Line 17  import os Line 17  import os
17  from wxPython.wx import *  from wxPython.wx import *
18    
19  import Thuban  import Thuban
20    from Thuban import _
21  from Thuban.Model.session import create_empty_session  from Thuban.Model.session import create_empty_session
22  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer
23  from Thuban.Model.color import Color  from Thuban.Model.color import Color
# Line 169  class MainWindow(wxFrame): Line 170  class MainWindow(wxFrame):
170                              command.IsCheckCommand())                              command.IsCheckCommand())
171                  self.bind_command_events(command, ID)                  self.bind_command_events(command, ID)
172              else:              else:
173                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
174    
175      def add_toolbar_command(self, toolbar, name):      def add_toolbar_command(self, toolbar, name):
176          """Add the command with name name to the toolbar toolbar.          """Add the command with name name to the toolbar toolbar.
# Line 191  class MainWindow(wxFrame): Line 192  class MainWindow(wxFrame):
192                                  isToggle = command.IsCheckCommand())                                  isToggle = command.IsCheckCommand())
193                  self.bind_command_events(command, ID)                  self.bind_command_events(command, ID)
194              else:              else:
195                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
196    
197      def Context(self):      def Context(self):
198          """Return the context object for a command invoked from this window          """Return the context object for a command invoked from this window
# Line 204  class MainWindow(wxFrame): Line 205  class MainWindow(wxFrame):
205              command = registry.Command(name)              command = registry.Command(name)
206              command.Execute(self.Context())              command.Execute(self.Context())
207          else:          else:
208              print "Unknown command ID %d" % event.GetId()              print _("Unknown command ID %d") % event.GetId()
209    
210      def update_command_ui(self, event):      def update_command_ui(self, event):
211          #print "update_command_ui", self.id_to_name[event.GetId()]          #print "update_command_ui", self.id_to_name[event.GetId()]
# Line 243  class MainWindow(wxFrame): Line 244  class MainWindow(wxFrame):
244    
245      def add_dialog(self, name, dialog):      def add_dialog(self, name, dialog):
246          if self.dialogs.has_key(name):          if self.dialogs.has_key(name):
247              raise RuntimeError("The Dialog named %s is already open" % name)              raise RuntimeError(_("The Dialog named %s is already open") % name)
248          self.dialogs[name] = dialog          self.dialogs[name] = dialog
249    
250      def dialog_open(self, name):      def dialog_open(self, name):
# Line 285  class MainWindow(wxFrame): Line 286  class MainWindow(wxFrame):
286              flags = wxYES_NO | wxICON_QUESTION              flags = wxYES_NO | wxICON_QUESTION
287              if can_veto:              if can_veto:
288                  flags = flags | wxCANCEL                  flags = flags | wxCANCEL
289              result = self.RunMessageBox("Exit",              result = self.RunMessageBox(_("Exit"),
290                                          ("The session has been modified."                                          _("The session has been modified."
291                                           " Do you want to save it?"),                                           " Do you want to save it?"),
292                                          flags)                                          flags)
293              if result == wxID_YES:              if result == wxID_YES:
# Line 295  class MainWindow(wxFrame): Line 296  class MainWindow(wxFrame):
296              result = wxID_NO              result = wxID_NO
297          return result          return result
298    
299        def prepare_new_session(self):
300            for d in self.dialogs.values():
301                if not isinstance(d, tree.SessionTreeView):
302                    d.Close()
303    
304      def NewSession(self):      def NewSession(self):
305          self.save_modified_session()          self.save_modified_session()
306            self.prepare_new_session()
307          self.application.SetSession(create_empty_session())          self.application.SetSession(create_empty_session())
308    
309      def OpenSession(self):      def OpenSession(self):
310          self.save_modified_session()          self.save_modified_session()
311          dlg = wxFileDialog(self, "Select a session file", ".", "",          dlg = wxFileDialog(self, _("Open Session"), ".", "", "*.thuban", wxOPEN)
                            "*.thuban", wxOPEN)  
312          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
313                self.prepare_new_session()
314              self.application.OpenSession(dlg.GetPath())              self.application.OpenSession(dlg.GetPath())
315          dlg.Destroy()          dlg.Destroy()
316    
317      def SaveSession(self):      def SaveSession(self):
318          if self.application.session.filename == None:          if self.application.session.filename == None:
319              self.SaveSessionAs()              self.SaveSessionAs()
320          self.application.SaveSession()          else:
321                self.application.SaveSession()
322    
323      def SaveSessionAs(self):      def SaveSessionAs(self):
324          dlg = wxFileDialog(self, "Enter a filename for session", ".", "",          dlg = wxFileDialog(self, _("Save Session As"), ".", "",
325                             "*.thuban", wxOPEN)                             "*.thuban", wxOPEN)
326          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
327              self.application.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
# Line 347  class MainWindow(wxFrame): Line 355  class MainWindow(wxFrame):
355          if dialog is None:          if dialog is None:
356              dialog = tree.SessionTreeView(self, self.application, name)              dialog = tree.SessionTreeView(self, self.application, name)
357              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
358              dialog.Show(true)              dialog.Show(True)
359          else:          else:
360              # FIXME: bring dialog to front here              # FIXME: bring dialog to front here
361              pass              pass
362    
363      def About(self):      def About(self):
364          self.RunMessageBox("About",          self.RunMessageBox(_("About"),
365                             ("Thuban is a program for\n"                             _("Thuban is a program for\n"
366                              "exploring geographic data.\n"                              "exploring geographic data.\n"
367                              "Copyright (C) 2001, 2002 Intevation GmbH.\n"                              "Copyright (C) 2001-2003 Intevation GmbH.\n"
368                              "Thuban is licensed under the GPL"),                              "Thuban is licensed under the GPL"),
369                             wxOK | wxICON_INFORMATION)                             wxOK | wxICON_INFORMATION)
370    
371      def AddLayer(self):      def AddLayer(self):
372          dlg = wxFileDialog(self, "Select a data file", ".", "", "*.*",          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",
373                             wxOPEN)                             wxOPEN)
374          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
375              filename = dlg.GetPath()              filename = dlg.GetPath()
# Line 373  class MainWindow(wxFrame): Line 381  class MainWindow(wxFrame):
381                  map.AddLayer(layer)                  map.AddLayer(layer)
382              except IOError:              except IOError:
383                  # the layer couldn't be opened                  # the layer couldn't be opened
384                  self.RunMessageBox("Add Layer",                  self.RunMessageBox(_("Add Layer"),
385                                     "Can't open the file '%s'." % filename)                                     _("Can't open the file '%s'.") % filename)
386              else:              else:
387                  if not has_layers:                  if not has_layers:
388                      # if we're adding a layer to an empty map, for the                      # if we're adding a layer to an empty map, for the
# Line 442  class MainWindow(wxFrame): Line 450  class MainWindow(wxFrame):
450          if layer is not None:          if layer is not None:
451              color = self.choose_color()              color = self.choose_color()
452              if color is not None:              if color is not None:
453                  layer.SetFill(color)                  layer.GetClassification().SetDefaultFill(color)
454    
455      def LayerTransparentFill(self):      def LayerTransparentFill(self):
456          layer = self.current_layer()          layer = self.current_layer()
457          if layer is not None:          if layer is not None:
458              layer.SetFill(None)              layer.GetClassification().SetDefaultFill(Color.None)
459    
460      def LayerOutlineColor(self):      def LayerOutlineColor(self):
461          layer = self.current_layer()          layer = self.current_layer()
462          if layer is not None:          if layer is not None:
463              color = self.choose_color()              color = self.choose_color()
464              if color is not None:              if color is not None:
465                  layer.SetStroke(color)                  layer.GetClassification().SetDefaultLineColor(color)
466    
467      def LayerNoOutline(self):      def LayerNoOutline(self):
468          layer = self.current_layer()          layer = self.current_layer()
469          if layer is not None:          if layer is not None:
470              layer.SetStroke(None)              layer.GetClassification().SetDefaultLineColor(Color.None)
471    
472      def HideLayer(self):      def HideLayer(self):
473          layer = self.current_layer()          layer = self.current_layer()
# Line 479  class MainWindow(wxFrame): Line 487  class MainWindow(wxFrame):
487              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
488              if dialog is None:              if dialog is None:
489                  dialog = tableview.LayerTableFrame(self, self.interactor, name,                  dialog = tableview.LayerTableFrame(self, self.interactor, name,
490                                                     "Table: %s" % layer.Title(),                                                     _("Table: %s") % layer.Title(),
491                                                     layer, table)                                                     layer, table)
492                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
493                  dialog.Show(true)                  dialog.Show(true)
# Line 505  class MainWindow(wxFrame): Line 513  class MainWindow(wxFrame):
513          proj4Dlg.Destroy()          proj4Dlg.Destroy()
514    
515      def Classify(self):      def Classify(self):
516          classifyDlg = classifier.Classifier(NULL, self.current_layer())  
517            #
518          classifyDlg.ShowModal()          # the menu option for this should only be available if there
519          classifyDlg.Destroy()          # is a current layer, so we don't need to check if the
520            # current layer is None
521            #
522    
523            layer = self.current_layer()
524            name = "classifier" + str(id(layer))
525            dialog = self.get_open_dialog(name)
526    
527            if dialog is None:
528                dialog = classifier.Classifier(self, self.interactor,
529                                               name, self.current_layer())
530                self.add_dialog(name, dialog)
531                dialog.Show()
532    
533      def ZoomInTool(self):      def ZoomInTool(self):
534          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
# Line 603  def _has_visible_map(context): Line 623  def _has_visible_map(context):
623    
624    
625  # File menu  # File menu
626  _method_command("new_session", "&New Session", "NewSession")  _method_command("new_session", _("&New Session"), "NewSession")
627  _method_command("open_session", "&Open Session", "OpenSession")  _method_command("open_session", _("&Open Session"), "OpenSession")
628  _method_command("save_session", "&Save Session", "SaveSession")  _method_command("save_session", _("&Save Session"), "SaveSession")
629  _method_command("save_session_as", "Save Session &As", "SaveSessionAs")  _method_command("save_session_as", _("Save Session &As"), "SaveSessionAs")
630  _method_command("show_session_tree", "Show Session &Tree", "ShowSessionTree",  _method_command("show_session_tree", _("Show Session &Tree"), "ShowSessionTree",
631                  sensitive = _has_tree_window_shown)                  sensitive = _has_tree_window_shown)
632  _method_command("exit", "E&xit", "Exit")  _method_command("exit", _("E&xit"), "Exit")
633    
634  # Help menu  # Help menu
635  _method_command("help_about", "&About", "About")  _method_command("help_about", _("&About"), "About")
636    
637    
638  # Map menu  # Map menu
639  _method_command("map_projection", "Pro&jection", "Projection")  _method_command("map_projection", _("Pro&jection"), "Projection")
   
640    
641  _tool_command("map_zoom_in_tool", "&Zoom in", "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
642                helptext = "Switch to map-mode 'zoom-in'", icon = "zoom_in",                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
643                sensitive = _has_visible_map)                sensitive = _has_visible_map)
644  _tool_command("map_zoom_out_tool", "Zoom &out", "ZoomOutTool", "ZoomOutTool",  _tool_command("map_zoom_out_tool", _("Zoom &out"), "ZoomOutTool", "ZoomOutTool",
645                helptext = "Switch to map-mode 'zoom-out'", icon = "zoom_out",                helptext = _("Switch to map-mode 'zoom-out'"), icon = "zoom_out",
646                sensitive = _has_visible_map)                sensitive = _has_visible_map)
647  _tool_command("map_pan_tool", "&Pan", "PanTool", "PanTool",  _tool_command("map_pan_tool", _("&Pan"), "PanTool", "PanTool",
648                helptext = "Switch to map-mode 'pan'", icon = "pan",                helptext = _("Switch to map-mode 'pan'"), icon = "pan",
649                sensitive = _has_visible_map)                sensitive = _has_visible_map)
650  _tool_command("map_identify_tool", "&Identify", "IdentifyTool", "IdentifyTool",  _tool_command("map_identify_tool", _("&Identify"), "IdentifyTool",
651                helptext = "Switch to map-mode 'identify'", icon = "identify",                "IdentifyTool",
652                  helptext = _("Switch to map-mode 'identify'"), icon = "identify",
653                sensitive = _has_visible_map)                sensitive = _has_visible_map)
654  _tool_command("map_label_tool", "&Label", "LabelTool", "LabelTool",  _tool_command("map_label_tool", _("&Label"), "LabelTool", "LabelTool",
655                helptext = "Add/Remove labels", icon = "label",                helptext = _("Add/Remove labels"), icon = "label",
656                sensitive = _has_visible_map)                sensitive = _has_visible_map)
657  _method_command("map_full_extent", "&Full extent", "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
658                 helptext = "Full Extent", icon = "fullextent",                 helptext = _("Full Extent"), icon = "fullextent",
659                sensitive = _has_visible_map)                sensitive = _has_visible_map)
660  _method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map")  _method_command("map_print", _("Prin&t"), "PrintMap",
661                    helptext = _("Print the map"))
662    
663  # Layer menu  # Layer menu
664  _method_command("layer_add", "&Add Layer", "AddLayer",  _method_command("layer_add", _("&Add Layer"), "AddLayer",
665                  helptext = "Add a new layer to active map")                  helptext = _("Add a new layer to active map"))
666  _method_command("layer_remove", "&Remove Layer", "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
667                  helptext = "Remove selected layer(s)",                  helptext = _("Remove selected layer(s)"),
668                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
669  _method_command("layer_fill_color", "&Fill Color", "LayerFillColor",  _method_command("layer_fill_color", _("&Fill Color"), "LayerFillColor",
670                  helptext = "Set the fill color of selected layer(s)",                  helptext = _("Set the fill color of selected layer(s)"),
671                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
672  _method_command("layer_transparent_fill", "&Transparent Fill",  _method_command("layer_transparent_fill", _("&Transparent Fill"),
673                  "LayerTransparentFill",                  "LayerTransparentFill",
674                  helptext = "Do not fill the selected layer(s)",                  helptext = _("Do not fill the selected layer(s)"),
675                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
676  _method_command("layer_outline_color", "&Outline Color", "LayerOutlineColor",  _method_command("layer_outline_color", _("&Outline Color"), "LayerOutlineColor",
677                  helptext = "Set the outline color of selected layer(s)",                  helptext = _("Set the outline color of selected layer(s)"),
678                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
679  _method_command("layer_no_outline", "&No Outline", "LayerNoOutline",  _method_command("layer_no_outline", _("&No Outline"), "LayerNoOutline",
680                  helptext = "Do not draw the outline of the selected layer(s)",                  helptext= _("Do not draw the outline of the selected layer(s)"),
681                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
682  _method_command("layer_raise", "&Raise", "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
683                  helptext = "Raise selected layer(s)",                  helptext = _("Raise selected layer(s)"),
684                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
685  _method_command("layer_lower", "&Lower", "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
686                  helptext = "Lower selected layer(s)",                  helptext = _("Lower selected layer(s)"),
687                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
688  _method_command("layer_show", "&Show", "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
689                  helptext = "Make selected layer(s) visible",                  helptext = _("Make selected layer(s) visible"),
690                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
691  _method_command("layer_hide", "&Hide", "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
692                  helptext = "Make selected layer(s) unvisible",                  helptext = _("Make selected layer(s) unvisible"),
693                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
694  _method_command("layer_show_table", "Show Ta&ble", "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
695                  helptext = "Show the selected layer's table",                  helptext = _("Show the selected layer's table"),
696                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
697    
698  _method_command("layer_classifier", "Classify", "Classify",  _method_command("layer_classifier", _("Classify"), "Classify",
699                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
700    
701  # the menu structure  # the menu structure
702  main_menu = Menu("<main>", "<main>",  main_menu = Menu("<main>", "<main>",
703                   [Menu("file", "&File",                   [Menu("file", _("&File"),
704                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
705                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
706                          "show_session_tree", None,                          "show_session_tree", None,
707                          "exit"]),                          "exit"]),
708                    Menu("map", "&Map",                    Menu("map", _("&Map"),
709                         ["layer_add", "layer_remove",                         ["layer_add", "layer_remove",
710                          None,                          None,
711                          "map_projection",                          "map_projection",
# Line 695  main_menu = Menu("<main>", "<main>", Line 716  main_menu = Menu("<main>", "<main>",
716                          "map_full_extent",                          "map_full_extent",
717                          None,                          None,
718                          "map_print"]),                          "map_print"]),
719                    Menu("layer", "&Layer",                    Menu("layer", _("&Layer"),
720                         ["layer_fill_color", "layer_transparent_fill",                         ["layer_fill_color", "layer_transparent_fill",
721                          "layer_outline_color", "layer_no_outline",                          "layer_outline_color", "layer_no_outline",
722                          None,                          None,
# Line 706  main_menu = Menu("<main>", "<main>", Line 727  main_menu = Menu("<main>", "<main>",
727                          "layer_show_table",                          "layer_show_table",
728                          None,                          None,
729                          "layer_classifier"]),                          "layer_classifier"]),
730                    Menu("help", "&Help",                    Menu("help", _("&Help"),
731                         ["help_about"])])                         ["help_about"])])
732    
733  # the main toolbar  # the main toolbar

Legend:
Removed from v.363  
changed lines
  Added in v.512

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26