/[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 217 by bh, Wed Jul 17 10:50:40 2002 UTC revision 374 by jan, Mon Jan 27 14:20:02 2003 UTC
# Line 13  from types import StringType Line 13  from types import StringType
13    
14  from wxPython.wx import *  from wxPython.wx import *
15    
16  from Thuban.Model.messages import MAPS_CHANGED, MAP_PROJECTION_CHANGED, \  from Thuban import _
17       LAYERS_CHANGED, LAYER_LEGEND_CHANGED, LAYER_VISIBILITY_CHANGED, \  
18       EXTENSIONS_CHANGED, EXTENSION_OBJECTS_CHANGED  from Thuban.Model.messages import CHANGED
19  from Thuban.Model.layer import Layer, shapetype_names  from Thuban.Model.layer import Layer
20  from Thuban.Model.map import Map  from Thuban.Model.map import Map
21    
22  from dialogs import NonModalDialog  from dialogs import NonModalDialog
# Line 45  class SessionTreeCtrl(wxTreeCtrl): Line 45  class SessionTreeCtrl(wxTreeCtrl):
45            value of TreeInfo.            value of TreeInfo.
46      """      """
47    
     # the session channels to subscribe to update the tree  
     session_channels = (MAPS_CHANGED, MAP_PROJECTION_CHANGED,  
                         LAYERS_CHANGED, LAYER_LEGEND_CHANGED,  
                         LAYER_VISIBILITY_CHANGED, EXTENSIONS_CHANGED,  
                         EXTENSION_OBJECTS_CHANGED)  
   
48      def __init__(self, parent, ID, app):      def __init__(self, parent, ID, app):
49          # 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.
50          wxTreeCtrl.__init__(self, parent, ID)          wxTreeCtrl.__init__(self, parent, ID)
# Line 76  class SessionTreeCtrl(wxTreeCtrl): Line 70  class SessionTreeCtrl(wxTreeCtrl):
70    
71      def unsubscribe_all(self):      def unsubscribe_all(self):
72          if self.session is not None:          if self.session is not None:
73              for channel in self.session_channels:              self.session.Unsubscribe(CHANGED, self.update_tree)
                 self.session.Unsubscribe(channel, self.update_tree)  
74              self.session = None              self.session = None
75          self.app.Unsubscribe(SESSION_CHANGED, self.session_changed)          self.app.Unsubscribe(SESSION_CHANGED, self.session_changed)
76          self.app.interactor.Unsubscribe(SELECTED_LAYER, self.layer_selected)          self.app.interactor.Unsubscribe(SELECTED_LAYER, self.layer_selected)
# Line 95  class SessionTreeCtrl(wxTreeCtrl): Line 88  class SessionTreeCtrl(wxTreeCtrl):
88          # select the selected layer          # select the selected layer
89          selected_layer = self.app.interactor.selected_layer          selected_layer = self.app.interactor.selected_layer
90          if selected_layer is not None:          if selected_layer is not None:
91              self.SelectItem(self.layer_to_item[id(selected_layer)])              # One would expect that the selected_layer's id is in
92                # layer_to_item at this point as we've just rebuilt that
93                # mapping completely. However, when a new session is loaded
94                # for instance, it can happen that the tree view is updated
95                # before the interactor in which case selected_layer may be
96                # a layer of the old session.
97                item = self.layer_to_item.get(id(selected_layer))
98                if item is not None:
99                    self.SelectItem(item)
100    
101      def add_items(self, parent, items):      def add_items(self, parent, items):
102          for item in items:          for item in items:
# Line 123  class SessionTreeCtrl(wxTreeCtrl): Line 124  class SessionTreeCtrl(wxTreeCtrl):
124          # if the session has changed subscribe/unsubscribe          # if the session has changed subscribe/unsubscribe
125          if self.session is not new_session:          if self.session is not new_session:
126              if self.session is not None:              if self.session is not None:
127                  for channel in self.session_channels:                  self.session.Unsubscribe(CHANGED, self.update_tree)
                     self.session.Unsubscribe(channel, self.update_tree)  
128              if new_session is not None:              if new_session is not None:
129                  for channel in self.session_channels:                  new_session.Subscribe(CHANGED, self.update_tree)
                     new_session.Subscribe(channel, self.update_tree)  
130              self.session = new_session              self.session = new_session
131          self.update_tree()          self.update_tree()
132    
# Line 139  class SessionTreeCtrl(wxTreeCtrl): Line 138  class SessionTreeCtrl(wxTreeCtrl):
138              if isinstance(object, Layer) or isinstance(object, Map):              if isinstance(object, Layer) or isinstance(object, Map):
139                  break                  break
140              item = self.GetItemParent(item)              item = self.GetItemParent(item)
141            else:
142                # No layer or map was found in the chain of parents, so
143                # there's nothing we can do.
144                return
145    
146          self.changing_selection = 1          self.changing_selection = 1
147          try:          try:
# Line 176  class SessionTreeView(NonModalDialog): Line 179  class SessionTreeView(NonModalDialog):
179      """Non modal dialog showing the session as a tree"""      """Non modal dialog showing the session as a tree"""
180    
181      def __init__(self, parent, app, name):      def __init__(self, parent, app, name):
182          NonModalDialog.__init__(self, parent, app.interactor, name, "Session")          NonModalDialog.__init__(self, parent, app.interactor, name,
183                                    _("Session"))
184          self.tree = SessionTreeCtrl(self, -1, app)          self.tree = SessionTreeCtrl(self, -1, app)
185    
186      def OnClose(self, event):      def OnClose(self, event):

Legend:
Removed from v.217  
changed lines
  Added in v.374

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26