59 |
import weakref |
import weakref |
60 |
class ClassGrid(wxGrid): |
class ClassGrid(wxGrid): |
61 |
|
|
62 |
|
|
63 |
def __init__(self, parent): |
def __init__(self, parent): |
64 |
"""Constructor. |
"""Constructor. |
65 |
|
|
73 |
wxGrid.__init__(self, parent, ID_CLASS_TABLE) |
wxGrid.__init__(self, parent, ID_CLASS_TABLE) |
74 |
#self.SetTable(ClassTable(fieldData, layer.ShapeType(), self), True) |
#self.SetTable(ClassTable(fieldData, layer.ShapeType(), self), True) |
75 |
|
|
76 |
|
self.currentSelection = [] |
77 |
|
|
78 |
EVT_GRID_CELL_LEFT_DCLICK(self, self._OnCellDClick) |
EVT_GRID_CELL_LEFT_DCLICK(self, self._OnCellDClick) |
79 |
EVT_GRID_RANGE_SELECT(self, self._OnSelectedRange) |
EVT_GRID_RANGE_SELECT(self, self._OnSelectedRange) |
80 |
EVT_GRID_SELECT_CELL(self, self._OnSelectedCell) |
EVT_GRID_SELECT_CELL(self, self._OnSelectedCell) |
81 |
|
|
82 |
self.currentSelection = [] |
print "123123123: ", ('Show' in dir(self)) |
83 |
|
|
84 |
|
def Show(self): |
85 |
|
print "SHOW!" |
86 |
|
|
87 |
|
def Refresh(self): |
88 |
|
self.Show() |
89 |
|
def Update(self): |
90 |
|
self.Show() |
91 |
|
|
92 |
def CreateTable(self, clazz, shapeType): |
def CreateTable(self, clazz, shapeType, group = None): |
93 |
|
|
94 |
assert(isinstance(clazz, Classification)) |
assert(isinstance(clazz, Classification)) |
95 |
|
|
100 |
h = self.GetDefaultRowSize() * 4 + self.GetDefaultColLabelSize() |
h = self.GetDefaultRowSize() * 4 + self.GetDefaultColLabelSize() |
101 |
self.SetDimensions(-1, -1, w, h) |
self.SetDimensions(-1, -1, w, h) |
102 |
self.SetSizeHints(w, h, -1, -1) |
self.SetSizeHints(w, h, -1, -1) |
103 |
self.SetTable(ClassTable(clazz, self.shapeType, self), True) |
table = ClassTable(self) |
104 |
else: |
self.SetTable(table, True) |
105 |
table.Reset(clazz, self.shapeType) |
|
106 |
|
|
107 |
self.SetSelectionMode(wxGrid.wxGridSelectRows) |
self.SetSelectionMode(wxGrid.wxGridSelectRows) |
108 |
self.ClearSelection() |
self.ClearSelection() |
109 |
|
|
110 |
|
print "8------------------" |
111 |
|
table.Reset(clazz, self.shapeType, group) |
112 |
|
print "9------------------" |
113 |
|
|
114 |
|
# def Show(self, show = True): |
115 |
|
# print "SHOW!" |
116 |
|
# wxGrid.Show(self, show) |
117 |
|
|
118 |
|
# sel = self.GetCurrentSelection() |
119 |
|
|
120 |
|
# print "( 1" |
121 |
|
# if len(sel) == 1: |
122 |
|
# print "( 2" |
123 |
|
# self.MakeCellVisible(sel[0], 0) |
124 |
|
|
125 |
def GetCurrentSelection(self): |
def GetCurrentSelection(self): |
126 |
"""Return the currently highlighted rows as an increasing list |
"""Return the currently highlighted rows as an increasing list |
127 |
of row numbers.""" |
of row numbers.""" |
128 |
|
print "@@ ", self.currentSelection |
129 |
sel = copy.copy(self.currentSelection) |
sel = copy.copy(self.currentSelection) |
130 |
sel.sort() |
sel.sort() |
131 |
return sel |
return sel |
132 |
|
|
133 |
|
def GetSelectedRows(self): |
134 |
|
return self.GetCurrentSelection() |
135 |
|
|
136 |
def SetCellRenderer(self, row, col): |
def SetCellRenderer(self, row, col): |
137 |
raise ValueError(_("Must not allow setting of renderer in ClassGrid!")) |
raise ValueError(_("Must not allow setting of renderer in ClassGrid!")) |
138 |
|
|
199 |
r = self.GetNumberRows() - 1 |
r = self.GetNumberRows() - 1 |
200 |
self.SelectRow(r) |
self.SelectRow(r) |
201 |
|
|
202 |
|
|
203 |
|
def SelectGroup(self, group, makeVisible = True): |
204 |
|
if group is None: return |
205 |
|
|
206 |
|
assert(isinstance(group, ClassGroup)) |
207 |
|
|
208 |
|
table = self.GetTable() |
209 |
|
|
210 |
|
assert(table is not None) |
211 |
|
|
212 |
|
|
213 |
|
print "-- ", group |
214 |
|
for i in range(table.GetNumberRows()): |
215 |
|
g = table.GetClassGroup(i) |
216 |
|
print "1", g |
217 |
|
if g is group: |
218 |
|
print "2" |
219 |
|
self.SelectRow(i) |
220 |
|
if makeVisible: |
221 |
|
print "3" |
222 |
|
self.MakeCellVisible(i, 0) |
223 |
|
break |
224 |
|
|
225 |
|
|
226 |
|
|
227 |
# |
# |
228 |
# XXX: This isn't working, and there is no way to deselect rows wxPython! |
# XXX: This isn't working, and there is no way to deselect rows wxPython! |
229 |
# |
# |
263 |
if event.Selecting(): |
if event.Selecting(): |
264 |
for index in range( event.GetTopRow(), event.GetBottomRow()+1): |
for index in range( event.GetTopRow(), event.GetBottomRow()+1): |
265 |
if index not in self.currentSelection: |
if index not in self.currentSelection: |
266 |
|
print " ", index |
267 |
self.currentSelection.append( index ) |
self.currentSelection.append( index ) |
268 |
else: |
else: |
269 |
for index in range( event.GetTopRow(), event.GetBottomRow()+1): |
for index in range( event.GetTopRow(), event.GetBottomRow()+1): |
270 |
while index in self.currentSelection: |
while index in self.currentSelection: |
271 |
|
print " ", index |
272 |
self.currentSelection.remove( index ) |
self.currentSelection.remove( index ) |
273 |
#self.ConfigureForSelection() |
#self.ConfigureForSelection() |
274 |
|
|
275 |
|
print self.GetCurrentSelection() |
276 |
event.Skip() |
event.Skip() |
277 |
|
|
278 |
def _OnSelectedCell( self, event ): |
def _OnSelectedCell( self, event ): |
279 |
"""Internal update to the selection tracking list""" |
"""Internal update to the selection tracking list""" |
280 |
|
print "selecting cell: ", event.GetRow() |
281 |
self.currentSelection = [ event.GetRow() ] |
self.currentSelection = [ event.GetRow() ] |
282 |
#self.ConfigureForSelection() |
#self.ConfigureForSelection() |
283 |
event.Skip() |
event.Skip() |
289 |
|
|
290 |
__col_labels = [_("Symbol"), _("Value"), _("Label")] |
__col_labels = [_("Symbol"), _("Value"), _("Label")] |
291 |
|
|
292 |
def __init__(self, clazz, shapeType, view = None): |
|
293 |
|
def __init__(self, view = None): |
294 |
|
#def __init__(self, clazz, shapeType, view = None): |
295 |
"""Constructor. |
"""Constructor. |
296 |
|
|
297 |
shapeType -- the type of shape that the layer uses |
shapeType -- the type of shape that the layer uses |
304 |
self.SetView(view) |
self.SetView(view) |
305 |
self.tdata = [] |
self.tdata = [] |
306 |
|
|
307 |
self.Reset(clazz, shapeType) |
#self.Reset(clazz, shapeType) |
308 |
|
|
309 |
def Reset(self, clazz, shapeType): |
def Reset(self, clazz, shapeType, group = None): |
310 |
"""Reset the table with the given data. |
"""Reset the table with the given data. |
311 |
|
|
312 |
This is necessary because wxWindows does not allow a grid's |
This is necessary because wxWindows does not allow a grid's |
331 |
|
|
332 |
self.tdata = [] |
self.tdata = [] |
333 |
|
|
334 |
|
print "9------------------" |
335 |
# |
# |
336 |
# copy the data out of the classification and into our |
# copy the data out of the classification and into our |
337 |
# array |
# array |
338 |
# |
# |
339 |
for p in clazz: |
row = -1 |
340 |
np = copy.deepcopy(p) |
for g in clazz: |
341 |
self.__SetRow(-1, np) |
ng = copy.deepcopy(g) |
342 |
|
self.__SetRow(-1, ng) |
343 |
|
if g is group: |
344 |
|
row = self.GetNumberRows() - 1 |
345 |
|
print "selecting row..." |
346 |
|
|
347 |
|
print "10------------------" |
348 |
|
|
349 |
self.__Modified(-1) |
self.__Modified(-1) |
350 |
|
|
351 |
self.__NotifyRowChanges(old_len, len(self.tdata)) |
self.__NotifyRowChanges(old_len, len(self.tdata)) |
352 |
|
print "11------------------" |
353 |
|
|
354 |
|
if row > -1: |
355 |
|
self.GetView().ClearSelection() |
356 |
|
self.GetView().SelectRow(row) |
357 |
|
self.GetView().MakeCellVisible(row, 0) |
358 |
|
|
359 |
self.GetView().EndBatch() |
self.GetView().EndBatch() |
360 |
|
|
653 |
|
|
654 |
class Classifier(NonModalDialog): |
class Classifier(NonModalDialog): |
655 |
|
|
656 |
def __init__(self, parent, name, layer): |
def __init__(self, parent, name, layer, group = None): |
657 |
NonModalDialog.__init__(self, parent, name, |
NonModalDialog.__init__(self, parent, name, |
658 |
_("Classifier: %s") % layer.Title()) |
_("Classifier: %s") % layer.Title()) |
659 |
|
|
714 |
|
|
715 |
panelBox.Add(propertyBox, 0, wxGROW, 4) |
panelBox.Add(propertyBox, 0, wxGROW, 4) |
716 |
|
|
717 |
########### |
|
718 |
# |
# |
719 |
# Classification data table |
# Control Box |
720 |
# |
# |
|
|
|
721 |
controlBox = wxBoxSizer(wxHORIZONTAL) |
controlBox = wxBoxSizer(wxHORIZONTAL) |
722 |
|
|
|
self.classGrid = ClassGrid(panel) |
|
|
self.__SetGridTable(self.__cur_field) |
|
|
|
|
|
controlBox.Add(self.classGrid, 1, wxGROW, 0) |
|
723 |
|
|
724 |
########### |
########### |
725 |
# |
# |
733 |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
734 |
self.controlButtons.append(button) |
self.controlButtons.append(button) |
735 |
|
|
736 |
#button = wxButton(panel, ID_CLASSIFY_GENRANGE, _("Generate Ranges")) |
button = wxButton(panel, ID_CLASSIFY_GENRANGE, _("Generate Ranges")) |
737 |
#controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
738 |
#self.controlButtons.append(button) |
self.controlButtons.append(button) |
739 |
|
|
740 |
button = wxButton(panel, ID_CLASSIFY_MOVEUP, _("Move Up")) |
button = wxButton(panel, ID_CLASSIFY_MOVEUP, _("Move Up")) |
741 |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
controlButtonBox.Add(button, 0, wxGROW | wxALL, 4) |
751 |
controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4) |
controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4) |
752 |
self.controlButtons.append(button) |
self.controlButtons.append(button) |
753 |
|
|
754 |
|
|
755 |
|
########### |
756 |
|
# |
757 |
|
# Classification data table |
758 |
|
# |
759 |
|
|
760 |
|
self.classGrid = ClassGrid(panel) |
761 |
|
#self.__SetGridTable(self.__cur_field, group) |
762 |
|
#self.fields.SetSelection(self.__cur_field) |
763 |
|
|
764 |
|
# calling __SelectField after creating the classGrid fills in the |
765 |
|
# grid with the correct information |
766 |
|
print "2------------------" |
767 |
|
self.__SelectField(self.__cur_field, group = group) |
768 |
|
|
769 |
|
#self.classGrid.SelectGroup(group) |
770 |
|
|
771 |
|
controlBox.Add(self.classGrid, 1, wxGROW, 0) |
772 |
|
|
773 |
|
|
774 |
|
|
775 |
controlBox.Add(controlButtonBox, 0, wxGROW, 10) |
controlBox.Add(controlButtonBox, 0, wxGROW, 10) |
776 |
panelBox.Add(controlBox, 1, wxGROW, 10) |
panelBox.Add(controlBox, 1, wxGROW, 10) |
777 |
|
|
800 |
|
|
801 |
########### |
########### |
802 |
|
|
|
self.fields.SetSelection(self.__cur_field) |
|
|
self.__SelectField(self.__cur_field) |
|
803 |
|
|
804 |
panel.SetAutoLayout(True) |
panel.SetAutoLayout(True) |
805 |
panel.SetSizer(panelBox) |
panel.SetSizer(panelBox) |
810 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
811 |
self.SetSizer(topBox) |
self.SetSizer(topBox) |
812 |
|
|
813 |
|
print "1------------------" |
814 |
|
#self.Fit() |
815 |
###################### |
###################### |
816 |
|
|
817 |
self.haveApplied = False |
self.haveApplied = False |
841 |
|
|
842 |
return clazz |
return clazz |
843 |
|
|
844 |
def __SetGridTable(self, fieldIndex): |
def __SetGridTable(self, fieldIndex, group = None): |
845 |
|
|
846 |
clazz = self.fields.GetClientData(fieldIndex) |
clazz = self.fields.GetClientData(fieldIndex) |
847 |
|
|
856 |
fieldType = self.layer.GetFieldType(fieldName) |
fieldType = self.layer.GetFieldType(fieldName) |
857 |
clazz.SetFieldType(fieldType) |
clazz.SetFieldType(fieldType) |
858 |
|
|
859 |
self.classGrid.CreateTable(clazz, self.layer.ShapeType()) |
print "6------------------" |
860 |
|
self.classGrid.CreateTable(clazz, self.layer.ShapeType(), group) |
861 |
|
print "7------------------" |
862 |
|
|
863 |
|
|
864 |
|
|
877 |
|
|
878 |
self.fieldTypeText.SetLabel(_("Field Type: %s") % text) |
self.fieldTypeText.SetLabel(_("Field Type: %s") % text) |
879 |
|
|
880 |
def __SelectField(self, newIndex, oldIndex = -1): |
def __SelectField(self, newIndex, oldIndex = -1, group = None): |
881 |
|
|
882 |
|
print "3------------------" |
883 |
|
|
884 |
assert(oldIndex >= -1) |
assert(oldIndex >= -1) |
885 |
|
|
886 |
|
self.fields.SetSelection(newIndex) |
887 |
|
|
888 |
if oldIndex != -1: |
if oldIndex != -1: |
889 |
clazz = self.__BuildClassification(oldIndex) |
clazz = self.__BuildClassification(oldIndex) |
890 |
self.fields.SetClientData(oldIndex, clazz) |
self.fields.SetClientData(oldIndex, clazz) |
891 |
|
|
892 |
self.__SetGridTable(newIndex) |
print "4------------------" |
893 |
|
self.__SetGridTable(newIndex, group) |
894 |
|
print "5------------------" |
895 |
|
|
896 |
enabled = newIndex != 0 |
enabled = newIndex != 0 |
897 |
|
|
947 |
def _OnMoveUp(self, event): |
def _OnMoveUp(self, event): |
948 |
sel = self.classGrid.GetCurrentSelection() |
sel = self.classGrid.GetCurrentSelection() |
949 |
|
|
950 |
|
print "sel: ", sel |
951 |
|
|
952 |
if len(sel) == 1: |
if len(sel) == 1: |
953 |
i = sel[0] |
i = sel[0] |
954 |
if i > 1: |
if i > 1: |
959 |
table.SetClassGroup(i, x) |
table.SetClassGroup(i, x) |
960 |
self.classGrid.ClearSelection() |
self.classGrid.ClearSelection() |
961 |
self.classGrid.SelectRow(i - 1) |
self.classGrid.SelectRow(i - 1) |
962 |
|
self.classGrid.MakeCellVisible(i - 1, 0) |
963 |
|
|
964 |
def _OnMoveDown(self, event): |
def _OnMoveDown(self, event): |
965 |
sel = self.classGrid.GetCurrentSelection() |
sel = self.classGrid.GetCurrentSelection() |
974 |
table.SetClassGroup(i + 1, x) |
table.SetClassGroup(i + 1, x) |
975 |
self.classGrid.ClearSelection() |
self.classGrid.ClearSelection() |
976 |
self.classGrid.SelectRow(i + 1) |
self.classGrid.SelectRow(i + 1) |
977 |
|
self.classGrid.MakeCellVisible(i + 1, 0) |
978 |
|
|
979 |
|
|
980 |
ID_SELPROP_OK = 4001 |
ID_SELPROP_OK = 4001 |