/[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 353 by bh, Tue Dec 3 17:35:30 2002 UTC revision 417 by jonathan, Wed Feb 19 16:53:22 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    
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 20  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 44  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 61  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 97  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    
110            if items is None: return
111    
112          for item in items:          for item in items:
113              if hasattr(item, "TreeInfo"):              if hasattr(item, "TreeInfo"):
114                  # Supports the TreeInfo protocol                  # Supports the TreeInfo protocol
# Line 107  class SessionTreeCtrl(wxTreeCtrl): Line 119  class SessionTreeCtrl(wxTreeCtrl):
119                  self.Expand(treeitem)                  self.Expand(treeitem)
120                  if isinstance(item, Layer):                  if isinstance(item, Layer):
121                      self.layer_to_item[id(item)] = treeitem                      self.layer_to_item[id(item)] = treeitem
122              elif isinstance(item, StringType):              elif isinstance(item, StringType) or \
123                     isinstance(item, UnicodeType):
124                  # it's a string                  # it's a string
                 # FIXME: What to do about UNICODE  
125                  self.AppendItem(parent, item)                  self.AppendItem(parent, item)
126              else:              else:
127                  # assume its a sequence (title, items)                  # assume its a sequence (title, items)
128                  treeitem = self.AppendItem(parent, item[0])                  if isinstance(item[1], Color):
129                  self.add_items(treeitem, item[1])  
130                        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):
# Line 177  class SessionTreeView(NonModalDialog): Line 210  class SessionTreeView(NonModalDialog):
210      """Non modal dialog showing the session as a tree"""      """Non modal dialog showing the session as a tree"""
211    
212      def __init__(self, parent, app, name):      def __init__(self, parent, app, name):
213          NonModalDialog.__init__(self, parent, app.interactor, name, "Session")          NonModalDialog.__init__(self, parent, app.interactor, name,
214                                    _("Session"))
215          self.tree = SessionTreeCtrl(self, -1, app)          self.tree = SessionTreeCtrl(self, -1, app)
216    
217      def OnClose(self, event):      def OnClose(self, event):

Legend:
Removed from v.353  
changed lines
  Added in v.417

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26