/[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 374 by jan, Mon Jan 27 14:20:02 2003 UTC revision 443 by jonathan, Thu Feb 27 15:55:42 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 _  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
# Line 22  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 46  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 63  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 99  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 109  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):

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26