/[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 521 by jonathan, Wed Mar 12 13:18:50 2003 UTC revision 535 by bh, Fri Mar 14 20:42:18 2003 UTC
# Line 1  Line 1 
1  #! /usr/bin/python  #! /usr/bin/python
2  # Copyright (c) 2001, 2002 by Intevation GmbH  # Copyright (c) 2001, 2002, 2003 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 23  from Thuban.Model.layer import Layer Line 23  from Thuban.Model.layer import Layer
23  from Thuban.Model.map import Map  from Thuban.Model.map import Map
24    
25  from dialogs import NonModalDialog  from dialogs import NonModalDialog
26  from messages import SESSION_REPLACED, SELECTED_LAYER  from messages import SESSION_REPLACED, LAYER_SELECTED
27    
28  BMP_SIZE = 15  BMP_SIZE = 15
29    
# Line 49  class SessionTreeCtrl(wxTreeCtrl): Line 49  class SessionTreeCtrl(wxTreeCtrl):
49            value of TreeInfo.            value of TreeInfo.
50      """      """
51    
52      def __init__(self, parent, ID, app):      def __init__(self, parent, ID, mainwindow, app):
53    
54          # 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.
55          wxTreeCtrl.__init__(self, parent, ID)          wxTreeCtrl.__init__(self, parent, ID)
56    
57            self.mainwindow = mainwindow
58          self.app = app          self.app = app
59          # boolean to indicate that we manipulate the selection ourselves          # boolean to indicate that we manipulate the selection ourselves
60          # so that we can ignore the selection events generated          # so that we can ignore the selection events generated
# Line 63  class SessionTreeCtrl(wxTreeCtrl): Line 64  class SessionTreeCtrl(wxTreeCtrl):
64          self.layer_to_item = {}          self.layer_to_item = {}
65    
66          self.app.Subscribe(SESSION_REPLACED, self.session_changed)          self.app.Subscribe(SESSION_REPLACED, self.session_changed)
67          self.app.interactor.Subscribe(SELECTED_LAYER, self.layer_selected)          self.mainwindow.Subscribe(LAYER_SELECTED, self.layer_selected)
68    
69          # the session currently displayed in the tree          # the session currently displayed in the tree
70          self.session = None          self.session = None
# Line 79  class SessionTreeCtrl(wxTreeCtrl): Line 80  class SessionTreeCtrl(wxTreeCtrl):
80              self.session.Unsubscribe(CHANGED, self.update_tree)              self.session.Unsubscribe(CHANGED, self.update_tree)
81              self.session = None              self.session = None
82          self.app.Unsubscribe(SESSION_REPLACED, self.session_changed)          self.app.Unsubscribe(SESSION_REPLACED, self.session_changed)
83          self.app.interactor.Unsubscribe(SELECTED_LAYER, self.layer_selected)          self.mainwindow.Unsubscribe(LAYER_SELECTED, self.layer_selected)
84    
85      def update_tree(self, *args):      def update_tree(self, *args):
86          """Clear and rebuild the tree"""          """Clear and rebuild the tree"""
# Line 106  class SessionTreeCtrl(wxTreeCtrl): Line 107  class SessionTreeCtrl(wxTreeCtrl):
107          self.add_items(root, info[1])          self.add_items(root, info[1])
108          self.Expand(root)          self.Expand(root)
109          # select the selected layer          # select the selected layer
110          selected_layer = self.app.interactor.selected_layer          selected_layer = self.mainwindow.current_layer()
111          if selected_layer is not None:          if selected_layer is not None:
112              # One would expect that the selected_layer's id is in              # One would expect that the selected_layer's id is in
113              # layer_to_item at this point as we've just rebuilt that              # layer_to_item at this point as we've just rebuilt that
114              # mapping completely. However, when a new session is loaded              # mapping completely. However, when a new session is loaded
115              # for instance, it can happen that the tree view is updated              # for instance, it can happen that the tree view is updated
116              # before the interactor in which case selected_layer may be              # before the canvas's selection in which case selected_layer
117              # a layer of the old session.              # may be a layer of the old session.
118              item = self.layer_to_item.get(id(selected_layer))              item = self.layer_to_item.get(id(selected_layer))
119              if item is not None:              if item is not None:
120                  self.SelectItem(item)                  self.SelectItem(item)
# Line 208  class SessionTreeCtrl(wxTreeCtrl): Line 209  class SessionTreeCtrl(wxTreeCtrl):
209              return              return
210          self.normalize_selection()          self.normalize_selection()
211          # SelectedLayer returns None if no layer is selected. Since          # SelectedLayer returns None if no layer is selected. Since
212          # passing None to interactor.SelectLayer deselects the layer we          # passing None to SelectLayer deselects the layer we can simply
213          # can simply pass the result of SelectedLayer on in all cases          # pass the result of SelectedLayer on in all cases
214          self.app.interactor.SelectLayer(self.SelectedLayer())          self.mainwindow.SelectLayer(self.SelectedLayer())
215    
216      def layer_selected(self, layer):      def layer_selected(self, layer):
217          item = self.layer_to_item.get(id(layer))          item = self.layer_to_item.get(id(layer))
# Line 223  class SessionTreeView(NonModalDialog): Line 224  class SessionTreeView(NonModalDialog):
224      """Non modal dialog showing the session as a tree"""      """Non modal dialog showing the session as a tree"""
225    
226      def __init__(self, parent, app, name):      def __init__(self, parent, app, name):
227          NonModalDialog.__init__(self, parent, app.interactor, name,          NonModalDialog.__init__(self, parent, name, _("Session"))
228                                  _("Session"))          self.tree = SessionTreeCtrl(self, -1, parent, app)
         self.tree = SessionTreeCtrl(self, -1, app)  
229    
230      def OnClose(self, event):      def OnClose(self, event):
231          NonModalDialog.OnClose(self, event)          NonModalDialog.OnClose(self, event)

Legend:
Removed from v.521  
changed lines
  Added in v.535

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26