/[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 233 by bh, Fri Jul 19 15:15:16 2002 UTC revision 488 by jonathan, Fri Mar 7 18:21:25 2003 UTC
# Line 9  Line 9 
9    
10  __version__ = "$Revision$"  __version__ = "$Revision$"
11    
12  from types import StringType  from types import StringType, UnicodeType
13    
14  from wxPython.wx import *  from wxPython.wx import *
15    
16    from Thuban import _
17    from Thuban.UI.common import *
18    
19    from Thuban.Model.color import Color
20    
21  from Thuban.Model.messages import CHANGED  from Thuban.Model.messages import CHANGED
22  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer
23  from Thuban.Model.map import Map  from Thuban.Model.map import Map
# Line 20  from Thuban.Model.map import Map Line 25  from Thuban.Model.map import Map
25  from dialogs import NonModalDialog  from dialogs import NonModalDialog
26  from messages import SESSION_CHANGED, SELECTED_LAYER  from messages import SESSION_CHANGED, SELECTED_LAYER
27    
28    BMP_SIZE = 15
29    
30  class SessionTreeCtrl(wxTreeCtrl):  class SessionTreeCtrl(wxTreeCtrl):
31    
# Line 44  class SessionTreeCtrl(wxTreeCtrl): Line 50  class SessionTreeCtrl(wxTreeCtrl):
50      """      """
51    
52      def __init__(self, parent, ID, app):      def __init__(self, parent, ID, 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    
# Line 61  class SessionTreeCtrl(wxTreeCtrl): Line 68  class SessionTreeCtrl(wxTreeCtrl):
68          # the session currently displayed in the tree          # the session currently displayed in the tree
69          self.session = None          self.session = None
70    
71            self.image_list = wxImageList(BMP_SIZE, BMP_SIZE)
72            self.AssignImageList(self.image_list)
73    
74          # pretend the session has changed to build the initial tree          # pretend the session has changed to build the initial tree
75          self.session_changed()          self.session_changed()
76    
# Line 97  class SessionTreeCtrl(wxTreeCtrl): Line 107  class SessionTreeCtrl(wxTreeCtrl):
107                  self.SelectItem(item)                  self.SelectItem(item)
108    
109      def add_items(self, parent, items):      def add_items(self, parent, items):
110    
111            if items is None: return
112    
113          for item in items:          for item in items:
114              if hasattr(item, "TreeInfo"):              if hasattr(item, "TreeInfo"):
115                  # Supports the TreeInfo protocol                  # Supports the TreeInfo protocol
# Line 107  class SessionTreeCtrl(wxTreeCtrl): Line 120  class SessionTreeCtrl(wxTreeCtrl):
120                  self.Expand(treeitem)                  self.Expand(treeitem)
121                  if isinstance(item, Layer):                  if isinstance(item, Layer):
122                      self.layer_to_item[id(item)] = treeitem                      self.layer_to_item[id(item)] = treeitem
123              elif isinstance(item, StringType):              elif isinstance(item, StringType) or \
124                     isinstance(item, UnicodeType):
125                  # it's a string                  # it's a string
                 # FIXME: What to do about UNICODE  
126                  self.AppendItem(parent, item)                  self.AppendItem(parent, item)
127              else:              else:
128                  # assume its a sequence (title, items)                  # assume its a sequence (title, items)
129                  treeitem = self.AppendItem(parent, item[0])                  if isinstance(item[1], Color):
130                  self.add_items(treeitem, item[1])  
131                        treeitem = self.AppendItem(parent, "(%s)" % item[0])
132    
133                        bmp = wxEmptyBitmap(BMP_SIZE, BMP_SIZE)
134                        brush = wxBrush(Color2wxColour(item[1]), wxSOLID)
135                        dc = wxMemoryDC()
136                        dc.SelectObject(bmp)
137                        dc.SetBrush(brush)
138                        dc.Clear()
139                        dc.DrawRoundedRectangle(0, 0,
140                                                bmp.GetWidth(), bmp.GetHeight(),
141                                                4)
142                        dc.SelectObject(wxNullBitmap)
143    
144                        i = self.image_list.Add(bmp)
145                        self.SetItemImage(treeitem, i)
146                    else:
147                        treeitem = self.AppendItem(parent, item[0])
148                        self.add_items(treeitem, item[1])
149                  self.Expand(treeitem)                  self.Expand(treeitem)
150    
151      def session_changed(self, *args):      def session_changed(self, *args):
# Line 136  class SessionTreeCtrl(wxTreeCtrl): Line 167  class SessionTreeCtrl(wxTreeCtrl):
167              if isinstance(object, Layer) or isinstance(object, Map):              if isinstance(object, Layer) or isinstance(object, Map):
168                  break                  break
169              item = self.GetItemParent(item)              item = self.GetItemParent(item)
170            else:
171                # No layer or map was found in the chain of parents, so
172                # there's nothing we can do.
173                return
174    
175          self.changing_selection = 1          self.changing_selection = 1
176          try:          try:
# Line 173  class SessionTreeView(NonModalDialog): Line 208  class SessionTreeView(NonModalDialog):
208      """Non modal dialog showing the session as a tree"""      """Non modal dialog showing the session as a tree"""
209    
210      def __init__(self, parent, app, name):      def __init__(self, parent, app, name):
211          NonModalDialog.__init__(self, parent, app.interactor, name, "Session")          NonModalDialog.__init__(self, parent, app.interactor, name,
212                                    _("Session"))
213          self.tree = SessionTreeCtrl(self, -1, app)          self.tree = SessionTreeCtrl(self, -1, app)
214    
215      def OnClose(self, event):      def Shutdown(self):
         #self.interactor.Unsubscribe(SELECTED_SHAPE, self.select_shape)  
         NonModalDialog.OnClose(self, event)  
   
216          # if there were a way to get notified when the tree control          # if there were a way to get notified when the tree control
217          # itself is destroyed we could use that to unsubscribe instead          # itself is destroyed we could use that to unsubscribe instead
218          # of doing it here. (EVT_WINDOW_DESTROY doesn't seem to sent at          # of doing it here. (EVT_WINDOW_DESTROY doesn't seem to sent at
219          # all)          # all)
220          self.tree.unsubscribe_all()          self.tree.unsubscribe_all()
221    
222            # this needs to come last because Destroy will be called
223            NonModalDialog.Shutdown(self)
224    

Legend:
Removed from v.233  
changed lines
  Added in v.488

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26