/[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 383 by jonathan, Tue Jan 28 18:38:03 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    
18    from Thuban.Model.color import Color
19    
20  from Thuban.Model.messages import CHANGED  from Thuban.Model.messages import CHANGED
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
# Line 22  from Thuban.Model.map import Map Line 24  from Thuban.Model.map import Map
24  from dialogs import NonModalDialog  from dialogs import NonModalDialog
25  from messages import SESSION_CHANGED, SELECTED_LAYER  from messages import SESSION_CHANGED, SELECTED_LAYER
26    
27    BMP_SIZE = 15
28    
29  class SessionTreeCtrl(wxTreeCtrl):  class SessionTreeCtrl(wxTreeCtrl):
30    
# Line 46  class SessionTreeCtrl(wxTreeCtrl): Line 49  class SessionTreeCtrl(wxTreeCtrl):
49      """      """
50    
51      def __init__(self, parent, ID, app):      def __init__(self, parent, ID, 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    
# Line 63  class SessionTreeCtrl(wxTreeCtrl): Line 67  class SessionTreeCtrl(wxTreeCtrl):
67          # the session currently displayed in the tree          # the session currently displayed in the tree
68          self.session = None          self.session = None
69    
70            self.image_list = wxImageList(BMP_SIZE, BMP_SIZE)
71            self.AssignImageList(self.image_list)
72    
73          # pretend the session has changed to build the initial tree          # pretend the session has changed to build the initial tree
74          self.session_changed()          self.session_changed()
75    
# Line 99  class SessionTreeCtrl(wxTreeCtrl): Line 106  class SessionTreeCtrl(wxTreeCtrl):
106                  self.SelectItem(item)                  self.SelectItem(item)
107    
108      def add_items(self, parent, items):      def add_items(self, parent, items):
109            # print "\n---\n", 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])                      treeitem = self.AppendItem(parent, _("(%s)") % item[0])
131    
132                        bmp = wxEmptyBitmap(BMP_SIZE, BMP_SIZE)
133                        brush = wxBrush(wxColour(item[1].red * 255,
134                                                 item[1].green * 255,
135                                                 item[1].blue * 255),
136                                        wxSOLID)
137                        dc = wxMemoryDC()
138                        dc.SelectObject(bmp)
139                        dc.SetBrush(brush)
140                        dc.Clear()
141                        dc.DrawRoundedRectangle(0, 0,
142                                                bmp.GetWidth(), bmp.GetHeight(),
143                                                4)
144                        dc.SelectObject(wxNullBitmap)
145    
146                        i = self.image_list.Add(bmp)
147                        self.SetItemImage(treeitem, i)
148                    else:
149                        treeitem = self.AppendItem(parent, item[0])
150                        self.add_items(treeitem, item[1])
151                  self.Expand(treeitem)                  self.Expand(treeitem)
152    
153      def session_changed(self, *args):      def session_changed(self, *args):

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26