/[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 1454 by bh, Fri Jul 18 14:41:04 2003 UTC revision 1552 by bh, Wed Aug 6 17:21:32 2003 UTC
# Line 14  __version__ = "$Revision$" Line 14  __version__ = "$Revision$"
14    
15  from Thuban import _  from Thuban import _
16    
 import sys  
17  import os.path  import os.path
18    
 from math import hypot  
   
19  from wxPython.wx import wxWindow, \  from wxPython.wx import wxWindow, \
20       wxPaintDC, wxColour, wxClientDC, wxINVERT, wxTRANSPARENT_BRUSH, wxFont,\       wxPaintDC, wxColour, wxClientDC, wxINVERT, wxTRANSPARENT_BRUSH, wxFont,\
21       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, \
22       wxBITMAP_TYPE_XPM, wxCursor, wxPlatform, \       wxPlatform, wxBeginBusyCursor, wxEndBusyCursor, wxFileDialog, wxSAVE, \
      wxBeginBusyCursor, wxEndBusyCursor, wxFileDialog, wxSAVE, \  
23       wxOVERWRITE_PROMPT, wxID_OK       wxOVERWRITE_PROMPT, wxID_OK
24    
25  # Export related stuff  # Export related stuff
# Line 32  if wxPlatform == '__WXMSW__': Line 28  if wxPlatform == '__WXMSW__':
28    
29  from wxPython import wx  from wxPython import wx
30    
31  from wxproj import point_in_polygon_shape, shape_centroid  from Thuban.Model.messages import MAP_LAYERS_CHANGED, LAYER_CHANGED, \
32         LAYER_VISIBILITY_CHANGED
 from Thuban.Model.messages import \  
      MAP_PROJECTION_CHANGED, MAP_LAYERS_CHANGED, \  
      LAYER_PROJECTION_CHANGED, LAYER_CHANGED, LAYER_VISIBILITY_CHANGED  
33    
34  from renderer import ScreenRenderer, ExportRenderer, PrinterRenderer  from renderer import ScreenRenderer, ExportRenderer, PrinterRenderer
35    
# Line 118  class MapCanvas(wxWindow, ViewPort): Line 111  class MapCanvas(wxWindow, ViewPort):
111    
112          self.backgroundColor = wx.wxWHITE_BRUSH          self.backgroundColor = wx.wxWHITE_BRUSH
113    
114            # Set to true if there ever is an error during redraw. There
115            # should never be errors, but unfortunately bugs happen.
116            self.error_on_redraw = 0
117    
118          # subscribe the WX events we're interested in          # subscribe the WX events we're interested in
119          EVT_PAINT(self, self.OnPaint)          EVT_PAINT(self, self.OnPaint)
120          EVT_LEFT_DOWN(self, self.OnLeftDown)          EVT_LEFT_DOWN(self, self.OnLeftDown)
# Line 180  class MapCanvas(wxWindow, ViewPort): Line 177  class MapCanvas(wxWindow, ViewPort):
177              dc.EndDrawing()              dc.EndDrawing()
178    
179      def OnIdle(self, event):      def OnIdle(self, event):
180          # render the screen if necessary          """Idle handler. Redraw the bitmap if necessary"""
181    
182          if self.bitmap != -1:          if self.bitmap != -1:
183              return              return
184            if self.error_on_redraw:
185                return
186    
187          wxBeginBusyCursor()          wxBeginBusyCursor()
188          try:          try:
189              width, height = self.GetSizeTuple()              try:
190                    self._do_redraw()
191                except:
192                    self.error_on_redraw = True
193                    raise
194            finally:
195                wxEndBusyCursor()
196    
197              bitmap = wx.wxEmptyBitmap(width, height)      def _do_redraw(self):
198              dc = wx.wxMemoryDC()          """Called by OnIdle to do the actual redraw.
199              dc.SelectObject(bitmap)          """
200              dc.BeginDrawing()          width, height = self.GetSizeTuple()
201    
202              dc.SetBackground(self.backgroundColor)          bitmap = wx.wxEmptyBitmap(width, height)
203              dc.Clear()          dc = wx.wxMemoryDC()
204            dc.SelectObject(bitmap)
205            dc.BeginDrawing()
206    
207              selected_layer = self.selection.SelectedLayer()          dc.SetBackground(self.backgroundColor)
208              selected_shapes = self.selection.SelectedShapes()          dc.Clear()
209    
210              # draw the map into the bitmap          selected_layer = self.selection.SelectedLayer()
211              renderer = ScreenRenderer(dc, self.scale, self.offset)          selected_shapes = self.selection.SelectedShapes()
212    
213              # Pass the entire bitmap as update region to the renderer.          # draw the map into the bitmap
214              # We're redrawing the whole bitmap, after all.          renderer = ScreenRenderer(dc, self.scale, self.offset)
             renderer.RenderMap(self.Map(), (0, 0, width, height),  
                                selected_layer, selected_shapes)  
215    
216              dc.EndDrawing()          # Pass the entire bitmap as update region to the renderer.
217              dc.SelectObject(wx.wxNullBitmap)          # We're redrawing the whole bitmap, after all.
218            renderer.RenderMap(self.Map(), (0, 0, width, height),
219                               selected_layer, selected_shapes)
220    
221              self.bitmap = bitmap          dc.EndDrawing()
222          finally:          dc.SelectObject(wx.wxNullBitmap)
             wxEndBusyCursor()  
             pass  
223    
224            self.bitmap = bitmap
225          # This causes a paint event that then draws the bitmap          # This causes a paint event that then draws the bitmap
226          self.redraw()          self.redraw()
227    
# Line 295  class MapCanvas(wxWindow, ViewPort): Line 301  class MapCanvas(wxWindow, ViewPort):
301              self.drag_dc.SetLogicalFunction(wxINVERT)              self.drag_dc.SetLogicalFunction(wxINVERT)
302              self.drag_dc.SetBrush(wxTRANSPARENT_BRUSH)              self.drag_dc.SetBrush(wxTRANSPARENT_BRUSH)
303              self.tool.Show(self.drag_dc)              self.tool.Show(self.drag_dc)
304                self.CaptureMouse()
305              self.dragging = 1              self.dragging = 1
306    
307      def OnLeftUp(self, event):      def OnLeftUp(self, event):

Legend:
Removed from v.1454  
changed lines
  Added in v.1552

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26