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

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

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

revision 111 by jan, Sun Apr 21 17:29:50 2002 UTC revision 177 by bh, Wed May 15 14:02:09 2002 UTC
# Line 1  Line 1 
1  #! /usr/bin/python  #! /usr/bin/python
2  # Copyright (c) 2001 by Intevation GmbH  # Copyright (c) 2001, 2002 by Intevation GmbH
3  # Authors:  # Authors:
4  # Jan-Oliver Wagner <[email protected]>  # Jan-Oliver Wagner <[email protected]>
5  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
# Line 27  def color_string(color): Line 27  def color_string(color):
27    
28  class SessionTreeCtrl(wxTreeCtrl):  class SessionTreeCtrl(wxTreeCtrl):
29    
30        # the session channels to subscribe to to update the tree
31        session_channels = (MAPS_CHANGED, MAP_PROJECTION_CHANGED,
32                            LAYERS_CHANGED, LAYER_LEGEND_CHANGED,
33                            LAYER_VISIBILITY_CHANGED)
34    
35      def __init__(self, parent, ID, app):      def __init__(self, parent, ID, app):
36          # Use the WANTS_CHARS style so the panel doesn't eat the Return key.          # Use the WANTS_CHARS style so the panel doesn't eat the Return key.
37          wxTreeCtrl.__init__(self, parent, ID)          wxTreeCtrl.__init__(self, parent, ID)
# Line 41  class SessionTreeCtrl(wxTreeCtrl): Line 46  class SessionTreeCtrl(wxTreeCtrl):
46    
47          self.app.Subscribe(SESSION_CHANGED, self.session_changed)          self.app.Subscribe(SESSION_CHANGED, self.session_changed)
48          self.app.interactor.Subscribe(SELECTED_LAYER, self.layer_selected)          self.app.interactor.Subscribe(SELECTED_LAYER, self.layer_selected)
49    
50            # the session currently displayed in the tree
51            self.session = None
52    
53          # pretend the session has changed to build the initial tree          # pretend the session has changed to build the initial tree
54          self.session_changed()          self.session_changed()
55    
56          EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)          EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)
57    
58        def unsubscribe_all(self):
59            if self.session is not None:
60                for channel in self.session_channels:
61                    self.session.Unsubscribe(channel, self.update_tree)
62                self.session = None
63            self.app.Unsubscribe(SESSION_CHANGED, self.session_changed)
64            self.app.interactor.Unsubscribe(SELECTED_LAYER, self.layer_selected)
65    
66      def update_tree(self, *args):      def update_tree(self, *args):
67          """Clear and rebuild the tree"""          """Clear and rebuild the tree"""
68          self.DeleteAllItems()          self.DeleteAllItems()
# Line 64  class SessionTreeCtrl(wxTreeCtrl): Line 81  class SessionTreeCtrl(wxTreeCtrl):
81          for map in session.Maps():          for map in session.Maps():
82              mapitem = self.AppendItem(root, "Map: %s" % map.title)              mapitem = self.AppendItem(root, "Map: %s" % map.title)
83              self.SetPyData(mapitem, map)              self.SetPyData(mapitem, map)
84              self.AppendItem(mapitem, ("Extent (lat-lon): (%g, %g, %g, %g)"              if map.BoundingBox() != None:
85                                        % map.BoundingBox()))                  self.AppendItem(mapitem, ("Extent (lat-lon): (%g, %g, %g, %g)"
86                                              % map.BoundingBox()))
87              if map.projection and len(map.projection.params) > 0:              if map.projection and len(map.projection.params) > 0:
88                  self.AppendItem(mapitem,                  self.AppendItem(mapitem,
89                                  ("Extent (projected): (%g, %g, %g, %g)"                                  ("Extent (projected): (%g, %g, %g, %g)"
# Line 93  class SessionTreeCtrl(wxTreeCtrl): Line 111  class SessionTreeCtrl(wxTreeCtrl):
111                          text = "Hidden"                          text = "Hidden"
112                      self.AppendItem(layeritem, text)                      self.AppendItem(layeritem, text)
113                      self.AppendItem(layeritem, "Shapes: %d" %layer.NumShapes())                      self.AppendItem(layeritem, "Shapes: %d" %layer.NumShapes())
114                      self.AppendItem(layeritem,                      bbox = layer.LatLongBoundingBox()
115                                      ("Extent (lat-lon): (%g, %g, %g, %g)"                      if bbox is not None:
116                                       % layer.LatLongBoundingBox()))                          self.AppendItem(layeritem,
117                                            ("Extent (lat-lon): (%g, %g, %g, %g)"
118                                             % bbox))
119                        else:
120                            self.AppendItem(layeritem, ("Extent (lat-lon):"))
121                      self.AppendItem(layeritem,                      self.AppendItem(layeritem,
122                                      "Shapetype: %s"                                      "Shapetype: %s"
123                                      % shapetype_names[layer.ShapeType()])                                      % shapetype_names[layer.ShapeType()])
# Line 108  class SessionTreeCtrl(wxTreeCtrl): Line 130  class SessionTreeCtrl(wxTreeCtrl):
130          self.Expand(root)          self.Expand(root)
131    
132      def session_changed(self, *args):      def session_changed(self, *args):
133          for channel in (MAPS_CHANGED,          new_session = self.app.session
134                          MAP_PROJECTION_CHANGED,          # if the session has changed subscribe/unsubscribe
135                          LAYERS_CHANGED,          if self.session is not new_session:
136                          LAYER_LEGEND_CHANGED,              if self.session is not None:
137                          LAYER_VISIBILITY_CHANGED):                  for channel in self.session_channels:
138              self.app.session.Subscribe(channel, self.update_tree)                      self.session.Unsubscribe(channel, self.update_tree)
139                if new_session is not None:
140                    for channel in self.session_channels:
141                        new_session.Subscribe(channel, self.update_tree)
142                self.session = new_session
143          self.update_tree()          self.update_tree()
144    
145      def normalize_selection(self):      def normalize_selection(self):
# Line 168  class SessionTreeView(NonModalDialog): Line 194  class SessionTreeView(NonModalDialog):
194          #self.interactor.Unsubscribe(SELECTED_SHAPE, self.select_shape)          #self.interactor.Unsubscribe(SELECTED_SHAPE, self.select_shape)
195          NonModalDialog.OnClose(self, event)          NonModalDialog.OnClose(self, event)
196    
197            # if there were a way to get notified when the tree control
198            # itself is destroyed we could use that to unsubscribe instead
199            # of doing it here. (EVT_WINDOW_DESTROY doesn't seem to sent at
200            # all)
201            self.tree.unsubscribe_all()

Legend:
Removed from v.111  
changed lines
  Added in v.177

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26