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

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

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

revision 542 by jonathan, Thu Mar 20 09:43:16 2003 UTC revision 914 by frank, Fri May 16 16:25:41 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001, 2002, 2003 by Intevation GmbH  # Copyright (c) 2001, 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Jonathan Coles <[email protected]>  # Jonathan Coles <[email protected]>
4    # Frank Koormann <[email protected]>
5  #  #
6  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
7  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 9  __version__ = "$Revision$" Line 10  __version__ = "$Revision$"
10    
11  from Thuban import _  from Thuban import _
12    
13    import resource
14    
15  from wxPython.wx import *  from wxPython.wx import *
 from dialogs import NonModalDialog  
16    
17  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer
18  from Thuban.Model.map import Map  from Thuban.Model.map import Map
19    from Thuban.Model.classification import ClassGroup
20    
21  from Thuban.Model.messages import *  from Thuban.Model.messages import \
22        MAP_STACKING_CHANGED, MAP_LAYERS_ADDED, MAP_LAYERS_REMOVED, LAYER_CHANGED,\
23        LAYER_VISIBILITY_CHANGED, TITLE_CHANGED
24    
25  from Thuban.Model.classification import ClassGroup  from Thuban.UI.messages import SCALE_CHANGED
26    
27  from Thuban.UI.classifier import ClassDataPreviewer  from Thuban.UI.classifier import ClassDataPreviewer
28    from Thuban.UI.dock import DockPanel
29    from Thuban.UI.scalebar import ScaleBar
30    
31  ID_LEGEND_MOVEUP = 4001  from Thuban.Lib.connector import ConnectorError
32  ID_LEGEND_MOVEDOWN = 4002  
33    ID_LEGEND_RAISE = 4001
34    ID_LEGEND_LOWER = 4002
35  ID_LEGEND_TREE = 4003  ID_LEGEND_TREE = 4003
36  ID_LEGEND_CLASSIFY = 4004  ID_LEGEND_PROPS = 4004
37  ID_LEGEND_SHOWLAYER = 4005  ID_LEGEND_SHOWLAYER = 4005
38  ID_LEGEND_HIDELAYER = 4006  ID_LEGEND_HIDELAYER = 4006
39    
40  BMP_SIZE_W = 30  BMP_SIZE_W = 30
41  BMP_SIZE_H = 15  BMP_SIZE_H = 15
42    
43  class Legend(NonModalDialog):  RAISE_BMP = "raise_layer"
44    LOWER_BMP = "lower_layer"
45    SHOW_BMP  = "show_layer"
46    HIDE_BMP  = "hide_layer"
47    PROPS_BMP = "layer_properties"
48    
     def __init__(self, parent, name, map):  
         NonModalDialog.__init__(self, parent, name,  
                                 _("Legend: %s") % map.Title())  
49    
50          self.parent = parent  class LegendPanel(DockPanel):
51    
52        def __init__(self, parent, map, mainWindow):
53            DockPanel.__init__(self, parent, -1)
54    
55          panel = wxPanel(self, -1)          self.mainWindow = mainWindow
56            self.parent = parent
57    
58            self.buttons = []
59    
         topBox = wxBoxSizer(wxVERTICAL)  
60          panelBox = wxBoxSizer(wxVERTICAL)          panelBox = wxBoxSizer(wxVERTICAL)
61    
62          buttonBox = wxGridSizer(2, 3, 0, 0)          self.toolBar = wxToolBar(self, -1)
63            self.toolBar.SetToolBitmapSize(wxSize(24, 24))
64    
65          self.buttons = []          bmp = resource.GetBitmapResource(RAISE_BMP, wxBITMAP_TYPE_XPM)
66            self.toolBar.AddTool(ID_LEGEND_RAISE, bmp,
67                shortHelpString=_("Raise Layer"))
68    
69            bmp = resource.GetBitmapResource(LOWER_BMP, wxBITMAP_TYPE_XPM)
70            self.toolBar.AddTool(ID_LEGEND_LOWER, bmp,
71                shortHelpString=_("Lower Layer"))
72    
73          button = wxButton(self, ID_LEGEND_MOVEUP, _("Move Up"))          bmp = resource.GetBitmapResource(SHOW_BMP, wxBITMAP_TYPE_XPM)
74          buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0)          self.toolBar.AddTool(ID_LEGEND_SHOWLAYER, bmp,
75          self.buttons.append(button)              shortHelpString=_("Show Layer"))
76    
77          button = wxButton(self, ID_LEGEND_SHOWLAYER, _("Show Layer"))          bmp = resource.GetBitmapResource(HIDE_BMP, wxBITMAP_TYPE_XPM)
78          buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0)          self.toolBar.AddTool(ID_LEGEND_HIDELAYER, bmp,
79          self.buttons.append(button)              shortHelpString=_("Hide Layer"))
80    
81          button = wxButton(self, ID_LEGEND_CLASSIFY, _("Classify"))          bmp = resource.GetBitmapResource(PROPS_BMP, wxBITMAP_TYPE_XPM)
82          buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0)          self.toolBar.AddTool(ID_LEGEND_PROPS, bmp,
83          self.buttons.append(button)              shortHelpString=_("Edit Layer Properties"))
84    
85          button = wxButton(self, ID_LEGEND_MOVEDOWN, _("Move Down"))          self.toolBar.Realize()
86          buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0)          panelBox.Add(self.toolBar, 0, wxGROW, 0)
         self.buttons.append(button)  
87    
88          button = wxButton(self, ID_LEGEND_HIDELAYER, _("Hide Layer"))          EVT_TOOL(self, ID_LEGEND_RAISE, self._OnMoveUp)
89          buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0)          EVT_TOOL(self, ID_LEGEND_LOWER, self._OnMoveDown)
90          self.buttons.append(button)          EVT_TOOL(self, ID_LEGEND_PROPS, self._OnProperties)
91            EVT_TOOL(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer)
92            EVT_TOOL(self, ID_LEGEND_HIDELAYER, self._OnHideLayer)
93    
94            self.tree = LegendTree(self, ID_LEGEND_TREE, map, mainWindow)
95    
96          EVT_BUTTON(self, ID_LEGEND_MOVEUP, self._OnMoveUp)          panelBox.Add(self.tree, 1, wxGROW, 0)
         EVT_BUTTON(self, ID_LEGEND_MOVEDOWN, self._OnMoveDown)  
         EVT_BUTTON(self, ID_LEGEND_CLASSIFY, self._OnClassify)  
         EVT_BUTTON(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer)  
         EVT_BUTTON(self, ID_LEGEND_HIDELAYER, self._OnHideLayer)  
97    
98          panelBox.Add(buttonBox, 0, 0, 4)          self.scalebarbitmap = ScaleBarBitmap(self, map, mainWindow)
99            panelBox.Add(self.scalebarbitmap, 0, wxGROW, 0)
100    
101          self.tree = LegendTree(self, ID_LEGEND_TREE, map)          self.SetAutoLayout(True)
102            self.SetSizer(panelBox)
103            panelBox.SetSizeHints(self)
104    
         panelBox.Add(self.tree, 1, wxGROW, 4)  
105    
106          panel.SetAutoLayout(True)          self.panelBox = panelBox
         panel.SetSizer(panelBox)  
         panelBox.SetSizeHints(panel)  
107    
108          topBox.Add(panel, 1, wxGROW, 0)          self.__EnableButtons(False)
         panelBox.SetSizeHints(self)  
109    
110          self.SetAutoLayout(True)          self.Create()
111          self.SetSizer(topBox)  
112            EVT_CLOSE(self, self._OnClose)
113    
114    
115        def GetMap(self):
116            return self.tree.GetMap()
117    
118        def SetMap(self, map):
119            self.tree.SetMap(map)
120            self.scalebarbitmap.SetCanvas(self.mainWindow.canvas)
121    
122        def DoOnSelChanged(self, layer, group):
123    
124            ok = isinstance(layer, Layer)
125            self.__EnableButtons(ok)
126    
127            self.mainWindow.SelectLayer(layer)
128    
129      def DoOnSelChanged(self):      def DoOnProperties(self):
130          self.__EnableButtons(self.tree.GetSelection().IsOk())          list = self.tree.GetSelectedHierarchy()
131    
132      def _OnClassify(self, event):          ok = isinstance(list[0], Layer)
133          self.tree.DoOnClassify()          if ok:
134                self.mainWindow.OpenLayerProperties(list[0], list[1])
135    
136        def Destroy(self):
137            self.__Close()
138    
139        def _OnProperties(self, event):
140            self.DoOnProperties()
141    
142      def _OnMoveUp(self, event):      def _OnMoveUp(self, event):
143          self.tree.MoveCurrentItemUp()          self.tree.MoveCurrentItemUp()
# Line 109  class Legend(NonModalDialog): Line 149  class Legend(NonModalDialog):
149          self.tree.DoOnShowLayer()          self.tree.DoOnShowLayer()
150          pass          pass
151    
152        #def Close(self, force = False):
153            #DockPanel.Close(self, force)
154            
155        def _OnClose(self, event):
156            self.__Close()
157    
158      def _OnHideLayer(self, event):      def _OnHideLayer(self, event):
159          self.tree.DoOnHideLayer()          self.tree.DoOnHideLayer()
160          pass          pass
161    
   
162      def __EnableButtons(self, on):      def __EnableButtons(self, on):
163          for b in self.buttons:          self.toolBar.EnableTool(ID_LEGEND_RAISE, on)
164              b.Enable(on)          self.toolBar.EnableTool(ID_LEGEND_LOWER, on)
165            self.toolBar.EnableTool(ID_LEGEND_SHOWLAYER,  on)
166            self.toolBar.EnableTool(ID_LEGEND_HIDELAYER,  on)
167            self.toolBar.EnableTool(ID_LEGEND_PROPS, on)
168    
169        def __Close(self):
170            self.tree.Close()
171    
172  class LegendTree(wxTreeCtrl):  class LegendTree(wxTreeCtrl):
173    
174      def __init__(self, parent, id, map):      def __init__(self, parent, id, map, mainWindow):
175          wxTreeCtrl.__init__(self, parent, id,          wxTreeCtrl.__init__(self, parent, id,
176                              style = wxTR_DEFAULT_STYLE | wxTR_HIDE_ROOT,                              style = wxTR_DEFAULT_STYLE | wxTR_HIDE_ROOT,
177                              size = (200, 200))                              size = (200, 200))
178    
179            self.mainWindow = mainWindow
180            self.map = None
181          self.parent = parent          self.parent = parent
182          self.map = map          self.layer2id = {}
         self.layer2id = None  
   
183    
184          self.image_list = None          self.image_list = None
185          self.emptyImageIndex = 0          self.emptyImageIndex = 0
186    
187          self.previewer = ClassDataPreviewer()          self.previewer = ClassDataPreviewer()
188    
   
189          EVT_TREE_ITEM_ACTIVATED(self, ID_LEGEND_TREE, self._OnItemActivated)          EVT_TREE_ITEM_ACTIVATED(self, ID_LEGEND_TREE, self._OnItemActivated)
190          EVT_TREE_SEL_CHANGED(self, ID_LEGEND_TREE, self._OnSelChanged)          EVT_TREE_SEL_CHANGED(self, ID_LEGEND_TREE, self._OnSelChanged)
191    
192          map.Subscribe(MAP_STACKING_CHANGED, self._OnMsgMapStackingChanged)          EVT_CLOSE(self, self._OnClose)
         map.Subscribe(MAP_LAYERS_CHANGED, self._OnMsgMapLayersChanged)  
193    
194          self.__FillTree(map)          self.SetMap(map)
195    
196      def MoveCurrentItemUp(self):      def _OnClose(self, event):
197          cur_id = self.GetSelection()          self.SetMap(None)
         assert(cur_id.IsOk())  
198    
199          cur_data = self.GetPyData(cur_id)      def GetMap(self):
200            return self.map
201    
202        def SetMap(self, map):
203    
204            sub_list = [(MAP_STACKING_CHANGED, self._OnMsgMapStackingChanged),
205                        (MAP_LAYERS_ADDED, self._OnMsgMapLayersAddedRemoved),
206                        (MAP_LAYERS_REMOVED, self._OnMsgMapLayersAddedRemoved)]
207    
208            if self.map is not None:
209                for msg, func in sub_list: self.map.Unsubscribe(msg, func)
210                #self.mainWindow.application.Unsubscribe(SESSION_REPLACED,
211                    #self._OnMsgMapsChanged)
212                #try:
213                    #self.mainWindow.application.session.Unsubscribe(MAPS_CHANGED,
214                        #self._OnMsgMapsChanged)
215                #except ConnectorError:
216                    #pass
217                self.__DeleteAllItems()
218            
219            self.map = map
220    
221          #prev_id = self.GetPrevSibling(cur_id)          if self.map is not None:
222                for msg, func in sub_list: self.map.Subscribe(msg, func)
223                #self.mainWindow.application.session.Subscribe(MAPS_CHANGED,
224                    #self._OnMsgMapsChanged)
225                #self.mainWindow.application.Subscribe(SESSION_REPLACED,
226                    #self._OnMsgMapsChanged)
227                self.__FillTree(self.map)
228    
229          #      def MoveCurrentItemUp(self):
230          # Get out if there's nowhere to go          layer, group = self.GetSelectedHierarchy()
         #  
         #if prev_id == INVALID_TREE_ID: return  
231    
232          if isinstance(cur_data, Layer):          if layer is not None:
233              self.map.RaiseLayer(cur_data)              self.map.RaiseLayer(layer)
         elif isinstance(cur_data, ClassGroup):  
             pass  
234          else:          else:
235              assert(False, "Shouldn't be here.")              assert False, "Shouldn't be allowed."
236              pass              pass
237    
238      def MoveCurrentItemDown(self):      def MoveCurrentItemDown(self):
239          cur_id = self.GetSelection()          layer, group = self.GetSelectedHierarchy()
         assert(cur_id.IsOk())  
240    
241          cur_data = self.GetPyData(cur_id)          if layer is not None:
242                self.map.LowerLayer(layer)
         if isinstance(cur_data, Layer):  
             self.map.LowerLayer(cur_data)  
         elif isinstance(cur_data, ClassGroup):  
             pass  
243          else:          else:
244              assert(False, "Shouldn't be here.")              assert False, "Shouldn't be allowed."
245              pass              pass
246    
   
247      def OnCompareItems(self, item1, item2):      def OnCompareItems(self, item1, item2):
248    
249          data1 = self.GetPyData(item1)          data1 = self.GetPyData(item1)
# Line 191  class LegendTree(wxTreeCtrl): Line 255  class LegendTree(wxTreeCtrl):
255          else:          else:
256              return wxTreeCtrl.OnCompareItems(self, item1, item2)              return wxTreeCtrl.OnCompareItems(self, item1, item2)
257    
   
258      def DoOnShowLayer(self):      def DoOnShowLayer(self):
259          self.__ShowHideLayer(True)          #self.__ShowHideLayer(True)
260            layer, group = self.GetSelectedHierarchy()
261            layer.SetVisible(True)
262    
263      def DoOnHideLayer(self):      def DoOnHideLayer(self):
264          self.__ShowHideLayer(False)          #self.__ShowHideLayer(False)
265            layer, group = self.GetSelectedHierarchy()
266            layer.SetVisible(False)
267    
268      def DoOnClassify(self):      def Sort(self):
269          id = self.GetSelection()          self.SortChildren(self.GetRootItem())
         assert(id.IsOk())  
270    
271          item = self.GetPyData(id)      def GetSelectedHierarchy(self):
272          if isinstance(item, ClassGroup):          id = self.GetSelection()
             id = self.GetItemParent(id)  
             assert(id.IsOk())  
             item = self.GetPyData(id)  
273    
274          self.parent.parent.OpenClassifier(item)          if not id.IsOk():
275                return (None, None)
276    
277      def Sort(self):          layer = self.GetPyData(id)
278          self.SortChildren(self.GetRootItem())          group = None
279    
280            if isinstance(layer, ClassGroup):
281                id = self.GetItemParent(id)
282                assert id.IsOk()
283                group = layer
284                layer = self.GetPyData(id)
285    
286            return (layer, group)
287    
288        def _OnMsgMapsChanged(self):
289            #print self.map is self.mainWindow.Map()
290            self.SetMap(self.mainWindow.Map())
291            
292      def _OnSelChanged(self, event):      def _OnSelChanged(self, event):
293          self.parent.DoOnSelChanged()          self.__UpdateSelection()
294    
295      def _OnItemActivated(self, event):      def _OnItemActivated(self, event):
296          self.DoOnClassify()          self.parent.DoOnProperties()
297    
298      def _OnMsgLayerChanged(self, layer):      def _OnMsgLayerChanged(self, layer):
299          assert(isinstance(layer, Layer))          assert isinstance(layer, Layer)
300    
301          id = self.layer2id[layer]          id = self.layer2id[layer]
302            assert id.IsOk()
303    
304          self.__FillTreeLayer(id)          # XXX: yikes! this is so bad, we should be doing what is
305            #      commented out, but there is a problem with keeping
306            #      track of the images in the image list when we replace
307            #      a layer. it ends up causing a seg fault.
308            self.__FillTree(self.map)
309            self.__UpdateSelection()
310            #self.__FillTreeLayer(id)
311    
312      def _OnMsgMapStackingChanged(self, *args):      def _OnMsgMapStackingChanged(self, *args):
313          self.Sort()          self.Sort()
314            id = self.GetSelection()
315    
316      def _OnMsgMapLayersChanged(self, map):          if id.IsOk():
317          assert(id(map) == id(self.map))              self.EnsureVisible(id)
318            self.__UpdateSelection()
319    
320        def _OnMsgMapLayersAddedRemoved(self, map):
321            assert map is self.map
322    
323          self.__FillTree(self.map)          self.__FillTree(self.map)
324            self.__UpdateSelection()
325    
326      def __FillTree(self, map):      def _OnMsgLayerVisibilityChanged(self, layer):
327            assert isinstance(layer, Layer)
328    
329            self.__ShowHideLayer(layer)
330            self.__UpdateSelection()
331    
332          assert(isinstance(map, Map))      def _OnMsgLayerTitleChanged(self, layer):
333    
334            id = self.layer2id[layer]
335            if id.IsOk():
336                self.SetItemText(id, layer.Title())
337            self.__UpdateSelection()
338    
339        def __UpdateSelection(self):
340            layer, group = self.GetSelectedHierarchy()
341            self.parent.DoOnSelChanged(layer, group)
342            
343        def __FillTree(self, map):
344    
345          self.Freeze()          self.Freeze()
346    
# Line 263  class LegendTree(wxTreeCtrl): Line 367  class LegendTree(wxTreeCtrl):
367              for l in map.Layers():              for l in map.Layers():
368                  id = self.PrependItem(root, l.Title())                  id = self.PrependItem(root, l.Title())
369                  l.Subscribe(LAYER_CHANGED, self._OnMsgLayerChanged)                  l.Subscribe(LAYER_CHANGED, self._OnMsgLayerChanged)
370                    l.Subscribe(LAYER_VISIBILITY_CHANGED,
371                                self._OnMsgLayerVisibilityChanged)
372                    l.Subscribe(TITLE_CHANGED, self._OnMsgLayerTitleChanged)
373                  self.SetPyData(id, l)                  self.SetPyData(id, l)
374                  font = self.GetItemFont(id)                  self.__SetVisibilityStyle(l.Visible(), id)
                 if not l.Visible():  
                     font.SetStyle(wxITALIC)  
                     self.SetItemFont(id, font)  
375    
376                  self.layer2id[l] = id                  self.layer2id[l] = id
377    
# Line 287  class LegendTree(wxTreeCtrl): Line 391  class LegendTree(wxTreeCtrl):
391    
392          shapeType = layer.ShapeType()          shapeType = layer.ShapeType()
393    
394            show = layer.Visible()
395          for g in clazz:          for g in clazz:
396              id = self.AppendItem(pid, g.GetDisplayText())              if g.IsVisible():
397              self.SetPyData(id, g)                  id = self.AppendItem(pid, g.GetDisplayText())
398                    self.SetPyData(id, g)
399              bmp = self.__BuildGroupImage(g, shapeType)                  self.__SetVisibilityStyle(show, id)
400    
401              if bmp is None:                  bmp = self.__BuildGroupImage(g, shapeType)
402                  self.SetItemImage(id, self.emptyImageIndex)  
403              else:                  if bmp is None:
404                  i = self.image_list.Add(bmp)                      self.SetItemImage(id, self.emptyImageIndex)
405                  self.SetItemImage(id, i)                  else:
406                        i = self.image_list.Add(bmp)
407              #self.layer2id[g] = id                      self.SetItemImage(id, i)
408    
409          self.Thaw()          self.Thaw()
410    
411      def __BuildGroupImage(self, group, shapeType):      def __BuildGroupImage(self, group, shapeType):
         assert(isinstance(group, ClassGroup))  
412    
413          bmp = wxEmptyBitmap(BMP_SIZE_W, BMP_SIZE_H)          bmp = wxEmptyBitmap(BMP_SIZE_W, BMP_SIZE_H)
414          #brush = wxBrush(Color2wxColour(item[1]), wxSOLID)          #brush = wxBrush(Color2wxColour(item[1]), wxSOLID)
# Line 317  class LegendTree(wxTreeCtrl): Line 421  class LegendTree(wxTreeCtrl):
421          return bmp          return bmp
422    
423      def __DeleteAllItems(self):      def __DeleteAllItems(self):
424    
425            while len(self.layer2id) > 0:
426                layer, id = self.layer2id.popitem()
427                layer.Unsubscribe(LAYER_CHANGED,
428                                  self._OnMsgLayerChanged)
429                layer.Unsubscribe(LAYER_VISIBILITY_CHANGED,
430                                  self._OnMsgLayerVisibilityChanged)
431                layer.Unsubscribe(TITLE_CHANGED, self._OnMsgLayerTitleChanged)
432    
433          self.DeleteAllItems()          self.DeleteAllItems()
         self.layer2id = {}  
434    
435        def __SetVisibilityStyle(self, visible, id):
436            font = self.GetItemFont(id)
437    
438      def __ShowHideLayer(self, show):          if visible:
439          id = self.GetSelection()              font.SetStyle(wxNORMAL)
440          assert(id.IsOk())              color = wxBLACK
441            else:
442                font.SetStyle(wxITALIC)
443                color = wxLIGHT_GREY
444    
445            self.SetItemTextColour(id, color)
446            self.SetItemFont(id, font)
447                    
448          item = self.GetPyData(id)      def __ShowHideLayer(self, layer):
449          if isinstance(item, ClassGroup):          parent = self.layer2id[layer]
450              id = self.GetItemParent(id)          assert parent.IsOk()
451              assert(id.IsOk())  
452              item = self.GetPyData(id)          visible = layer.Visible()
453    
454            self.__SetVisibilityStyle(visible, parent)
455    
456            id, cookie = self.GetFirstChild(parent, 123)
457    
458            while id.IsOk():
459                self.__SetVisibilityStyle(visible, id)
460                id, cookie = self.GetNextChild(parent, cookie)
461                
462    class ScaleBarBitmap(wxBoxSizer):
463    
464          if show != item.Visible():      def __init__(self, parent, map, mainWindow):
465            # While the width is fixed, get the height _now_.
466            dc = wxMemoryDC()
467            textwidth, textheight = dc.GetTextExtent("%d"%0)
468            self.width = 200
469            self.height = textheight + 3*2 + 8
470    
471            wxBoxSizer.__init__(self, wxVERTICAL)
472            bmp=wxEmptyBitmap(self.width, self.height)
473            self.scalebarBitmap = wxStaticBitmap(parent, -1, bmp)
474            self.Add(self.scalebarBitmap, 0, wxALIGN_CENTER|wxLEFT|wxTOP|wxRIGHT, 1)
475    
476            self.mainWindow = mainWindow
477            self.parent = parent
478            self.canvas = None
479            self.SetCanvas(self.mainWindow.canvas)
480    
481        def SetCanvas(self, canvas):
482            sub_list = [(SCALE_CHANGED, self._OnMsgScaleChanged)]
483    
484            if self.canvas is not None:
485                for msg, func in sub_list: self.canvas.Unsubscribe(msg, func)
486            
487            self.canvas = canvas
488            self.scalebar = ScaleBar(canvas.map)
489    
490            if self.canvas is not None:
491                for msg, func in sub_list: self.canvas.Subscribe(msg, func)
492                self.__SetScale(self.canvas.scale)
493    
494              item.SetVisible(show)      def _OnMsgScaleChanged(self, scale):
495            self.__SetScale(scale)
496    
497              font = self.GetItemFont(id)      def __SetScale(self, scale):
498              if show:          bmp = wxEmptyBitmap(self.width, self.height)
499                  font.SetStyle(wxNORMAL)          dc = wxMemoryDC()
500                  self.SetItemFont(id, font)          dc.SelectObject(bmp)
501              else:          dc.Clear()
                 font.SetStyle(wxITALIC)  
                 self.SetItemFont(id, font)  
502    
503            self.scalebar.DrawScaleBar(scale, dc, (0,0), dc.GetSizeTuple())
504    
505            self.scalebarBitmap.SetBitmap(bmp)
506    

Legend:
Removed from v.542  
changed lines
  Added in v.914

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26