/[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

trunk/thuban/Thuban/UI/view.py revision 2454 by bh, Mon Dec 13 18:26:11 2004 UTC branches/WIP-pyshapelib-bramz/Thuban/UI/view.py revision 2734 by bramz, Thu Mar 1 12:42:59 2007 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001, 2002, 2003, 2004 by Intevation GmbH  # opyright (c) 2001, 2002, 2003, 2004 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  # Frank Koormann <[email protected]>  # Frank Koormann <[email protected]>
# Line 20  import os.path Line 20  import os.path
20  import time  import time
21  import traceback  import traceback
22    
23  from wxPython.wx import wxWindow, \  import wx
      wxPaintDC, wxColour, wxClientDC, wxINVERT, wxTRANSPARENT_BRUSH, wxFont,\  
      EVT_PAINT, EVT_LEFT_DOWN, EVT_LEFT_UP, EVT_MOTION, EVT_LEAVE_WINDOW, \  
      wxPlatform, wxBeginBusyCursor, wxEndBusyCursor, wxFileDialog, wxSAVE, \  
      wxOVERWRITE_PROMPT, wxID_OK  
24    
25  # Export related stuff  # Export related stuff
26  if wxPlatform == '__WXMSW__':  if wx.Platform == '__WXMSW__':
27      from wxPython.wx import wxMetaFileDC      from wx import MetaFileDC
   
 from wxPython import wx  
28    
29  from Thuban import _  from Thuban import _
30    
# Line 54  class CanvasPanTool(PanTool): Line 48  class CanvasPanTool(PanTool):
48              x, y = self.current              x, y = self.current
49              width, height = self.view.GetSizeTuple()              width, height = self.view.GetSizeTuple()
50    
51              bitmapdc = wx.wxMemoryDC()              bitmapdc = wx.MemoryDC()
52              bitmapdc.SelectObject(self.view.PreviewBitmap())              bitmapdc.SelectObject(self.view.PreviewBitmap())
53    
54              dc = self.view.drag_dc              dc = self.view.drag_dc
55              dc.Blit(0, 0, width, height, bitmapdc, sx - x, sy - y)              dc.Blit(0, 0, width, height, bitmapdc, sx - x, sy - y)
56    
57  class MapPrintout(wx.wxPrintout):  class MapPrintout(wx.Printout):
58    
59      """      """
60      wxPrintout class for printing Thuban maps      wxPrintout class for printing Thuban maps
61      """      """
62    
63      def __init__(self, canvas, map, region, selected_layer, selected_shapes):      def __init__(self, canvas, map, region, selected_layer, selected_shapes):
64          wx.wxPrintout.__init__(self)          wx.Printout.__init__(self)
65          self.canvas = canvas          self.canvas = canvas
66          self.map = map          self.map = map
67          self.region = region          self.region = region
# Line 103  class MapPrintout(wx.wxPrintout): Line 97  class MapPrintout(wx.wxPrintout):
97          return True          return True
98    
99    
100  class MapCanvas(wxWindow, ViewPort):  class MapCanvas(wx.Window, ViewPort):
101    
102      """A widget that displays a map and offers some interaction"""      """A widget that displays a map and offers some interaction"""
103    
104      def __init__(self, parent, winid):      def __init__(self, parent, winid):
105          wxWindow.__init__(self, parent, winid)          wx.Window.__init__(self, parent, winid)
106          ViewPort.__init__(self)          ViewPort.__init__(self)
107    
108          self.SetBackgroundColour(wxColour(255, 255, 255))          self.SetBackgroundColour(wx.Colour(255, 255, 255))
109    
110          # the bitmap serving as backing store          # the bitmap serving as backing store
111          self.bitmap = None          self.bitmap = None
112          # the monochrome bitmap with the selection if any          # the monochrome bitmap with the selection if any
113          self.selection_bitmap = None          self.selection_bitmap = None
114    
115          self.backgroundColor = wx.wxWHITE_BRUSH          self.backgroundColor = wx.WHITE_BRUSH
116    
117          # The rendering iterator object. Used when rendering          # The rendering iterator object. Used when rendering
118          # incrementally          # incrementally
119          self.render_iter = None          self.render_iter = None
120    
121          # subscribe the WX events we're interested in          # subscribe the WX events we're interested in
122          EVT_PAINT(self, self.OnPaint)          self.Bind(wx.EVT_PAINT, self.OnPaint)
123          EVT_LEFT_DOWN(self, self.OnLeftDown)          self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
124          EVT_LEFT_UP(self, self.OnLeftUp)          self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
125          EVT_MOTION(self, self.OnMotion)          self.Bind(wx.EVT_MIDDLE_DOWN, self.OnMiddleDown)
126          EVT_LEAVE_WINDOW(self, self.OnLeaveWindow)          self.Bind(wx.EVT_MIDDLE_UP, self.OnMiddleUp)
127          wx.EVT_SIZE(self, self.OnSize)          self.Bind(wx.EVT_MOTION, self.OnMotion)
128          wx.EVT_IDLE(self, self.OnIdle)          self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)
129            self.Bind(wx.EVT_SIZE, self.OnSize)
130            self.Bind(wx.EVT_IDLE, self.OnIdle)
131    
132      def __del__(self):      def __del__(self):
133          wxWindow.__del__(self)          wx.Window.__del__(self)
134          ViewPort.__del__(self)          ViewPort.__del__(self)
135    
136      def PreviewBitmap(self):      def PreviewBitmap(self):
# Line 143  class MapCanvas(wxWindow, ViewPort): Line 139  class MapCanvas(wxWindow, ViewPort):
139      def PanTool(self):      def PanTool(self):
140          """Start the canvas pan tool"""          """Start the canvas pan tool"""
141          self.SelectTool(CanvasPanTool(self))          self.SelectTool(CanvasPanTool(self))
142            
143      def SetMap(self, map):      def SetMap(self, map):
144          redraw_channels = (MAP_LAYERS_CHANGED, LAYER_CHANGED,          redraw_channels = (MAP_LAYERS_CHANGED, LAYER_CHANGED,
145                             LAYER_VISIBILITY_CHANGED)                             LAYER_VISIBILITY_CHANGED)
# Line 163  class MapCanvas(wxWindow, ViewPort): Line 159  class MapCanvas(wxWindow, ViewPort):
159          self.full_redraw()          self.full_redraw()
160    
161      def OnPaint(self, event):      def OnPaint(self, event):
162          dc = wxPaintDC(self)          dc = wx.PaintDC(self)
163          if self.Map() is not None and self.Map().HasLayers():          if self.Map() is not None and self.Map().HasLayers():
164              if self.bitmap is not None:              if self.bitmap is not None:
165                  dc.BeginDrawing()                  dc.BeginDrawing()
# Line 210  class MapCanvas(wxWindow, ViewPort): Line 206  class MapCanvas(wxWindow, ViewPort):
206                      # the current tool is drawing on the window.                      # the current tool is drawing on the window.
207                      if not self.dragging \                      if not self.dragging \
208                             and time.time() - self.render_last_preview > 0.5:                             and time.time() - self.render_last_preview > 0.5:
209                          client_dc = wxClientDC(self)                          client_dc = wx.ClientDC(self)
210                          client_dc.BeginDrawing()                          client_dc.BeginDrawing()
211                          client_dc.DrawBitmap(self.bitmap, 0, 0)                          client_dc.DrawBitmap(self.bitmap, 0, 0)
212                          client_dc.EndDrawing()                          client_dc.EndDrawing()
# Line 237  class MapCanvas(wxWindow, ViewPort): Line 233  class MapCanvas(wxWindow, ViewPort):
233    
234      def _render_iterator(self):      def _render_iterator(self):
235          width, height = self.GetSizeTuple()          width, height = self.GetSizeTuple()
236          dc = wx.wxMemoryDC()          dc = wx.MemoryDC()
237    
238          render_start = time.time()          render_start = time.time()
239    
240          if self.bitmap is None:          if self.bitmap is None:
241              self.bitmap = wx.wxEmptyBitmap(width, height)              self.bitmap = wx.EmptyBitmap(width, height)
242              dc.SelectObject(self.bitmap)              dc.SelectObject(self.bitmap)
243              dc.BeginDrawing()              dc.BeginDrawing()
244    
# Line 256  class MapCanvas(wxWindow, ViewPort): Line 252  class MapCanvas(wxWindow, ViewPort):
252                  yield True                  yield True
253    
254              dc.EndDrawing()              dc.EndDrawing()
255              dc.SelectObject(wx.wxNullBitmap)              dc.SelectObject(wx.NullBitmap)
256    
257          if self.HasSelectedShapes() and self.selection_bitmap is None:          if self.HasSelectedShapes() and self.selection_bitmap is None:
258              bitmap = wx.wxEmptyBitmap(width, height)              bitmap = wx.EmptyBitmap(width, height)
259              dc.SelectObject(bitmap)              dc.SelectObject(bitmap)
260              dc.BeginDrawing()              dc.BeginDrawing()
261              dc.SetBackground(wx.wxWHITE_BRUSH)              dc.SetBackground(wx.WHITE_BRUSH)
262              dc.Clear()              dc.Clear()
263    
264              renderer = ScreenRenderer(dc, self.Map(), self.scale, self.offset,              renderer = ScreenRenderer(dc, self.Map(), self.scale, self.offset,
# Line 273  class MapCanvas(wxWindow, ViewPort): Line 269  class MapCanvas(wxWindow, ViewPort):
269                  yield True                  yield True
270    
271              dc.EndDrawing()              dc.EndDrawing()
272              dc.SelectObject(wx.wxNullBitmap)              dc.SelectObject(wx.NullBitmap)
273    
274              bitmap.SetMask(wx.wxMaskColour(bitmap, wx.wxWHITE))              bitmap.SetMask(wx.Mask(bitmap, wx.WHITE))
275              self.selection_bitmap = bitmap              self.selection_bitmap = bitmap
276    
277          yield False          yield False
# Line 286  class MapCanvas(wxWindow, ViewPort): Line 282  class MapCanvas(wxWindow, ViewPort):
282              export_path = self.export_path              export_path = self.export_path
283          else:          else:
284              export_path="."              export_path="."
285          dlg = wxFileDialog(self, _("Export Map"), export_path, "",          dlg = wx.FileDialog(self, _("Export Map"), export_path, "",
286                             "Enhanced Metafile (*.wmf)|*.wmf",                             "Enhanced Metafile (*.wmf)|*.wmf",
287                             wxSAVE|wxOVERWRITE_PROMPT)                             wx.SAVE|wx.OVERWRITE_PROMPT)
288          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wx.ID_OK:
289              self.export_path = os.path.dirname(dlg.GetPath())              self.export_path = os.path.dirname(dlg.GetPath())
290              dc = wxMetaFileDC(dlg.GetPath())              dc = wx.MetaFileDC(dlg.GetPath())
291        
292              scale, offset, mapregion = output_transform(self.scale,              scale, offset, mapregion = output_transform(self.scale,
293                                                          self.offset,                                                          self.offset,
294                                                          self.GetSizeTuple(),                                                          self.GetSizeTuple(),
# Line 312  class MapCanvas(wxWindow, ViewPort): Line 308  class MapCanvas(wxWindow, ViewPort):
308              dc.EndDrawing()              dc.EndDrawing()
309              dc.Close()              dc.Close()
310          dlg.Destroy()          dlg.Destroy()
311            
312      def Print(self):      def Print(self):
313          printer = wx.wxPrinter()          printer = wx.Printer()
314          width, height = self.GetSizeTuple()          width, height = self.GetSizeTuple()
315          selected_layer = self.selection.SelectedLayer()          selected_layer = self.selection.SelectedLayer()
316          selected_shapes = self.selection.SelectedShapes()          selected_shapes = self.selection.SelectedShapes()
317            
318          printout = MapPrintout(self, self.Map(), (0, 0, width, height),          printout = MapPrintout(self, self.Map(), (0, 0, width, height),
319                                 selected_layer, selected_shapes)                                 selected_layer, selected_shapes)
320          printer.Print(self, printout, True)          printer.Print(self, printout, True)
321          printout.Destroy()          printout.Destroy()
# Line 353  class MapCanvas(wxWindow, ViewPort): Line 349  class MapCanvas(wxWindow, ViewPort):
349      def GetPortSizeTuple(self):      def GetPortSizeTuple(self):
350          return self.GetSizeTuple()          return self.GetSizeTuple()
351    
352        def OnMiddleDown(self, event):
353            self.remembertool = self.tool
354            if self.Map() is not None and self.Map().HasLayers():
355                self.PanTool()
356                self.OnLeftDown(event)
357    
358        def OnMiddleUp(self, event):
359            self.OnLeftUp(event)
360            if self.remembertool:
361                self.SelectTool(self.remembertool)
362    
363      def OnLeftDown(self, event):      def OnLeftDown(self, event):
364          self.MouseLeftDown(event)          self.MouseLeftDown(event)
365          if self.tool is not None:          if self.tool is not None:
366              self.drag_dc = wxClientDC(self)              self.drag_dc = wx.ClientDC(self)
367              self.drag_dc.SetLogicalFunction(wxINVERT)              self.drag_dc.SetLogicalFunction(wx.INVERT)
368              self.drag_dc.SetBrush(wxTRANSPARENT_BRUSH)              self.drag_dc.SetBrush(wx.TRANSPARENT_BRUSH)
369              self.tool.Show(self.drag_dc)              self.tool.Show(self.drag_dc)
370              self.CaptureMouse()              self.CaptureMouse()
371              self.dragging = 1              self.dragging = 1
# Line 415  class MapCanvas(wxWindow, ViewPort): Line 422  class MapCanvas(wxWindow, ViewPort):
422          self.redraw_selection()          self.redraw_selection()
423    
424      def GetTextExtent(self, text):      def GetTextExtent(self, text):
425          dc = wxClientDC(self)          dc = wx.ClientDC(self)
426          font = wxFont(10, wx.wxSWISS, wx.wxNORMAL, wx.wxNORMAL)          font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL)
427          dc.SetFont(font)          dc.SetFont(font)
428          return dc.GetTextExtent(text)          return dc.GetTextExtent(text.decode('iso-8859-1'))
429    
430      def LabelShapeAt(self, x, y, text=None):      def LabelShapeAt(self, x, y, text=None):
431          """Add or remove a label at window position x, y.          """Add or remove a label at window position x, y.
# Line 427  class MapCanvas(wxWindow, ViewPort): Line 434  class MapCanvas(wxWindow, ViewPort):
434          determine the shape at the position, run the label dialog and          determine the shape at the position, run the label dialog and
435          unless the user cancels the dialog, add a label.          unless the user cancels the dialog, add a label.
436          """          """
         label_layer = self.map.LabelLayer()  
437          layer, shape_index = self.find_shape_at(x, y, select_labels = 1)          layer, shape_index = self.find_shape_at(x, y, select_labels = 1)
438          if layer is None and shape_index is not None:          if layer is None and shape_index is not None:
439              ViewPort.LabelShapeAt(self, x, y)              ViewPort.LabelShapeAt(self, x, y)
# Line 436  class MapCanvas(wxWindow, ViewPort): Line 442  class MapCanvas(wxWindow, ViewPort):
442                                                  layer.ShapeStore().Table(),                                                  layer.ShapeStore().Table(),
443                                                  shape_index)                                                  shape_index)
444              ViewPort.LabelShapeAt(self, x, y, text)              ViewPort.LabelShapeAt(self, x, y, text)
445    
446    

Legend:
Removed from v.2454  
changed lines
  Added in v.2734

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26