10 |
from Thuban import _ |
from Thuban import _ |
11 |
|
|
12 |
from wxPython.wx import * |
from wxPython.wx import * |
|
from dialogs import NonModalDialog |
|
13 |
|
|
14 |
from Thuban.Model.layer import Layer |
from Thuban.Model.layer import Layer |
15 |
from Thuban.Model.map import Map |
from Thuban.Model.map import Map |
|
|
|
16 |
from Thuban.Model.messages import * |
from Thuban.Model.messages import * |
|
|
|
17 |
from Thuban.Model.classification import ClassGroup |
from Thuban.Model.classification import ClassGroup |
18 |
|
|
19 |
from Thuban.UI.classifier import ClassDataPreviewer |
from Thuban.UI.classifier import ClassDataPreviewer |
20 |
|
from Thuban.UI.dock import DockPanel |
21 |
|
|
22 |
ID_LEGEND_MOVEUP = 4001 |
ID_LEGEND_MOVEUP = 4001 |
23 |
ID_LEGEND_MOVEDOWN = 4002 |
ID_LEGEND_MOVEDOWN = 4002 |
25 |
ID_LEGEND_CLASSIFY = 4004 |
ID_LEGEND_CLASSIFY = 4004 |
26 |
ID_LEGEND_SHOWLAYER = 4005 |
ID_LEGEND_SHOWLAYER = 4005 |
27 |
ID_LEGEND_HIDELAYER = 4006 |
ID_LEGEND_HIDELAYER = 4006 |
28 |
|
ID_LEGEND_DOCK = 4007 |
29 |
|
ID_LEGEND_UNDOCK = 4008 |
30 |
|
|
31 |
BMP_SIZE_W = 30 |
BMP_SIZE_W = 30 |
32 |
BMP_SIZE_H = 15 |
BMP_SIZE_H = 15 |
33 |
|
|
34 |
class Legend(NonModalDialog): |
#class LegendDialog(NonModalDialog): |
35 |
|
|
36 |
def __init__(self, parent, name, map): |
#def __init__(self, parent, name, panel): |
37 |
NonModalDialog.__init__(self, parent, name, |
#NonModalDialog.__init__(self, parent, name, |
38 |
_("Legend: %s") % map.Title()) |
#_("Legend: %s") % map.Title()) |
39 |
|
|
40 |
self.parent = parent |
##topBox = wxBoxSizer(wxVERTICAL) |
41 |
|
|
42 |
|
#panel = LegendPanel(self, map) |
43 |
|
|
44 |
|
#self.panel = panel |
45 |
|
|
46 |
|
#topBox.Add(panel, 1, wxGROW, 4) |
47 |
|
|
48 |
|
##self.SetAutoLayout(True) |
49 |
|
##self.SetSizer(topBox) |
50 |
|
|
51 |
|
#def GetLegendPanel(self): |
52 |
|
#return self.panel |
53 |
|
|
54 |
panel = wxPanel(self, -1) |
#def OnClose(self, event): |
55 |
|
#NonModalDialog.OnClose(self, event) |
56 |
|
|
57 |
|
#self.panel.SetMap(None) |
58 |
|
|
59 |
|
class LegendPanel(DockPanel): |
60 |
|
|
61 |
|
def __init__(self, parent, map, mainWindow): |
62 |
|
DockPanel.__init__(self, parent, -1) |
63 |
|
|
64 |
|
self.mainWindow = mainWindow |
65 |
|
self.parent = parent |
66 |
|
|
|
topBox = wxBoxSizer(wxVERTICAL) |
|
67 |
panelBox = wxBoxSizer(wxVERTICAL) |
panelBox = wxBoxSizer(wxVERTICAL) |
68 |
|
|
69 |
buttonBox = wxGridSizer(2, 3, 0, 0) |
buttonBox = wxGridSizer(2, 3, 0, 0) |
90 |
buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0) |
buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0) |
91 |
self.buttons.append(button) |
self.buttons.append(button) |
92 |
|
|
93 |
|
# button = wxButton(self, ID_LEGEND_DOCK, _("Dock")) |
94 |
|
# buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0) |
95 |
|
# self.buttons.append(button) |
96 |
|
|
97 |
|
# button = wxButton(self, ID_LEGEND_UNDOCK, _("Undock")) |
98 |
|
# buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0) |
99 |
|
# self.buttons.append(button) |
100 |
|
|
101 |
|
|
102 |
EVT_BUTTON(self, ID_LEGEND_MOVEUP, self._OnMoveUp) |
EVT_BUTTON(self, ID_LEGEND_MOVEUP, self._OnMoveUp) |
103 |
EVT_BUTTON(self, ID_LEGEND_MOVEDOWN, self._OnMoveDown) |
EVT_BUTTON(self, ID_LEGEND_MOVEDOWN, self._OnMoveDown) |
104 |
EVT_BUTTON(self, ID_LEGEND_CLASSIFY, self._OnClassify) |
EVT_BUTTON(self, ID_LEGEND_CLASSIFY, self._OnClassify) |
105 |
EVT_BUTTON(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer) |
EVT_BUTTON(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer) |
106 |
EVT_BUTTON(self, ID_LEGEND_HIDELAYER, self._OnHideLayer) |
EVT_BUTTON(self, ID_LEGEND_HIDELAYER, self._OnHideLayer) |
107 |
|
#EVT_BUTTON(self, ID_LEGEND_DOCK, self._OnDock) |
108 |
|
#EVT_BUTTON(self, ID_LEGEND_UNDOCK, self._OnUndock) |
109 |
|
|
110 |
panelBox.Add(buttonBox, 0, 0, 4) |
panelBox.Add(buttonBox, 0, 0, 4) |
111 |
|
|
112 |
self.tree = LegendTree(self, ID_LEGEND_TREE, map) |
self.tree = LegendTree(self, ID_LEGEND_TREE, map, mainWindow) |
113 |
|
|
114 |
panelBox.Add(self.tree, 1, wxGROW, 4) |
panelBox.Add(self.tree, 1, wxGROW, 4) |
115 |
|
|
116 |
panel.SetAutoLayout(True) |
self.SetAutoLayout(True) |
117 |
panel.SetSizer(panelBox) |
self.SetSizer(panelBox) |
|
panelBox.SetSizeHints(panel) |
|
|
|
|
|
topBox.Add(panel, 1, wxGROW, 0) |
|
118 |
panelBox.SetSizeHints(self) |
panelBox.SetSizeHints(self) |
119 |
|
|
120 |
self.SetAutoLayout(True) |
#panelBox.SetSizeHints(self.parent) |
121 |
self.SetSizer(topBox) |
|
122 |
|
self.panelBox = panelBox |
123 |
|
|
124 |
|
def GetMap(self): |
125 |
|
return self.tree.GetMap() |
126 |
|
|
127 |
|
def SetMap(self, map): |
128 |
|
self.tree.SetMap(map) |
129 |
|
|
130 |
def DoOnSelChanged(self): |
def DoOnSelChanged(self): |
131 |
self.__EnableButtons(self.tree.GetSelection().IsOk()) |
self.__EnableButtons(self.tree.GetSelection().IsOk()) |
147 |
self.tree.DoOnHideLayer() |
self.tree.DoOnHideLayer() |
148 |
pass |
pass |
149 |
|
|
150 |
|
def _OnDock(self, event): |
151 |
|
self.Dock() |
152 |
|
|
153 |
|
def _OnUndock(self, event): |
154 |
|
self.UnDock() |
155 |
|
|
156 |
def __EnableButtons(self, on): |
def __EnableButtons(self, on): |
157 |
for b in self.buttons: |
for b in self.buttons: |
159 |
|
|
160 |
class LegendTree(wxTreeCtrl): |
class LegendTree(wxTreeCtrl): |
161 |
|
|
162 |
def __init__(self, parent, id, map): |
def __init__(self, parent, id, map, mainWindow): |
163 |
wxTreeCtrl.__init__(self, parent, id, |
wxTreeCtrl.__init__(self, parent, id, |
164 |
style = wxTR_DEFAULT_STYLE | wxTR_HIDE_ROOT, |
style = wxTR_DEFAULT_STYLE | wxTR_HIDE_ROOT, |
165 |
size = (200, 200)) |
size = (200, 200)) |
166 |
|
|
167 |
|
self.map = None |
168 |
self.parent = parent |
self.parent = parent |
|
self.map = map |
|
169 |
self.layer2id = None |
self.layer2id = None |
170 |
|
|
171 |
|
|
174 |
|
|
175 |
self.previewer = ClassDataPreviewer() |
self.previewer = ClassDataPreviewer() |
176 |
|
|
|
|
|
177 |
EVT_TREE_ITEM_ACTIVATED(self, ID_LEGEND_TREE, self._OnItemActivated) |
EVT_TREE_ITEM_ACTIVATED(self, ID_LEGEND_TREE, self._OnItemActivated) |
178 |
EVT_TREE_SEL_CHANGED(self, ID_LEGEND_TREE, self._OnSelChanged) |
EVT_TREE_SEL_CHANGED(self, ID_LEGEND_TREE, self._OnSelChanged) |
179 |
|
|
180 |
map.Subscribe(MAP_STACKING_CHANGED, self._OnMsgMapStackingChanged) |
self.SetMap(map) |
181 |
map.Subscribe(MAP_LAYERS_CHANGED, self._OnMsgMapLayersChanged) |
|
182 |
|
def GetMap(self): |
183 |
|
return self.map |
184 |
|
|
185 |
self.__FillTree(map) |
def SetMap(self, map): |
186 |
|
|
187 |
|
sub_list = [(MAP_STACKING_CHANGED, self._OnMsgMapStackingChanged), |
188 |
|
(MAP_LAYERS_ADDED, self._OnMsgMapLayersAddedRemoved), |
189 |
|
(MAP_LAYERS_REMOVED, self._OnMsgMapLayersAddedRemoved)] |
190 |
|
|
191 |
|
if self.map is not None: |
192 |
|
for msg, func in sub_list: self.map.Unsubscribe(msg, func) |
193 |
|
self.__DeleteAllItems() |
194 |
|
|
195 |
|
self.map = map |
196 |
|
|
197 |
|
if self.map is not None: |
198 |
|
for msg, func in sub_list: self.map.Subscribe(msg, func) |
199 |
|
self.__FillTree(self.map) |
200 |
|
|
201 |
|
|
202 |
def MoveCurrentItemUp(self): |
def MoveCurrentItemUp(self): |
203 |
cur_id = self.GetSelection() |
cur_id = self.GetSelection() |
204 |
assert(cur_id.IsOk()) |
assert(cur_id.IsOk()) |
256 |
def DoOnClassify(self): |
def DoOnClassify(self): |
257 |
id = self.GetSelection() |
id = self.GetSelection() |
258 |
assert(id.IsOk()) |
assert(id.IsOk()) |
259 |
|
assert(id.IsOk()) |
260 |
|
|
261 |
item = self.GetPyData(id) |
item = self.GetPyData(id) |
262 |
if isinstance(item, ClassGroup): |
if isinstance(item, ClassGroup): |
264 |
assert(id.IsOk()) |
assert(id.IsOk()) |
265 |
item = self.GetPyData(id) |
item = self.GetPyData(id) |
266 |
|
|
267 |
self.parent.parent.OpenClassifier(item) |
# XXX: THIS IS SUCH AWFUL STYLE! YUCK! |
268 |
|
self.parent.mainWindow.OpenClassifier(item) |
269 |
|
#assert(False, "XXX: FIXME HERE") |
270 |
|
|
271 |
def Sort(self): |
def Sort(self): |
272 |
self.SortChildren(self.GetRootItem()) |
self.SortChildren(self.GetRootItem()) |
286 |
|
|
287 |
def _OnMsgMapStackingChanged(self, *args): |
def _OnMsgMapStackingChanged(self, *args): |
288 |
self.Sort() |
self.Sort() |
289 |
|
id = self.GetSelection() |
290 |
|
|
291 |
|
if id.IsOk(): |
292 |
|
self.EnsureVisible(id) |
293 |
|
|
294 |
def _OnMsgMapLayersChanged(self, map): |
def _OnMsgMapLayersAddedRemoved(self, map): |
295 |
assert(id(map) == id(self.map)) |
assert(id(map) == id(self.map)) |
296 |
|
|
297 |
self.__FillTree(self.map) |
self.__FillTree(self.map) |