/[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 517 by jonathan, Tue Mar 11 17:28:39 2003 UTC
# Line 12  The main window Line 12  The main window
12    
13  __version__ = "$Revision$"  __version__ = "$Revision$"
14    
15    __ThubanVersion__ = "0.2" #"$THUBAN_0_2$"
16    #__BuildDate__ = "$Date$"
17    
18  import os  import os
19    
20  from wxPython.wx import *  from wxPython.wx import *
21    
22  import Thuban  import Thuban
23    from Thuban import _
24  from Thuban.Model.session import create_empty_session  from Thuban.Model.session import create_empty_session
25  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer
26  from Thuban.Model.color import Color  from Thuban.Model.color import Color
# Line 169  class MainWindow(wxFrame): Line 173  class MainWindow(wxFrame):
173                              command.IsCheckCommand())                              command.IsCheckCommand())
174                  self.bind_command_events(command, ID)                  self.bind_command_events(command, ID)
175              else:              else:
176                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
177    
178      def add_toolbar_command(self, toolbar, name):      def add_toolbar_command(self, toolbar, name):
179          """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 195  class MainWindow(wxFrame):
195                                  isToggle = command.IsCheckCommand())                                  isToggle = command.IsCheckCommand())
196                  self.bind_command_events(command, ID)                  self.bind_command_events(command, ID)
197              else:              else:
198                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
199    
200      def Context(self):      def Context(self):
201          """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 208  class MainWindow(wxFrame):
208              command = registry.Command(name)              command = registry.Command(name)
209              command.Execute(self.Context())              command.Execute(self.Context())
210          else:          else:
211              print "Unknown command ID %d" % event.GetId()              print _("Unknown command ID %d") % event.GetId()
212    
213      def update_command_ui(self, event):      def update_command_ui(self, event):
214          #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 247  class MainWindow(wxFrame):
247    
248      def add_dialog(self, name, dialog):      def add_dialog(self, name, dialog):
249          if self.dialogs.has_key(name):          if self.dialogs.has_key(name):
250              raise RuntimeError("The Dialog named %s is already open" % name)              raise RuntimeError(_("The Dialog named %s is already open") % name)
251          self.dialogs[name] = dialog          self.dialogs[name] = dialog
252    
253      def dialog_open(self, name):      def dialog_open(self, name):
# Line 285  class MainWindow(wxFrame): Line 289  class MainWindow(wxFrame):
289              flags = wxYES_NO | wxICON_QUESTION              flags = wxYES_NO | wxICON_QUESTION
290              if can_veto:              if can_veto:
291                  flags = flags | wxCANCEL                  flags = flags | wxCANCEL
292              result = self.RunMessageBox("Exit",              result = self.RunMessageBox(_("Exit"),
293                                          ("The session has been modified."                                          _("The session has been modified."
294                                           " Do you want to save it?"),                                           " Do you want to save it?"),
295                                          flags)                                          flags)
296              if result == wxID_YES:              if result == wxID_YES:
# Line 295  class MainWindow(wxFrame): Line 299  class MainWindow(wxFrame):
299              result = wxID_NO              result = wxID_NO
300          return result          return result
301    
302        def prepare_new_session(self):
303            for d in self.dialogs.values():
304                if not isinstance(d, tree.SessionTreeView):
305                    d.Close()
306    
307      def NewSession(self):      def NewSession(self):
308          self.save_modified_session()          self.save_modified_session()
309            self.prepare_new_session()
310          self.application.SetSession(create_empty_session())          self.application.SetSession(create_empty_session())
311    
312      def OpenSession(self):      def OpenSession(self):
313          self.save_modified_session()          self.save_modified_session()
314          dlg = wxFileDialog(self, "Select a session file", ".", "",          dlg = wxFileDialog(self, _("Open Session"), ".", "", "*.thuban", wxOPEN)
                            "*.thuban", wxOPEN)  
315          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
316                self.prepare_new_session()
317              self.application.OpenSession(dlg.GetPath())              self.application.OpenSession(dlg.GetPath())
318          dlg.Destroy()          dlg.Destroy()
319    
320      def SaveSession(self):      def SaveSession(self):
321          if self.application.session.filename == None:          if self.application.session.filename == None:
322              self.SaveSessionAs()              self.SaveSessionAs()
323          self.application.SaveSession()          else:
324                self.application.SaveSession()
325    
326      def SaveSessionAs(self):      def SaveSessionAs(self):
327          dlg = wxFileDialog(self, "Enter a filename for session", ".", "",          dlg = wxFileDialog(self, _("Save Session As"), ".", "",
328                             "*.thuban", wxOPEN)                             "*.thuban", wxOPEN)
329          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
330              self.application.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
# Line 347  class MainWindow(wxFrame): Line 358  class MainWindow(wxFrame):
358          if dialog is None:          if dialog is None:
359              dialog = tree.SessionTreeView(self, self.application, name)              dialog = tree.SessionTreeView(self, self.application, name)
360              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
361              dialog.Show(true)              dialog.Show(True)
362          else:          else:
363              # FIXME: bring dialog to front here              # FIXME: bring dialog to front here
364              pass              pass
365    
366    
367      def About(self):      def About(self):
368          self.RunMessageBox("About",          self.RunMessageBox(_("About"),
369                             ("Thuban is a program for\n"                             _("Thuban v%s\n"
370                                #"Build Date: %s\n"
371                                "\n"
372                                "Thuban is a program for\n"
373                              "exploring geographic data.\n"                              "exploring geographic data.\n"
374                              "Copyright (C) 2001, 2002 Intevation GmbH.\n"                              "Copyright (C) 2001-2003 Intevation GmbH.\n"
375                              "Thuban is licensed under the GPL"),                              "Thuban is licensed under the GNU GPL"
376                               % __ThubanVersion__), #__BuildDate__)),
377                             wxOK | wxICON_INFORMATION)                             wxOK | wxICON_INFORMATION)
378    
379      def AddLayer(self):      def AddLayer(self):
380          dlg = wxFileDialog(self, "Select a data file", ".", "", "*.*",          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",
381                             wxOPEN)                             wxOPEN)
382          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
383              filename = dlg.GetPath()              filename = dlg.GetPath()
# Line 373  class MainWindow(wxFrame): Line 389  class MainWindow(wxFrame):
389                  map.AddLayer(layer)                  map.AddLayer(layer)
390              except IOError:              except IOError:
391                  # the layer couldn't be opened                  # the layer couldn't be opened
392                  self.RunMessageBox("Add Layer",                  self.RunMessageBox(_("Add Layer"),
393                                     "Can't open the file '%s'." % filename)                                     _("Can't open the file '%s'.") % filename)
394              else:              else:
395                  if not has_layers:                  if not has_layers:
396                      # 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 458  class MainWindow(wxFrame):
458          if layer is not None:          if layer is not None:
459              color = self.choose_color()              color = self.choose_color()
460              if color is not None:              if color is not None:
461                  layer.SetFill(color)                  layer.GetClassification().SetDefaultFill(color)
462    
463      def LayerTransparentFill(self):      def LayerTransparentFill(self):
464          layer = self.current_layer()          layer = self.current_layer()
465          if layer is not None:          if layer is not None:
466              layer.SetFill(None)              layer.GetClassification().SetDefaultFill(Color.None)
467    
468      def LayerOutlineColor(self):      def LayerOutlineColor(self):
469          layer = self.current_layer()          layer = self.current_layer()
470          if layer is not None:          if layer is not None:
471              color = self.choose_color()              color = self.choose_color()
472              if color is not None:              if color is not None:
473                  layer.SetStroke(color)                  layer.GetClassification().SetDefaultLineColor(color)
474    
475      def LayerNoOutline(self):      def LayerNoOutline(self):
476          layer = self.current_layer()          layer = self.current_layer()
477          if layer is not None:          if layer is not None:
478              layer.SetStroke(None)              layer.GetClassification().SetDefaultLineColor(Color.None)
479    
480      def HideLayer(self):      def HideLayer(self):
481          layer = self.current_layer()          layer = self.current_layer()
# Line 479  class MainWindow(wxFrame): Line 495  class MainWindow(wxFrame):
495              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
496              if dialog is None:              if dialog is None:
497                  dialog = tableview.LayerTableFrame(self, self.interactor, name,                  dialog = tableview.LayerTableFrame(self, self.interactor, name,
498                                                     "Table: %s" % layer.Title(),                                                     _("Table: %s") % layer.Title(),
499                                                     layer, table)                                                     layer, table)
500                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
501                  dialog.Show(true)                  dialog.Show(true)
# Line 505  class MainWindow(wxFrame): Line 521  class MainWindow(wxFrame):
521          proj4Dlg.Destroy()          proj4Dlg.Destroy()
522    
523      def Classify(self):      def Classify(self):
524          classifyDlg = classifier.Classifier(NULL, self.current_layer())  
525            #
526          classifyDlg.ShowModal()          # the menu option for this should only be available if there
527          classifyDlg.Destroy()          # is a current layer, so we don't need to check if the
528            # current layer is None
529            #
530    
531            layer = self.current_layer()
532            name = "classifier" + str(id(layer))
533            dialog = self.get_open_dialog(name)
534    
535            if dialog is None:
536                dialog = classifier.Classifier(self, self.interactor,
537                                               name, self.current_layer())
538                self.add_dialog(name, dialog)
539                dialog.Show()
540    
541      def ZoomInTool(self):      def ZoomInTool(self):
542          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
# Line 603  def _has_visible_map(context): Line 631  def _has_visible_map(context):
631    
632    
633  # File menu  # File menu
634  _method_command("new_session", "&New Session", "NewSession")  _method_command("new_session", _("&New Session"), "NewSession")
635  _method_command("open_session", "&Open Session", "OpenSession")  _method_command("open_session", _("&Open Session"), "OpenSession")
636  _method_command("save_session", "&Save Session", "SaveSession")  _method_command("save_session", _("&Save Session"), "SaveSession")
637  _method_command("save_session_as", "Save Session &As", "SaveSessionAs")  _method_command("save_session_as", _("Save Session &As"), "SaveSessionAs")
638  _method_command("show_session_tree", "Show Session &Tree", "ShowSessionTree",  _method_command("show_session_tree", _("Show Session &Tree"), "ShowSessionTree",
639                  sensitive = _has_tree_window_shown)                  sensitive = _has_tree_window_shown)
640  _method_command("exit", "E&xit", "Exit")  _method_command("exit", _("E&xit"), "Exit")
641    
642  # Help menu  # Help menu
643  _method_command("help_about", "&About", "About")  _method_command("help_about", _("&About"), "About")
644    
645    
646  # Map menu  # Map menu
647  _method_command("map_projection", "Pro&jection", "Projection")  _method_command("map_projection", _("Pro&jection"), "Projection")
   
648    
649  _tool_command("map_zoom_in_tool", "&Zoom in", "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
650                helptext = "Switch to map-mode 'zoom-in'", icon = "zoom_in",                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
651                sensitive = _has_visible_map)                sensitive = _has_visible_map)
652  _tool_command("map_zoom_out_tool", "Zoom &out", "ZoomOutTool", "ZoomOutTool",  _tool_command("map_zoom_out_tool", _("Zoom &out"), "ZoomOutTool", "ZoomOutTool",
653                helptext = "Switch to map-mode 'zoom-out'", icon = "zoom_out",                helptext = _("Switch to map-mode 'zoom-out'"), icon = "zoom_out",
654                sensitive = _has_visible_map)                sensitive = _has_visible_map)
655  _tool_command("map_pan_tool", "&Pan", "PanTool", "PanTool",  _tool_command("map_pan_tool", _("&Pan"), "PanTool", "PanTool",
656                helptext = "Switch to map-mode 'pan'", icon = "pan",                helptext = _("Switch to map-mode 'pan'"), icon = "pan",
657                sensitive = _has_visible_map)                sensitive = _has_visible_map)
658  _tool_command("map_identify_tool", "&Identify", "IdentifyTool", "IdentifyTool",  _tool_command("map_identify_tool", _("&Identify"), "IdentifyTool",
659                helptext = "Switch to map-mode 'identify'", icon = "identify",                "IdentifyTool",
660                  helptext = _("Switch to map-mode 'identify'"), icon = "identify",
661                sensitive = _has_visible_map)                sensitive = _has_visible_map)
662  _tool_command("map_label_tool", "&Label", "LabelTool", "LabelTool",  _tool_command("map_label_tool", _("&Label"), "LabelTool", "LabelTool",
663                helptext = "Add/Remove labels", icon = "label",                helptext = _("Add/Remove labels"), icon = "label",
664                sensitive = _has_visible_map)                sensitive = _has_visible_map)
665  _method_command("map_full_extent", "&Full extent", "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
666                 helptext = "Full Extent", icon = "fullextent",                 helptext = _("Full Extent"), icon = "fullextent",
667                sensitive = _has_visible_map)                sensitive = _has_visible_map)
668  _method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map")  _method_command("map_print", _("Prin&t"), "PrintMap",
669                    helptext = _("Print the map"))
670    
671  # Layer menu  # Layer menu
672  _method_command("layer_add", "&Add Layer", "AddLayer",  _method_command("layer_add", _("&Add Layer"), "AddLayer",
673                  helptext = "Add a new layer to active map")                  helptext = _("Add a new layer to active map"))
674  _method_command("layer_remove", "&Remove Layer", "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
675                  helptext = "Remove selected layer(s)",                  helptext = _("Remove selected layer(s)"),
676                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
677  _method_command("layer_fill_color", "&Fill Color", "LayerFillColor",  _method_command("layer_fill_color", _("&Fill Color"), "LayerFillColor",
678                  helptext = "Set the fill color of selected layer(s)",                  helptext = _("Set the fill color of selected layer(s)"),
679                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
680  _method_command("layer_transparent_fill", "&Transparent Fill",  _method_command("layer_transparent_fill", _("&Transparent Fill"),
681                  "LayerTransparentFill",                  "LayerTransparentFill",
682                  helptext = "Do not fill the selected layer(s)",                  helptext = _("Do not fill the selected layer(s)"),
683                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
684  _method_command("layer_outline_color", "&Outline Color", "LayerOutlineColor",  _method_command("layer_outline_color", _("&Outline Color"), "LayerOutlineColor",
685                  helptext = "Set the outline color of selected layer(s)",                  helptext = _("Set the outline color of selected layer(s)"),
686                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
687  _method_command("layer_no_outline", "&No Outline", "LayerNoOutline",  _method_command("layer_no_outline", _("&No Outline"), "LayerNoOutline",
688                  helptext = "Do not draw the outline of the selected layer(s)",                  helptext= _("Do not draw the outline of the selected layer(s)"),
689                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
690  _method_command("layer_raise", "&Raise", "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
691                  helptext = "Raise selected layer(s)",                  helptext = _("Raise selected layer(s)"),
692                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
693  _method_command("layer_lower", "&Lower", "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
694                  helptext = "Lower selected layer(s)",                  helptext = _("Lower selected layer(s)"),
695                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
696  _method_command("layer_show", "&Show", "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
697                  helptext = "Make selected layer(s) visible",                  helptext = _("Make selected layer(s) visible"),
698                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
699  _method_command("layer_hide", "&Hide", "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
700                  helptext = "Make selected layer(s) unvisible",                  helptext = _("Make selected layer(s) unvisible"),
701                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
702  _method_command("layer_show_table", "Show Ta&ble", "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
703                  helptext = "Show the selected layer's table",                  helptext = _("Show the selected layer's table"),
704                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
705    
706  _method_command("layer_classifier", "Classify", "Classify",  _method_command("layer_classifier", _("Classify"), "Classify",
707                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
708    
709  # the menu structure  # the menu structure
710  main_menu = Menu("<main>", "<main>",  main_menu = Menu("<main>", "<main>",
711                   [Menu("file", "&File",                   [Menu("file", _("&File"),
712                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
713                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
714                          "show_session_tree", None,                          "show_session_tree", None,
715                          "exit"]),                          "exit"]),
716                    Menu("map", "&Map",                    Menu("map", _("&Map"),
717                         ["layer_add", "layer_remove",                         ["layer_add", "layer_remove",
718                          None,                          None,
719                          "map_projection",                          "map_projection",
# Line 695  main_menu = Menu("<main>", "<main>", Line 724  main_menu = Menu("<main>", "<main>",
724                          "map_full_extent",                          "map_full_extent",
725                          None,                          None,
726                          "map_print"]),                          "map_print"]),
727                    Menu("layer", "&Layer",                    Menu("layer", _("&Layer"),
728                         ["layer_fill_color", "layer_transparent_fill",                         ["layer_fill_color", "layer_transparent_fill",
729                          "layer_outline_color", "layer_no_outline",                          "layer_outline_color", "layer_no_outline",
730                          None,                          None,
# Line 706  main_menu = Menu("<main>", "<main>", Line 735  main_menu = Menu("<main>", "<main>",
735                          "layer_show_table",                          "layer_show_table",
736                          None,                          None,
737                          "layer_classifier"]),                          "layer_classifier"]),
738                    Menu("help", "&Help",                    Menu("help", _("&Help"),
739                         ["help_about"])])                         ["help_about"])])
740    
741  # the main toolbar  # the main toolbar

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26