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 |
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 |
|
|
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 |
|
|
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 |
|
|
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 |
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): |
212 |
_("Session")) |
_("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 |
|
|