/[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 638 by jonathan, Thu Apr 10 14:35:20 2003 UTC revision 650 by jonathan, Fri Apr 11 14:27:41 2003 UTC
# Line 31  from Thuban.UI.classgen import ClassGenD Line 31  from Thuban.UI.classgen import ClassGenD
31    
32  from dialogs import NonModalDialog  from dialogs import NonModalDialog
33    
 # widget id's  
 ID_PROPERTY_SELECT = 4010  
34  ID_CLASS_TABLE = 40011  ID_CLASS_TABLE = 40011
35    
36    
# Line 87  class ClassGrid(wxGrid): Line 85  class ClassGrid(wxGrid):
85    
86          table = self.GetTable()          table = self.GetTable()
87          if table is None:          if table is None:
88              w = self.GetDefaultColSize() * 3 + self.GetDefaultRowLabelSize()              w = self.GetDefaultColSize() * NUM_COLS \
89              h = self.GetDefaultRowSize() * 4 + self.GetDefaultColLabelSize()                  + self.GetDefaultRowLabelSize()
90                h = self.GetDefaultRowSize() * 4 \
91                    + self.GetDefaultColLabelSize()
92    
93              self.SetDimensions(-1, -1, w, h)              self.SetDimensions(-1, -1, w, h)
94              self.SetSizeHints(w, h, -1, -1)              self.SetSizeHints(w, h, -1, -1)
95              table = ClassTable(self)              table = ClassTable(self)
# Line 515  class ClassTable(wxPyGridTableBase): Line 516  class ClassTable(wxPyGridTableBase):
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()
# Line 649  class ClassTable(wxPyGridTableBase): Line 650  class ClassTable(wxPyGridTableBase):
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_REVERT = 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_TRY = 4008  ID_PROPERTY_TRY = 4008
661  ID_CLASSIFY_EDITSYM = 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
# Line 667  BTN_UP = 3 Line 671  BTN_UP = 3
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"),
# Line 675  class Classifier(NonModalDialog): Line 683  class Classifier(NonModalDialog):
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    
# Line 689  class Classifier(NonModalDialog): Line 696  class Classifier(NonModalDialog):
696          self.genDlg = None          self.genDlg = None
697    
698          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
         panelBox = wxBoxSizer(wxVERTICAL)  
699    
700          #panelBox.Add(wxStaticText(panel, -1, _("Layer: %s") % layer.Title()),          sizer = wxBoxSizer(wxHORIZONTAL)
701              #0, wxALIGN_LEFT | wxALL, 4)          sizer.Add(wxStaticText(self, -1, _("Title: ")),
702          panelBox.Add(wxStaticText(panel, -1,              0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 4)
703                                  _("Layer Type: %s") % layer.ShapeType()),          sizer.Add(wxTextCtrl(self, ID_PROPERTY_TITLE, layer.Title()),
704                      1, wxGROW | wxALL, 4)
705            EVT_TEXT(self, ID_PROPERTY_TITLE, self._OnTitleChanged)
706    
707            topBox.Add(sizer, 0, wxGROW, 4)
708    
709            topBox.Add(wxStaticText(self, -1,
710                                    _("Type: %s") % layer.ShapeType()),
711              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
712    
713            panel = wxPanel(self, -1, size=(100, 100))
714    
715            #####################
716    
717            #panelBox = wxBoxSizer(wxVERTICAL)
718            panelBox = wxStaticBoxSizer(
719                        wxStaticBox(panel, -1, _("Classification")), wxVERTICAL)
720    
721    
722          #          #
723          # make field combo box          # make field combo box
# Line 710  class Classifier(NonModalDialog): Line 731  class Classifier(NonModalDialog):
731          self.__cur_field = 0          self.__cur_field = 0
732    
733          self.fields.Append("<None>")          self.fields.Append("<None>")
734          self.fields.SetClientData(0, None)  
735            if self.originalClass.GetFieldType() is None:
736                self.fields.SetClientData(0, copy.deepcopy(self.originalClass))
737            else:
738                self.fields.SetClientData(0, None)
739    
740          for i in range(self.num_cols):          for i in range(self.num_cols):
741              type, name, len, decc = layer.table.field_info(i)              type, name, len, decc = layer.table.field_info(i)
# Line 726  class Classifier(NonModalDialog): Line 751  class Classifier(NonModalDialog):
751    
752          ###########          ###########
753    
         self.fieldTypeText = wxStaticText(panel, -1, "")  
         panelBox.Add(self.fieldTypeText, 0,  
                      wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4)  
754    
755          propertyBox = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
756          propertyBox.Add(wxStaticText(panel, -1, _("Field: ")),          sizer.Add(wxStaticText(panel, ID_PROPERTY_FIELDTEXT, _("Field: ")),
757              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 4)
758          propertyBox.Add(self.fields, 1, wxGROW|wxALL, 4)          sizer.Add(self.fields, 1, wxGROW | wxALL, 4)
759          EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect)          EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect)
760    
761          panelBox.Add(propertyBox, 0, wxGROW, 4)          panelBox.Add(sizer, 0, wxGROW, 4)
762    
763            self.fieldTypeText = wxStaticText(panel, -1, "")
764            panelBox.Add(self.fieldTypeText, 0,
765                         wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4)
766    
767    
768          #          #
# Line 749  class Classifier(NonModalDialog): Line 775  class Classifier(NonModalDialog):
775          #          #
776          # Control buttons:          # Control buttons:
777          #          #
         self.controlButtons = []  
   
778          controlButtonBox = wxBoxSizer(wxVERTICAL)          controlButtonBox = wxBoxSizer(wxVERTICAL)
779    
780          button = wxButton(panel, ID_CLASSIFY_GENCLASS, _("Generate Class"))          button = wxButton(panel, ID_PROPERTY_GENCLASS, _("Generate Class"))
781          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
782    
783          button = wxButton(panel, ID_CLASSIFY_ADD, _("Add"))          button = wxButton(panel, ID_PROPERTY_ADD, _("Add"))
784          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
785    
786          button = wxButton(panel, ID_CLASSIFY_MOVEUP, _("Move Up"))          button = wxButton(panel, ID_PROPERTY_MOVEUP, _("Move Up"))
787          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
788    
789          button = wxButton(panel, ID_CLASSIFY_MOVEDOWN, _("Move Down"))          button = wxButton(panel, ID_PROPERTY_MOVEDOWN, _("Move Down"))
790          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
791    
792          button = wxButton(panel, ID_CLASSIFY_EDITSYM, _("Edit Symbol"))          button = wxButton(panel, ID_PROPERTY_EDITSYM, _("Edit Symbol"))
793          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
794    
795          controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)          controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)
796    
797          button = wxButton(panel, ID_CLASSIFY_REMOVE, _("Remove"))          button = wxButton(panel, ID_PROPERTY_REMOVE, _("Remove"))
798          controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)
         self.controlButtons.append(button)  
799    
800    
801          ###########          ###########
# Line 786  class Classifier(NonModalDialog): Line 804  class Classifier(NonModalDialog):
804          #          #
805    
806          self.classGrid = ClassGrid(panel, self)          self.classGrid = ClassGrid(panel, self)
 #       self.classGrid = wxGrid(panel, -1)  
 #       self.classGrid.SetDefaultRenderer(wxGridCellBoolRenderer())  
 #       self.classGrid.SetDefaultEditor(wxGridCellBoolEditor())  
         #self.classGrid.CreateGrid(5, 5)  
         #self.classGrid.SetCellEditor(0, 0, wxGridCellBoolEditor())  
         #self.classGrid.SetCellRenderer(0, 0, wxGridCellBoolRenderer())  
         #print self.classGrid.GetCellEditor(0, 0)  
         #print self.classGrid.GetCellRenderer(0, 0)  
         #self.classGrid = ClassGrid(panel, self)  
   
         # need these  
         self.__SetGridTable(self.__cur_field, group)  
         self.fields.SetSelection(self.__cur_field)  
         #self.classGrid.SetCellEditor(0, 0, wxGridCellBoolEditor())  
         #self.classGrid.SetCellRenderer(0, 0, wxGridCellBoolRenderer())  
807    
808          # calling __SelectField after creating the classGrid fills in the          # calling __SelectField after creating the classGrid fills in the
809          # grid with the correct information          # grid with the correct information
810          #self.fields.SetSelection(self.__cur_field)          self.fields.SetSelection(self.__cur_field)
811          #self.__SelectField(self.__cur_field, group = group)          self.__SelectField(self.__cur_field, group = group)
   
         #self.classGrid.SelectGroup(group)  
812    
813          controlBox.Add(self.classGrid, 1, wxGROW, 0)          controlBox.Add(self.classGrid, 1, wxGROW, 0)
814    
   
   
815          controlBox.Add(controlButtonBox, 0, wxGROW, 10)          controlBox.Add(controlButtonBox, 0, wxGROW, 10)
816          panelBox.Add(controlBox, 1, wxGROW, 10)          panelBox.Add(controlBox, 1, wxGROW, 10)
817    
818          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)          EVT_BUTTON(self, ID_PROPERTY_ADD, self._OnAdd)
819          EVT_BUTTON(self, ID_CLASSIFY_EDITSYM, self._OnEditSymbol)          EVT_BUTTON(self, ID_PROPERTY_EDITSYM, self._OnEditSymbol)
820          EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove)          EVT_BUTTON(self, ID_PROPERTY_REMOVE, self._OnRemove)
821          EVT_BUTTON(self, ID_CLASSIFY_GENCLASS, self._OnGenClass)          EVT_BUTTON(self, ID_PROPERTY_GENCLASS, self._OnGenClass)
822          EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp)          EVT_BUTTON(self, ID_PROPERTY_MOVEUP, self._OnMoveUp)
823          EVT_BUTTON(self, ID_CLASSIFY_MOVEDOWN, self._OnMoveDown)          EVT_BUTTON(self, ID_PROPERTY_MOVEDOWN, self._OnMoveDown)
824    
825            ###########
826    
827            panel.SetAutoLayout(True)
828            panel.SetSizer(panelBox)
829            panelBox.SetSizeHints(panel)
830    
831            topBox.Add(panel, 1, wxGROW | wxALL, 4)
832    
833          ###########          ###########
834    
835          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
836          buttonBox.Add(wxButton(panel, ID_CLASSIFY_TRY, _("Try")),          buttonBox.Add(wxButton(self, ID_PROPERTY_TRY, _("Try")),
837                        0, wxALL, 4)                        0, wxALL, 4)
838          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
839          buttonBox.Add(wxButton(panel, ID_CLASSIFY_REVERT, _("Revert")),          buttonBox.Add(wxButton(self, ID_PROPERTY_REVERT, _("Revert")),
840                        0, wxALL, 4)                        0, wxALL, 4)
841          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
842          buttonBox.Add(wxButton(panel, ID_CLASSIFY_OK, _("OK")),          buttonBox.Add(wxButton(self, ID_PROPERTY_OK, _("OK")),
843                        0, wxALL, 4)                        0, wxALL, 4)
844          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
845          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CLOSE, _("Close")),          buttonBox.Add(wxButton(self, ID_PROPERTY_CLOSE, _("Close")),
846                        0, wxALL, 4)                        0, wxALL, 4)
847          panelBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)
848    
849          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)          EVT_BUTTON(self, ID_PROPERTY_OK, self._OnOK)
850          EVT_BUTTON(self, ID_CLASSIFY_TRY, self._OnTry)          EVT_BUTTON(self, ID_PROPERTY_TRY, self._OnTry)
851          EVT_BUTTON(self, ID_CLASSIFY_CLOSE, self._OnCloseBtn)          EVT_BUTTON(self, ID_PROPERTY_CLOSE, self._OnCloseBtn)
852          EVT_BUTTON(self, ID_CLASSIFY_REVERT, self._OnRevert)          EVT_BUTTON(self, ID_PROPERTY_REVERT, self._OnRevert)
853    
854          ###########          ###########
855    
856            topBox.SetSizeHints(self)
         panel.SetAutoLayout(True)  
         panel.SetSizer(panelBox)  
         panelBox.SetSizeHints(panel)  
   
         topBox.Add(panel, 1, wxGROW, 0)  
         panelBox.SetSizeHints(self)  
857          self.SetAutoLayout(True)          self.SetAutoLayout(True)
858          self.SetSizer(topBox)          self.SetSizer(topBox)
859    
# Line 936  class Classifier(NonModalDialog): Line 937  class Classifier(NonModalDialog):
937    
938          text = Classifier.type2string[fieldType]          text = Classifier.type2string[fieldType]
939    
940          self.fieldTypeText.SetLabel(_("Field Type: %s") % text)          self.fieldTypeText.SetLabel(_("Data Type: %s") % text)
941    
942      def __SelectField(self, newIndex, oldIndex = -1, group = None):      def __SelectField(self, newIndex, oldIndex = -1, group = None):
943          """This method assumes that the current selection for the          """This method assumes that the current selection for the
# Line 951  class Classifier(NonModalDialog): Line 952  class Classifier(NonModalDialog):
952    
953          self.__SetGridTable(newIndex, group)          self.__SetGridTable(newIndex, group)
954    
955          enabled = newIndex != 0          self.__EnableButtons(EB_SELECT_FIELD, newIndex != 0)
   
         for b in self.controlButtons:  
             b.Enable(enabled)  
956    
957          self.__SetFieldTypeText(newIndex)          self.__SetFieldTypeText(newIndex)
958    
959        def __SetTitle(self, title):
960            if title != "":
961                title = ": " + title
962    
963            self.SetTitle(_("Layer Properties") + title)
964    
965      def _OnEditSymbol(self, event):      def _OnEditSymbol(self, event):
966          sel = self.classGrid.GetCurrentSelection()          sel = self.classGrid.GetCurrentSelection()
# Line 1015  class Classifier(NonModalDialog): Line 1018  class Classifier(NonModalDialog):
1018    
1019      def _OnGenClass(self, event):      def _OnGenClass(self, event):
1020    
         #if self.genDlg is None:  
1021          self.genDlg = ClassGenDialog(self, self.layer,          self.genDlg = ClassGenDialog(self, self.layer,
1022                            self.fields.GetString(self.__cur_field))                            self.fields.GetString(self.__cur_field))
1023    
1024          EVT_CLOSE(self.genDlg, self._OnGenDialogClose)          EVT_CLOSE(self.genDlg, self._OnGenDialogClose)
1025    
1026          self.fields.Enable(False)          self.__EnableButtons(EB_GEN_CLASS, False)
         self.controlButtons[BTN_EDIT].Enable(False)  
         self.controlButtons[BTN_GEN].Enable(False)  
1027    
1028          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()  
1029    
1030      def _OnGenDialogClose(self, event):      def _OnGenDialogClose(self, event):
1031          self.genDlg.Destroy()          self.genDlg.Destroy()
1032            self.__EnableButtons(EB_GEN_CLASS, True)
         self.fields.Enable(True)  
         self.controlButtons[BTN_EDIT].Enable(True)  
         self.controlButtons[BTN_GEN].Enable(True)  
1033    
1034      def _OnMoveUp(self, event):      def _OnMoveUp(self, event):
1035          sel = self.classGrid.GetCurrentSelection()          sel = self.classGrid.GetCurrentSelection()
# Line 1070  class Classifier(NonModalDialog): Line 1061  class Classifier(NonModalDialog):
1061                  self.classGrid.SelectRow(i + 1)                  self.classGrid.SelectRow(i + 1)
1062                  self.classGrid.MakeCellVisible(i + 1, 0)                  self.classGrid.MakeCellVisible(i + 1, 0)
1063    
1064        def _OnTitleChanged(self, event):
1065            obj = event.GetEventObject()
1066    
1067            self.layer.SetTitle(obj.GetValue())
1068            self.__SetTitle(self.layer.Title())
1069    
1070            self.__EnableButtons(EB_LAYER_TITLE, self.layer.Title() != "")
1071    
1072        def __EnableButtons(self, case, enable):
1073    
1074            if case == EB_LAYER_TITLE:  
1075                list = (ID_PROPERTY_OK,
1076                        ID_PROPERTY_CLOSE)
1077    
1078            elif case == EB_SELECT_FIELD:
1079                list = (ID_PROPERTY_GENCLASS,
1080                        ID_PROPERTY_ADD,
1081                        ID_PROPERTY_MOVEUP,
1082                        ID_PROPERTY_MOVEDOWN,
1083                        ID_PROPERTY_EDITSYM,
1084                        ID_PROPERTY_REMOVE)
1085    
1086            elif case == EB_GEN_CLASS:
1087                list = (ID_PROPERTY_SELECT,
1088                        ID_PROPERTY_FIELDTEXT,
1089                        ID_PROPERTY_GENCLASS,
1090                        ID_PROPERTY_EDITSYM)
1091    
1092            for id in list:
1093                self.FindWindowById(id).Enable(enable)
1094    
1095  ID_SELPROP_OK = 4001  ID_SELPROP_OK = 4001
1096  ID_SELPROP_CANCEL = 4002  ID_SELPROP_CANCEL = 4002

Legend:
Removed from v.638  
changed lines
  Added in v.650

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26