/[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 2529 by russell, Thu Jan 20 17:55:23 2005 UTC revision 2551 by jonathan, Thu Jan 27 14:19:41 2005 UTC
# Line 1  Line 1 
1  # Copyright (C) 2001, 2002, 2003, 2004 by Intevation GmbH  # Copyright (C) 2001, 2002, 2003, 2004, 2005 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 23  from wxPython.wx import * Line 23  from wxPython.wx import *
23  import Thuban  import Thuban
24    
25  from Thuban import _  from Thuban import _
26  from Thuban.Model.messages import TITLE_CHANGED  from Thuban.Model.messages import TITLE_CHANGED, LAYER_PROJECTION_CHANGED, \
27         MAP_PROJECTION_CHANGED, MAP_LAYERS_ADDED, MAP_LAYERS_REMOVED
28    
29  from Thuban.Model.session import create_empty_session  from Thuban.Model.session import create_empty_session
30  from Thuban.Model.layer import Layer, RasterLayer  from Thuban.Model.layer import Layer, RasterLayer
31  from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support  from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support
# Line 52  import Thuban.Model.resource Line 54  import Thuban.Model.resource
54    
55  import projdialog  import projdialog
56    
57    from Thuban.UI.classifier import Classifier
58    from Thuban.UI.rasterlayerproperties import RasterLayerProperties
59    from Thuban.Model.layer import RasterLayer
60    
61  from Thuban.Lib.classmapper import ClassMapper  from Thuban.Lib.classmapper import ClassMapper
62    
63  layer_properties_dialogs = ClassMapper()  layer_properties_dialogs = ClassMapper()
64    layer_properties_dialogs.add(RasterLayer, RasterLayerProperties)
65    layer_properties_dialogs.add(Layer, Classifier)
66    
67  class MainWindow(DockFrame):  class MainWindow(DockFrame):
68    
# Line 75  class MainWindow(DockFrame): Line 83  class MainWindow(DockFrame):
83                           "SelectedShapes": "canvas",                           "SelectedShapes": "canvas",
84                           }                           }
85    
86        # Messages from the canvas that may require a status bar update.
87        # The update_status_bar method will be subscribed to these messages.
88        update_status_bar_messages = (VIEW_POSITION, LAYER_PROJECTION_CHANGED,
89                                      MAP_PROJECTION_CHANGED, MAP_LAYERS_ADDED,
90                                      MAP_LAYERS_REMOVED)
91    
92      def __init__(self, parent, ID, title, application, interactor,      def __init__(self, parent, ID, title, application, interactor,
93                   initial_message = None, size = wxSize(-1, -1)):                   initial_message = None, size = wxSize(-1, -1)):
94          DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)          DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
# Line 101  class MainWindow(DockFrame): Line 115  class MainWindow(DockFrame):
115    
116          # Create the map canvas          # Create the map canvas
117          canvas = view.MapCanvas(self, -1)          canvas = view.MapCanvas(self, -1)
         canvas.Subscribe(VIEW_POSITION, self.view_position_changed)  
118          canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)          canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)
119          self.canvas = canvas          self.canvas = canvas
120          self.canvas.Subscribe(TITLE_CHANGED, self.title_changed)          self.canvas.Subscribe(TITLE_CHANGED, self.title_changed)
121    
122            for channel in self.update_status_bar_messages:
123                self.canvas.Subscribe(channel, self.update_status_bar)
124    
125          self.SetMainWindow(self.canvas)          self.SetMainWindow(self.canvas)
126    
127          self.SetAutoLayout(True)          self.SetAutoLayout(True)
# Line 334  class MainWindow(DockFrame): Line 350  class MainWindow(DockFrame):
350      def get_open_dialog(self, name):      def get_open_dialog(self, name):
351          return self.dialogs.get(name)          return self.dialogs.get(name)
352    
353      def view_position_changed(self):      def update_status_bar(self, *args):
354            """Handler for a bunch of messages that may require a status bar update
355    
356            Currently this handles the canvas' VIEW_POSITION_CHANGED
357            messages as well as several messages about changes in the map
358            which may affect whether and how projections are used.
359    
360            These messages affect the text in the status bar in the following way:
361    
362            When VIEW_POSITION_CHANGED messages are sent and the mouse is
363            actually in the canvas window, display the current mouse
364            coordinates as defined by the canvas' CurrentPosition method.
365    
366            If there is no current position to show, check whether there is
367            a potential problem with the map and layer projections and
368            display a message about it.  Otherwise the status bar will
369            become empty.
370    
371            The text is displayed in the status bar using the
372            set_position_text method.
373            """
374            # Implementation note: We do not really have to know which
375            # message was sent.  We can simply call the canvas'
376            # CurrentPosition method and if that returns a tuple, it was a
377            # VIEW_POSITION_CHANGED message and we have to display it.
378            # Otherwise it was a VIEW_POSITION_CHANGED message where the
379            # mouse has left the canvas or it was a message about a change
380            # to the map, in which case we check the projections.
381            #
382            # When changing this method, keep in mind that the
383            # VIEW_POSITION_CHANGED message are sent for every mouse move in
384            # the canvas window, that is they happen very often, so the path
385            # taken in that case has to be fast.
386            text = ""
387          pos = self.canvas.CurrentPosition()          pos = self.canvas.CurrentPosition()
388          if pos is not None:          if pos is not None:
389              text = "(%10.10g, %10.10g)" % pos              text = "(%10.10g, %10.10g)" % pos
390          else:          else:
391              text = ""              for layer in self.canvas.Map().Layers():
             map = self.canvas.Map()  
             for layer in map.layers:  
392                  bbox = layer.LatLongBoundingBox()                  bbox = layer.LatLongBoundingBox()
393                  if bbox:                  if bbox:
394                      left, bottom, right, top = bbox                      left, bottom, right, top = bbox
395                      if not (-180 <= left <= 180 and                      if not (-180 <= left <= 180 and
396                          -180 <= right <= 180 and                              -180 <= right <= 180 and
397                          -90 <= top <= 90 and                              -90 <= top <= 90 and
398                          -90 <= bottom <= 90):                              -90 <= bottom <= 90):
399                          text = ("Select '"+layer.title+"' and pick a " +                          text = _("Select layer '%s' and pick a projection "
400                              "projection using Layer/Projection...")                                   "using Layer/Projection...") % layer.title
401                          break                          break
402    
403          self.set_position_text(text)          self.set_position_text(text)
404    
405      def set_position_text(self, text):      def set_position_text(self, text):
406          """Set the statusbar text showing the current position.          """Set the statusbar text to that created by update_status_bar
407    
408          By default the text is shown in field 0 of the status bar.          By default the text is shown in field 0 of the status bar.
409          Override this method in derived classes to put it into a          Override this method in derived classes to put it into a
410          different field of the statusbar.          different field of the statusbar.
411          """  
412            For historical reasons this method is called set_position_text
413            because at first the text was always either the current position
414            or the empty string.  Now it can contain other messages as well.
415            The method will be renamed at one point.
416            """
417            # Note: If this method is renamed we should perhaps think about
418            # some backwards compatibility measures for projects like
419            # GREAT-ER which override this method.
420          self.SetStatusText(text)          self.SetStatusText(text)
421    
422      def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw):      def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw):
# Line 453  class MainWindow(DockFrame): Line 508  class MainWindow(DockFrame):
508              # FIXME: it would be better to tie the unsubscription to              # FIXME: it would be better to tie the unsubscription to
509              # wx's destroy event, but that isn't implemented for wxGTK              # wx's destroy event, but that isn't implemented for wxGTK
510              # yet.              # yet.
511              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)              for channel in self.update_status_bar_messages:
512                    self.canvas.Unsubscribe(channel, self.update_status_bar)
513    
514              DockFrame.OnClose(self, event)              DockFrame.OnClose(self, event)
515              for dlg in self.dialogs.values():              for dlg in self.dialogs.values():
516                  dlg.Destroy()                  dlg.Destroy()

Legend:
Removed from v.2529  
changed lines
  Added in v.2551

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26