/[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 500 by jonathan, Mon Mar 10 15:11:24 2003 UTC revision 549 by jonathan, Thu Mar 20 09:45:07 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 89  class ClassGrid(wxGrid): Line 89  class ClassGrid(wxGrid):
89              h = self.GetDefaultRowSize() * 4 + self.GetDefaultColLabelSize()              h = self.GetDefaultRowSize() * 4 + self.GetDefaultColLabelSize()
90              self.SetDimensions(-1, -1, w, h)              self.SetDimensions(-1, -1, w, h)
91              self.SetSizeHints(w, h, -1, -1)              self.SetSizeHints(w, h, -1, -1)
92              self.SetTable(ClassTable(clazz, self.shapeType, self), true)              self.SetTable(ClassTable(clazz, self.shapeType, self), True)
93          else:          else:
94              table.Reset(clazz, self.shapeType)              table.Reset(clazz, self.shapeType)
95    
# Line 296  class ClassTable(wxPyGridTableBase): Line 296  class ClassTable(wxPyGridTableBase):
296                          wxGRIDTABLE_NOTIFY_ROWS_APPENDED,                          wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
297                          newRows - curRows)    # how many                          newRows - curRows)    # how many
298              self.GetView().ProcessTableMessage(msg)              self.GetView().ProcessTableMessage(msg)
299                self.GetView().FitInside()
300          elif newRows < curRows:          elif newRows < curRows:
301              msg = wxGridTableMessage(self,              msg = wxGridTableMessage(self,
302                          wxGRIDTABLE_NOTIFY_ROWS_DELETED,                          wxGRIDTABLE_NOTIFY_ROWS_DELETED,
303                          curRows - newRows,    # position                          curRows - newRows,    # position
304                          curRows - newRows)    # how many                          curRows - newRows)    # how many
305              self.GetView().ProcessTableMessage(msg)              self.GetView().ProcessTableMessage(msg)
306                self.GetView().FitInside()
307    
308      def __SetRow(self, row, group):      def __SetRow(self, row, group):
309          """Set a row's data to that of the group.          """Set a row's data to that of the group.
# Line 578  class ClassTable(wxPyGridTableBase): Line 580  class ClassTable(wxPyGridTableBase):
580    
581    
582  class Classifier(NonModalDialog):  class Classifier(NonModalDialog):
583        
584      def __init__(self, parent, interactor, name, layer):      def __init__(self, parent, name, layer):
585          NonModalDialog.__init__(self, parent, interactor, name,          NonModalDialog.__init__(self, parent, name,
586                                  _("Classifier: %s") % layer.Title())                                  _("Classifier: %s") % layer.Title())
587    
588            panel = wxPanel(self, -1, size=(100, 100))
589    
590          self.layer = layer          self.layer = layer
591    
592          self.originalClass = self.layer.GetClassification()          self.originalClass = self.layer.GetClassification()
# Line 590  class Classifier(NonModalDialog): Line 594  class Classifier(NonModalDialog):
594          fieldType = self.originalClass.GetFieldType()          fieldType = self.originalClass.GetFieldType()
595    
596          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
597            panelBox = wxBoxSizer(wxVERTICAL)
598    
599          #topBox.Add(wxStaticText(self, -1, _("Layer: %s") % layer.Title()),          #panelBox.Add(wxStaticText(panel, -1, _("Layer: %s") % layer.Title()),
600              #0, wxALIGN_LEFT | wxALL, 4)              #0, wxALIGN_LEFT | wxALL, 4)
601          topBox.Add(wxStaticText(self, -1,          panelBox.Add(wxStaticText(panel, -1,
602                                  _("Layer Type: %s") % layer.ShapeType()),                                  _("Layer Type: %s") % layer.ShapeType()),
603              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
604    
# Line 601  class Classifier(NonModalDialog): Line 606  class Classifier(NonModalDialog):
606          #          #
607          # make field combo box          # make field combo box
608          #          #
609          self.fields = wxComboBox(self, ID_PROPERTY_SELECT, "",          self.fields = wxComboBox(panel, ID_PROPERTY_SELECT, "",
610                                       style = wxCB_READONLY)                                       style = wxCB_READONLY)
611    
612          self.num_cols = layer.table.field_count()          self.num_cols = layer.table.field_count()
# Line 623  class Classifier(NonModalDialog): Line 628  class Classifier(NonModalDialog):
628                  self.fields.SetClientData(i + 1, None)                  self.fields.SetClientData(i + 1, None)
629    
630    
631          #          ###########
         #  
         #  
   
         self.fieldTypeText = wxStaticText(self, -1, "")  
         self.__SetFieldTypeText(self.__cur_field)  
632    
633          topBox.Add(self.fieldTypeText, 0, wxALIGN_LEFT | wxALL, 4)          self.fieldTypeText = wxStaticText(panel, -1, "")
634          #self.fieldTypeText.SetLabel("asdfadsfs")          panelBox.Add(self.fieldTypeText, 0, wxGROW | wxALIGN_LEFT | wxALL, 4)
635    
636          propertyBox = wxBoxSizer(wxHORIZONTAL)          propertyBox = wxBoxSizer(wxHORIZONTAL)
637          propertyBox.Add(wxStaticText(self, -1, _("Field: ")),          propertyBox.Add(wxStaticText(panel, -1, _("Field: ")),
638              0, wxALIGN_CENTER | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
639          propertyBox.Add(self.fields, 1, wxGROW|wxALL, 4)          propertyBox.Add(self.fields, 1, wxGROW|wxALL, 4)
640          EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect)          EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect)
641    
642          topBox.Add(propertyBox, 0, wxGROW, 4)          panelBox.Add(propertyBox, 0, wxGROW, 4)
643    
644            ###########
645          #          #
646          # Classification data table          # Classification data table
647          #          #
648    
649          controlBox = wxBoxSizer(wxHORIZONTAL)          controlBox = wxBoxSizer(wxHORIZONTAL)
650    
651          self.classGrid = ClassGrid(self)          self.classGrid = ClassGrid(panel)
652          self.__SetGridTable(self.__cur_field)          self.__SetGridTable(self.__cur_field)
653    
654          controlBox.Add(self.classGrid, 1, wxGROW, 0)          controlBox.Add(self.classGrid, 1, wxGROW, 0)
655    
656          controlButtonBox = wxBoxSizer(wxVERTICAL)          ###########
   
657          #          #
658          # Control buttons:          # Control buttons:
659          #          #
660          self.controlButtons = []          self.controlButtons = []
661    
662          button = wxButton(self, ID_CLASSIFY_ADD, _("Add"))          controlButtonBox = wxBoxSizer(wxVERTICAL)
663    
664            button = wxButton(panel, ID_CLASSIFY_ADD, _("Add"))
665          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
666          self.controlButtons.append(button)          self.controlButtons.append(button)
667    
668          #button = wxButton(self, ID_CLASSIFY_GENRANGE, _("Generate Ranges"))          #button = wxButton(panel, ID_CLASSIFY_GENRANGE, _("Generate Ranges"))
669          #controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          #controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
670          #self.controlButtons.append(button)          #self.controlButtons.append(button)
671    
672          button = wxButton(self, ID_CLASSIFY_MOVEUP, _("Move Up"))          button = wxButton(panel, ID_CLASSIFY_MOVEUP, _("Move Up"))
673          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
674          self.controlButtons.append(button)          self.controlButtons.append(button)
675    
676          button = wxButton(self, ID_CLASSIFY_MOVEDOWN, _("Move Down"))          button = wxButton(panel, ID_CLASSIFY_MOVEDOWN, _("Move Down"))
677          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
678          self.controlButtons.append(button)          self.controlButtons.append(button)
679    
680          controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)          controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)
681    
682          button = wxButton(self, ID_CLASSIFY_REMOVE, _("Remove"))          button = wxButton(panel, ID_CLASSIFY_REMOVE, _("Remove"))
683          controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)
684          self.controlButtons.append(button)          self.controlButtons.append(button)
685    
686          controlBox.Add(controlButtonBox, 0, wxGROW, 10)          controlBox.Add(controlButtonBox, 0, wxGROW, 10)
687          topBox.Add(controlBox, 1, wxGROW, 10)          panelBox.Add(controlBox, 1, wxGROW, 10)
688    
689          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)
690          EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove)          EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove)
# Line 690  class Classifier(NonModalDialog): Line 692  class Classifier(NonModalDialog):
692          EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp)          EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp)
693          EVT_BUTTON(self, ID_CLASSIFY_MOVEDOWN, self._OnMoveDown)          EVT_BUTTON(self, ID_CLASSIFY_MOVEDOWN, self._OnMoveDown)
694    
695            ###########
696    
697          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
698          buttonBox.Add(wxButton(self, ID_CLASSIFY_OK, _("OK")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_OK, _("OK")),
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_APPLY, _("Apply")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_APPLY, _("Apply")),
702                        0, wxALL, 4)                        0, wxALL, 4)
703          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
704          buttonBox.Add(wxButton(self, ID_CLASSIFY_CANCEL, _("Cancel")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CANCEL, _("Cancel")),
705                        0, wxALL, 4)                        0, wxALL, 4)
706          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 10)          panelBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)
707    
708          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)
709          EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply)          EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply)
710          EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel)          EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel)
711    
712            ###########
713    
714          self.fields.SetSelection(self.__cur_field)          self.fields.SetSelection(self.__cur_field)
715          self.__SelectField(self.__cur_field)          self.__SelectField(self.__cur_field)
716    
717          self.SetAutoLayout(true)          panel.SetAutoLayout(True)
718            panel.SetSizer(panelBox)
719            panelBox.SetSizeHints(panel)
720    
721            topBox.Add(panel, 1, wxGROW, 0)
722            panelBox.SetSizeHints(self)
723            self.SetAutoLayout(True)
724          self.SetSizer(topBox)          self.SetSizer(topBox)
         topBox.Fit(self)  
         topBox.SetSizeHints(self)  
725    
726            ######################
727    
728            self.haveApplied = False
729    
730      def __BuildClassification(self, fieldIndex):      def __BuildClassification(self, fieldIndex):
731    
# Line 812  class Classifier(NonModalDialog): Line 825  class Classifier(NonModalDialog):
825    
826          self.layer.SetClassification(clazz)          self.layer.SetClassification(clazz)
827    
828            self.haveApplied = True
829    
830      def _OnOK(self, event):      def _OnOK(self, event):
831          self._OnApply(event)          self._OnApply(event)
832          self.OnClose(event)          self.OnClose(event)
833    
834      def _OnCancel(self, event):      def _OnCancel(self, event):
835          """The layer's current classification stays the same."""          """The layer's current classification stays the same."""
836          self.layer.SetClassification(self.originalClass)          if self.haveApplied:
837                self.layer.SetClassification(self.originalClass)
838    
839          self.OnClose(event)          self.OnClose(event)
840    
841      def _OnAdd(self, event):      def _OnAdd(self, event):
# Line 872  class SelectPropertiesDialog(wxDialog): Line 889  class SelectPropertiesDialog(wxDialog):
889    
890      def __init__(self, parent, prop, shapeType):      def __init__(self, parent, prop, shapeType):
891          wxDialog.__init__(self, parent, -1, _("Select Properties"),          wxDialog.__init__(self, parent, -1, _("Select Properties"),
892                            style = wxRESIZE_BORDER)                            style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
893    
894          self.prop = ClassGroupProperties(prop)          self.prop = ClassGroupProperties(prop)
895    
# Line 884  class SelectPropertiesDialog(wxDialog): Line 901  class SelectPropertiesDialog(wxDialog):
901          previewBox = wxBoxSizer(wxVERTICAL)          previewBox = wxBoxSizer(wxVERTICAL)
902          previewBox.Add(wxStaticText(self, -1, _("Preview:")),          previewBox.Add(wxStaticText(self, -1, _("Preview:")),
903              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
904          self.previewer = ClassDataPreviewer(None, self.prop, shapeType,          self.previewWin = ClassDataPreviewWindow(None, self.prop, shapeType,
905                                              self, ID_SELPROP_PREVIEW, (40, 40))                                              self, ID_SELPROP_PREVIEW, (40, 40))
906          previewBox.Add(self.previewer, 1, wxGROW, 15)          previewBox.Add(self.previewWin, 1, wxGROW, 15)
907    
908          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)
909    
# Line 951  class SelectPropertiesDialog(wxDialog): Line 968  class SelectPropertiesDialog(wxDialog):
968          EVT_BUTTON(self, ID_SELPROP_OK, self._OnOK)          EVT_BUTTON(self, ID_SELPROP_OK, self._OnOK)
969          EVT_BUTTON(self, ID_SELPROP_CANCEL, self._OnCancel)          EVT_BUTTON(self, ID_SELPROP_CANCEL, self._OnCancel)
970                                                                                                                                                                    
971          self.SetAutoLayout(true)          self.SetAutoLayout(True)
972          self.SetSizer(topBox)          self.SetSizer(topBox)
973          topBox.Fit(self)          topBox.Fit(self)
974          topBox.SetSizeHints(self)          topBox.SetSizeHints(self)
# Line 964  class SelectPropertiesDialog(wxDialog): Line 981  class SelectPropertiesDialog(wxDialog):
981    
982      def _OnSpin(self, event):      def _OnSpin(self, event):
983          self.prop.SetLineWidth(self.spinCtrl.GetValue())          self.prop.SetLineWidth(self.spinCtrl.GetValue())
984          self.previewer.Refresh()          self.previewWin.Refresh()
985    
986      def __GetColor(self, cur):      def __GetColor(self, cur):
987          dialog = wxColourDialog(self)          dialog = wxColourDialog(self)
# Line 981  class SelectPropertiesDialog(wxDialog): Line 998  class SelectPropertiesDialog(wxDialog):
998          clr = self.__GetColor(self.prop.GetLineColor())          clr = self.__GetColor(self.prop.GetLineColor())
999          if clr is not None:          if clr is not None:
1000              self.prop.SetLineColor(clr)              self.prop.SetLineColor(clr)
1001          self.previewer.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1002    
1003      def _OnChangeLineColorTrans(self, event):      def _OnChangeLineColorTrans(self, event):
1004          self.prop.SetLineColor(Color.None)          self.prop.SetLineColor(Color.None)
1005          self.previewer.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1006                    
1007      def _OnChangeFillColor(self, event):      def _OnChangeFillColor(self, event):
1008          clr = self.__GetColor(self.prop.GetFill())          clr = self.__GetColor(self.prop.GetFill())
1009          if clr is not None:          if clr is not None:
1010              self.prop.SetFill(clr)              self.prop.SetFill(clr)
1011          self.previewer.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1012    
1013      def _OnChangeFillColorTrans(self, event):      def _OnChangeFillColorTrans(self, event):
1014          self.prop.SetFill(Color.None)          self.prop.SetFill(Color.None)
1015          self.previewer.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1016    
1017      def GetClassGroupProperties(self):      def GetClassGroupProperties(self):
1018          return self.prop          return self.prop
1019    
1020    
1021  class ClassDataPreviewer(wxWindow):  class ClassDataPreviewWindow(wxWindow):
1022    
1023      def __init__(self, rect, prop, shapeType,      def __init__(self, rect, prop, shapeType,
1024                         parent = None, id = -1, size = wxDefaultSize):                         parent = None, id = -1, size = wxDefaultSize):
1025          if parent is not None:          if parent is not None:
1026              wxWindow.__init__(self, parent, id, size=size)              wxWindow.__init__(self, parent, id, (0, 0), size)
1027              EVT_PAINT(self, self._OnPaint)              EVT_PAINT(self, self._OnPaint)
1028    
1029          self.rect = rect          self.rect = rect
1030    
1031          self.prop = prop          self.prop = prop
1032          self.shapeType = shapeType          self.shapeType = shapeType
1033            self.previewer = ClassDataPreviewer()
1034    
1035      def _OnPaint(self, event):      def _OnPaint(self, event):
1036          dc = wxPaintDC(self)          dc = wxPaintDC(self)
# Line 1019  class ClassDataPreviewer(wxWindow): Line 1038  class ClassDataPreviewer(wxWindow):
1038          # XXX: this doesn't seem to be having an effect:          # XXX: this doesn't seem to be having an effect:
1039          dc.DestroyClippingRegion()          dc.DestroyClippingRegion()
1040    
1041          self.Draw(dc, None)          if self.rect is None:
1042                w, h = self.GetSize()
1043                rect = wxRect(0, 0, w, h)
1044            else:
1045                rect = self.rect
1046    
1047            self.previewer.Draw(dc, rect, self.prop, self.shapeType)
1048    
1049    class ClassDataPreviewer:
1050    
1051      def Draw(self, dc, rect, prop = None, shapeType = None):      def Draw(self, dc, rect, prop, shapeType):
1052    
1053          if prop is None: prop = self.prop          assert(dc is not None)
1054          if shapeType is None: shapeType = self.shapeType          assert(isinstance(prop, ClassGroupProperties))
1055    
1056          if rect is None:          if rect is None:
1057              x = y = 0              x = 0
1058              w, h = self.GetClientSizeTuple()              y = 0
1059                w, h = dc.GetSize()
1060          else:          else:
1061              x = rect.GetX()              x = rect.GetX()
1062              y = rect.GetY()              y = rect.GetY()
# Line 1068  class ClassRenderer(wxPyGridCellRenderer Line 1096  class ClassRenderer(wxPyGridCellRenderer
1096    
1097      def __init__(self, shapeType):      def __init__(self, shapeType):
1098          wxPyGridCellRenderer.__init__(self)          wxPyGridCellRenderer.__init__(self)
1099          self.previewer = ClassDataPreviewer(None, None, shapeType)          self.shapeType = shapeType
1100            self.previewer = ClassDataPreviewer()
1101    
1102      def Draw(self, grid, attr, dc, rect, row, col, isSelected):      def Draw(self, grid, attr, dc, rect, row, col, isSelected):
1103          data = grid.GetTable().GetClassGroup(row)          data = grid.GetTable().GetClassGroup(row)
# Line 1081  class ClassRenderer(wxPyGridCellRenderer Line 1110  class ClassRenderer(wxPyGridCellRenderer
1110                           rect.GetWidth(), rect.GetHeight())                           rect.GetWidth(), rect.GetHeight())
1111    
1112          if not isinstance(data, ClassGroupMap):          if not isinstance(data, ClassGroupMap):
1113              self.previewer.Draw(dc, rect, data.GetProperties())              self.previewer.Draw(dc, rect, data.GetProperties(), self.shapeType)
1114    
1115          if isSelected:          if isSelected:
1116              dc.SetPen(wxPen(wxColour(0 * 255, 0 * 255, 0 * 255),              dc.SetPen(wxPen(wxColour(0 * 255, 0 * 255, 0 * 255),

Legend:
Removed from v.500  
changed lines
  Added in v.549

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26