/[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 2516 by frank, Sun Jan 9 12:32:17 2005 UTC revision 2544 by bh, Mon Jan 24 11:19:53 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 75  class MainWindow(DockFrame): Line 77  class MainWindow(DockFrame):
77                           "SelectedShapes": "canvas",                           "SelectedShapes": "canvas",
78                           }                           }
79    
80        # Messages from the canvas that may require a status bar update.
81        # The update_status_bar method will be subscribed to these messages.
82        update_status_bar_messages = (VIEW_POSITION, LAYER_PROJECTION_CHANGED,
83                                      MAP_PROJECTION_CHANGED, MAP_LAYERS_ADDED,
84                                      MAP_LAYERS_REMOVED)
85    
86      def __init__(self, parent, ID, title, application, interactor,      def __init__(self, parent, ID, title, application, interactor,
87                   initial_message = None, size = wxSize(-1, -1)):                   initial_message = None, size = wxSize(-1, -1)):
88          DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)          DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
# Line 101  class MainWindow(DockFrame): Line 109  class MainWindow(DockFrame):
109    
110          # Create the map canvas          # Create the map canvas
111          canvas = view.MapCanvas(self, -1)          canvas = view.MapCanvas(self, -1)
         canvas.Subscribe(VIEW_POSITION, self.view_position_changed)  
112          canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)          canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)
113          self.canvas = canvas          self.canvas = canvas
114          self.canvas.Subscribe(TITLE_CHANGED, self.title_changed)          self.canvas.Subscribe(TITLE_CHANGED, self.title_changed)
115    
116            for channel in self.update_status_bar_messages:
117                self.canvas.Subscribe(channel, self.update_status_bar)
118    
119          self.SetMainWindow(self.canvas)          self.SetMainWindow(self.canvas)
120    
121          self.SetAutoLayout(True)          self.SetAutoLayout(True)
# Line 334  class MainWindow(DockFrame): Line 344  class MainWindow(DockFrame):
344      def get_open_dialog(self, name):      def get_open_dialog(self, name):
345          return self.dialogs.get(name)          return self.dialogs.get(name)
346    
347      def view_position_changed(self):      def update_status_bar(self, *args):
348            """Handler for a bunch of messages that may require a status bar update
349    
350            Currently this handles the canvas' VIEW_POSITION_CHANGED
351            messages as well as several messages about changes in the map
352            which may affect whether and how projections are used.
353    
354            These messages affect the text in the status bar in the following way:
355    
356            When VIEW_POSITION_CHANGED messages are sent and the mouse is
357            actually in the canvas window, display the current mouse
358            coordinates as defined by the canvas' CurrentPosition method.
359    
360            If there is no current position to show, check whether there is
361            a potential problem with the map and layer projections and
362            display a message about it.  Otherwise the status bar will
363            become empty.
364    
365            The text is displayed in the status bar using the
366            set_position_text method.
367            """
368            # Implementation note: We do not really have to know which
369            # message was sent.  We can simply call the canvas'
370            # CurrentPosition method and if that returns a tuple, it was a
371            # VIEW_POSITION_CHANGED message and we have to display it.
372            # Otherwise it was a VIEW_POSITION_CHANGED message where the
373            # mouse has left the canvas or it was a message about a change
374            # to the map, in which case we check the projections.
375            #
376            # When changing this method, keep in mind that the
377            # VIEW_POSITION_CHANGED message are sent for every mouse move in
378            # the canvas window, that is they happen very often, so the path
379            # taken in that case has to be fast.
380            text = ""
381          pos = self.canvas.CurrentPosition()          pos = self.canvas.CurrentPosition()
382          if pos is not None:          if pos is not None:
383              text = "(%10.10g, %10.10g)" % pos              text = "(%10.10g, %10.10g)" % pos
384          else:          else:
385              text = ""              for layer in self.canvas.Map().Layers():
386                    bbox = layer.LatLongBoundingBox()
387                    if bbox:
388                        left, bottom, right, top = bbox
389                        if not (-180 <= left <= 180 and
390                                -180 <= right <= 180 and
391                                -90 <= top <= 90 and
392                                -90 <= bottom <= 90):
393                            text = _("Select layer '%s' and pick a projection "
394                                     "using Layer/Projection...") % layer.title
395                            break
396    
397          self.set_position_text(text)          self.set_position_text(text)
398    
399      def set_position_text(self, text):      def set_position_text(self, text):
400          """Set the statusbar text showing the current position.          """Set the statusbar text to that created by update_status_bar
401    
402          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.
403          Override this method in derived classes to put it into a          Override this method in derived classes to put it into a
404          different field of the statusbar.          different field of the statusbar.
405          """  
406            For historical reasons this method is called set_position_text
407            because at first the text was always either the current position
408            or the empty string.  Now it can contain other messages as well.
409            The method will be renamed at one point.
410            """
411            # Note: If this method is renamed we should perhaps think about
412            # some backwards compatibility measures for projects like
413            # GREAT-ER which override this method.
414          self.SetStatusText(text)          self.SetStatusText(text)
415    
416      def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw):      def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw):
# Line 440  class MainWindow(DockFrame): Line 502  class MainWindow(DockFrame):
502              # FIXME: it would be better to tie the unsubscription to              # FIXME: it would be better to tie the unsubscription to
503              # wx's destroy event, but that isn't implemented for wxGTK              # wx's destroy event, but that isn't implemented for wxGTK
504              # yet.              # yet.
505              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)              for channel in self.update_status_bar_messages:
506                    self.canvas.Unsubscribe(channel, self.update_status_bar)
507    
508              DockFrame.OnClose(self, event)              DockFrame.OnClose(self, event)
509              for dlg in self.dialogs.values():              for dlg in self.dialogs.values():
510                  dlg.Destroy()                  dlg.Destroy()
# Line 653  class MainWindow(DockFrame): Line 717  class MainWindow(DockFrame):
717                                layer.ShapeStore(),                                layer.ShapeStore(),
718                                projection = layer.GetProjection())                                projection = layer.GetProjection())
719              new_classification = copy.deepcopy(layer.GetClassification())              new_classification = copy.deepcopy(layer.GetClassification())
720              new_layer.SetClassificationColumn(              new_layer.SetClassificationColumn(
721                                  layer.GetClassificationColumn())                      layer.GetClassificationColumn())
722              new_layer.SetClassification(new_classification)              new_layer.SetClassification(new_classification)
723              self.Map().AddLayer(new_layer)              self.Map().AddLayer(new_layer)
724    

Legend:
Removed from v.2516  
changed lines
  Added in v.2544

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26