/[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 450 by jonathan, Tue Mar 4 10:33:28 2003 UTC revision 550 by jonathan, Thu Mar 20 09:45:19 2003 UTC
# Line 1  Line 1 
1  # Copyright (C) 2001, 2002 by Intevation GmbH  # Copyright (C) 2001, 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Jan-Oliver Wagner <[email protected]>  # Jan-Oliver Wagner <[email protected]>
4  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
# 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 *
# Line 28  import tree Line 31  import tree
31  import proj4dialog  import proj4dialog
32  import tableview, identifyview  import tableview, identifyview
33  import classifier  import classifier
34    import legend
35  from menu import Menu  from menu import Menu
36    
37  from context import Context  from context import Context
38  from command import registry, Command, ToolCommand  from command import registry, Command, ToolCommand
39  from messages import SELECTED_SHAPE, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION
40    
41    
42  # the directory where the toolbar icons are stored  # the directory where the toolbar icons are stored
# Line 42  bitmapext = ".xpm" Line 46  bitmapext = ".xpm"
46    
47  class MainWindow(wxFrame):  class MainWindow(wxFrame):
48    
49        # Some messages that can be subscribed/unsubscribed directly through
50        # the MapCanvas come in fact from other objects. This is a map to
51        # map those messages to the names of the instance variables they
52        # actually come from. This delegation is implemented in the
53        # Subscribe and unsubscribed methods
54        delegated_messages = {LAYER_SELECTED: "canvas",
55                              SHAPES_SELECTED: "canvas"}
56    
57        # Methods delegated to some instance variables. The delegation is
58        # implemented in the __getattr__ method.
59        delegated_methods = {"SelectLayer": "canvas",
60                             "SelectShapes": "canvas",
61                             }
62    
63      def __init__(self, parent, ID, title, application, interactor,      def __init__(self, parent, ID, title, application, interactor,
64                   initial_message = None, size = wxSize(-1, -1)):                   initial_message = None, size = wxSize(-1, -1)):
65          wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)          wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
66    
67          self.application = application          self.application = application
         self.interactor = interactor  
68    
69          self.CreateStatusBar()          self.CreateStatusBar()
70          if initial_message:          if initial_message:
# Line 66  class MainWindow(wxFrame): Line 83  class MainWindow(wxFrame):
83          toolbar.Realize()          toolbar.Realize()
84    
85          # Create the map canvas          # Create the map canvas
86          canvas = view.MapCanvas(self, -1, interactor)          canvas = view.MapCanvas(self, -1)
87          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)
88            canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)
89          self.canvas = canvas          self.canvas = canvas
90    
91          self.init_dialogs()          self.init_dialogs()
92    
         interactor.Subscribe(SELECTED_SHAPE, self.identify_view_on_demand)  
   
93          EVT_CLOSE(self, self.OnClose)          EVT_CLOSE(self, self.OnClose)
94    
95        def Subscribe(self, channel, *args):
96            """Subscribe a function to a message channel.
97    
98            If channel is one of the delegated messages call the appropriate
99            object's Subscribe method. Otherwise do nothing.
100            """
101            if channel in self.delegated_messages:
102                object = getattr(self, self.delegated_messages[channel])
103                object.Subscribe(channel, *args)
104            else:
105                print "Trying to subscribe to unsupported channel %s" % channel
106    
107        def Unsubscribe(self, channel, *args):
108            """Unsubscribe a function from a message channel.
109    
110            If channel is one of the delegated messages call the appropriate
111            object's Unsubscribe method. Otherwise do nothing.
112            """
113            if channel in self.delegated_messages:
114                object = getattr(self, self.delegated_messages[channel])
115                object.Unsubscribe(channel, *args)
116    
117        def __getattr__(self, attr):
118            """If attr is one of the delegated methods return that method
119    
120            Otherwise raise AttributeError.
121            """
122            if attr in self.delegated_methods:
123                return getattr(getattr(self, self.delegated_methods[attr]), attr)
124            raise AttributeError(attr)
125    
126      def init_ids(self):      def init_ids(self):
127          """Initialize the ids"""          """Initialize the ids"""
128          self.current_id = 6000          self.current_id = 6000
# Line 296  class MainWindow(wxFrame): Line 343  class MainWindow(wxFrame):
343              result = wxID_NO              result = wxID_NO
344          return result          return result
345    
346        def prepare_new_session(self):
347            for d in self.dialogs.values():
348                if not isinstance(d, tree.SessionTreeView):
349                    d.Close()
350    
351      def NewSession(self):      def NewSession(self):
352          self.save_modified_session()          self.save_modified_session()
353            self.prepare_new_session()
354          self.application.SetSession(create_empty_session())          self.application.SetSession(create_empty_session())
355    
356      def OpenSession(self):      def OpenSession(self):
357          self.save_modified_session()          self.save_modified_session()
358          dlg = wxFileDialog(self, _("Open Session"), ".", "",          dlg = wxFileDialog(self, _("Open Session"), ".", "", "*.thuban", wxOPEN)
                            "*.thuban", wxOPEN)  
359          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
360                self.prepare_new_session()
361              self.application.OpenSession(dlg.GetPath())              self.application.OpenSession(dlg.GetPath())
362          dlg.Destroy()          dlg.Destroy()
363    
364      def SaveSession(self):      def SaveSession(self):
365          if self.application.session.filename == None:          if self.application.session.filename == None:
366              self.SaveSessionAs()              self.SaveSessionAs()
367          self.application.SaveSession()          else:
368                self.application.SaveSession()
369    
370      def SaveSessionAs(self):      def SaveSessionAs(self):
371          dlg = wxFileDialog(self, _("Save Session As"), ".", "",          dlg = wxFileDialog(self, _("Save Session As"), ".", "",
# Line 348  class MainWindow(wxFrame): Line 402  class MainWindow(wxFrame):
402          if dialog is None:          if dialog is None:
403              dialog = tree.SessionTreeView(self, self.application, name)              dialog = tree.SessionTreeView(self, self.application, name)
404              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
405              dialog.Show(true)              dialog.Show(True)
406          else:          else:
407              # FIXME: bring dialog to front here              # FIXME: bring dialog to front here
408              pass              pass
409    
410    
411      def About(self):      def About(self):
412          self.RunMessageBox(_("About"),          self.RunMessageBox(_("About"),
413                             _("Thuban is a program for\n"                             _("Thuban v%s\n"
414                                #"Build Date: %s\n"
415                                "\n"
416                                "Thuban is a program for\n"
417                              "exploring geographic data.\n"                              "exploring geographic data.\n"
418                              "Copyright (C) 2001-2003 Intevation GmbH.\n"                              "Copyright (C) 2001-2003 Intevation GmbH.\n"
419                              "Thuban is licensed under the GPL"),                              "Thuban is licensed under the GNU GPL"
420                               % __ThubanVersion__), #__BuildDate__)),
421                             wxOK | wxICON_INFORMATION)                             wxOK | wxICON_INFORMATION)
422    
423      def AddLayer(self):      def AddLayer(self):
# Line 378  class MainWindow(wxFrame): Line 437  class MainWindow(wxFrame):
437                                     _("Can't open the file '%s'.") % filename)                                     _("Can't open the file '%s'.") % filename)
438              else:              else:
439                  if not has_layers:                  if not has_layers:
440                      # if we're adding a layer to an empty map, for the                      # if we're adding a layer to an empty map, fit the
441                      # new map to the window                      # new map to the window
442                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
443          dlg.Destroy()          dlg.Destroy()
# Line 416  class MainWindow(wxFrame): Line 475  class MainWindow(wxFrame):
475    
476          If no layer is selected, return None          If no layer is selected, return None
477          """          """
478          return self.interactor.SelectedLayer()          return self.canvas.SelectedLayer()
479    
480      def has_selected_layer(self):      def has_selected_layer(self):
481          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
482          return self.interactor.HasSelectedLayer()          return self.canvas.HasSelectedLayer()
483    
484      def choose_color(self):      def choose_color(self):
485          """Run the color selection dialog and return the selected color.          """Run the color selection dialog and return the selected color.
# Line 455  class MainWindow(wxFrame): Line 514  class MainWindow(wxFrame):
514          if layer is not None:          if layer is not None:
515              color = self.choose_color()              color = self.choose_color()
516              if color is not None:              if color is not None:
517                  layer.GetClassification().SetDefaultStroke(color)                  layer.GetClassification().SetDefaultLineColor(color)
518    
519      def LayerNoOutline(self):      def LayerNoOutline(self):
520          layer = self.current_layer()          layer = self.current_layer()
521          if layer is not None:          if layer is not None:
522              layer.GetClassification().SetDefaultStroke(Color.None)              layer.GetClassification().SetDefaultLineColor(Color.None)
523    
524      def HideLayer(self):      def HideLayer(self):
525          layer = self.current_layer()          layer = self.current_layer()
# Line 479  class MainWindow(wxFrame): Line 538  class MainWindow(wxFrame):
538              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
539              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
540              if dialog is None:              if dialog is None:
541                  dialog = tableview.LayerTableFrame(self, self.interactor, name,                  dialog = tableview.LayerTableFrame(self, name,
542                                                     _("Table: %s") % layer.Title(),                                                 _("Table: %s") % layer.Title(),
543                                                     layer, table)                                                     layer, table)
544                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
545                  dialog.Show(true)                  dialog.Show(true)
# Line 506  class MainWindow(wxFrame): Line 565  class MainWindow(wxFrame):
565          proj4Dlg.Destroy()          proj4Dlg.Destroy()
566    
567      def Classify(self):      def Classify(self):
568          classifyDlg = classifier.Classifier(NULL, self.current_layer())  
569            #
570          classifyDlg.ShowModal()          # the menu option for this should only be available if there
571          classifyDlg.Destroy()          # is a current layer, so we don't need to check if the
572            # current layer is None
573            #
574    
575            layer = self.current_layer()
576            self.OpenClassifier(layer)
577    
578        def OpenClassifier(self, layer):
579            name = "classifier" + str(id(layer))
580            dialog = self.get_open_dialog(name)
581    
582            if dialog is None:
583                dialog = classifier.Classifier(self, name, layer)
584                self.add_dialog(name, dialog)
585                dialog.Show()
586    
587    
588        def ShowLegend(self):
589            name = "legend"
590            dialog = self.get_open_dialog(name)
591    
592            if dialog is None:
593                dialog = legend.Legend(self, name, self.Map())
594                self.add_dialog(name, dialog)
595                dialog.Show()
596    
597      def ZoomInTool(self):      def ZoomInTool(self):
598          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
# Line 533  class MainWindow(wxFrame): Line 616  class MainWindow(wxFrame):
616      def PrintMap(self):      def PrintMap(self):
617          self.canvas.Print()          self.canvas.Print()
618    
619      def identify_view_on_demand(self, layer, shape):      def identify_view_on_demand(self, layer, shapes):
620          name = "identify_view"          name = "identify_view"
621          if self.canvas.CurrentTool() == "IdentifyTool":          if self.canvas.CurrentTool() == "IdentifyTool":
622              if not self.dialog_open(name):              if not self.dialog_open(name):
623                  dialog = identifyview.IdentifyView(self, self.interactor, name)                  dialog = identifyview.IdentifyView(self, name)
624                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
625                  dialog.Show(true)                  dialog.Show(true)
626              else:              else:
# Line 602  def _has_visible_map(context): Line 685  def _has_visible_map(context):
685                  return 1                  return 1
686      return 0      return 0
687    
688    def _has_legend_shown(context):
689        """Return true if the legend window is shown"""
690        return context.mainwindow.get_open_dialog("legend") is None
691    
692    
693  # File menu  # File menu
694  _method_command("new_session", _("&New Session"), "NewSession")  _method_command("new_session", _("&New Session"), "NewSession")
# Line 675  _method_command("layer_hide", _("&Hide") Line 762  _method_command("layer_hide", _("&Hide")
762  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
763                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
764                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
   
765  _method_command("layer_classifier", _("Classify"), "Classify",  _method_command("layer_classifier", _("Classify"), "Classify",
766                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
767    _method_command("show_legend", _("Legend"), "ShowLegend",
768                    sensitive = _has_legend_shown)
769    
770  # the menu structure  # the menu structure
771  main_menu = Menu("<main>", "<main>",  main_menu = Menu("<main>", "<main>",
# Line 685  main_menu = Menu("<main>", "<main>", Line 773  main_menu = Menu("<main>", "<main>",
773                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
774                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
775                          "show_session_tree", None,                          "show_session_tree", None,
776                            "show_legend", None,
777                          "exit"]),                          "exit"]),
778                    Menu("map", _("&Map"),                    Menu("map", _("&Map"),
779                         ["layer_add", "layer_remove",                         ["layer_add", "layer_remove",

Legend:
Removed from v.450  
changed lines
  Added in v.550

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26