/[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 487 by jonathan, Fri Mar 7 18:21:03 2003 UTC revision 535 by bh, Fri Mar 14 20:42:18 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 32  from menu import Menu Line 35  from menu import Menu
35    
36  from context import Context  from context import Context
37  from command import registry, Command, ToolCommand  from command import registry, Command, ToolCommand
38  from messages import SELECTED_SHAPE, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION
39    
40    
41  # the directory where the toolbar icons are stored  # the directory where the toolbar icons are stored
# Line 42  bitmapext = ".xpm" Line 45  bitmapext = ".xpm"
45    
46  class MainWindow(wxFrame):  class MainWindow(wxFrame):
47    
48        # Some messages that can be subscribed/unsubscribed directly through
49        # the MapCanvas come in fact from other objects. This is a map to
50        # map those messages to the names of the instance variables they
51        # actually come from. This delegation is implemented in the
52        # Subscribe and unsubscribed methods
53        delegated_messages = {LAYER_SELECTED: "canvas",
54                              SHAPES_SELECTED: "canvas"}
55    
56        # Methods delegated to some instance variables. The delegation is
57        # implemented in the __getattr__ method.
58        delegated_methods = {"SelectLayer": "canvas",
59                             "SelectShapes": "canvas",
60                             }
61    
62      def __init__(self, parent, ID, title, application, interactor,      def __init__(self, parent, ID, title, application, interactor,
63                   initial_message = None, size = wxSize(-1, -1)):                   initial_message = None, size = wxSize(-1, -1)):
64          wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)          wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
65    
66          self.application = application          self.application = application
         self.interactor = interactor  
67    
68          self.CreateStatusBar()          self.CreateStatusBar()
69          if initial_message:          if initial_message:
# Line 66  class MainWindow(wxFrame): Line 82  class MainWindow(wxFrame):
82          toolbar.Realize()          toolbar.Realize()
83    
84          # Create the map canvas          # Create the map canvas
85          canvas = view.MapCanvas(self, -1, interactor)          canvas = view.MapCanvas(self, -1)
86          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)
87            canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)
88          self.canvas = canvas          self.canvas = canvas
89    
90          self.init_dialogs()          self.init_dialogs()
91    
         interactor.Subscribe(SELECTED_SHAPE, self.identify_view_on_demand)  
   
92          EVT_CLOSE(self, self.OnClose)          EVT_CLOSE(self, self.OnClose)
93    
94        def Subscribe(self, channel, *args):
95            """Subscribe a function to a message channel.
96    
97            If channel is one of the delegated messages call the appropriate
98            object's Subscribe method. Otherwise do nothing.
99            """
100            if channel in self.delegated_messages:
101                object = getattr(self, self.delegated_messages[channel])
102                object.Subscribe(channel, *args)
103            else:
104                print "Trying to subscribe to unsupported channel %s" % channel
105    
106        def Unsubscribe(self, channel, *args):
107            """Unsubscribe a function from a message channel.
108    
109            If channel is one of the delegated messages call the appropriate
110            object's Unsubscribe method. Otherwise do nothing.
111            """
112            if channel in self.delegated_messages:
113                object = getattr(self, self.delegated_messages[channel])
114                object.Unsubscribe(channel, *args)
115    
116        def __getattr__(self, attr):
117            """If attr is one of the delegated methods return that method
118    
119            Otherwise raise AttributeError.
120            """
121            if attr in self.delegated_methods:
122                return getattr(getattr(self, self.delegated_methods[attr]), attr)
123            raise AttributeError(attr)
124    
125      def init_ids(self):      def init_ids(self):
126          """Initialize the ids"""          """Initialize the ids"""
127          self.current_id = 6000          self.current_id = 6000
# Line 299  class MainWindow(wxFrame): Line 345  class MainWindow(wxFrame):
345      def prepare_new_session(self):      def prepare_new_session(self):
346          for d in self.dialogs.values():          for d in self.dialogs.values():
347              if not isinstance(d, tree.SessionTreeView):              if not isinstance(d, tree.SessionTreeView):
348                  d.Shutdown()                  d.Close()
349    
350      def NewSession(self):      def NewSession(self):
351          self.save_modified_session()          self.save_modified_session()
# Line 355  class MainWindow(wxFrame): Line 401  class MainWindow(wxFrame):
401          if dialog is None:          if dialog is None:
402              dialog = tree.SessionTreeView(self, self.application, name)              dialog = tree.SessionTreeView(self, self.application, name)
403              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
404              dialog.Show(true)              dialog.Show(True)
405          else:          else:
406              # FIXME: bring dialog to front here              # FIXME: bring dialog to front here
407              pass              pass
408    
409    
410      def About(self):      def About(self):
411          self.RunMessageBox(_("About"),          self.RunMessageBox(_("About"),
412                             _("Thuban is a program for\n"                             _("Thuban v%s\n"
413                                #"Build Date: %s\n"
414                                "\n"
415                                "Thuban is a program for\n"
416                              "exploring geographic data.\n"                              "exploring geographic data.\n"
417                              "Copyright (C) 2001-2003 Intevation GmbH.\n"                              "Copyright (C) 2001-2003 Intevation GmbH.\n"
418                              "Thuban is licensed under the GPL"),                              "Thuban is licensed under the GNU GPL"
419                               % __ThubanVersion__), #__BuildDate__)),
420                             wxOK | wxICON_INFORMATION)                             wxOK | wxICON_INFORMATION)
421    
422      def AddLayer(self):      def AddLayer(self):
# Line 385  class MainWindow(wxFrame): Line 436  class MainWindow(wxFrame):
436                                     _("Can't open the file '%s'.") % filename)                                     _("Can't open the file '%s'.") % filename)
437              else:              else:
438                  if not has_layers:                  if not has_layers:
439                      # if we're adding a layer to an empty map, for the                      # if we're adding a layer to an empty map, fit the
440                      # new map to the window                      # new map to the window
441                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
442          dlg.Destroy()          dlg.Destroy()
# Line 423  class MainWindow(wxFrame): Line 474  class MainWindow(wxFrame):
474    
475          If no layer is selected, return None          If no layer is selected, return None
476          """          """
477          return self.interactor.SelectedLayer()          return self.canvas.SelectedLayer()
478    
479      def has_selected_layer(self):      def has_selected_layer(self):
480          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
481          return self.interactor.HasSelectedLayer()          return self.canvas.HasSelectedLayer()
482    
483      def choose_color(self):      def choose_color(self):
484          """Run the color selection dialog and return the selected color.          """Run the color selection dialog and return the selected color.
# Line 486  class MainWindow(wxFrame): Line 537  class MainWindow(wxFrame):
537              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
538              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
539              if dialog is None:              if dialog is None:
540                  dialog = tableview.LayerTableFrame(self, self.interactor, name,                  dialog = tableview.LayerTableFrame(self, name,
541                                                     _("Table: %s") % layer.Title(),                                                 _("Table: %s") % layer.Title(),
542                                                     layer, table)                                                     layer, table)
543                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
544                  dialog.Show(true)                  dialog.Show(true)
# Line 525  class MainWindow(wxFrame): Line 576  class MainWindow(wxFrame):
576          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
577    
578          if dialog is None:          if dialog is None:
579              dialog = classifier.Classifier(self, self.interactor,              dialog = classifier.Classifier(self, name, self.current_layer())
                                            name, self.current_layer())  
580              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
581              dialog.Show()              dialog.Show()
582    
# Line 552  class MainWindow(wxFrame): Line 602  class MainWindow(wxFrame):
602      def PrintMap(self):      def PrintMap(self):
603          self.canvas.Print()          self.canvas.Print()
604    
605      def identify_view_on_demand(self, layer, shape):      def identify_view_on_demand(self, layer, shapes):
606          name = "identify_view"          name = "identify_view"
607          if self.canvas.CurrentTool() == "IdentifyTool":          if self.canvas.CurrentTool() == "IdentifyTool":
608              if not self.dialog_open(name):              if not self.dialog_open(name):
609                  dialog = identifyview.IdentifyView(self, self.interactor, name)                  dialog = identifyview.IdentifyView(self, name)
610                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
611                  dialog.Show(true)                  dialog.Show(true)
612              else:              else:

Legend:
Removed from v.487  
changed lines
  Added in v.535

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26