18 |
from Thuban.common import * |
from Thuban.common import * |
19 |
from Thuban.UI.common import * |
from Thuban.UI.common import * |
20 |
|
|
21 |
from Thuban.Model.classification import * #Classification, ClassData |
from Thuban.Model.classification import * |
22 |
|
|
23 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Color |
24 |
|
|
31 |
ID_CLASSIFY_CANCEL = 4002 |
ID_CLASSIFY_CANCEL = 4002 |
32 |
ID_CLASSIFY_ADD = 4003 |
ID_CLASSIFY_ADD = 4003 |
33 |
ID_CLASSIFY_GENRANGE = 4004 |
ID_CLASSIFY_GENRANGE = 4004 |
34 |
|
ID_CLASSIFY_REMOVE = 4005 |
35 |
|
|
36 |
COL_VISUAL = 0 |
COL_VISUAL = 0 |
37 |
COL_VALUE = 1 |
COL_VALUE = 1 |
38 |
COL_LABEL = 2 |
COL_LABEL = 2 |
39 |
|
|
40 |
|
FIELD_CLASS = 0 |
41 |
|
FIELD_TYPE = 1 |
42 |
|
FIELD_NAME = 2 |
43 |
|
|
44 |
|
FIELD_TYPE_STRING = "string" |
45 |
|
FIELD_TYPE_INT = "int" |
46 |
|
FIELD_TYPE_DOUBLE = "double" |
47 |
|
|
48 |
# |
# |
49 |
# this is a silly work around to ensure that the table that is |
# this is a silly work around to ensure that the table that is |
50 |
# passed into SetTable is the same that is returned by GetTable |
# passed into SetTable is the same that is returned by GetTable |
52 |
import weakref |
import weakref |
53 |
class ClassGrid(wxGrid): |
class ClassGrid(wxGrid): |
54 |
|
|
55 |
def __init__(self, parent, layer): |
def __init__(self, parent, layer, fieldData): |
56 |
wxGrid.__init__(self, parent, ID_CLASS_TABLE, size = (300, 150)) |
wxGrid.__init__(self, parent, ID_CLASS_TABLE, size = (340, 160)) |
57 |
self.SetTable( |
self.SetTable(ClassTable(fieldData, layer.ShapeType(), self), true) |
58 |
ClassTable(layer.GetClassification(), layer.ShapeType(), self), |
self.SetSelectionMode(wxGrid.wxGridSelectRows) |
59 |
true) |
EVT_GRID_CELL_LEFT_DCLICK(self, self.OnCellDClick) |
60 |
|
|
61 |
|
EVT_GRID_RANGE_SELECT(self, self._OnSelectedRange) |
62 |
|
EVT_GRID_SELECT_CELL(self, self._OnSelectedCell) |
63 |
|
|
64 |
|
self.layer = layer |
65 |
|
self.currentSelection = [] |
66 |
|
|
67 |
|
def GetCurrentSelection(self): |
68 |
|
sel = copy.copy(self.currentSelection) |
69 |
|
sel.sort() |
70 |
|
return sel |
71 |
|
|
72 |
def SetCellRenderer(self, row, col): |
def SetCellRenderer(self, row, col): |
73 |
raise ValueError(_("Must not allow setting of renderer in ClassGrid!")) |
raise ValueError(_("Must not allow setting of renderer in ClassGrid!")) |
79 |
def GetTable(self): |
def GetTable(self): |
80 |
return self.tableRef() |
return self.tableRef() |
81 |
|
|
82 |
|
def DeleteSelectedRows(self): |
83 |
|
sel = self.GetCurrentSelection() |
84 |
|
|
85 |
|
if len(sel) == 0: return |
86 |
|
if len(sel) == 1: |
87 |
|
group = self.GetTable().GetValueAsCustom(sel[0], COL_VISUAL, None) |
88 |
|
if isinstance(group, ClassGroupDefault): |
89 |
|
wxMessageDialog(self, |
90 |
|
"The Default group cannot be removed.", |
91 |
|
style = wxOK | wxICON_EXCLAMATION).ShowModal() |
92 |
|
return |
93 |
|
|
94 |
|
self.ClearSelection() |
95 |
|
|
96 |
|
sel.reverse() |
97 |
|
table = self.GetTable() |
98 |
|
for row in sel: |
99 |
|
table.DeleteRows(row) |
100 |
|
|
101 |
|
if len(sel) == 1: |
102 |
|
r = sel[0] |
103 |
|
if r > self.GetNumberRows() - 1: |
104 |
|
r = self.GetNumberRows() - 1 |
105 |
|
self.SelectRow(r) |
106 |
|
|
107 |
|
# |
108 |
|
# XXX: This isn't working, and there is no way to deselect rows wxPython! |
109 |
|
# |
110 |
|
# def DeselectRow(self, row): |
111 |
|
# self.ProcessEvent( |
112 |
|
# wxGridRangeSelectEvent(-1, |
113 |
|
# wxEVT_GRID_RANGE_SELECT, |
114 |
|
# self, |
115 |
|
# (row, row), (row, row), |
116 |
|
# sel = False)) |
117 |
|
|
118 |
|
def OnCellDClick(self, event): |
119 |
|
r = event.GetRow() |
120 |
|
c = event.GetCol() |
121 |
|
if c == COL_VISUAL: |
122 |
|
# XXX: getting the properties is only possible with non-Maps!!! |
123 |
|
group = self.GetTable().GetValueAsCustom(r, c, None) |
124 |
|
prop = group.GetProperties() |
125 |
|
propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType()) |
126 |
|
if propDlg.ShowModal() == wxID_OK: |
127 |
|
new_prop = propDlg.GetClassGroupProperties() |
128 |
|
prop.SetStroke(new_prop.GetStroke()) |
129 |
|
prop.SetStrokeWidth(new_prop.GetStrokeWidth()) |
130 |
|
prop.SetFill(new_prop.GetFill()) |
131 |
|
self.Refresh() |
132 |
|
propDlg.Destroy() |
133 |
|
|
134 |
|
# |
135 |
|
# _OnSelectedRange() and _OnSelectedCell() were borrowed |
136 |
|
# from http://wiki.wxpython.org |
137 |
|
# |
138 |
|
def _OnSelectedRange(self, event): |
139 |
|
"""Internal update to the selection tracking list""" |
140 |
|
if event.Selecting(): |
141 |
|
for index in range( event.GetTopRow(), event.GetBottomRow()+1): |
142 |
|
if index not in self.currentSelection: |
143 |
|
self.currentSelection.append( index ) |
144 |
|
else: |
145 |
|
for index in range( event.GetTopRow(), event.GetBottomRow()+1): |
146 |
|
while index in self.currentSelection: |
147 |
|
self.currentSelection.remove( index ) |
148 |
|
#self.ConfigureForSelection() |
149 |
|
|
150 |
|
event.Skip() |
151 |
|
|
152 |
|
def _OnSelectedCell( self, event ): |
153 |
|
"""Internal update to the selection tracking list""" |
154 |
|
self.currentSelection = [ event.GetRow() ] |
155 |
|
#self.ConfigureForSelection() |
156 |
|
event.Skip() |
157 |
|
|
158 |
class ClassTable(wxPyGridTableBase): |
class ClassTable(wxPyGridTableBase): |
159 |
|
|
160 |
NUM_COLS = 3 |
NUM_COLS = 3 |
161 |
|
|
162 |
__col_labels = [_("Visual"), _("Value"), _("Label")] |
__col_labels = [_("Symbol"), _("Value"), _("Label")] |
163 |
|
|
164 |
def __init__(self, clazz, shapeType, view = None): |
def __init__(self, fieldData, shapeType, view = None): |
165 |
wxPyGridTableBase.__init__(self) |
wxPyGridTableBase.__init__(self) |
166 |
self.SetView(view) |
self.SetView(view) |
167 |
self.tdata = [] |
self.tdata = [] |
168 |
|
|
169 |
self.Reset(clazz, shapeType) |
self.Reset(fieldData, shapeType) |
170 |
|
|
171 |
def Reset(self, clazz, shapeType): |
def Reset(self, fieldData, shapeType): |
172 |
|
|
173 |
self.GetView().BeginBatch() |
self.GetView().BeginBatch() |
174 |
|
|
175 |
|
self.fieldData = fieldData |
176 |
self.shapeType = shapeType |
self.shapeType = shapeType |
177 |
self.renderer = ClassRenderer(self.shapeType) |
self.renderer = ClassRenderer(self.shapeType) |
178 |
|
|
179 |
old_tdata = self.tdata |
old_len = len(self.tdata) |
180 |
|
|
181 |
self.tdata = [] |
self.tdata = [] |
182 |
|
|
183 |
|
clazz = fieldData[FIELD_CLASS] |
184 |
if clazz is None: |
if clazz is None: |
185 |
clazz = Classification() |
clazz = Classification() |
186 |
|
|
207 |
|
|
208 |
self.modified = 0 |
self.modified = 0 |
209 |
|
|
210 |
|
self.__NotifyRowChanges(old_len, len(self.tdata)) |
211 |
|
self.GetView().EndBatch() |
212 |
|
|
213 |
|
def __NotifyRowChanges(self, curRows, newRows): |
214 |
# |
# |
215 |
# silly message processing for updates to the number of |
# silly message processing for updates to the number of |
216 |
# rows and columns |
# rows and columns |
217 |
# |
# |
|
curRows = len(old_tdata) |
|
|
newRows = len(self.tdata) |
|
218 |
if newRows > curRows: |
if newRows > curRows: |
219 |
msg = wxGridTableMessage(self, |
msg = wxGridTableMessage(self, |
220 |
wxGRIDTABLE_NOTIFY_ROWS_APPENDED, |
wxGRIDTABLE_NOTIFY_ROWS_APPENDED, |
227 |
curRows - newRows) # how many |
curRows - newRows) # how many |
228 |
self.GetView().ProcessTableMessage(msg) |
self.GetView().ProcessTableMessage(msg) |
229 |
|
|
|
self.GetView().EndBatch() |
|
230 |
|
|
231 |
def __SetRow(self, row, group): |
def __SetRow(self, row, group): |
232 |
|
|
233 |
if isinstance(group, ClassGroupDefault): |
if isinstance(group, ClassGroupDefault): |
234 |
data = [group, 'DEFAULT', group.GetLabel()] |
data = [group, _('DEFAULT'), group.GetLabel()] |
235 |
elif isinstance(group, ClassGroupSingleton): |
elif isinstance(group, ClassGroupSingleton): |
236 |
data = [group, group.GetValue(), group.GetLabel()] |
data = [group, group.GetValue(), group.GetLabel()] |
237 |
elif isinstance(group, ClassGroupRange): |
elif isinstance(group, ClassGroupRange): |
238 |
data = [group, |
data = [group, |
239 |
'%s - %s' % (group.GetMin(), group.GetMax()), |
_('%s - %s') % (group.GetMin(), group.GetMax()), |
240 |
group.GetLabel()] |
group.GetLabel()] |
241 |
|
|
242 |
if row >= len(self.tdata): |
if row >= len(self.tdata): |
249 |
|
|
250 |
def GetRowLabelValue(self, row): |
def GetRowLabelValue(self, row): |
251 |
data = self.tdata[row][COL_VISUAL] |
data = self.tdata[row][COL_VISUAL] |
252 |
if isinstance(data, ClassGroupDefault): return _("Default") |
if isinstance(data, ClassGroupDefault): return _("Default") |
253 |
if isinstance(data, ClassGroupSingleton): return _("Singleton") |
if isinstance(data, ClassGroupSingleton): return _("Singleton") |
254 |
if isinstance(data, ClassGroupRange): return _("Range") |
if isinstance(data, ClassGroupRange): return _("Range") |
255 |
if isinstance(data, ClassGroupMap): return _("Map") |
if isinstance(data, ClassGroupMap): return _("Map") |
256 |
|
|
257 |
def GetNumberRows(self): |
def GetNumberRows(self): |
258 |
return len(self.tdata) |
return len(self.tdata) |
278 |
(a single number or a range) |
(a single number or a range) |
279 |
""" |
""" |
280 |
|
|
281 |
# |
type = self.fieldData[FIELD_TYPE] |
|
# first try to take the input as a single number |
|
|
# if there's an exception try to break it into |
|
|
# a range seperated by a '-'. take care to ignore |
|
|
# a leading '-' as that could be for a negative number. |
|
|
# then try to parse the individual parts. if there |
|
|
# is an exception here, let it pass up to the calling |
|
|
# function. |
|
|
# |
|
|
try: |
|
|
return (Str2Num(value)) |
|
|
except: |
|
|
i = value.find('-') |
|
|
if i == 0: |
|
|
i = value.find('-', 1) |
|
282 |
|
|
283 |
return (Str2Num(value[:i]), Str2Num(value[i+1:])) |
if type == FIELD_TYPE_STRING: |
284 |
|
return (value,) |
285 |
|
elif type == FIELD_TYPE_INT or type == FIELD_TYPE_DOUBLE: |
286 |
|
|
287 |
|
# |
288 |
|
# first try to take the input as a single number |
289 |
|
# if there's an exception try to break it into |
290 |
|
# a range seperated by a '-'. take care to ignore |
291 |
|
# a leading '-' as that could be for a negative number. |
292 |
|
# then try to parse the individual parts. if there |
293 |
|
# is an exception here, let it pass up to the calling |
294 |
|
# function. |
295 |
|
# |
296 |
|
try: |
297 |
|
return (Str2Num(value),) |
298 |
|
except: |
299 |
|
i = value.find('-') |
300 |
|
if i == 0: |
301 |
|
i = value.find('-', 1) |
302 |
|
|
303 |
|
return (Str2Num(value[:i]), Str2Num(value[i+1:])) |
304 |
|
|
305 |
|
|
306 |
def SetValueAsCustom(self, row, col, typeName, value): |
def SetValueAsCustom(self, row, col, typeName, value): |
307 |
data = self.tdata[row][COL_VISUAL] |
group = self.tdata[row][COL_VISUAL] |
308 |
|
|
309 |
if col == COL_VISUAL: |
if col == COL_VISUAL: |
310 |
self.tdata[row][COL_VISUAL] = value |
self.tdata[row][COL_VISUAL] = value |
311 |
elif col == COL_VALUE: |
elif col == COL_VALUE: |
312 |
if row != 0: # DefaultData row |
if isinstance(group, ClassGroupDefault): |
313 |
|
# not allowed to modify the default value |
314 |
if isinstance(data, ClassGroupMap): |
pass |
315 |
# something special |
elif isinstance(group, ClassGroupMap): |
316 |
|
# something special |
317 |
|
pass |
318 |
|
else: # SINGLETON, RANGE |
319 |
|
try: |
320 |
|
dataInfo = self.__ParseInput(value) |
321 |
|
except: |
322 |
|
# bad input, ignore the request |
323 |
pass |
pass |
324 |
else: # POINT, RANGE |
else: |
|
try: |
|
|
dataInfo = self.__ParseInput(value) |
|
|
except: pass |
|
|
# bad input, ignore the request |
|
|
else: |
|
|
|
|
|
if len(dataInfo) == 1: |
|
|
if not isinstance(data, ClassGroupSingleton): |
|
|
ndata = ClassGroupSingleton(prop = data) |
|
|
ndata.SetValue(dataInfo[1]) |
|
|
elif len(dataInfo) == 2: |
|
|
if not isinstance(data, ClassGroupRange): |
|
|
data = ClassDataRange(classData = data) |
|
|
data.SetRange(dataInfo[1], dataInfo[2]) |
|
325 |
|
|
326 |
ndata.SetLabel(data.GetLabel()) |
ngroup = group |
327 |
self.__SetRow(row, ndata) |
props = group.GetProperties() |
328 |
|
if len(dataInfo) == 1: |
329 |
|
if not isinstance(group, ClassGroupSingleton): |
330 |
|
ngroup = ClassGroupSingleton(prop = props) |
331 |
|
ngroup.SetValue(dataInfo[0]) |
332 |
|
elif len(dataInfo) == 2: |
333 |
|
if not isinstance(group, ClassGroupRange): |
334 |
|
ngroup = ClassGroupRange(prop = props) |
335 |
|
ngroup.SetRange(dataInfo[0], dataInfo[1]) |
336 |
|
else: |
337 |
|
assert(False) |
338 |
|
|
339 |
#self.tdata[row][COL_VISUAL] = data |
ngroup.SetLabel(group.GetLabel()) |
340 |
|
self.__SetRow(row, ngroup) |
341 |
|
|
342 |
self.GetView().Refresh() |
self.GetView().Refresh() |
343 |
|
|
344 |
elif col == COL_LABEL: |
elif col == COL_LABEL: |
345 |
data.SetLabel(value) |
group.SetLabel(value) |
346 |
self.tdata[row][COL_LABEL] = data.GetLabel() |
self.tdata[row][COL_LABEL] = group.GetLabel() |
347 |
else: |
else: |
348 |
raise ValueError(_("Invalid column request")) |
raise ValueError(_("Invalid column request")) |
349 |
|
|
368 |
def IsModified(self): |
def IsModified(self): |
369 |
return self.modified |
return self.modified |
370 |
|
|
371 |
def AddNewDataRow(self): |
def DeleteRows(self, pos, numRows = 1): |
372 |
np = ClassDataPoint() |
assert(pos >= 0) |
373 |
self.tdata.append([np, np.GetValue(), np.GetLabel()]) |
old_len = len(self.tdata) |
374 |
msg = wxGridTableMessage(self, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1) |
for row in range(pos, pos - numRows, -1): |
375 |
self.GetView().ProcessTableMessage(msg) |
group = self.GetValueAsCustom(row, COL_VISUAL, None) |
376 |
self.GetView().Refresh() |
if not isinstance(group, ClassGroupDefault): |
377 |
|
self.tdata.pop(row) |
378 |
|
self.__Modified() |
379 |
|
|
380 |
|
if self.IsModified(): |
381 |
|
self.__NotifyRowChanges(old_len, len(self.tdata)) |
382 |
|
|
383 |
|
def AppendRows(self, numRows = 1): |
384 |
|
old_len = len(self.tdata) |
385 |
|
for i in range(numRows): |
386 |
|
np = ClassGroupSingleton() |
387 |
|
self.tdata.append([np, np.GetValue(), np.GetLabel()]) |
388 |
|
self.__Modified() |
389 |
|
|
390 |
|
if self.IsModified(): |
391 |
|
self.__NotifyRowChanges(old_len, len(self.tdata)) |
392 |
|
|
393 |
|
|
394 |
class Classifier(wxDialog): |
class Classifier(wxDialog): |
395 |
|
|
396 |
def __init__(self, parent, layer): |
def __init__(self, parent, layer): |
397 |
wxDialog.__init__(self, parent, -1, _("Classify"), |
wxDialog.__init__(self, parent, -1, _("Classify"), |
398 |
style = wxRESIZE_BORDER) |
style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) |
399 |
|
|
400 |
|
|
401 |
self.layer = layer |
self.layer = layer |
402 |
|
|
403 |
topBox = wxBoxSizer(wxVERTICAL) |
topBox = wxBoxSizer(wxVERTICAL) |
404 |
|
|
405 |
topBox.Add(wxStaticText(self, -1, _("Layer: %s") % layer.Title()), |
topBox.Add(wxStaticText(self, -1, _("Layer: %s") % layer.Title()), |
406 |
0, wxALIGN_LEFT | wxBOTTOM, 4) |
0, wxALIGN_LEFT | wxALL, 4) |
407 |
topBox.Add(wxStaticText(self, -1, _("Type: %s") % layer.ShapeType()), |
topBox.Add(wxStaticText(self, -1, _("Type: %s") % layer.ShapeType()), |
408 |
0, wxALIGN_LEFT | wxBOTTOM, 4) |
0, wxALIGN_LEFT | wxALL, 4) |
409 |
|
|
410 |
propertyBox = wxBoxSizer(wxHORIZONTAL) |
propertyBox = wxBoxSizer(wxHORIZONTAL) |
411 |
propertyBox.Add(wxStaticText(self, -1, _("Property: ")), |
propertyBox.Add(wxStaticText(self, -1, _("Field: ")), |
412 |
0, wxALIGN_CENTER | wxALL, 4) |
0, wxALIGN_CENTER | wxALL, 4) |
413 |
|
|
414 |
self.properties = wxComboBox(self, ID_PROPERTY_SELECT, "", |
self.fields = wxComboBox(self, ID_PROPERTY_SELECT, "", |
415 |
style = wxCB_READONLY) |
style = wxCB_READONLY) |
416 |
|
|
417 |
self.num_cols = layer.table.field_count() |
self.num_cols = layer.table.field_count() |
418 |
# just assume the first field in case one hasn't been |
# just assume the first field in case one hasn't been |
419 |
# specified in the file. |
# specified in the file. |
420 |
self.__cur_prop = 0 |
self.__cur_field = 0 |
421 |
field = layer.GetClassification().GetField() |
clazz = layer.GetClassification() |
422 |
|
field = clazz.GetField() |
423 |
for i in range(self.num_cols): |
for i in range(self.num_cols): |
424 |
type, name, len, decc = layer.table.field_info(i) |
type, name, len, decc = layer.table.field_info(i) |
425 |
|
self.fields.Append(name) |
426 |
|
|
427 |
if name == field: |
if name == field: |
428 |
self.__cur_prop = i |
self.__cur_field = i |
429 |
self.properties.Append(name) |
self.fields.SetClientData(i, [clazz, type, name, len, decc]) |
430 |
self.properties.SetClientData(i, None) |
else: |
431 |
|
self.fields.SetClientData(i, [None, type, name, len, decc]) |
432 |
self.properties.SetSelection(self.__cur_prop) |
|
433 |
propertyBox.Add(self.properties, 1, wxGROW|wxALL, 0) |
self.fields.SetSelection(self.__cur_field) |
434 |
EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self.OnPropertySelect) |
|
435 |
|
propertyBox.Add(self.fields, 1, wxGROW|wxALL, 4) |
436 |
|
EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self.OnFieldSelect) |
437 |
|
|
438 |
topBox.Add(propertyBox, 0, wxGROW, 4) |
topBox.Add(propertyBox, 0, wxGROW, 4) |
439 |
|
|
442 |
# |
# |
443 |
|
|
444 |
controlBox = wxBoxSizer(wxHORIZONTAL) |
controlBox = wxBoxSizer(wxHORIZONTAL) |
445 |
self.classGrid = ClassGrid(self, layer) |
self.classGrid = ClassGrid(self, |
446 |
|
layer, |
447 |
|
self.fields.GetClientData(self.__cur_field)) |
448 |
|
|
449 |
controlBox.Add(self.classGrid, 1, wxGROW, 0) |
controlBox.Add(self.classGrid, 1, wxGROW, 0) |
450 |
|
|
454 |
controlButtonBox.Add(wxButton(self, ID_CLASSIFY_GENRANGE, |
controlButtonBox.Add(wxButton(self, ID_CLASSIFY_GENRANGE, |
455 |
_("Generate Ranges")), 0, wxGROW | wxALL, 4) |
_("Generate Ranges")), 0, wxGROW | wxALL, 4) |
456 |
|
|
457 |
|
controlButtonBox.Add(wxButton(self, ID_CLASSIFY_REMOVE, |
458 |
|
_("Remove")), 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4) |
459 |
|
|
460 |
controlBox.Add(controlButtonBox, 0, wxGROW, 10) |
controlBox.Add(controlButtonBox, 0, wxGROW, 10) |
461 |
topBox.Add(controlBox, 1, wxGROW, 10) |
topBox.Add(controlBox, 1, wxGROW, 10) |
462 |
|
|
463 |
EVT_BUTTON(self, ID_CLASSIFY_ADD, self.OnAdd) |
EVT_BUTTON(self, ID_CLASSIFY_ADD, self.OnAdd) |
464 |
|
EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self.OnRemove) |
465 |
EVT_BUTTON(self, ID_CLASSIFY_GENRANGE, self.OnGenRange) |
EVT_BUTTON(self, ID_CLASSIFY_GENRANGE, self.OnGenRange) |
|
EVT_GRID_CELL_LEFT_DCLICK(self.classGrid, self.OnCellDClick) |
|
466 |
|
|
467 |
# |
# |
468 |
# Control buttons: |
# Control buttons: |
477 |
EVT_BUTTON(self, ID_CLASSIFY_OK, self.OnOK) |
EVT_BUTTON(self, ID_CLASSIFY_OK, self.OnOK) |
478 |
EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self.OnCancel) |
EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self.OnCancel) |
479 |
|
|
480 |
|
|
481 |
|
|
482 |
self.SetAutoLayout(true) |
self.SetAutoLayout(true) |
483 |
self.SetSizer(topBox) |
self.SetSizer(topBox) |
484 |
topBox.Fit(self) |
topBox.Fit(self) |
487 |
def __BuildClassification(self, prop): |
def __BuildClassification(self, prop): |
488 |
|
|
489 |
clazz = Classification() |
clazz = Classification() |
490 |
clazz.SetField(self.properties.GetStringSelection()) |
clazz.SetField(self.fields.GetString(prop)) |
491 |
|
|
492 |
numRows = self.classGrid.GetNumberRows() |
numRows = self.classGrid.GetNumberRows() |
493 |
|
|
500 |
|
|
501 |
return clazz |
return clazz |
502 |
|
|
503 |
def OnPropertySelect(self, event): |
def OnFieldSelect(self, event): |
504 |
self.properties.SetClientData( |
data = self.fields.GetClientData(self.__cur_field) |
505 |
self.__cur_prop, self.__BuildClassification(self.__cur_prop)) |
data[FIELD_CLASS] = self.__BuildClassification(self.__cur_field) |
506 |
|
|
507 |
self.__cur_prop = self.properties.GetSelection() |
self.fields.SetClientData(self.__cur_field, data) |
508 |
clazz = self.properties.GetClientData(self.__cur_prop) |
|
509 |
table = self.classGrid.GetTable() |
self.__cur_field = self.fields.GetSelection() |
510 |
|
fieldData = self.fields.GetClientData(self.__cur_field) |
511 |
table.Reset(clazz, self.layer.ShapeType()) |
self.classGrid.GetTable().Reset(fieldData, self.layer.ShapeType()) |
512 |
|
|
513 |
def OnOK(self, event): |
def OnOK(self, event): |
514 |
"""Put the data from the table into a new Classification and hand |
"""Put the data from the table into a new Classification and hand |
515 |
it to the layer. |
it to the layer. |
516 |
""" |
""" |
517 |
|
|
518 |
clazz = self.properties.GetClientData(self.__cur_prop) |
clazz = self.fields.GetClientData(self.__cur_field)[FIELD_CLASS] |
519 |
|
|
520 |
# |
# |
521 |
# only build the classification if there wasn't one to |
# only build the classification if there wasn't one to |
522 |
# to begin with or it has been modified |
# to begin with or it has been modified |
523 |
# |
# |
524 |
if clazz is None or self.classGrid.GetTable().IsModified(): |
if clazz is None or self.classGrid.GetTable().IsModified(): |
525 |
clazz = self.__BuildClassification(self.__cur_prop) |
clazz = self.__BuildClassification(self.__cur_field) |
526 |
|
|
527 |
clazz.SetLayer(self.layer) |
clazz.SetLayer(self.layer) |
528 |
|
|
534 |
"""Do nothing. The layer's current classification stays the same.""" |
"""Do nothing. The layer's current classification stays the same.""" |
535 |
self.EndModal(wxID_CANCEL) |
self.EndModal(wxID_CANCEL) |
536 |
|
|
|
|
|
537 |
def OnAdd(self, event): |
def OnAdd(self, event): |
538 |
self.classGrid.GetTable().AddNewDataRow() |
self.classGrid.AppendRows() |
539 |
print "Classifier.OnAdd()" |
|
540 |
|
def OnRemove(self, event): |
541 |
|
self.classGrid.DeleteSelectedRows() |
542 |
|
|
543 |
def OnGenRange(self, event): |
def OnGenRange(self, event): |
544 |
print "Classifier.OnGenRange()" |
print "Classifier.OnGenRange()" |
545 |
|
|
|
def OnCellDClick(self, event): |
|
|
r = event.GetRow() |
|
|
c = event.GetCol() |
|
|
if c == COL_VISUAL: |
|
|
# XXX: getting the properties is only possible with non-Maps!!! |
|
|
group = self.classGrid.GetTable().GetValueAsCustom(r, c, None) |
|
|
prop = group.GetProperties() |
|
|
propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType()) |
|
|
if propDlg.ShowModal() == wxID_OK: |
|
|
new_prop = propDlg.GetClassGroupProperties() |
|
|
prop.SetStroke(new_prop.GetStroke()) |
|
|
prop.SetStrokeWidth(new_prop.GetStrokeWidth()) |
|
|
prop.SetFill(new_prop.GetFill()) |
|
|
self.classGrid.Refresh() |
|
|
propDlg.Destroy() |
|
|
|
|
546 |
|
|
547 |
ID_SELPROP_OK = 4001 |
ID_SELPROP_OK = 4001 |
548 |
ID_SELPROP_CANCEL = 4002 |
ID_SELPROP_CANCEL = 4002 |
577 |
ctrlBox = wxBoxSizer(wxVERTICAL) |
ctrlBox = wxBoxSizer(wxVERTICAL) |
578 |
ctrlBox.Add( |
ctrlBox.Add( |
579 |
wxButton(self, ID_SELPROP_STROKECLR, "Change Stroke Color"), |
wxButton(self, ID_SELPROP_STROKECLR, "Change Stroke Color"), |
580 |
0, wxALIGN_CENTER_HORIZONTAL | wxALL | wxGROW, 4) |
1, wxALIGN_CENTER_HORIZONTAL | wxALL | wxGROW, 4) |
581 |
EVT_BUTTON(self, ID_SELPROP_STROKECLR, self.OnChangeStrokeColor) |
EVT_BUTTON(self, ID_SELPROP_STROKECLR, self.OnChangeStrokeColor) |
582 |
|
|
583 |
if shapeType != SHAPETYPE_ARC: |
if shapeType != SHAPETYPE_ARC: |
728 |
self.previewer = ClassDataPreviewer(None, None, shapeType) |
self.previewer = ClassDataPreviewer(None, None, shapeType) |
729 |
|
|
730 |
def Draw(self, grid, attr, dc, rect, row, col, isSelected): |
def Draw(self, grid, attr, dc, rect, row, col, isSelected): |
731 |
data = grid.GetTable().GetValueAsCustom(row, col, "") |
data = grid.GetTable().GetValueAsCustom(row, col, None) |
|
|
|
732 |
|
|
733 |
dc.SetClippingRegion(rect.GetX(), rect.GetY(), |
dc.SetClippingRegion(rect.GetX(), rect.GetY(), |
734 |
rect.GetWidth(), rect.GetHeight()) |
rect.GetWidth(), rect.GetHeight()) |