/[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 520 by jonathan, Wed Mar 12 10:35:49 2003 UTC revision 882 by jonathan, Fri May 9 16:34:28 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 14  from types import StringType, UnicodeTyp Line 14  from types import StringType, UnicodeTyp
14  from wxPython.wx import *  from wxPython.wx import *
15    
16  from Thuban import _  from Thuban import _
17  from Thuban.UI.common import *  from Thuban.UI.common import Color2wxColour
18    
19  from Thuban.Model.color import Color  from Thuban.Model.color import Color
20    
# 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"""
87          self.DeleteAllItems()          self.DeleteAllItems()
88          self.layer_to_item.clear()          self.layer_to_item.clear()
89          self.image_list = wxImageList(BMP_SIZE, BMP_SIZE, False, 0)          self.image_list = wxImageList(BMP_SIZE, BMP_SIZE, False, 0)
90    
91            bmp = wxEmptyBitmap(BMP_SIZE, BMP_SIZE)
92            dc = wxMemoryDC()
93            dc.SelectObject(bmp)
94            dc.SetBrush(wxBLACK_BRUSH)
95            dc.Clear()
96            dc.SelectObject(wxNullBitmap)
97    
98            self.emptyImageIndex = \
99                self.image_list.AddWithColourMask(bmp, wxColour(0, 0, 0))
100    
101          self.AssignImageList(self.image_list)          self.AssignImageList(self.image_list)
         bmp = wxEmptyBitmap(0, 0)  
         self.image_list.AddWithColourMask(bmp, wxColour(0, 0, 0))  
102    
103          session = self.app.session          session = self.app.session
104          info = session.TreeInfo()          info = session.TreeInfo()
105          root = self.AddRoot(info[0], 0, -1, None)          root = self.AddRoot(info[0], -1, -1, None)
106            self.SetItemImage(root, self.emptyImageIndex)
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 116  class SessionTreeCtrl(wxTreeCtrl): Line 127  class SessionTreeCtrl(wxTreeCtrl):
127              if hasattr(item, "TreeInfo"):              if hasattr(item, "TreeInfo"):
128                  # Supports the TreeInfo protocol                  # Supports the TreeInfo protocol
129                  info = item.TreeInfo()                  info = item.TreeInfo()
130                  #treeitem = self.AppendItem(parent, info[0])                  treeitem = self.AppendItem(parent, info[0], -1, -1, None)
131                  treeitem = self.AppendItem(parent, info[0], 0, -1, None)                  self.SetItemImage(treeitem, self.emptyImageIndex)
132                  self.SetPyData(treeitem, item)                  self.SetPyData(treeitem, item)
133                  self.add_items(treeitem, info[1])                  self.add_items(treeitem, info[1])
134                  self.Expand(treeitem)                  self.Expand(treeitem)
# Line 126  class SessionTreeCtrl(wxTreeCtrl): Line 137  class SessionTreeCtrl(wxTreeCtrl):
137              elif isinstance(item, StringType) or \              elif isinstance(item, StringType) or \
138                   isinstance(item, UnicodeType):                   isinstance(item, UnicodeType):
139                  # it's a string                  # it's a string
140                  treeitem = self.AppendItem(parent, item, 0, -1, None)                  treeitem = self.AppendItem(parent, item, -1, -1, None)
141                  #self.SetItemImage(treeitem, -1)                  self.SetItemImage(treeitem, self.emptyImageIndex)
142              else:              else:
143                  # assume its a sequence (title, items)                  # assume its a sequence (title, items)
144                  if isinstance(item[1], Color):                  if isinstance(item[1], Color):
# Line 148  class SessionTreeCtrl(wxTreeCtrl): Line 159  class SessionTreeCtrl(wxTreeCtrl):
159                      i = self.image_list.Add(bmp)                      i = self.image_list.Add(bmp)
160                      self.SetItemImage(treeitem, i)                      self.SetItemImage(treeitem, i)
161                  else:                  else:
162                      #treeitem = self.AppendItem(parent, item[0])                      treeitem = self.AppendItem(parent, item[0], -1, -1, None)
163                      treeitem = self.AppendItem(parent, item[0], 0, -1, None)                      self.SetItemImage(treeitem, self.emptyImageIndex)
164                      self.add_items(treeitem, item[1])                      self.add_items(treeitem, item[1])
165                  self.Expand(treeitem)                  self.Expand(treeitem)
166    
# Line 198  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 213  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.520  
changed lines
  Added in v.882

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26