/[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 864 by frank, Thu May 8 12:29:23 2003 UTC revision 990 by frank, Thu May 22 16:51:24 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 13  import resource Line 14  import resource
14    
15  from wxPython.wx import *  from wxPython.wx import *
16    
17  from Thuban.Model.layer import Layer  from Thuban.Model.layer import BaseLayer
18  from Thuban.Model.map import Map  from Thuban.Model.map import Map
 from Thuban.Model.messages import *  
19  from Thuban.Model.classification import ClassGroup  from Thuban.Model.classification import ClassGroup
20    
21  from Thuban.UI.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.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  from Thuban.UI.dock import DockPanel
29  from Thuban.UI.scalebar import ScaleBar  from Thuban.UI.scalebar import ScaleBar
30    
31  from Thuban.Lib.connector import ConnectorError  from Thuban.Lib.connector import ConnectorError
32    
33  ID_LEGEND_RAISE = 4001  ID_LEGEND_TOP = 4001
34  ID_LEGEND_LOWER = 4002  ID_LEGEND_RAISE = 4002
35  ID_LEGEND_TREE = 4003  ID_LEGEND_LOWER = 4003
36  ID_LEGEND_PROPS = 4004  ID_LEGEND_BOTTOM = 4004
37  ID_LEGEND_SHOWLAYER = 4005  ID_LEGEND_TREE = 4005
38  ID_LEGEND_HIDELAYER = 4006  ID_LEGEND_PROPS = 4006
39    ID_LEGEND_SHOWLAYER = 4007
40    ID_LEGEND_HIDELAYER = 4008
41    
42  BMP_SIZE_W = 30  BMP_SIZE_W = 30
43  BMP_SIZE_H = 15  BMP_SIZE_H = 15
44    
45    TOP_BMP = "top_layer"
46  RAISE_BMP = "raise_layer"  RAISE_BMP = "raise_layer"
47  LOWER_BMP = "lower_layer"  LOWER_BMP = "lower_layer"
48    BOTTOM_BMP = "bottom_layer"
49  SHOW_BMP  = "show_layer"  SHOW_BMP  = "show_layer"
50  HIDE_BMP  = "hide_layer"  HIDE_BMP  = "hide_layer"
51  PROPS_BMP = "layer_properties"  PROPS_BMP = "layer_properties"
# Line 57  class LegendPanel(DockPanel): Line 66  class LegendPanel(DockPanel):
66          self.toolBar = wxToolBar(self, -1)          self.toolBar = wxToolBar(self, -1)
67          self.toolBar.SetToolBitmapSize(wxSize(24, 24))          self.toolBar.SetToolBitmapSize(wxSize(24, 24))
68    
69            bmp = resource.GetBitmapResource(TOP_BMP, wxBITMAP_TYPE_XPM)
70            self.toolBar.AddTool(ID_LEGEND_TOP, bmp,
71                shortHelpString=_("Top Layer"))
72    
73          bmp = resource.GetBitmapResource(RAISE_BMP, wxBITMAP_TYPE_XPM)          bmp = resource.GetBitmapResource(RAISE_BMP, wxBITMAP_TYPE_XPM)
74          self.toolBar.AddTool(ID_LEGEND_RAISE, bmp,          self.toolBar.AddTool(ID_LEGEND_RAISE, bmp,
75              shortHelpString=_("Raise Layer"))              shortHelpString=_("Raise Layer"))
# Line 65  class LegendPanel(DockPanel): Line 78  class LegendPanel(DockPanel):
78          self.toolBar.AddTool(ID_LEGEND_LOWER, bmp,          self.toolBar.AddTool(ID_LEGEND_LOWER, bmp,
79              shortHelpString=_("Lower Layer"))              shortHelpString=_("Lower Layer"))
80    
81            bmp = resource.GetBitmapResource(BOTTOM_BMP, wxBITMAP_TYPE_XPM)
82            self.toolBar.AddTool(ID_LEGEND_BOTTOM, bmp,
83                shortHelpString=_("Bottom Layer"))
84    
85          bmp = resource.GetBitmapResource(SHOW_BMP, wxBITMAP_TYPE_XPM)          bmp = resource.GetBitmapResource(SHOW_BMP, wxBITMAP_TYPE_XPM)
86          self.toolBar.AddTool(ID_LEGEND_SHOWLAYER, bmp,          self.toolBar.AddTool(ID_LEGEND_SHOWLAYER, bmp,
87              shortHelpString=_("Show Layer"))              shortHelpString=_("Show Layer"))
# Line 80  class LegendPanel(DockPanel): Line 97  class LegendPanel(DockPanel):
97          self.toolBar.Realize()          self.toolBar.Realize()
98          panelBox.Add(self.toolBar, 0, wxGROW, 0)          panelBox.Add(self.toolBar, 0, wxGROW, 0)
99    
100            EVT_TOOL(self, ID_LEGEND_TOP, self._OnMoveTop)
101          EVT_TOOL(self, ID_LEGEND_RAISE, self._OnMoveUp)          EVT_TOOL(self, ID_LEGEND_RAISE, self._OnMoveUp)
102          EVT_TOOL(self, ID_LEGEND_LOWER, self._OnMoveDown)          EVT_TOOL(self, ID_LEGEND_LOWER, self._OnMoveDown)
103            EVT_TOOL(self, ID_LEGEND_BOTTOM, self._OnMoveBottom)
104          EVT_TOOL(self, ID_LEGEND_PROPS, self._OnProperties)          EVT_TOOL(self, ID_LEGEND_PROPS, self._OnProperties)
105          EVT_TOOL(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer)          EVT_TOOL(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer)
106          EVT_TOOL(self, ID_LEGEND_HIDELAYER, self._OnHideLayer)          EVT_TOOL(self, ID_LEGEND_HIDELAYER, self._OnHideLayer)
# Line 116  class LegendPanel(DockPanel): Line 135  class LegendPanel(DockPanel):
135    
136      def DoOnSelChanged(self, layer, group):      def DoOnSelChanged(self, layer, group):
137    
138          ok = isinstance(layer, Layer)          ok = isinstance(layer, BaseLayer)
139          self.__EnableButtons(ok)          self.__EnableButtons(ok)
140    
141          self.mainWindow.SelectLayer(layer)          self.mainWindow.SelectLayer(layer)
# Line 124  class LegendPanel(DockPanel): Line 143  class LegendPanel(DockPanel):
143      def DoOnProperties(self):      def DoOnProperties(self):
144          list = self.tree.GetSelectedHierarchy()          list = self.tree.GetSelectedHierarchy()
145    
146          ok = isinstance(list[0], Layer)          ok = isinstance(list[0], BaseLayer)
147          if ok:          if ok:
148              self.mainWindow.OpenLayerProperties(list[0], list[1])              self.mainWindow.OpenLayerProperties(list[0], list[1])
149    
# Line 134  class LegendPanel(DockPanel): Line 153  class LegendPanel(DockPanel):
153      def _OnProperties(self, event):      def _OnProperties(self, event):
154          self.DoOnProperties()          self.DoOnProperties()
155    
156        def _OnMoveTop(self, event):
157            self.tree.MoveCurrentItemTop()
158            
159      def _OnMoveUp(self, event):      def _OnMoveUp(self, event):
160          self.tree.MoveCurrentItemUp()          self.tree.MoveCurrentItemUp()
161    
162      def _OnMoveDown(self, event):      def _OnMoveDown(self, event):
163          self.tree.MoveCurrentItemDown()          self.tree.MoveCurrentItemDown()
164    
165        def _OnMoveBottom(self, event):
166            self.tree.MoveCurrentItemBottom()
167    
168      def _OnShowLayer(self, event):      def _OnShowLayer(self, event):
169          self.tree.DoOnShowLayer()          self.tree.DoOnShowLayer()
170          pass          pass
# Line 155  class LegendPanel(DockPanel): Line 180  class LegendPanel(DockPanel):
180          pass          pass
181    
182      def __EnableButtons(self, on):      def __EnableButtons(self, on):
183            self.toolBar.EnableTool(ID_LEGEND_TOP, on)
184          self.toolBar.EnableTool(ID_LEGEND_RAISE, on)          self.toolBar.EnableTool(ID_LEGEND_RAISE, on)
185          self.toolBar.EnableTool(ID_LEGEND_LOWER, on)          self.toolBar.EnableTool(ID_LEGEND_LOWER, on)
186            self.toolBar.EnableTool(ID_LEGEND_BOTTOM, on)
187          self.toolBar.EnableTool(ID_LEGEND_SHOWLAYER,  on)          self.toolBar.EnableTool(ID_LEGEND_SHOWLAYER,  on)
188          self.toolBar.EnableTool(ID_LEGEND_HIDELAYER,  on)          self.toolBar.EnableTool(ID_LEGEND_HIDELAYER,  on)
189          self.toolBar.EnableTool(ID_LEGEND_PROPS, on)          self.toolBar.EnableTool(ID_LEGEND_PROPS, on)
# Line 221  class LegendTree(wxTreeCtrl): Line 248  class LegendTree(wxTreeCtrl):
248                  #self._OnMsgMapsChanged)                  #self._OnMsgMapsChanged)
249              self.__FillTree(self.map)              self.__FillTree(self.map)
250    
251        def MoveCurrentItemTop(self):
252            layer, group = self.GetSelectedHierarchy()
253    
254            if layer is not None:
255                self.map.TopLayer(layer)
256            else:
257                assert False, "Shouldn't be allowed."
258                pass
259    
260      def MoveCurrentItemUp(self):      def MoveCurrentItemUp(self):
261          layer, group = self.GetSelectedHierarchy()          layer, group = self.GetSelectedHierarchy()
262    
# Line 239  class LegendTree(wxTreeCtrl): Line 275  class LegendTree(wxTreeCtrl):
275              assert False, "Shouldn't be allowed."              assert False, "Shouldn't be allowed."
276              pass              pass
277    
278        def MoveCurrentItemBottom(self):
279            layer, group = self.GetSelectedHierarchy()
280    
281            if layer is not None:
282                self.map.BottomLayer(layer)
283            else:
284                assert False, "Shouldn't be allowed."
285                pass
286    
287      def OnCompareItems(self, item1, item2):      def OnCompareItems(self, item1, item2):
288    
289          data1 = self.GetPyData(item1)          data1 = self.GetPyData(item1)
290          data2 = self.GetPyData(item2)          data2 = self.GetPyData(item2)
291    
292          if isinstance(data1, Layer):          if isinstance(data1, BaseLayer):
293              layers = self.map.Layers()              layers = self.map.Layers()
294              return layers.index(data2) - layers.index(data1)              return layers.index(data2) - layers.index(data1)
295          else:          else:
296              return wxTreeCtrl.OnCompareItems(self, item1, item2)              return wxTreeCtrl.OnCompareItems(self, item1, item2)
297    
   
298      def DoOnShowLayer(self):      def DoOnShowLayer(self):
299          #self.__ShowHideLayer(True)          #self.__ShowHideLayer(True)
300          layer, group = self.GetSelectedHierarchy()          layer, group = self.GetSelectedHierarchy()
# Line 292  class LegendTree(wxTreeCtrl): Line 336  class LegendTree(wxTreeCtrl):
336          self.parent.DoOnProperties()          self.parent.DoOnProperties()
337    
338      def _OnMsgLayerChanged(self, layer):      def _OnMsgLayerChanged(self, layer):
339          assert isinstance(layer, Layer)          assert isinstance(layer, BaseLayer)
340    
341          id = self.layer2id[layer]          id = self.layer2id[layer]
342          assert id.IsOk()          assert id.IsOk()
# Line 320  class LegendTree(wxTreeCtrl): Line 364  class LegendTree(wxTreeCtrl):
364          self.__UpdateSelection()          self.__UpdateSelection()
365    
366      def _OnMsgLayerVisibilityChanged(self, layer):      def _OnMsgLayerVisibilityChanged(self, layer):
367          assert isinstance(layer, Layer)          assert isinstance(layer, BaseLayer)
368    
369          self.__ShowHideLayer(layer)          self.__ShowHideLayer(layer)
370          self.__UpdateSelection()          self.__UpdateSelection()
# Line 383  class LegendTree(wxTreeCtrl): Line 427  class LegendTree(wxTreeCtrl):
427    
428          self.DeleteChildren(pid)          self.DeleteChildren(pid)
429    
430          clazz = layer.GetClassification()          if layer.HasClassification():
431    
432          shapeType = layer.ShapeType()              clazz = layer.GetClassification()
433    
434          show = layer.Visible()              shapeType = layer.ShapeType()
435          for g in clazz:  
436              if g.IsVisible():              show = layer.Visible()
437                  id = self.AppendItem(pid, g.GetDisplayText())              for g in clazz:
438                  self.SetPyData(id, g)                  if g.IsVisible():
439                  self.__SetVisibilityStyle(show, id)                      id = self.AppendItem(pid, g.GetDisplayText())
440                        self.SetPyData(id, g)
441                  bmp = self.__BuildGroupImage(g, shapeType)                      self.__SetVisibilityStyle(show, id)
442    
443                  if bmp is None:                      bmp = self.__BuildGroupImage(g, shapeType)
444                      self.SetItemImage(id, self.emptyImageIndex)  
445                  else:                      if bmp is None:
446                      i = self.image_list.Add(bmp)                          self.SetItemImage(id, self.emptyImageIndex)
447                      self.SetItemImage(id, i)                      else:
448                            i = self.image_list.Add(bmp)
449                            self.SetItemImage(id, i)
450    
451          self.Thaw()          self.Thaw()
452    
# Line 435  class LegendTree(wxTreeCtrl): Line 481  class LegendTree(wxTreeCtrl):
481              font.SetStyle(wxNORMAL)              font.SetStyle(wxNORMAL)
482              color = wxBLACK              color = wxBLACK
483          else:          else:
484              font.SetStyle(wxITALIC)              #font.SetStyle(wxITALIC)
485                font.SetStyle(wxNORMAL)
486              color = wxLIGHT_GREY              color = wxLIGHT_GREY
487    
488          self.SetItemTextColour(id, color)          self.SetItemTextColour(id, color)
# Line 461  class ScaleBarBitmap(wxBoxSizer): Line 508  class ScaleBarBitmap(wxBoxSizer):
508          # While the width is fixed, get the height _now_.          # While the width is fixed, get the height _now_.
509          dc = wxMemoryDC()          dc = wxMemoryDC()
510          textwidth, textheight = dc.GetTextExtent("%d"%0)          textwidth, textheight = dc.GetTextExtent("%d"%0)
511          self.width = 200          self.width = 210
512          self.height = textheight + 3*2 + 8          self.height = textheight + 3*2 + 8
513    
514          wxBoxSizer.__init__(self, wxVERTICAL)          wxBoxSizer.__init__(self, wxVERTICAL)
# Line 496  class ScaleBarBitmap(wxBoxSizer): Line 543  class ScaleBarBitmap(wxBoxSizer):
543          dc.SelectObject(bmp)          dc.SelectObject(bmp)
544          dc.Clear()          dc.Clear()
545    
546          self.scalebar.DrawScalebar(scale, dc)          self.scalebar.DrawScaleBar(scale, dc, (0,0), dc.GetSizeTuple())
547    
548          self.scalebarBitmap.SetBitmap(bmp)          self.scalebarBitmap.SetBitmap(bmp)
549    

Legend:
Removed from v.864  
changed lines
  Added in v.990

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26