623 |
else: |
else: |
624 |
self.fields.SetClientData(i + 1, None) |
self.fields.SetClientData(i + 1, None) |
625 |
|
|
|
self.fields.SetSelection(self.__cur_field) |
|
626 |
|
|
627 |
# |
# |
628 |
# |
# |
650 |
|
|
651 |
self.classGrid = ClassGrid(self) |
self.classGrid = ClassGrid(self) |
652 |
self.__SetGridTable(self.__cur_field) |
self.__SetGridTable(self.__cur_field) |
|
print self.classGrid.GetSizeTuple() |
|
653 |
|
|
654 |
controlBox.Add(self.classGrid, 1, wxGROW, 0) |
controlBox.Add(self.classGrid, 1, wxGROW, 0) |
655 |
|
|
706 |
EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply) |
EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply) |
707 |
EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel) |
EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel) |
708 |
|
|
709 |
|
self.fields.SetSelection(self.__cur_field) |
710 |
|
self.__SelectField(self.__cur_field) |
711 |
|
|
712 |
self.SetAutoLayout(true) |
self.SetAutoLayout(true) |
713 |
self.SetSizer(topBox) |
self.SetSizer(topBox) |
714 |
topBox.Fit(self) |
topBox.Fit(self) |
717 |
|
|
718 |
def __BuildClassification(self, fieldIndex): |
def __BuildClassification(self, fieldIndex): |
719 |
|
|
720 |
|
numRows = self.classGrid.GetNumberRows() |
721 |
|
assert(numRows > 0) # there should always be a default row |
722 |
|
|
723 |
clazz = Classification() |
clazz = Classification() |
724 |
fieldName = self.fields.GetString(fieldIndex) |
if fieldIndex == 0: |
725 |
fieldType = self.layer.GetFieldType(fieldName) |
fieldName = None |
726 |
|
fieldType = None |
727 |
|
else: |
728 |
|
fieldName = self.fields.GetString(fieldIndex) |
729 |
|
fieldType = self.layer.GetFieldType(fieldName) |
730 |
|
|
731 |
clazz.SetField(fieldName) |
clazz.SetField(fieldName) |
732 |
clazz.SetFieldType(fieldType) |
clazz.SetFieldType(fieldType) |
733 |
|
|
|
numRows = self.classGrid.GetNumberRows() |
|
|
|
|
|
assert(numRows > 0) # there should always be a default row |
|
734 |
|
|
735 |
table = self.classGrid.GetTable() |
table = self.classGrid.GetTable() |
736 |
clazz.SetDefaultGroup(table.GetClassGroup(0)) |
clazz.SetDefaultGroup(table.GetClassGroup(0)) |
757 |
|
|
758 |
self.classGrid.CreateTable(clazz, self.layer.ShapeType()) |
self.classGrid.CreateTable(clazz, self.layer.ShapeType()) |
759 |
|
|
760 |
|
|
761 |
|
|
762 |
|
type2string = {None: "None", |
763 |
|
FIELDTYPE_STRING: "Text", |
764 |
|
FIELDTYPE_INT: "Integer", |
765 |
|
FIELDTYPE_DOUBLE: "Decimal"} |
766 |
|
|
767 |
def __SetFieldTypeText(self, fieldIndex): |
def __SetFieldTypeText(self, fieldIndex): |
768 |
fieldName = self.fields.GetString(fieldIndex) |
fieldName = self.fields.GetString(fieldIndex) |
769 |
fieldType = self.layer.GetFieldType(fieldName) |
fieldType = self.layer.GetFieldType(fieldName) |
770 |
|
|
771 |
if fieldType is None: |
assert(Classifier.type2string.has_key(fieldType)) |
772 |
text = "None" |
|
773 |
elif fieldType == FIELDTYPE_STRING: |
text = Classifier.type2string[fieldType] |
|
text = "Text" |
|
|
elif fieldType == FIELDTYPE_INT: |
|
|
text = "Integer" |
|
|
elif fieldType == FIELDTYPE_DOUBLE: |
|
|
text = "Decimal" # Rational? |
|
|
else: |
|
|
assert(False) |
|
|
text = "UNKNOWN" |
|
774 |
|
|
775 |
self.fieldTypeText.SetLabel(_("Field Type: %s") % text) |
self.fieldTypeText.SetLabel(_("Field Type: %s") % text) |
776 |
|
|
777 |
def _OnFieldSelect(self, event): |
def __SelectField(self, fieldIndex): |
778 |
clazz = self.__BuildClassification(self.__cur_field) |
clazz = self.__BuildClassification(fieldIndex) |
779 |
self.fields.SetClientData(self.__cur_field, clazz) |
self.fields.SetClientData(fieldIndex, clazz) |
780 |
|
|
781 |
self.__cur_field = self.fields.GetSelection() |
self.__cur_field = self.fields.GetSelection() |
782 |
self.__SetGridTable(self.__cur_field) |
self.__SetGridTable(fieldIndex) |
783 |
|
|
784 |
enabled = self.__cur_field != 0 |
enabled = fieldIndex != 0 |
785 |
|
|
786 |
for b in self.controlButtons: |
for b in self.controlButtons: |
787 |
b.Enable(enabled) |
b.Enable(enabled) |
788 |
|
|
789 |
self.__SetFieldTypeText(self.__cur_field) |
self.__SetFieldTypeText(fieldIndex) |
790 |
|
|
791 |
|
|
792 |
|
def _OnFieldSelect(self, event): |
793 |
|
self.__SelectField(self.__cur_field) |
794 |
|
|
795 |
def _OnApply(self, event): |
def _OnApply(self, event): |
796 |
"""Put the data from the table into a new Classification and hand |
"""Put the data from the table into a new Classification and hand |