/[thuban]/trunk/thuban/Thuban/UI/classifier.py
ViewVC logotype

Diff of /trunk/thuban/Thuban/UI/classifier.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 489 by jonathan, Fri Mar 7 18:22:47 2003 UTC revision 509 by jonathan, Tue Mar 11 09:45:59 2003 UTC
# Line 70  class ClassGrid(wxGrid): Line 70  class ClassGrid(wxGrid):
70    
71          #wxGrid.__init__(self, parent, ID_CLASS_TABLE, size = (340, 160))          #wxGrid.__init__(self, parent, ID_CLASS_TABLE, size = (340, 160))
72          wxGrid.__init__(self, parent, ID_CLASS_TABLE)          wxGrid.__init__(self, parent, ID_CLASS_TABLE)
73          #self.SetTable(ClassTable(fieldData, layer.ShapeType(), self), true)          #self.SetTable(ClassTable(fieldData, layer.ShapeType(), self), True)
74    
75          EVT_GRID_CELL_LEFT_DCLICK(self, self._OnCellDClick)          EVT_GRID_CELL_LEFT_DCLICK(self, self._OnCellDClick)
76          EVT_GRID_RANGE_SELECT(self, self._OnSelectedRange)          EVT_GRID_RANGE_SELECT(self, self._OnSelectedRange)
# Line 85  class ClassGrid(wxGrid): Line 85  class ClassGrid(wxGrid):
85          self.shapeType = shapeType          self.shapeType = shapeType
86          table = self.GetTable()          table = self.GetTable()
87          if table is None:          if table is None:
88              self.SetTable(ClassTable(clazz, self.shapeType, self), true)              w = self.GetDefaultColSize() * 3 + self.GetDefaultRowLabelSize()
89                h = self.GetDefaultRowSize() * 4 + self.GetDefaultColLabelSize()
90                self.SetDimensions(-1, -1, w, h)
91                self.SetSizeHints(w, h, -1, -1)
92                self.SetTable(ClassTable(clazz, self.shapeType, self), True)
93          else:          else:
94              table.Reset(clazz, self.shapeType)              table.Reset(clazz, self.shapeType)
95    
# Line 279  class ClassTable(wxPyGridTableBase): Line 283  class ClassTable(wxPyGridTableBase):
283    
284          self.__NotifyRowChanges(old_len, len(self.tdata))          self.__NotifyRowChanges(old_len, len(self.tdata))
285    
         view = self.GetView()  
         w = view.GetDefaultColSize() * 3 + view.GetDefaultRowLabelSize()  
         h = view.GetDefaultRowSize() * 4 + view.GetDefaultColLabelSize()  
         view.SetDimensions(-1, -1, w, h)  
         view.SetSizeHints(w, h, -1, -1)  
286                            
287          self.GetView().EndBatch()          self.GetView().EndBatch()
288    
# Line 584  class Classifier(NonModalDialog): Line 583  class Classifier(NonModalDialog):
583          NonModalDialog.__init__(self, parent, interactor, name,          NonModalDialog.__init__(self, parent, interactor, name,
584                                  _("Classifier: %s") % layer.Title())                                  _("Classifier: %s") % layer.Title())
585    
586            panel = wxPanel(self, -1)
587    
588          self.layer = layer          self.layer = layer
589    
590          self.originalClass = self.layer.GetClassification()          self.originalClass = self.layer.GetClassification()
# Line 592  class Classifier(NonModalDialog): Line 593  class Classifier(NonModalDialog):
593    
594          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
595    
596          #topBox.Add(wxStaticText(self, -1, _("Layer: %s") % layer.Title()),          #topBox.Add(wxStaticText(panel, -1, _("Layer: %s") % layer.Title()),
597              #0, wxALIGN_LEFT | wxALL, 4)              #0, wxALIGN_LEFT | wxALL, 4)
598          topBox.Add(wxStaticText(self, -1,          topBox.Add(wxStaticText(panel, -1,
599                                  _("Layer Type: %s") % layer.ShapeType()),                                  _("Layer Type: %s") % layer.ShapeType()),
600              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
601    
# Line 602  class Classifier(NonModalDialog): Line 603  class Classifier(NonModalDialog):
603          #          #
604          # make field combo box          # make field combo box
605          #          #
606          self.fields = wxComboBox(self, ID_PROPERTY_SELECT, "",          self.fields = wxComboBox(panel, ID_PROPERTY_SELECT, "",
607                                       style = wxCB_READONLY)                                       style = wxCB_READONLY)
608    
609          self.num_cols = layer.table.field_count()          self.num_cols = layer.table.field_count()
# Line 623  class Classifier(NonModalDialog): Line 624  class Classifier(NonModalDialog):
624              else:              else:
625                  self.fields.SetClientData(i + 1, None)                  self.fields.SetClientData(i + 1, None)
626    
         self.fields.SetSelection(self.__cur_field)  
   
         #  
         #  
         #  
627    
628          self.fieldTypeText = wxStaticText(self, -1, "")          ###########
         self.__SetFieldTypeText(self.__cur_field)  
629    
630          topBox.Add(self.fieldTypeText, 0, wxALIGN_LEFT | wxALL, 4)          self.fieldTypeText = wxStaticText(panel, -1, "")
631          #self.fieldTypeText.SetLabel("asdfadsfs")          topBox.Add(self.fieldTypeText, 0, wxGROW | wxALIGN_LEFT | wxALL, 4)
632    
633          propertyBox = wxBoxSizer(wxHORIZONTAL)          propertyBox = wxBoxSizer(wxHORIZONTAL)
634          propertyBox.Add(wxStaticText(self, -1, _("Field: ")),          propertyBox.Add(wxStaticText(panel, -1, _("Field: ")),
635              0, wxALIGN_CENTER | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
636          propertyBox.Add(self.fields, 1, wxGROW|wxALL, 4)          propertyBox.Add(self.fields, 1, wxGROW|wxALL, 4)
637          EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect)          EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect)
638    
639          topBox.Add(propertyBox, 0, wxGROW, 4)          topBox.Add(propertyBox, 0, wxGROW, 4)
640    
641            ###########
642          #          #
643          # Classification data table          # Classification data table
644          #          #
# Line 654  class Classifier(NonModalDialog): Line 650  class Classifier(NonModalDialog):
650    
651          controlBox.Add(self.classGrid, 1, wxGROW, 0)          controlBox.Add(self.classGrid, 1, wxGROW, 0)
652    
653          controlButtonBox = wxBoxSizer(wxVERTICAL)          ###########
   
654          #          #
655          # Control buttons:          # Control buttons:
656          #          #
657          self.controlButtons = []          self.controlButtons = []
658    
659          button = wxButton(self, ID_CLASSIFY_ADD, _("Add"))          controlButtonBox = wxBoxSizer(wxVERTICAL)
660    
661            button = wxButton(panel, ID_CLASSIFY_ADD, _("Add"))
662          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
663          self.controlButtons.append(button)          self.controlButtons.append(button)
664    
665          #button = wxButton(self, ID_CLASSIFY_GENRANGE, _("Generate Ranges"))          #button = wxButton(panel, ID_CLASSIFY_GENRANGE, _("Generate Ranges"))
666          #controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          #controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
667          #self.controlButtons.append(button)          #self.controlButtons.append(button)
668    
669          button = wxButton(self, ID_CLASSIFY_MOVEUP, _("Move Up"))          button = wxButton(panel, ID_CLASSIFY_MOVEUP, _("Move Up"))
670          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
671          self.controlButtons.append(button)          self.controlButtons.append(button)
672    
673          button = wxButton(self, ID_CLASSIFY_MOVEDOWN, _("Move Down"))          button = wxButton(panel, ID_CLASSIFY_MOVEDOWN, _("Move Down"))
674          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
675          self.controlButtons.append(button)          self.controlButtons.append(button)
676    
677          controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)          controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)
678    
679          button = wxButton(self, ID_CLASSIFY_REMOVE, _("Remove"))          button = wxButton(panel, ID_CLASSIFY_REMOVE, _("Remove"))
680          controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)
681          self.controlButtons.append(button)          self.controlButtons.append(button)
682    
683          controlBox.Add(controlButtonBox, 0, wxGROW, 10)          controlBox.Add(controlButtonBox, 0, wxGROW, 10)
684          topBox.Add(controlBox, 1, wxGROW, 10)          topBox.Add(controlBox, 0, wxGROW, 10)
685    
686          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)
687          EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove)          EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove)
# Line 692  class Classifier(NonModalDialog): Line 689  class Classifier(NonModalDialog):
689          EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp)          EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp)
690          EVT_BUTTON(self, ID_CLASSIFY_MOVEDOWN, self._OnMoveDown)          EVT_BUTTON(self, ID_CLASSIFY_MOVEDOWN, self._OnMoveDown)
691    
692            ###########
693    
694          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
695          buttonBox.Add(wxButton(self, ID_CLASSIFY_OK, _("OK")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_OK, _("OK")),
696                        0, wxALL, 4)                        0, wxALL, 4)
697          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
698          buttonBox.Add(wxButton(self, ID_CLASSIFY_APPLY, _("Apply")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_APPLY, _("Apply")),
699                        0, wxALL, 4)                        0, wxALL, 4)
700          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
701          buttonBox.Add(wxButton(self, ID_CLASSIFY_CANCEL, _("Cancel")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CANCEL, _("Cancel")),
702                        0, wxALL, 4)                        0, wxALL, 4)
703          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 10)          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)
704    
705          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)
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.SetAutoLayout(true)          ###########
710          self.SetSizer(topBox)  
711          topBox.Fit(self)          self.fields.SetSelection(self.__cur_field)
712          topBox.SetSizeHints(self)          self.__SelectField(self.__cur_field)
713    
714            panel.SetAutoLayout(True)
715            panel.SetSizer(topBox)
716    
717            topBox.SetSizeHints(panel)
718            topBox.Fit(panel)
719    
720            self.SetAutoLayout(True)
721            self.Fit()
722    
723    
724      def __BuildClassification(self, fieldIndex):      def __BuildClassification(self, fieldIndex):
725    
726            numRows = self.classGrid.GetNumberRows()
727            assert(numRows > 0) # there should always be a default row
728    
729          clazz = Classification()          clazz = Classification()
730          fieldName = self.fields.GetString(fieldIndex)          if fieldIndex == 0:
731          fieldType = self.layer.GetFieldType(fieldName)              fieldName = None
732                fieldType = None
733            else:
734                fieldName = self.fields.GetString(fieldIndex)
735                fieldType = self.layer.GetFieldType(fieldName)
736    
737          clazz.SetField(fieldName)          clazz.SetField(fieldName)
738          clazz.SetFieldType(fieldType)          clazz.SetFieldType(fieldType)
739    
         numRows = self.classGrid.GetNumberRows()  
   
         assert(numRows > 0) # there should always be a default row  
740    
741          table = self.classGrid.GetTable()          table = self.classGrid.GetTable()
742          clazz.SetDefaultGroup(table.GetClassGroup(0))          clazz.SetDefaultGroup(table.GetClassGroup(0))
# Line 751  class Classifier(NonModalDialog): Line 763  class Classifier(NonModalDialog):
763                                    
764          self.classGrid.CreateTable(clazz, self.layer.ShapeType())          self.classGrid.CreateTable(clazz, self.layer.ShapeType())
765    
766    
767    
768        type2string = {None:             _("None"),
769                       FIELDTYPE_STRING: _("Text"),
770                       FIELDTYPE_INT:    _("Integer"),
771                       FIELDTYPE_DOUBLE: _("Decimal")}
772    
773      def __SetFieldTypeText(self, fieldIndex):      def __SetFieldTypeText(self, fieldIndex):
774          fieldName = self.fields.GetString(fieldIndex)          fieldName = self.fields.GetString(fieldIndex)
775          fieldType = self.layer.GetFieldType(fieldName)          fieldType = self.layer.GetFieldType(fieldName)
776    
777          if fieldType is None:          assert(Classifier.type2string.has_key(fieldType))
778              text = "None"  
779          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"  
780    
781          self.fieldTypeText.SetLabel(_("Field Type: %s") % text)          self.fieldTypeText.SetLabel(_("Field Type: %s") % text)
782    
783      def _OnFieldSelect(self, event):      def __SelectField(self, newIndex, oldIndex = -1):
         clazz = self.__BuildClassification(self.__cur_field)  
         self.fields.SetClientData(self.__cur_field, clazz)  
784    
785          self.__cur_field = self.fields.GetSelection()          assert(oldIndex >= -1)
786          self.__SetGridTable(self.__cur_field)  
787            if oldIndex != -1:
788                clazz = self.__BuildClassification(oldIndex)
789                self.fields.SetClientData(oldIndex, clazz)
790    
791            self.__SetGridTable(newIndex)
792    
793          enabled = self.__cur_field != 0          enabled = newIndex != 0
794    
795          for b in self.controlButtons:          for b in self.controlButtons:
796              b.Enable(enabled)              b.Enable(enabled)
797    
798          self.__SetFieldTypeText(self.__cur_field)          self.__SetFieldTypeText(newIndex)
799    
800    
801        def _OnFieldSelect(self, event):
802            index = self.fields.GetSelection()
803            self.__SelectField(index, self.__cur_field)
804            self.__cur_field = index
805    
806      def _OnApply(self, event):      def _OnApply(self, event):
807          """Put the data from the table into a new Classification and hand          """Put the data from the table into a new Classification and hand
# Line 860  class SelectPropertiesDialog(wxDialog): Line 879  class SelectPropertiesDialog(wxDialog):
879    
880      def __init__(self, parent, prop, shapeType):      def __init__(self, parent, prop, shapeType):
881          wxDialog.__init__(self, parent, -1, _("Select Properties"),          wxDialog.__init__(self, parent, -1, _("Select Properties"),
882                            style = wxRESIZE_BORDER)                            style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
883    
884          self.prop = ClassGroupProperties(prop)          self.prop = ClassGroupProperties(prop)
885    
# Line 883  class SelectPropertiesDialog(wxDialog): Line 902  class SelectPropertiesDialog(wxDialog):
902    
903          lineColorBox = wxBoxSizer(wxHORIZONTAL)          lineColorBox = wxBoxSizer(wxHORIZONTAL)
904          lineColorBox.Add(          lineColorBox.Add(
905              wxButton(self, ID_SELPROP_STROKECLR, "Change Line Color"),              wxButton(self, ID_SELPROP_STROKECLR, _("Change Line Color")),
906              1, wxALL | wxGROW, 4)              1, wxALL | wxGROW, 4)
907          EVT_BUTTON(self, ID_SELPROP_STROKECLR, self._OnChangeLineColor)          EVT_BUTTON(self, ID_SELPROP_STROKECLR, self._OnChangeLineColor)
908    
909          lineColorBox.Add(          lineColorBox.Add(
910              wxButton(self, ID_SELPROP_STROKECLRTRANS, "Transparent"),              wxButton(self, ID_SELPROP_STROKECLRTRANS, _("Transparent")),
911              1, wxALL | wxGROW, 4)              1, wxALL | wxGROW, 4)
912          EVT_BUTTON(self, ID_SELPROP_STROKECLRTRANS,          EVT_BUTTON(self, ID_SELPROP_STROKECLRTRANS,
913                     self._OnChangeLineColorTrans)                     self._OnChangeLineColorTrans)
# Line 899  class SelectPropertiesDialog(wxDialog): Line 918  class SelectPropertiesDialog(wxDialog):
918          if shapeType != SHAPETYPE_ARC:          if shapeType != SHAPETYPE_ARC:
919              fillColorBox = wxBoxSizer(wxHORIZONTAL)              fillColorBox = wxBoxSizer(wxHORIZONTAL)
920              fillColorBox.Add(              fillColorBox.Add(
921                  wxButton(self, ID_SELPROP_FILLCLR, "Change Fill Color"),                  wxButton(self, ID_SELPROP_FILLCLR, _("Change Fill Color")),
922                  1, wxALL | wxGROW, 4)                  1, wxALL | wxGROW, 4)
923              EVT_BUTTON(self, ID_SELPROP_FILLCLR, self._OnChangeFillColor)              EVT_BUTTON(self, ID_SELPROP_FILLCLR, self._OnChangeFillColor)
924              fillColorBox.Add(              fillColorBox.Add(
925                  wxButton(self, ID_SELPROP_FILLCLRTRANS, "Transparent"),                  wxButton(self, ID_SELPROP_FILLCLRTRANS, _("Transparent")),
926                  1, wxALL | wxGROW, 4)                  1, wxALL | wxGROW, 4)
927              EVT_BUTTON(self, ID_SELPROP_FILLCLRTRANS,              EVT_BUTTON(self, ID_SELPROP_FILLCLRTRANS,
928                         self._OnChangeFillColorTrans)                         self._OnChangeFillColorTrans)
# Line 939  class SelectPropertiesDialog(wxDialog): Line 958  class SelectPropertiesDialog(wxDialog):
958          EVT_BUTTON(self, ID_SELPROP_OK, self._OnOK)          EVT_BUTTON(self, ID_SELPROP_OK, self._OnOK)
959          EVT_BUTTON(self, ID_SELPROP_CANCEL, self._OnCancel)          EVT_BUTTON(self, ID_SELPROP_CANCEL, self._OnCancel)
960                                                                                                                                                                    
961          self.SetAutoLayout(true)          self.SetAutoLayout(True)
962          self.SetSizer(topBox)          self.SetSizer(topBox)
963          topBox.Fit(self)          topBox.Fit(self)
964          topBox.SetSizeHints(self)          topBox.SetSizeHints(self)

Legend:
Removed from v.489  
changed lines
  Added in v.509

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26