/[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 1221 by jonathan, Tue Jun 17 15:24:45 2003 UTC revision 1344 by jonathan, Tue Jul 1 16:11:26 2003 UTC
# Line 19  import os.path Line 19  import os.path
19    
20  from math import hypot  from math import hypot
21    
22  from wxPython.wx import wxWindow,\  from wxPython.wx import wxWindow, \
23       wxPaintDC, wxColour, wxClientDC, wxINVERT, wxTRANSPARENT_BRUSH, wxFont,\       wxPaintDC, wxColour, wxClientDC, wxINVERT, wxTRANSPARENT_BRUSH, wxFont,\
24       EVT_PAINT, EVT_LEFT_DOWN, EVT_LEFT_UP, EVT_MOTION, EVT_LEAVE_WINDOW, \       EVT_PAINT, EVT_LEFT_DOWN, EVT_LEFT_UP, EVT_MOTION, EVT_LEAVE_WINDOW, \
25       wxBITMAP_TYPE_XPM, wxBeginBusyCursor, wxEndBusyCursor, wxCursor, \       wxBITMAP_TYPE_XPM, wxCursor, wxImageFromBitmap, wxPlatform, \
26       wxImageFromBitmap, wxPlatform       wxBeginBusyCursor, wxEndBusyCursor
27    
28    
29  # Export related stuff  # Export related stuff
30  if wxPlatform == '__WXMSW__':  if wxPlatform == '__WXMSW__':
# Line 42  from Thuban.Model.layer import SHAPETYPE Line 43  from Thuban.Model.layer import SHAPETYPE
43  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \
44       ALIGN_LEFT, ALIGN_RIGHT       ALIGN_LEFT, ALIGN_RIGHT
45  from Thuban.Lib.connector import Publisher  from Thuban.Lib.connector import Publisher
46  from Thuban.Model.color import Color  from Thuban.Model.color import Color, Transparent
47    
48  import resource  import resource
49    
# Line 54  import labeldialog Line 55  import labeldialog
55  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, \  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, \
56                       SCALE_CHANGED                       SCALE_CHANGED
57    
58    #from common import ThubanBeginBusyCursor, ThubanEndBusyCursor
59    
60  #  #
61  #   The tools  #   The tools
# Line 274  class MapPrintout(wx.wxPrintout): Line 276  class MapPrintout(wx.wxPrintout):
276                             self.selected_layer, self.selected_shapes)                             self.selected_layer, self.selected_shapes)
277          return True          return True
278    
   
279  class MapCanvas(wxWindow, Publisher):  class MapCanvas(wxWindow, Publisher):
280    
281      """A widget that displays a map and offers some interaction"""      """A widget that displays a map and offers some interaction"""
# Line 336  class MapCanvas(wxWindow, Publisher): Line 337  class MapCanvas(wxWindow, Publisher):
337          self.last_selected_layer = None          self.last_selected_layer = None
338          self.last_selected_shape = None          self.last_selected_shape = None
339    
340            self.backgroundColor = wx.wxWHITE_BRUSH
341    
342          # subscribe the WX events we're interested in          # subscribe the WX events we're interested in
343          EVT_PAINT(self, self.OnPaint)          EVT_PAINT(self, self.OnPaint)
344          EVT_LEFT_DOWN(self, self.OnLeftDown)          EVT_LEFT_DOWN(self, self.OnLeftDown)
# Line 343  class MapCanvas(wxWindow, Publisher): Line 346  class MapCanvas(wxWindow, Publisher):
346          EVT_MOTION(self, self.OnMotion)          EVT_MOTION(self, self.OnMotion)
347          EVT_LEAVE_WINDOW(self, self.OnLeaveWindow)          EVT_LEAVE_WINDOW(self, self.OnLeaveWindow)
348          wx.EVT_SIZE(self, self.OnSize)          wx.EVT_SIZE(self, self.OnSize)
349            wx.EVT_IDLE(self, self.OnIdle)
350    
351      def __del__(self):      def __del__(self):
352          wxWindow.__del__(self)          wxWindow.__del__(self)
# Line 381  class MapCanvas(wxWindow, Publisher): Line 385  class MapCanvas(wxWindow, Publisher):
385    
386      def OnPaint(self, event):      def OnPaint(self, event):
387          dc = wxPaintDC(self)          dc = wxPaintDC(self)
         clear = self.map is None or not self.map.HasLayers()  
388    
389          wxBeginBusyCursor()          if self.map is not None and self.map.HasLayers():
390          try:              if self.bitmap in (None, -1):
391              if not clear:                  # set the flag that we should redraw the
392                  self.do_redraw()                  # bitmap in idle time
393                  try:                  self.bitmap = -1
394                      pass                  return
                 except:  
                     print "Error during drawing:", sys.exc_info()[0]  
                     clear = True  
   
             if clear:  
                 # If we've got no map or if the map is empty, simply clear  
                 # the screen.  
   
                 # XXX it's probably possible to get rid of this. The  
                 # background color of the window is already white and the  
                 # only thing we may have to do is to call self.Refresh()  
                 # with a true argument in the right places.  
                 dc.BeginDrawing()  
                 dc.Clear()  
                 dc.EndDrawing()  
         finally:  
             wxEndBusyCursor()  
395    
396      def do_redraw(self):              # blit the bitmap to the screen
397          # This should only be called if we have a non-empty map.              dc.BeginDrawing()
398                dc.DrawBitmap(self.bitmap, 0, 0)
399                dc.EndDrawing()
400            else:
401                # If we've got no map or if the map is empty, simply clear
402                # the screen.
403    
404          # Get the window size.              # XXX it's probably possible to get rid of this. The
405          width, height = self.GetSizeTuple()              # background color of the window is already white and the
406                # only thing we may have to do is to call self.Refresh()
407                # with a true argument in the right places.
408                dc.BeginDrawing()
409                dc.SetBackground(self.backgroundColor)
410                dc.Clear()
411                dc.EndDrawing()
412    
413        def OnIdle(self, event):
414            # render the screen if necessary
415    
416            if self.bitmap != -1:
417                return
418    
419            wxBeginBusyCursor()
420            try:
421                width, height = self.GetSizeTuple()
422    
         # If self.bitmap's still there, reuse it. Otherwise redraw it  
         if self.bitmap is not None:  
             bitmap = self.bitmap  
         else:  
423              bitmap = wx.wxEmptyBitmap(width, height)              bitmap = wx.wxEmptyBitmap(width, height)
424              dc = wx.wxMemoryDC()              dc = wx.wxMemoryDC()
425              dc.SelectObject(bitmap)              dc.SelectObject(bitmap)
426              dc.BeginDrawing()              dc.BeginDrawing()
427    
428              # clear the background              dc.SetBackground(self.backgroundColor)
             #dc.SetBrush(wx.wxWHITE_BRUSH)  
             #dc.SetPen(wx.wxTRANSPARENT_PEN)  
             #dc.DrawRectangle(0, 0, width, height)  
             dc.SetBackground(wx.wxWHITE_BRUSH)  
429              dc.Clear()              dc.Clear()
430    
431              selected_layer = self.selection.SelectedLayer()              selected_layer = self.selection.SelectedLayer()
# Line 442  class MapCanvas(wxWindow, Publisher): Line 441  class MapCanvas(wxWindow, Publisher):
441    
442              dc.EndDrawing()              dc.EndDrawing()
443              dc.SelectObject(wx.wxNullBitmap)              dc.SelectObject(wx.wxNullBitmap)
444    
445              self.bitmap = bitmap              self.bitmap = bitmap
446            finally:
447                wxEndBusyCursor()
448                pass
449    
450          # blit the bitmap to the screen          # This causes a paint event that then draws the bitmap
451          dc = wx.wxMemoryDC()          self.redraw()
         dc.SelectObject(bitmap)  
         clientdc = wxClientDC(self)  
         clientdc.BeginDrawing()  
         clientdc.Blit(0, 0, width, height, dc, 0, 0)  
         clientdc.EndDrawing()  
452    
453      def Export(self):      def Export(self):
454          if self.scale == 0:          if self.scale == 0:
# Line 530  class MapCanvas(wxWindow, Publisher): Line 528  class MapCanvas(wxWindow, Publisher):
528          return self.map          return self.map
529    
530      def redraw(self, *args):      def redraw(self, *args):
531          self.Refresh(0)          self.Refresh(False)
532    
533      def full_redraw(self, *args):      def full_redraw(self, *args):
534          self.bitmap = None          self.bitmap = None
# Line 653  class MapCanvas(wxWindow, Publisher): Line 651  class MapCanvas(wxWindow, Publisher):
651          Set the scale so that the map fits exactly into the window and          Set the scale so that the map fits exactly into the window and
652          center it in the window.          center it in the window.
653          """          """
654          bbox = self.map.ProjectedBoundingBox()          if self.map is not None:
655          if bbox is not None:              bbox = self.map.ProjectedBoundingBox()
656              self.FitRectToWindow(bbox)              if bbox is not None:
657                    self.FitRectToWindow(bbox)
658    
659      def FitLayerToWindow(self, layer):      def FitLayerToWindow(self, layer):
660          """Fit the given layer to the window.          """Fit the given layer to the window.
# Line 942  class MapCanvas(wxWindow, Publisher): Line 941  class MapCanvas(wxWindow, Publisher):
941              layer = layers[layer_index]              layer = layers[layer_index]
942    
943              # search only in visible layers              # search only in visible layers
944              if not layer.Visible():              if not layer.Visible() or not layer.HasShapes():
945                  continue                  continue
946    
947              filled = layer.GetClassification().GetDefaultFill() \              filled = layer.GetClassification().GetDefaultFill() \
948                       is not Color.Transparent                       is not Transparent
949              stroked = layer.GetClassification().GetDefaultLineColor() \              stroked = layer.GetClassification().GetDefaultLineColor() \
950                        is not Color.Transparent                        is not Transparent
951    
952              layer_proj = layer.projection              layer_proj = layer.projection
953              if layer_proj is not None:              if layer_proj is not None:

Legend:
Removed from v.1221  
changed lines
  Added in v.1344

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26