18 |
from wxPython.grid import * |
from wxPython.grid import * |
19 |
|
|
20 |
from Thuban import _ |
from Thuban import _ |
|
from Thuban.common import * |
|
21 |
from Thuban.UI.common import * |
from Thuban.UI.common import * |
22 |
|
|
23 |
from Thuban.Model.classification import * |
from Thuban.Model.classification import * |
30 |
|
|
31 |
from dialogs import NonModalDialog |
from dialogs import NonModalDialog |
32 |
|
|
|
# widget id's |
|
|
ID_PROPERTY_SELECT = 4010 |
|
33 |
ID_CLASS_TABLE = 40011 |
ID_CLASS_TABLE = 40011 |
34 |
|
|
35 |
|
|
36 |
# table columns |
# table columns |
37 |
COL_SYMBOL = 0 |
COL_VISIBLE = 0 |
38 |
COL_VALUE = 1 |
COL_SYMBOL = 1 |
39 |
COL_LABEL = 2 |
COL_VALUE = 2 |
40 |
|
COL_LABEL = 3 |
41 |
|
NUM_COLS = 4 |
42 |
|
|
43 |
# indices into the client data lists in Classifier.fields |
# indices into the client data lists in Classifier.fields |
44 |
FIELD_CLASS = 0 |
FIELD_CLASS = 0 |
62 |
use for display. |
use for display. |
63 |
""" |
""" |
64 |
|
|
|
#wxGrid.__init__(self, parent, ID_CLASS_TABLE, size = (340, 160)) |
|
65 |
wxGrid.__init__(self, parent, ID_CLASS_TABLE) |
wxGrid.__init__(self, parent, ID_CLASS_TABLE) |
|
#self.SetTable(ClassTable(fieldData, layer.ShapeType(), self), True) |
|
66 |
|
|
67 |
self.classifier = classifier |
self.classifier = classifier |
68 |
|
|
74 |
EVT_GRID_COL_SIZE(self, self._OnCellResize) |
EVT_GRID_COL_SIZE(self, self._OnCellResize) |
75 |
EVT_GRID_ROW_SIZE(self, self._OnCellResize) |
EVT_GRID_ROW_SIZE(self, self._OnCellResize) |
76 |
|
|
77 |
|
#def GetCellAttr(self, row, col): |
78 |
|
#print "GetCellAttr ", row, col |
79 |
|
#wxGrid.GetCellAttr(self, row, col) |
80 |
|
|
81 |
def CreateTable(self, clazz, shapeType, group = None): |
def CreateTable(self, clazz, shapeType, group = None): |
82 |
|
|
83 |
assert isinstance(clazz, Classification) |
assert isinstance(clazz, Classification) |
84 |
|
|
85 |
table = self.GetTable() |
table = self.GetTable() |
86 |
if table is None: |
if table is None: |
87 |
w = self.GetDefaultColSize() * 3 + self.GetDefaultRowLabelSize() |
w = self.GetDefaultColSize() * NUM_COLS \ |
88 |
h = self.GetDefaultRowSize() * 4 + self.GetDefaultColLabelSize() |
+ self.GetDefaultRowLabelSize() |
89 |
|
h = self.GetDefaultRowSize() * 4 \ |
90 |
|
+ self.GetDefaultColLabelSize() |
91 |
|
|
92 |
self.SetDimensions(-1, -1, w, h) |
self.SetDimensions(-1, -1, w, h) |
93 |
self.SetSizeHints(w, h, -1, -1) |
self.SetSizeHints(w, h, -1, -1) |
94 |
table = ClassTable(self) |
table = ClassTable(self) |
110 |
def GetSelectedRows(self): |
def GetSelectedRows(self): |
111 |
return self.GetCurrentSelection() |
return self.GetCurrentSelection() |
112 |
|
|
113 |
def SetCellRenderer(self, row, col): |
#def SetCellRenderer(self, row, col, renderer): |
114 |
raise ValueError(_("Must not allow setting of renderer in ClassGrid!")) |
#raise ValueError(_("Must not allow setting of renderer in ClassGrid!")) |
115 |
|
|
116 |
# |
# |
117 |
# [Set|Get]Table is taken from http://wiki.wxpython.org |
# [Set|Get]Table is taken from http://wiki.wxpython.org |
206 |
# sel = False)) |
# sel = False)) |
207 |
|
|
208 |
def _OnCellDClick(self, event): |
def _OnCellDClick(self, event): |
209 |
"""Handle a double on a cell.""" |
"""Handle a double click on a cell.""" |
210 |
|
|
211 |
r = event.GetRow() |
r = event.GetRow() |
212 |
c = event.GetCol() |
c = event.GetCol() |
|
if c == COL_SYMBOL: |
|
|
self.classifier.EditGroupProperties(r) |
|
213 |
|
|
214 |
|
if c == COL_SYMBOL: |
215 |
|
self.classifier.EditSymbol(r) |
216 |
|
else: |
217 |
|
event.Skip() |
218 |
|
|
219 |
# |
# |
220 |
# _OnSelectedRange() and _OnSelectedCell() were borrowed |
# _OnSelectedRange() and _OnSelectedCell() were borrowed |
247 |
class ClassTable(wxPyGridTableBase): |
class ClassTable(wxPyGridTableBase): |
248 |
"""Represents the underlying data structure for the grid.""" |
"""Represents the underlying data structure for the grid.""" |
249 |
|
|
250 |
NUM_COLS = 3 |
__col_labels = [_("Visible"), _("Symbol"), _("Value"), _("Label")] |
|
|
|
|
__col_labels = [_("Symbol"), _("Value"), _("Label")] |
|
251 |
|
|
252 |
|
|
253 |
def __init__(self, view = None): |
def __init__(self, view = None): |
261 |
|
|
262 |
wxPyGridTableBase.__init__(self) |
wxPyGridTableBase.__init__(self) |
263 |
|
|
264 |
self.SetView(view) |
assert len(ClassTable.__col_labels) == NUM_COLS |
265 |
|
|
266 |
self.clazz = None |
self.clazz = None |
267 |
|
self.__colAttr = {} |
268 |
|
|
269 |
#self.Reset(clazz, shapeType) |
self.SetView(view) |
270 |
|
|
271 |
def Reset(self, clazz, shapeType, group = None): |
def Reset(self, clazz, shapeType, group = None): |
272 |
"""Reset the table with the given data. |
"""Reset the table with the given data. |
292 |
self.SetClassification(clazz, group) |
self.SetClassification(clazz, group) |
293 |
self.__Modified(-1) |
self.__Modified(-1) |
294 |
|
|
295 |
|
self.__colAttr = {} |
296 |
|
|
297 |
|
attr = wxGridCellAttr() |
298 |
|
attr.SetEditor(wxGridCellBoolEditor()) |
299 |
|
attr.SetRenderer(wxGridCellBoolRenderer()) |
300 |
|
attr.SetAlignment(wxALIGN_CENTER, wxALIGN_CENTER) |
301 |
|
self.__colAttr[COL_VISIBLE] = attr |
302 |
|
|
303 |
|
attr = wxGridCellAttr() |
304 |
|
attr.SetRenderer(ClassRenderer(self.shapeType)) |
305 |
|
attr.SetReadOnly() |
306 |
|
self.__colAttr[COL_SYMBOL] = attr |
307 |
|
|
308 |
self.GetView().EndBatch() |
self.GetView().EndBatch() |
309 |
self.GetView().FitInside() |
self.GetView().FitInside() |
310 |
|
|
317 |
|
|
318 |
old_len = self.GetNumberRows() |
old_len = self.GetNumberRows() |
319 |
|
|
|
# |
|
|
# copy the data out of the classification and into our |
|
|
# array |
|
|
# |
|
320 |
row = -1 |
row = -1 |
|
# for g in clazz: |
|
|
# ng = copy.deepcopy(g) |
|
|
# self.__SetRow(None, ng) |
|
|
# if g is group: |
|
|
# row = self.GetNumberRows() - 1 |
|
|
# #print "selecting row..." |
|
|
|
|
|
|
|
|
#self.clazz = copy.deepcopy(clazz) |
|
321 |
self.clazz = clazz |
self.clazz = clazz |
322 |
|
|
323 |
self.__NotifyRowChanges(old_len, self.GetNumberRows()) |
self.__NotifyRowChanges(old_len, self.GetNumberRows()) |
324 |
|
|
325 |
|
# |
326 |
|
# XXX: this is dead code at the moment |
327 |
|
# |
328 |
if row > -1: |
if row > -1: |
329 |
self.GetView().ClearSelection() |
self.GetView().ClearSelection() |
330 |
self.GetView().SelectRow(row) |
self.GetView().SelectRow(row) |
332 |
|
|
333 |
self.__Modified() |
self.__Modified() |
334 |
|
|
335 |
|
|
336 |
self.GetView().EndBatch() |
self.GetView().EndBatch() |
337 |
self.GetView().FitInside() |
self.GetView().FitInside() |
338 |
|
|
397 |
if isinstance(group, ClassGroupMap): return _("Map") |
if isinstance(group, ClassGroupMap): return _("Map") |
398 |
|
|
399 |
assert False # shouldn't get here |
assert False # shouldn't get here |
400 |
return _("") |
return "" |
401 |
|
|
402 |
def GetNumberRows(self): |
def GetNumberRows(self): |
403 |
"""Return the number of rows.""" |
"""Return the number of rows.""" |
408 |
|
|
409 |
def GetNumberCols(self): |
def GetNumberCols(self): |
410 |
"""Return the number of columns.""" |
"""Return the number of columns.""" |
411 |
return self.NUM_COLS |
return NUM_COLS |
412 |
|
|
413 |
def IsEmptyCell(self, row, col): |
def IsEmptyCell(self, row, col): |
414 |
"""Determine if a cell is empty. This is always false.""" |
"""Determine if a cell is empty. This is always false.""" |
426 |
""" |
""" |
427 |
|
|
428 |
self.SetValueAsCustom(row, col, None, value) |
self.SetValueAsCustom(row, col, None, value) |
|
self.__Modified() |
|
429 |
|
|
430 |
def GetValueAsCustom(self, row, col, typeName): |
def GetValueAsCustom(self, row, col, typeName): |
431 |
"""Return the object that is used to represent the given |
"""Return the object that is used to represent the given |
440 |
group = self.clazz.GetGroup(row - 1) |
group = self.clazz.GetGroup(row - 1) |
441 |
|
|
442 |
|
|
443 |
|
if col == COL_VISIBLE: |
444 |
|
return group.IsVisible() |
445 |
|
|
446 |
if col == COL_SYMBOL: |
if col == COL_SYMBOL: |
447 |
return group.GetProperties() |
return group.GetProperties() |
448 |
|
|
477 |
elif type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE): |
elif type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE): |
478 |
|
|
479 |
if type == FIELDTYPE_INT: |
if type == FIELDTYPE_INT: |
480 |
|
# the float call allows the user to enter 1.0 for 1 |
481 |
conv = lambda p: int(float(p)) |
conv = lambda p: int(float(p)) |
482 |
else: |
else: |
483 |
conv = lambda p: p |
conv = lambda p: p |
492 |
# function. |
# function. |
493 |
# |
# |
494 |
try: |
try: |
495 |
return (conv(Str2Num(value)),) |
return (conv(value),) |
496 |
except ValueError: |
except ValueError: |
497 |
i = value.find('-') |
i = value.find('-') |
498 |
if i == 0: |
if i == 0: |
499 |
i = value.find('-', 1) |
i = value.find('-', 1) |
500 |
|
|
501 |
return (conv(Str2Num(value[:i])), conv(Str2Num(value[i+1:]))) |
return (conv(value[:i]), conv(value[i+1:])) |
502 |
|
|
503 |
assert False # shouldn't get here |
assert False # shouldn't get here |
504 |
return (0,) |
return (0,) |
516 |
typeName -- unused, but needed to overload wxPyGridTableBase |
typeName -- unused, but needed to overload wxPyGridTableBase |
517 |
""" |
""" |
518 |
|
|
519 |
assert col >= 0 and col < self.GetNumberCols() |
assert 0 <= col < self.GetNumberCols() |
520 |
assert row >= 0 and row < self.GetNumberRows() |
assert 0 <= row < self.GetNumberRows() |
521 |
|
|
522 |
if row == 0: |
if row == 0: |
523 |
group = self.clazz.GetDefaultGroup() |
group = self.clazz.GetDefaultGroup() |
526 |
|
|
527 |
mod = True # assume the data will change |
mod = True # assume the data will change |
528 |
|
|
529 |
if col == COL_SYMBOL: |
if col == COL_VISIBLE: |
530 |
|
group.SetVisible(value) |
531 |
|
elif col == COL_SYMBOL: |
532 |
group.SetProperties(value) |
group.SetProperties(value) |
533 |
elif col == COL_LABEL: |
elif col == COL_LABEL: |
534 |
group.SetLabel(value) |
group.SetLabel(value) |
558 |
# |
# |
559 |
if len(dataInfo) == 1: |
if len(dataInfo) == 1: |
560 |
if not isinstance(group, ClassGroupSingleton): |
if not isinstance(group, ClassGroupSingleton): |
561 |
ngroup = ClassGroupSingleton(prop = props) |
ngroup = ClassGroupSingleton(props = props) |
562 |
changed = True |
changed = True |
563 |
ngroup.SetValue(dataInfo[0]) |
ngroup.SetValue(dataInfo[0]) |
564 |
elif len(dataInfo) == 2: |
elif len(dataInfo) == 2: |
565 |
if not isinstance(group, ClassGroupRange): |
if not isinstance(group, ClassGroupRange): |
566 |
ngroup = ClassGroupRange(prop = props) |
ngroup = ClassGroupRange(props = props) |
567 |
changed = True |
changed = True |
568 |
ngroup.SetRange(dataInfo[0], dataInfo[1]) |
ngroup.SetRange(dataInfo[0], dataInfo[1]) |
569 |
else: |
else: |
584 |
def GetAttr(self, row, col, someExtraParameter): |
def GetAttr(self, row, col, someExtraParameter): |
585 |
"""Returns the cell attributes""" |
"""Returns the cell attributes""" |
586 |
|
|
587 |
attr = wxGridCellAttr() |
return self.__colAttr.get(col, wxGridCellAttr()).Clone() |
|
#attr = wxPyGridTableBase.GetAttr(self, row, col, someExtraParameter) |
|
|
|
|
|
if col == COL_SYMBOL: |
|
|
# we need to create a new renderer each time, because |
|
|
# SetRenderer takes control of the parameter |
|
|
attr.SetRenderer(ClassRenderer(self.shapeType)) |
|
|
attr.SetReadOnly() |
|
|
|
|
|
return attr |
|
588 |
|
|
589 |
def GetClassGroup(self, row): |
def GetClassGroup(self, row): |
590 |
"""Return the ClassGroup object representing row 'row'.""" |
"""Return the ClassGroup object representing row 'row'.""" |
650 |
self.__NotifyRowChanges(old_len, self.GetNumberRows()) |
self.__NotifyRowChanges(old_len, self.GetNumberRows()) |
651 |
|
|
652 |
|
|
653 |
ID_CLASSIFY_OK = 4001 |
ID_PROPERTY_OK = 4001 |
654 |
ID_CLASSIFY_CANCEL = 4002 |
ID_PROPERTY_REVERT = 4002 |
655 |
ID_CLASSIFY_ADD = 4003 |
ID_PROPERTY_ADD = 4003 |
656 |
ID_CLASSIFY_GENCLASS = 4004 |
ID_PROPERTY_GENCLASS = 4004 |
657 |
ID_CLASSIFY_REMOVE = 4005 |
ID_PROPERTY_REMOVE = 4005 |
658 |
ID_CLASSIFY_MOVEUP = 4006 |
ID_PROPERTY_MOVEUP = 4006 |
659 |
ID_CLASSIFY_MOVEDOWN = 4007 |
ID_PROPERTY_MOVEDOWN = 4007 |
660 |
ID_CLASSIFY_APPLY = 4008 |
ID_PROPERTY_TRY = 4008 |
661 |
ID_CLASSIFY_EDITPROPS = 4009 |
ID_PROPERTY_EDITSYM = 4009 |
662 |
ID_CLASSIFY_CLOSE = 4010 |
ID_PROPERTY_CLOSE = 4010 |
663 |
|
ID_PROPERTY_SELECT = 4011 |
664 |
|
ID_PROPERTY_TITLE = 4012 |
665 |
|
ID_PROPERTY_FIELDTEXT = 4013 |
666 |
|
|
667 |
BTN_ADD = 0 |
BTN_ADD = 0 |
668 |
BTN_EDIT = 1 |
BTN_EDIT = 1 |
671 |
BTN_DOWN = 4 |
BTN_DOWN = 4 |
672 |
BTN_RM = 5 |
BTN_RM = 5 |
673 |
|
|
674 |
|
EB_LAYER_TITLE = 0 |
675 |
|
EB_SELECT_FIELD = 1 |
676 |
|
EB_GEN_CLASS = 2 |
677 |
|
|
678 |
class Classifier(NonModalDialog): |
class Classifier(NonModalDialog): |
679 |
|
|
680 |
type2string = {None: _("None"), |
type2string = {None: _("None"), |
683 |
FIELDTYPE_DOUBLE: _("Decimal")} |
FIELDTYPE_DOUBLE: _("Decimal")} |
684 |
|
|
685 |
def __init__(self, parent, name, layer, group = None): |
def __init__(self, parent, name, layer, group = None): |
686 |
NonModalDialog.__init__(self, parent, name, |
NonModalDialog.__init__(self, parent, name, "") |
|
_("Classifier: %s") % layer.Title()) |
|
687 |
|
|
688 |
panel = wxPanel(self, -1, size=(100, 100)) |
self.__SetTitle(layer.Title()) |
689 |
|
|
690 |
self.layer = layer |
self.layer = layer |
691 |
|
|
696 |
self.genDlg = None |
self.genDlg = None |
697 |
|
|
698 |
topBox = wxBoxSizer(wxVERTICAL) |
topBox = wxBoxSizer(wxVERTICAL) |
699 |
|
|
700 |
|
panel = wxPanel(self, -1, size=(100, 100)) |
701 |
|
|
702 |
panelBox = wxBoxSizer(wxVERTICAL) |
panelBox = wxBoxSizer(wxVERTICAL) |
703 |
|
|
704 |
#panelBox.Add(wxStaticText(panel, -1, _("Layer: %s") % layer.Title()), |
sizer = wxBoxSizer(wxHORIZONTAL) |
705 |
#0, wxALIGN_LEFT | wxALL, 4) |
sizer.Add(wxStaticText(panel, -1, _("Title: ")), |
706 |
|
0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 4) |
707 |
|
sizer.Add(wxTextCtrl(panel, ID_PROPERTY_TITLE, layer.Title()), |
708 |
|
1, wxGROW | wxALL, 4) |
709 |
|
EVT_TEXT(self, ID_PROPERTY_TITLE, self._OnTitleChanged) |
710 |
|
|
711 |
|
panelBox.Add(sizer, 0, wxGROW, 4) |
712 |
|
|
713 |
panelBox.Add(wxStaticText(panel, -1, |
panelBox.Add(wxStaticText(panel, -1, |
714 |
_("Layer Type: %s") % layer.ShapeType()), |
_("Type: %s") % layer.ShapeType()), |
715 |
0, wxALIGN_LEFT | wxALL, 4) |
0, wxALIGN_LEFT | wxALL, 4) |
716 |
|
|
717 |
|
|
718 |
|
##################### |
719 |
|
|
720 |
|
#panelBox = wxBoxSizer(wxVERTICAL) |
721 |
|
classBox = wxStaticBoxSizer( |
722 |
|
wxStaticBox(panel, -1, _("Classification")), wxVERTICAL) |
723 |
|
|
724 |
|
|
725 |
# |
# |
726 |
# make field combo box |
# make field choice box |
727 |
# |
# |
728 |
self.fields = wxComboBox(panel, ID_PROPERTY_SELECT, "", |
self.fields = wxChoice(panel, ID_PROPERTY_SELECT,) |
729 |
style = wxCB_READONLY) |
#self.fields = wxComboBox(panel, ID_PROPERTY_SELECT, "", |
730 |
|
# style = wxCB_READONLY) |
731 |
|
|
732 |
self.num_cols = layer.table.field_count() |
self.num_cols = layer.table.field_count() |
733 |
# just assume the first field in case one hasn't been |
# just assume the first field in case one hasn't been |
735 |
self.__cur_field = 0 |
self.__cur_field = 0 |
736 |
|
|
737 |
self.fields.Append("<None>") |
self.fields.Append("<None>") |
738 |
self.fields.SetClientData(0, None) |
|
739 |
|
if self.originalClass.GetFieldType() is None: |
740 |
|
self.fields.SetClientData(0, copy.deepcopy(self.originalClass)) |
741 |
|
else: |
742 |
|
self.fields.SetClientData(0, None) |
743 |
|
|
744 |
for i in range(self.num_cols): |
for i in range(self.num_cols): |
745 |
type, name, len, decc = layer.table.field_info(i) |
type, name, len, decc = layer.table.field_info(i) |
755 |
|
|
756 |
########### |
########### |
757 |
|
|
|
self.fieldTypeText = wxStaticText(panel, -1, "") |
|
|
panelBox.Add(self.fieldTypeText, 0, |
|
|
wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4) |
|
758 |
|
|
759 |
propertyBox = wxBoxSizer(wxHORIZONTAL) |
sizer = wxBoxSizer(wxHORIZONTAL) |
760 |
propertyBox.Add(wxStaticText(panel, -1, _("Field: ")), |
sizer.Add(wxStaticText(panel, ID_PROPERTY_FIELDTEXT, _("Field: ")), |
761 |
0, wxALIGN_LEFT | wxALL, 4) |
0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 4) |
762 |
propertyBox.Add(self.fields, 1, wxGROW|wxALL, 4) |
sizer.Add(self.fields, 1, wxGROW | wxALL, 4) |
763 |
EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect) |
EVT_CHOICE(self, ID_PROPERTY_SELECT, self._OnFieldSelect) |
764 |
|
#EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect) |
765 |
|
|
766 |
panelBox.Add(propertyBox, 0, wxGROW, 4) |
classBox.Add(sizer, 0, wxGROW, 4) |
767 |
|
|
768 |
|
self.fieldTypeText = wxStaticText(panel, -1, "") |
769 |
|
classBox.Add(self.fieldTypeText, 0, |
770 |
|
wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4) |
771 |
|
|
772 |
|
|
773 |
# |
# |
780 |
# |
# |
781 |
# Control buttons: |
# Control buttons: |
782 |
# |
# |
|
self.controlButtons = [] |
|
|
|
|
783 |
controlButtonBox = wxBoxSizer(wxVERTICAL) |
controlButtonBox = wxBoxSizer(wxVERTICAL) |
784 |
|
|
785 |
button = wxButton(panel, ID_CLASSIFY_ADD, _("Add")) |
button = wxButton(panel, ID_PROPERTY_GENCLASS, _("Generate Class")) |
786 |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
|
self.controlButtons.append(button) |
|
787 |
|
|
788 |
button = wxButton(panel, ID_CLASSIFY_EDITPROPS, _("Edit Properties")) |
button = wxButton(panel, ID_PROPERTY_ADD, _("Add")) |
789 |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
|
self.controlButtons.append(button) |
|
790 |
|
|
791 |
button = wxButton(panel, ID_CLASSIFY_GENCLASS, _("Generate Class")) |
button = wxButton(panel, ID_PROPERTY_MOVEUP, _("Move Up")) |
792 |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
|
self.controlButtons.append(button) |
|
793 |
|
|
794 |
button = wxButton(panel, ID_CLASSIFY_MOVEUP, _("Move Up")) |
button = wxButton(panel, ID_PROPERTY_MOVEDOWN, _("Move Down")) |
795 |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
|
self.controlButtons.append(button) |
|
796 |
|
|
797 |
button = wxButton(panel, ID_CLASSIFY_MOVEDOWN, _("Move Down")) |
button = wxButton(panel, ID_PROPERTY_EDITSYM, _("Edit Symbol")) |
798 |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
|
self.controlButtons.append(button) |
|
799 |
|
|
800 |
controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4) |
controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4) |
801 |
|
|
802 |
button = wxButton(panel, ID_CLASSIFY_REMOVE, _("Remove")) |
button = wxButton(panel, ID_PROPERTY_REMOVE, _("Remove")) |
803 |
controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4) |
controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4) |
|
self.controlButtons.append(button) |
|
804 |
|
|
805 |
|
|
806 |
########### |
########### |
809 |
# |
# |
810 |
|
|
811 |
self.classGrid = ClassGrid(panel, self) |
self.classGrid = ClassGrid(panel, self) |
|
#self.__SetGridTable(self.__cur_field, group) |
|
|
#self.fields.SetSelection(self.__cur_field) |
|
812 |
|
|
813 |
# calling __SelectField after creating the classGrid fills in the |
# calling __SelectField after creating the classGrid fills in the |
814 |
# grid with the correct information |
# grid with the correct information |
815 |
self.fields.SetSelection(self.__cur_field) |
self.fields.SetSelection(self.__cur_field) |
816 |
self.__SelectField(self.__cur_field, group = group) |
self.__SelectField(self.__cur_field, group = group) |
817 |
|
|
|
#self.classGrid.SelectGroup(group) |
|
|
|
|
818 |
controlBox.Add(self.classGrid, 1, wxGROW, 0) |
controlBox.Add(self.classGrid, 1, wxGROW, 0) |
819 |
|
controlBox.Add(controlButtonBox, 0, wxGROW, 10) |
820 |
|
|
821 |
|
classBox.Add(controlBox, 1, wxGROW, 10) |
822 |
|
panelBox.Add(classBox, 1, wxGROW, 0) |
823 |
|
|
824 |
|
EVT_BUTTON(self, ID_PROPERTY_ADD, self._OnAdd) |
825 |
|
EVT_BUTTON(self, ID_PROPERTY_EDITSYM, self._OnEditSymbol) |
826 |
|
EVT_BUTTON(self, ID_PROPERTY_REMOVE, self._OnRemove) |
827 |
|
EVT_BUTTON(self, ID_PROPERTY_GENCLASS, self._OnGenClass) |
828 |
|
EVT_BUTTON(self, ID_PROPERTY_MOVEUP, self._OnMoveUp) |
829 |
|
EVT_BUTTON(self, ID_PROPERTY_MOVEDOWN, self._OnMoveDown) |
830 |
|
|
831 |
|
########### |
832 |
|
|
|
controlBox.Add(controlButtonBox, 0, wxGROW, 10) |
|
|
panelBox.Add(controlBox, 1, wxGROW, 10) |
|
833 |
|
|
834 |
EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd) |
panel.SetAutoLayout(True) |
835 |
EVT_BUTTON(self, ID_CLASSIFY_EDITPROPS, self._OnEditGroupProperties) |
panel.SetSizer(panelBox) |
836 |
EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove) |
panelBox.SetSizeHints(panel) |
837 |
EVT_BUTTON(self, ID_CLASSIFY_GENCLASS, self._OnGenClass) |
|
838 |
EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp) |
topBox.Add(panel, 1, wxGROW | wxALL, 4) |
|
EVT_BUTTON(self, ID_CLASSIFY_MOVEDOWN, self._OnMoveDown) |
|
839 |
|
|
840 |
########### |
########### |
841 |
|
|
842 |
buttonBox = wxBoxSizer(wxHORIZONTAL) |
buttonBox = wxBoxSizer(wxHORIZONTAL) |
843 |
buttonBox.Add(wxButton(panel, ID_CLASSIFY_OK, _("OK")), |
buttonBox.Add(wxButton(self, ID_PROPERTY_TRY, _("Try")), |
844 |
0, wxALL, 4) |
0, wxALL, 4) |
845 |
buttonBox.Add(60, 20, 0, wxALL, 4) |
buttonBox.Add(60, 20, 0, wxALL, 4) |
846 |
buttonBox.Add(wxButton(panel, ID_CLASSIFY_APPLY, _("Apply")), |
buttonBox.Add(wxButton(self, ID_PROPERTY_REVERT, _("Revert")), |
847 |
0, wxALL, 4) |
0, wxALL, 4) |
848 |
buttonBox.Add(60, 20, 0, wxALL, 4) |
buttonBox.Add(60, 20, 0, wxALL, 4) |
849 |
buttonBox.Add(wxButton(panel, ID_CLASSIFY_CLOSE, _("Close")), |
buttonBox.Add(wxButton(self, ID_PROPERTY_OK, _("OK")), |
850 |
0, wxALL, 4) |
0, wxALL, 4) |
851 |
buttonBox.Add(60, 20, 0, wxALL, 4) |
buttonBox.Add(60, 20, 0, wxALL, 4) |
852 |
buttonBox.Add(wxButton(panel, ID_CLASSIFY_CANCEL, _("Cancel")), |
buttonBox.Add(wxButton(self, ID_PROPERTY_CLOSE, _("Close")), |
853 |
0, wxALL, 4) |
0, wxALL, 4) |
854 |
panelBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0) |
topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0) |
855 |
|
|
856 |
EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK) |
EVT_BUTTON(self, ID_PROPERTY_OK, self._OnOK) |
857 |
EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply) |
EVT_BUTTON(self, ID_PROPERTY_TRY, self._OnTry) |
858 |
EVT_BUTTON(self, ID_CLASSIFY_CLOSE, self._OnCloseBtn) |
EVT_BUTTON(self, ID_PROPERTY_CLOSE, self._OnCloseBtn) |
859 |
EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel) |
EVT_BUTTON(self, ID_PROPERTY_REVERT, self._OnRevert) |
860 |
|
|
861 |
########### |
########### |
862 |
|
|
863 |
|
topBox.SetSizeHints(self) |
|
panel.SetAutoLayout(True) |
|
|
panel.SetSizer(panelBox) |
|
|
panelBox.SetSizeHints(panel) |
|
|
|
|
|
topBox.Add(panel, 1, wxGROW, 0) |
|
|
panelBox.SetSizeHints(self) |
|
864 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
865 |
self.SetSizer(topBox) |
self.SetSizer(topBox) |
866 |
|
|
869 |
|
|
870 |
self.haveApplied = False |
self.haveApplied = False |
871 |
|
|
872 |
def EditGroupProperties(self, row): |
def EditSymbol(self, row): |
873 |
table = self.classGrid.GetTable() |
table = self.classGrid.GetTable() |
874 |
prop = table.GetValueAsCustom(row, COL_SYMBOL, None) |
prop = table.GetValueAsCustom(row, COL_SYMBOL, None) |
875 |
|
|
944 |
|
|
945 |
text = Classifier.type2string[fieldType] |
text = Classifier.type2string[fieldType] |
946 |
|
|
947 |
self.fieldTypeText.SetLabel(_("Field Type: %s") % text) |
self.fieldTypeText.SetLabel(_("Data Type: %s") % text) |
948 |
|
|
949 |
def __SelectField(self, newIndex, oldIndex = -1, group = None): |
def __SelectField(self, newIndex, oldIndex = -1, group = None): |
950 |
"""This method assumes that the current selection for the |
"""This method assumes that the current selection for the |
959 |
|
|
960 |
self.__SetGridTable(newIndex, group) |
self.__SetGridTable(newIndex, group) |
961 |
|
|
962 |
enabled = newIndex != 0 |
self.__EnableButtons(EB_SELECT_FIELD, newIndex != 0) |
|
|
|
|
for b in self.controlButtons: |
|
|
b.Enable(enabled) |
|
963 |
|
|
964 |
self.__SetFieldTypeText(newIndex) |
self.__SetFieldTypeText(newIndex) |
965 |
|
|
966 |
|
def __SetTitle(self, title): |
967 |
|
if title != "": |
968 |
|
title = ": " + title |
969 |
|
|
970 |
|
self.SetTitle(_("Layer Properties") + title) |
971 |
|
|
972 |
def _OnEditGroupProperties(self, event): |
def _OnEditSymbol(self, event): |
973 |
sel = self.classGrid.GetCurrentSelection() |
sel = self.classGrid.GetCurrentSelection() |
974 |
|
|
975 |
if len(sel) == 1: |
if len(sel) == 1: |
976 |
self.EditGroupProperties(sel[0]) |
self.EditSymbol(sel[0]) |
977 |
|
|
978 |
def _OnFieldSelect(self, event): |
def _OnFieldSelect(self, event): |
979 |
index = self.fields.GetSelection() |
index = self.fields.GetSelection() |
980 |
self.__SelectField(index, self.__cur_field) |
self.__SelectField(index, self.__cur_field) |
981 |
self.__cur_field = index |
self.__cur_field = index |
982 |
|
|
983 |
def _OnApply(self, event): |
def _OnTry(self, event): |
984 |
"""Put the data from the table into a new Classification and hand |
"""Put the data from the table into a new Classification and hand |
985 |
it to the layer. |
it to the layer. |
986 |
""" |
""" |
999 |
self.haveApplied = True |
self.haveApplied = True |
1000 |
|
|
1001 |
def _OnOK(self, event): |
def _OnOK(self, event): |
1002 |
self._OnApply(event) |
self._OnTry(event) |
1003 |
self.Close() |
self.Close() |
1004 |
|
|
1005 |
def _OnCloseBtn(self, event): |
def _OnCloseBtn(self, event): |
1010 |
|
|
1011 |
self.Close() |
self.Close() |
1012 |
|
|
1013 |
def _OnCancel(self, event): |
def _OnRevert(self, event): |
1014 |
"""The layer's current classification stays the same.""" |
"""The layer's current classification stays the same.""" |
1015 |
if self.haveApplied: |
if self.haveApplied: |
1016 |
self.layer.SetClassification(self.originalClass) |
self.layer.SetClassification(self.originalClass) |
1017 |
|
|
1018 |
self.Close() |
#self.Close() |
1019 |
|
|
1020 |
def _OnAdd(self, event): |
def _OnAdd(self, event): |
1021 |
self.classGrid.AppendRows() |
self.classGrid.AppendRows() |
1025 |
|
|
1026 |
def _OnGenClass(self, event): |
def _OnGenClass(self, event): |
1027 |
|
|
|
#if self.genDlg is None: |
|
1028 |
self.genDlg = ClassGenDialog(self, self.layer, |
self.genDlg = ClassGenDialog(self, self.layer, |
1029 |
self.fields.GetString(self.__cur_field)) |
self.fields.GetString(self.__cur_field)) |
1030 |
|
|
1031 |
EVT_CLOSE(self.genDlg, self._OnGenDialogClose) |
EVT_CLOSE(self.genDlg, self._OnGenDialogClose) |
1032 |
|
|
1033 |
self.fields.Enable(False) |
self.__EnableButtons(EB_GEN_CLASS, False) |
|
self.controlButtons[BTN_EDIT].Enable(False) |
|
|
self.controlButtons[BTN_GEN].Enable(False) |
|
1034 |
|
|
1035 |
self.genDlg.Show() |
self.genDlg.Show() |
|
#if self.genDlg.ShowModal() == wxID_OK: |
|
|
# clazz = self.genDlg.GetClassification() |
|
|
# self.fields.SetClientData(self.__cur_field, clazz) |
|
|
# self.classGrid.GetTable().SetClassification(clazz) |
|
|
#self.Enable(True) |
|
|
#self.genDlg.Destroy() |
|
1036 |
|
|
1037 |
def _OnGenDialogClose(self, event): |
def _OnGenDialogClose(self, event): |
1038 |
self.genDlg.Destroy() |
self.genDlg.Destroy() |
1039 |
|
self.__EnableButtons(EB_GEN_CLASS, True) |
|
self.fields.Enable(True) |
|
|
self.controlButtons[BTN_EDIT].Enable(True) |
|
|
self.controlButtons[BTN_GEN].Enable(True) |
|
1040 |
|
|
1041 |
def _OnMoveUp(self, event): |
def _OnMoveUp(self, event): |
1042 |
sel = self.classGrid.GetCurrentSelection() |
sel = self.classGrid.GetCurrentSelection() |
1068 |
self.classGrid.SelectRow(i + 1) |
self.classGrid.SelectRow(i + 1) |
1069 |
self.classGrid.MakeCellVisible(i + 1, 0) |
self.classGrid.MakeCellVisible(i + 1, 0) |
1070 |
|
|
1071 |
|
def _OnTitleChanged(self, event): |
1072 |
|
obj = event.GetEventObject() |
1073 |
|
|
1074 |
|
self.layer.SetTitle(obj.GetValue()) |
1075 |
|
self.__SetTitle(self.layer.Title()) |
1076 |
|
|
1077 |
|
self.__EnableButtons(EB_LAYER_TITLE, self.layer.Title() != "") |
1078 |
|
|
1079 |
|
def __EnableButtons(self, case, enable): |
1080 |
|
|
1081 |
|
if case == EB_LAYER_TITLE: |
1082 |
|
list = (ID_PROPERTY_OK, |
1083 |
|
ID_PROPERTY_CLOSE) |
1084 |
|
|
1085 |
|
elif case == EB_SELECT_FIELD: |
1086 |
|
list = (ID_PROPERTY_GENCLASS, |
1087 |
|
ID_PROPERTY_ADD, |
1088 |
|
ID_PROPERTY_MOVEUP, |
1089 |
|
ID_PROPERTY_MOVEDOWN, |
1090 |
|
ID_PROPERTY_EDITSYM, |
1091 |
|
ID_PROPERTY_REMOVE) |
1092 |
|
|
1093 |
|
elif case == EB_GEN_CLASS: |
1094 |
|
list = (ID_PROPERTY_SELECT, |
1095 |
|
ID_PROPERTY_FIELDTEXT, |
1096 |
|
ID_PROPERTY_GENCLASS, |
1097 |
|
ID_PROPERTY_EDITSYM) |
1098 |
|
|
1099 |
|
for id in list: |
1100 |
|
self.FindWindowById(id).Enable(enable) |
1101 |
|
|
1102 |
ID_SELPROP_OK = 4001 |
ID_SELPROP_OK = 4001 |
1103 |
ID_SELPROP_CANCEL = 4002 |
ID_SELPROP_CANCEL = 4002 |