/[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 1766 by jan, Wed Oct 1 09:52:28 2003 UTC
# Line 1  Line 1 
1  #! /usr/bin/python  # Copyright (c) 2001, 2002, 2003 by Intevation GmbH
 # Copyright (c) 2001, 2002 by Intevation GmbH  
2  # Authors:  # Authors:
3  # Jan-Oliver Wagner <[email protected]>  # Jan-Oliver Wagner <[email protected]>
4  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
# Line 14  from types import StringType, UnicodeTyp Line 13  from types import StringType, UnicodeTyp
13  from wxPython.wx import *  from wxPython.wx import *
14    
15  from Thuban import _  from Thuban import _
16  from Thuban.UI.common import *  from Thuban.UI.common import Color2wxColour
17    
18  from Thuban.Model.color import Color  from Thuban.Model.color import Color
19    
# Line 22  from Thuban.Model.messages import CHANGE Line 21  from Thuban.Model.messages import CHANGE
21  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer
22  from Thuban.Model.map import Map  from Thuban.Model.map import Map
23    
24  from dialogs import NonModalDialog  from dialogs import NonModalNonParentDialog
25  from messages import SESSION_REPLACED, SELECTED_LAYER  from messages import SESSION_REPLACED, LAYER_SELECTED
26    
27  BMP_SIZE = 15  BMP_SIZE = 15
28    
# Line 49  class SessionTreeCtrl(wxTreeCtrl): Line 48  class SessionTreeCtrl(wxTreeCtrl):
48            value of TreeInfo.            value of TreeInfo.
49      """      """
50    
51      def __init__(self, parent, ID, app):      def __init__(self, parent, ID, mainwindow, app):
52    
53          # 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.
54          wxTreeCtrl.__init__(self, parent, ID)          wxTreeCtrl.__init__(self, parent, ID)
55    
56            self.mainwindow = mainwindow
57          self.app = app          self.app = app
58          # boolean to indicate that we manipulate the selection ourselves          # boolean to indicate that we manipulate the selection ourselves
59          # so that we can ignore the selection events generated          # so that we can ignore the selection events generated
# Line 63  class SessionTreeCtrl(wxTreeCtrl): Line 63  class SessionTreeCtrl(wxTreeCtrl):
63          self.layer_to_item = {}          self.layer_to_item = {}
64    
65          self.app.Subscribe(SESSION_REPLACED, self.session_changed)          self.app.Subscribe(SESSION_REPLACED, self.session_changed)
66          self.app.interactor.Subscribe(SELECTED_LAYER, self.layer_selected)          self.mainwindow.Subscribe(LAYER_SELECTED, self.layer_selected)
67    
68          # the session currently displayed in the tree          # the session currently displayed in the tree
69          self.session = None          self.session = None
# Line 79  class SessionTreeCtrl(wxTreeCtrl): Line 79  class SessionTreeCtrl(wxTreeCtrl):
79              self.session.Unsubscribe(CHANGED, self.update_tree)              self.session.Unsubscribe(CHANGED, self.update_tree)
80              self.session = None              self.session = None
81          self.app.Unsubscribe(SESSION_REPLACED, self.session_changed)          self.app.Unsubscribe(SESSION_REPLACED, self.session_changed)
82          self.app.interactor.Unsubscribe(SELECTED_LAYER, self.layer_selected)          self.mainwindow.Unsubscribe(LAYER_SELECTED, self.layer_selected)
83    
84      def update_tree(self, *args):      def update_tree(self, *args):
85          """Clear and rebuild the tree"""          """Clear and rebuild the tree"""
# Line 106  class SessionTreeCtrl(wxTreeCtrl): Line 106  class SessionTreeCtrl(wxTreeCtrl):
106          self.add_items(root, info[1])          self.add_items(root, info[1])
107          self.Expand(root)          self.Expand(root)
108          # select the selected layer          # select the selected layer
109          selected_layer = self.app.interactor.selected_layer          selected_layer = self.mainwindow.current_layer()
110          if selected_layer is not None:          if selected_layer is not None:
111              # One would expect that the selected_layer's id is in              # One would expect that the selected_layer's id is in
112              # layer_to_item at this point as we've just rebuilt that              # layer_to_item at this point as we've just rebuilt that
113              # mapping completely. However, when a new session is loaded              # mapping completely. However, when a new session is loaded
114              # for instance, it can happen that the tree view is updated              # for instance, it can happen that the tree view is updated
115              # before the interactor in which case selected_layer may be              # before the canvas's selection in which case selected_layer
116              # a layer of the old session.              # may be a layer of the old session.
117              item = self.layer_to_item.get(id(selected_layer))              item = self.layer_to_item.get(id(selected_layer))
118              if item is not None:              if item is not None:
119                  self.SelectItem(item)                  self.SelectItem(item)
# Line 208  class SessionTreeCtrl(wxTreeCtrl): Line 208  class SessionTreeCtrl(wxTreeCtrl):
208              return              return
209          self.normalize_selection()          self.normalize_selection()
210          # SelectedLayer returns None if no layer is selected. Since          # SelectedLayer returns None if no layer is selected. Since
211          # passing None to interactor.SelectLayer deselects the layer we          # passing None to SelectLayer deselects the layer we can simply
212          # can simply pass the result of SelectedLayer on in all cases          # pass the result of SelectedLayer on in all cases
213          self.app.interactor.SelectLayer(self.SelectedLayer())          self.mainwindow.SelectLayer(self.SelectedLayer())
214    
215      def layer_selected(self, layer):      def layer_selected(self, layer):
216          item = self.layer_to_item.get(id(layer))          item = self.layer_to_item.get(id(layer))
# Line 218  class SessionTreeCtrl(wxTreeCtrl): Line 218  class SessionTreeCtrl(wxTreeCtrl):
218              self.SelectItem(item)              self.SelectItem(item)
219    
220    
221  class SessionTreeView(NonModalDialog):  class SessionTreeView(NonModalNonParentDialog):
222    
223      """Non modal dialog showing the session as a tree"""      """Non modal dialog showing the session as a tree"""
224    
225      def __init__(self, parent, app, name):      def __init__(self, parent, app, name):
226          NonModalDialog.__init__(self, parent, app.interactor, name,          NonModalNonParentDialog.__init__(self, parent, name, _("Session"))
227                                  _("Session"))          self.tree = SessionTreeCtrl(self, -1, parent, app)
         self.tree = SessionTreeCtrl(self, -1, app)  
228    
229      def OnClose(self, event):      def OnClose(self, event):
230          NonModalDialog.OnClose(self, event)          NonModalNonParentDialog.OnClose(self, event)
231    
232          # if there were a way to get notified when the tree control          # if there were a way to get notified when the tree control
233          # itself is destroyed we could use that to unsubscribe instead          # itself is destroyed we could use that to unsubscribe instead

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26