/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/view.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/view.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6 by bh, Tue Aug 28 15:41:52 2001 UTC revision 45 by bh, Fri Sep 7 15:00:21 2001 UTC
# Line 232  class MapCanvas(wxWindow): Line 232  class MapCanvas(wxWindow):
232    
233      """A widget that displays a map and offers some interaction"""      """A widget that displays a map and offers some interaction"""
234    
235      def __init__(self, parent, winid):      def __init__(self, parent, winid, interactor):
236          wxWindow.__init__(self, parent, winid)          wxWindow.__init__(self, parent, winid)
237          self.SetBackgroundColour(wxColour(255, 255, 255))          self.SetBackgroundColour(wxColour(255, 255, 255))
238          self.map = None          self.map = None
# Line 246  class MapCanvas(wxWindow): Line 246  class MapCanvas(wxWindow):
246          EVT_LEFT_UP(self, self.OnLeftUp)          EVT_LEFT_UP(self, self.OnLeftUp)
247          EVT_MOTION(self, self.OnMotion)          EVT_MOTION(self, self.OnMotion)
248          wx.EVT_IDLE(self, self.OnIdle)          wx.EVT_IDLE(self, self.OnIdle)
249          import main          self.interactor = interactor
         self.interactor = main.app.interactor  
250          self.interactor.Subscribe(SELECTED_SHAPE, self.shape_selected)          self.interactor.Subscribe(SELECTED_SHAPE, self.shape_selected)
251    
252      def OnPaint(self, event):      def OnPaint(self, event):
# Line 338  class MapCanvas(wxWindow): Line 337  class MapCanvas(wxWindow):
337      def FitRectToWindow(self, rect):      def FitRectToWindow(self, rect):
338          width, height = self.GetSizeTuple()          width, height = self.GetSizeTuple()
339          llx, lly, urx, ury = rect          llx, lly, urx, ury = rect
340            if llx == urx or lly == ury:
341                # zero with or zero height. Do Nothing
342                return
343          scalex = width / (urx - llx)          scalex = width / (urx - llx)
344          scaley = height / (ury - lly)          scaley = height / (ury - lly)
345          scale = min(scalex, scaley)          scale = min(scalex, scaley)
# Line 434  class MapCanvas(wxWindow): Line 436  class MapCanvas(wxWindow):
436      def shape_selected(self, layer, shape):      def shape_selected(self, layer, shape):
437          self.redraw()          self.redraw()
438    
439      def find_shape_at(self, px, py, select_labels = 0):      def find_shape_at(self, px, py, select_labels = 0, selected_layer = 1):
440          """Return a tuple shape at point px, py in window coords."""          """Determine the shape at point px, py in window coords
441    
442            Return the shape and the corresponding layer as a tuple (layer,
443            shape).
444    
445            If the optional parameter select_labels is true (default false)
446            search through the labels. If a label is found return it's index
447            as the shape and None as the layer.
448    
449            If the optional parameter selected_layer is true (default), only
450            search in the currently selected layer.
451            """
452          map_proj = self.map.projection          map_proj = self.map.projection
453          if map_proj is not None:          if map_proj is not None:
454              forward = map_proj.Forward              forward = map_proj.Forward
# Line 478  class MapCanvas(wxWindow): Line 491  class MapCanvas(wxWindow):
491                          y = y - height/2                          y = y - height/2
492                      if x <= px < x + width and y <= py <= y + height:                      if x <= px < x + width and y <= py <= y + height:
493                          return None, i                          return None, i
494                    
495          layers = self.map.Layers()          if selected_layer:
496                layer = self.interactor.SelectedLayer()
497                if layer is not None:
498                    layers = [layer]
499                else:
500                    # no layer selected. Use an empty list to effectively
501                    # ignore all layers.
502                    layers = []
503            else:
504                layers = self.map.Layers()
505    
506          for layer_index in range(len(layers) - 1, -1, -1):          for layer_index in range(len(layers) - 1, -1, -1):
507              layer = layers[layer_index]              layer = layers[layer_index]
508    
# Line 540  class MapCanvas(wxWindow): Line 563  class MapCanvas(wxWindow):
563    
564      def SelectShapeAt(self, x, y):      def SelectShapeAt(self, x, y):
565          layer, shape = self.find_shape_at(x, y)          layer, shape = self.find_shape_at(x, y)
566            # If layer is None, then shape will also be None. We don't want
567            # to deselect the currently selected layer, so we simply select
568            # the already selected layer again.
569            if layer is None:
570                layer = self.interactor.SelectedLayer()
571          self.interactor.SelectLayerAndShape(layer, shape)          self.interactor.SelectLayerAndShape(layer, shape)
572    
573      def LabelShapeAt(self, x, y):      def LabelShapeAt(self, x, y):

Legend:
Removed from v.6  
changed lines
  Added in v.45

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26