/[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 576 by jonathan, Mon Mar 31 18:31:17 2003 UTC
# Line 59  FIELD_NAME = 2 Line 59  FIELD_NAME = 2
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    
# Line 70  class ClassGrid(wxGrid): Line 71  class ClassGrid(wxGrid):
71    
72          #wxGrid.__init__(self, parent, ID_CLASS_TABLE, size = (340, 160))          #wxGrid.__init__(self, parent, ID_CLASS_TABLE, size = (340, 160))
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    
96          self.shapeType = shapeType          self.shapeType = shapeType
97          table = self.GetTable()          table = self.GetTable()
98          if table is None:          if table is None:
99              self.SetTable(ClassTable(clazz, self.shapeType, self), true)              w = self.GetDefaultColSize() * 3 + self.GetDefaultRowLabelSize()
100          else:              h = self.GetDefaultRowSize() * 4 + self.GetDefaultColLabelSize()
101              table.Reset(clazz, self.shapeType)              self.SetDimensions(-1, -1, w, h)
102                self.SetSizeHints(w, h, -1, -1)
103                table = ClassTable(self)
104                self.SetTable(table, True)
105    
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    
# Line 165  class ClassGrid(wxGrid): Line 199  class ClassGrid(wxGrid):
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  #  #
# Line 204  class ClassGrid(wxGrid): Line 263  class ClassGrid(wxGrid):
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()
# Line 226  class ClassTable(wxPyGridTableBase): Line 289  class ClassTable(wxPyGridTableBase):
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
# Line 239  class ClassTable(wxPyGridTableBase): Line 304  class ClassTable(wxPyGridTableBase):
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
# Line 266  class ClassTable(wxPyGridTableBase): Line 331  class ClassTable(wxPyGridTableBase):
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          view = self.GetView()          if row > -1:
355          w = view.GetDefaultColSize() * 3 + view.GetDefaultRowLabelSize()              self.GetView().ClearSelection()
356          h = view.GetDefaultRowSize() * 4 + view.GetDefaultColLabelSize()              self.GetView().SelectRow(row)
357          view.SetDimensions(-1, -1, w, h)              self.GetView().MakeCellVisible(row, 0)
         view.SetSizeHints(w, h, -1, -1)  
358                            
359          self.GetView().EndBatch()          self.GetView().EndBatch()
360    
# Line 297  class ClassTable(wxPyGridTableBase): Line 368  class ClassTable(wxPyGridTableBase):
368                          wxGRIDTABLE_NOTIFY_ROWS_APPENDED,                          wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
369                          newRows - curRows)    # how many                          newRows - curRows)    # how many
370              self.GetView().ProcessTableMessage(msg)              self.GetView().ProcessTableMessage(msg)
371                self.GetView().FitInside()
372          elif newRows < curRows:          elif newRows < curRows:
373              msg = wxGridTableMessage(self,              msg = wxGridTableMessage(self,
374                          wxGRIDTABLE_NOTIFY_ROWS_DELETED,                          wxGRIDTABLE_NOTIFY_ROWS_DELETED,
375                          curRows - newRows,    # position                          curRows - newRows,    # position
376                          curRows - newRows)    # how many                          curRows - newRows)    # how many
377              self.GetView().ProcessTableMessage(msg)              self.GetView().ProcessTableMessage(msg)
378                self.GetView().FitInside()
379    
380      def __SetRow(self, row, group):      def __SetRow(self, row, group):
381          """Set a row's data to that of the group.          """Set a row's data to that of the group.
# Line 579  class ClassTable(wxPyGridTableBase): Line 652  class ClassTable(wxPyGridTableBase):
652    
653    
654  class Classifier(NonModalDialog):  class Classifier(NonModalDialog):
655        
656      def __init__(self, parent, interactor, name, layer):      def __init__(self, parent, name, layer, group = None):
657          NonModalDialog.__init__(self, parent, interactor, name,          NonModalDialog.__init__(self, parent, name,
658                                  _("Classifier: %s") % layer.Title())                                  _("Classifier: %s") % layer.Title())
659    
660            panel = wxPanel(self, -1, size=(100, 100))
661    
662          self.layer = layer          self.layer = layer
663    
664          self.originalClass = self.layer.GetClassification()          self.originalClass = self.layer.GetClassification()
# Line 591  class Classifier(NonModalDialog): Line 666  class Classifier(NonModalDialog):
666          fieldType = self.originalClass.GetFieldType()          fieldType = self.originalClass.GetFieldType()
667    
668          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
669            panelBox = wxBoxSizer(wxVERTICAL)
670    
671          #topBox.Add(wxStaticText(self, -1, _("Layer: %s") % layer.Title()),          #panelBox.Add(wxStaticText(panel, -1, _("Layer: %s") % layer.Title()),
672              #0, wxALIGN_LEFT | wxALL, 4)              #0, wxALIGN_LEFT | wxALL, 4)
673          topBox.Add(wxStaticText(self, -1,          panelBox.Add(wxStaticText(panel, -1,
674                                  _("Layer Type: %s") % layer.ShapeType()),                                  _("Layer Type: %s") % layer.ShapeType()),
675              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
676    
# Line 602  class Classifier(NonModalDialog): Line 678  class Classifier(NonModalDialog):
678          #          #
679          # make field combo box          # make field combo box
680          #          #
681          self.fields = wxComboBox(self, ID_PROPERTY_SELECT, "",          self.fields = wxComboBox(panel, ID_PROPERTY_SELECT, "",
682                                       style = wxCB_READONLY)                                       style = wxCB_READONLY)
683    
684          self.num_cols = layer.table.field_count()          self.num_cols = layer.table.field_count()
# Line 623  class Classifier(NonModalDialog): Line 699  class Classifier(NonModalDialog):
699              else:              else:
700                  self.fields.SetClientData(i + 1, None)                  self.fields.SetClientData(i + 1, None)
701    
         self.fields.SetSelection(self.__cur_field)  
   
         #  
         #  
         #  
702    
703          self.fieldTypeText = wxStaticText(self, -1, "")          ###########
         self.__SetFieldTypeText(self.__cur_field)  
704    
705          topBox.Add(self.fieldTypeText, 0, wxALIGN_LEFT | wxALL, 4)          self.fieldTypeText = wxStaticText(panel, -1, "")
706          #self.fieldTypeText.SetLabel("asdfadsfs")          panelBox.Add(self.fieldTypeText, 0,
707                         wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4)
708    
709          propertyBox = wxBoxSizer(wxHORIZONTAL)          propertyBox = wxBoxSizer(wxHORIZONTAL)
710          propertyBox.Add(wxStaticText(self, -1, _("Field: ")),          propertyBox.Add(wxStaticText(panel, -1, _("Field: ")),
711              0, wxALIGN_CENTER | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
712          propertyBox.Add(self.fields, 1, wxGROW|wxALL, 4)          propertyBox.Add(self.fields, 1, wxGROW|wxALL, 4)
713          EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect)          EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect)
714    
715          topBox.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(self)  
         self.__SetGridTable(self.__cur_field)  
   
         controlBox.Add(self.classGrid, 1, wxGROW, 0)  
   
         controlButtonBox = wxBoxSizer(wxVERTICAL)  
723    
724            ###########
725          #          #
726          # Control buttons:          # Control buttons:
727          #          #
728          self.controlButtons = []          self.controlButtons = []
729    
730          button = wxButton(self, ID_CLASSIFY_ADD, _("Add"))          controlButtonBox = wxBoxSizer(wxVERTICAL)
731    
732            button = wxButton(panel, ID_CLASSIFY_ADD, _("Add"))
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(self, 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(self, 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)
742          self.controlButtons.append(button)          self.controlButtons.append(button)
743    
744          button = wxButton(self, ID_CLASSIFY_MOVEDOWN, _("Move Down"))          button = wxButton(panel, ID_CLASSIFY_MOVEDOWN, _("Move Down"))
745          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
746          self.controlButtons.append(button)          self.controlButtons.append(button)
747    
748          controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)          controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)
749    
750          button = wxButton(self, ID_CLASSIFY_REMOVE, _("Remove"))          button = wxButton(panel, ID_CLASSIFY_REMOVE, _("Remove"))
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          topBox.Add(controlBox, 1, wxGROW, 10)          panelBox.Add(controlBox, 1, wxGROW, 10)
777    
778          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)
779          EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove)          EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove)
# Line 692  class Classifier(NonModalDialog): Line 781  class Classifier(NonModalDialog):
781          EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp)          EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp)
782          EVT_BUTTON(self, ID_CLASSIFY_MOVEDOWN, self._OnMoveDown)          EVT_BUTTON(self, ID_CLASSIFY_MOVEDOWN, self._OnMoveDown)
783    
784            ###########
785    
786          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
787          buttonBox.Add(wxButton(self, ID_CLASSIFY_OK, _("OK")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_OK, _("OK")),
788                        0, wxALL, 4)                        0, wxALL, 4)
789          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
790          buttonBox.Add(wxButton(self, ID_CLASSIFY_APPLY, _("Apply")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_APPLY, _("Apply")),
791                        0, wxALL, 4)                        0, wxALL, 4)
792          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
793          buttonBox.Add(wxButton(self, ID_CLASSIFY_CANCEL, _("Cancel")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CANCEL, _("Cancel")),
794                        0, wxALL, 4)                        0, wxALL, 4)
795          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 10)          panelBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)
796    
797          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)
798          EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply)          EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply)
799          EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel)          EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel)
800    
801          self.SetAutoLayout(true)          ###########
802    
803    
804            panel.SetAutoLayout(True)
805            panel.SetSizer(panelBox)
806            panelBox.SetSizeHints(panel)
807    
808            topBox.Add(panel, 1, wxGROW, 0)
809            panelBox.SetSizeHints(self)
810            self.SetAutoLayout(True)
811          self.SetSizer(topBox)          self.SetSizer(topBox)
         topBox.Fit(self)  
         topBox.SetSizeHints(self)  
812    
813            #print "1------------------"
814            #self.Fit()
815            ######################
816    
817            self.haveApplied = False
818    
819      def __BuildClassification(self, fieldIndex):      def __BuildClassification(self, fieldIndex):
820    
821            numRows = self.classGrid.GetNumberRows()
822            assert(numRows > 0) # there should always be a default row
823    
824          clazz = Classification()          clazz = Classification()
825          fieldName = self.fields.GetString(fieldIndex)          if fieldIndex == 0:
826          fieldType = self.layer.GetFieldType(fieldName)              fieldName = None
827                fieldType = None
828            else:
829                fieldName = self.fields.GetString(fieldIndex)
830                fieldType = self.layer.GetFieldType(fieldName)
831    
832          clazz.SetField(fieldName)          clazz.SetField(fieldName)
833          clazz.SetFieldType(fieldType)          clazz.SetFieldType(fieldType)
834    
         numRows = self.classGrid.GetNumberRows()  
   
         assert(numRows > 0) # there should always be a default row  
835    
836          table = self.classGrid.GetTable()          table = self.classGrid.GetTable()
837          clazz.SetDefaultGroup(table.GetClassGroup(0))          clazz.SetDefaultGroup(table.GetClassGroup(0))
# Line 734  class Classifier(NonModalDialog): Line 841  class Classifier(NonModalDialog):
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    
# Line 749  class Classifier(NonModalDialog): Line 856  class Classifier(NonModalDialog):
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    
865        type2string = {None:             _("None"),
866                       FIELDTYPE_STRING: _("Text"),
867                       FIELDTYPE_INT:    _("Integer"),
868                       FIELDTYPE_DOUBLE: _("Decimal")}
869    
870      def __SetFieldTypeText(self, fieldIndex):      def __SetFieldTypeText(self, fieldIndex):
871          fieldName = self.fields.GetString(fieldIndex)          fieldName = self.fields.GetString(fieldIndex)
872          fieldType = self.layer.GetFieldType(fieldName)          fieldType = self.layer.GetFieldType(fieldName)
873    
874          if fieldType is None:          assert(Classifier.type2string.has_key(fieldType))
875              text = "None"  
876          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"  
877    
878          self.fieldTypeText.SetLabel(_("Field Type: %s") % text)          self.fieldTypeText.SetLabel(_("Field Type: %s") % text)
879    
880      def _OnFieldSelect(self, event):      def __SelectField(self, newIndex, oldIndex = -1, group = None):
881          clazz = self.__BuildClassification(self.__cur_field)  
882          self.fields.SetClientData(self.__cur_field, clazz)          #print "3------------------"
883    
884            assert(oldIndex >= -1)
885    
886            self.fields.SetSelection(newIndex)
887    
888            if oldIndex != -1:
889                clazz = self.__BuildClassification(oldIndex)
890                self.fields.SetClientData(oldIndex, clazz)
891    
892          self.__cur_field = self.fields.GetSelection()          #print "4------------------"
893          self.__SetGridTable(self.__cur_field)          self.__SetGridTable(newIndex, group)
894            #print "5------------------"
895    
896          enabled = self.__cur_field != 0          enabled = newIndex != 0
897    
898          for b in self.controlButtons:          for b in self.controlButtons:
899              b.Enable(enabled)              b.Enable(enabled)
900    
901          self.__SetFieldTypeText(self.__cur_field)          self.__SetFieldTypeText(newIndex)
902    
903    
904        def _OnFieldSelect(self, event):
905            index = self.fields.GetSelection()
906            self.__SelectField(index, self.__cur_field)
907            self.__cur_field = index
908    
909      def _OnApply(self, event):      def _OnApply(self, event):
910          """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 800  class Classifier(NonModalDialog): Line 922  class Classifier(NonModalDialog):
922    
923          self.layer.SetClassification(clazz)          self.layer.SetClassification(clazz)
924    
925            self.haveApplied = True
926    
927      def _OnOK(self, event):      def _OnOK(self, event):
928          self._OnApply(event)          self._OnApply(event)
929          self.OnClose(event)          self.OnClose(event)
930    
931      def _OnCancel(self, event):      def _OnCancel(self, event):
932          """The layer's current classification stays the same."""          """The layer's current classification stays the same."""
933          self.layer.SetClassification(self.originalClass)          if self.haveApplied:
934                self.layer.SetClassification(self.originalClass)
935    
936          self.OnClose(event)          self.OnClose(event)
937    
938      def _OnAdd(self, event):      def _OnAdd(self, event):
# Line 821  class Classifier(NonModalDialog): Line 947  class Classifier(NonModalDialog):
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:
# Line 831  class Classifier(NonModalDialog): Line 959  class Classifier(NonModalDialog):
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()
# Line 845  class Classifier(NonModalDialog): Line 974  class Classifier(NonModalDialog):
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
# Line 860  class SelectPropertiesDialog(wxDialog): Line 990  class SelectPropertiesDialog(wxDialog):
990    
991      def __init__(self, parent, prop, shapeType):      def __init__(self, parent, prop, shapeType):
992          wxDialog.__init__(self, parent, -1, _("Select Properties"),          wxDialog.__init__(self, parent, -1, _("Select Properties"),
993                            style = wxRESIZE_BORDER)                            style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
994    
995          self.prop = ClassGroupProperties(prop)          self.prop = ClassGroupProperties(prop)
996    
# Line 872  class SelectPropertiesDialog(wxDialog): Line 1002  class SelectPropertiesDialog(wxDialog):
1002          previewBox = wxBoxSizer(wxVERTICAL)          previewBox = wxBoxSizer(wxVERTICAL)
1003          previewBox.Add(wxStaticText(self, -1, _("Preview:")),          previewBox.Add(wxStaticText(self, -1, _("Preview:")),
1004              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
1005          self.previewer = ClassDataPreviewer(None, self.prop, shapeType,          self.previewWin = ClassDataPreviewWindow(None, self.prop, shapeType,
1006                                              self, ID_SELPROP_PREVIEW, (40, 40))                                              self, ID_SELPROP_PREVIEW, (40, 40))
1007          previewBox.Add(self.previewer, 1, wxGROW, 15)          previewBox.Add(self.previewWin, 1, wxGROW, 15)
1008    
1009          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)
1010    
# Line 883  class SelectPropertiesDialog(wxDialog): Line 1013  class SelectPropertiesDialog(wxDialog):
1013    
1014          lineColorBox = wxBoxSizer(wxHORIZONTAL)          lineColorBox = wxBoxSizer(wxHORIZONTAL)
1015          lineColorBox.Add(          lineColorBox.Add(
1016              wxButton(self, ID_SELPROP_STROKECLR, "Change Line Color"),              wxButton(self, ID_SELPROP_STROKECLR, _("Change Line Color")),
1017              1, wxALL | wxGROW, 4)              1, wxALL | wxGROW, 4)
1018          EVT_BUTTON(self, ID_SELPROP_STROKECLR, self._OnChangeLineColor)          EVT_BUTTON(self, ID_SELPROP_STROKECLR, self._OnChangeLineColor)
1019    
1020          lineColorBox.Add(          lineColorBox.Add(
1021              wxButton(self, ID_SELPROP_STROKECLRTRANS, "Transparent"),              wxButton(self, ID_SELPROP_STROKECLRTRANS, _("Transparent")),
1022              1, wxALL | wxGROW, 4)              1, wxALL | wxGROW, 4)
1023          EVT_BUTTON(self, ID_SELPROP_STROKECLRTRANS,          EVT_BUTTON(self, ID_SELPROP_STROKECLRTRANS,
1024                     self._OnChangeLineColorTrans)                     self._OnChangeLineColorTrans)
# Line 899  class SelectPropertiesDialog(wxDialog): Line 1029  class SelectPropertiesDialog(wxDialog):
1029          if shapeType != SHAPETYPE_ARC:          if shapeType != SHAPETYPE_ARC:
1030              fillColorBox = wxBoxSizer(wxHORIZONTAL)              fillColorBox = wxBoxSizer(wxHORIZONTAL)
1031              fillColorBox.Add(              fillColorBox.Add(
1032                  wxButton(self, ID_SELPROP_FILLCLR, "Change Fill Color"),                  wxButton(self, ID_SELPROP_FILLCLR, _("Change Fill Color")),
1033                  1, wxALL | wxGROW, 4)                  1, wxALL | wxGROW, 4)
1034              EVT_BUTTON(self, ID_SELPROP_FILLCLR, self._OnChangeFillColor)              EVT_BUTTON(self, ID_SELPROP_FILLCLR, self._OnChangeFillColor)
1035              fillColorBox.Add(              fillColorBox.Add(
1036                  wxButton(self, ID_SELPROP_FILLCLRTRANS, "Transparent"),                  wxButton(self, ID_SELPROP_FILLCLRTRANS, _("Transparent")),
1037                  1, wxALL | wxGROW, 4)                  1, wxALL | wxGROW, 4)
1038              EVT_BUTTON(self, ID_SELPROP_FILLCLRTRANS,              EVT_BUTTON(self, ID_SELPROP_FILLCLRTRANS,
1039                         self._OnChangeFillColorTrans)                         self._OnChangeFillColorTrans)
# Line 939  class SelectPropertiesDialog(wxDialog): Line 1069  class SelectPropertiesDialog(wxDialog):
1069          EVT_BUTTON(self, ID_SELPROP_OK, self._OnOK)          EVT_BUTTON(self, ID_SELPROP_OK, self._OnOK)
1070          EVT_BUTTON(self, ID_SELPROP_CANCEL, self._OnCancel)          EVT_BUTTON(self, ID_SELPROP_CANCEL, self._OnCancel)
1071                                                                                                                                                                    
1072          self.SetAutoLayout(true)          self.SetAutoLayout(True)
1073          self.SetSizer(topBox)          self.SetSizer(topBox)
1074          topBox.Fit(self)          topBox.Fit(self)
1075          topBox.SetSizeHints(self)          topBox.SetSizeHints(self)
# Line 952  class SelectPropertiesDialog(wxDialog): Line 1082  class SelectPropertiesDialog(wxDialog):
1082    
1083      def _OnSpin(self, event):      def _OnSpin(self, event):
1084          self.prop.SetLineWidth(self.spinCtrl.GetValue())          self.prop.SetLineWidth(self.spinCtrl.GetValue())
1085          self.previewer.Refresh()          self.previewWin.Refresh()
1086    
1087      def __GetColor(self, cur):      def __GetColor(self, cur):
1088          dialog = wxColourDialog(self)          dialog = wxColourDialog(self)
# Line 969  class SelectPropertiesDialog(wxDialog): Line 1099  class SelectPropertiesDialog(wxDialog):
1099          clr = self.__GetColor(self.prop.GetLineColor())          clr = self.__GetColor(self.prop.GetLineColor())
1100          if clr is not None:          if clr is not None:
1101              self.prop.SetLineColor(clr)              self.prop.SetLineColor(clr)
1102          self.previewer.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1103    
1104      def _OnChangeLineColorTrans(self, event):      def _OnChangeLineColorTrans(self, event):
1105          self.prop.SetLineColor(Color.None)          self.prop.SetLineColor(Color.None)
1106          self.previewer.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1107                    
1108      def _OnChangeFillColor(self, event):      def _OnChangeFillColor(self, event):
1109          clr = self.__GetColor(self.prop.GetFill())          clr = self.__GetColor(self.prop.GetFill())
1110          if clr is not None:          if clr is not None:
1111              self.prop.SetFill(clr)              self.prop.SetFill(clr)
1112          self.previewer.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1113    
1114      def _OnChangeFillColorTrans(self, event):      def _OnChangeFillColorTrans(self, event):
1115          self.prop.SetFill(Color.None)          self.prop.SetFill(Color.None)
1116          self.previewer.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1117    
1118      def GetClassGroupProperties(self):      def GetClassGroupProperties(self):
1119          return self.prop          return self.prop
1120    
1121    
1122  class ClassDataPreviewer(wxWindow):  class ClassDataPreviewWindow(wxWindow):
1123    
1124      def __init__(self, rect, prop, shapeType,      def __init__(self, rect, prop, shapeType,
1125                         parent = None, id = -1, size = wxDefaultSize):                         parent = None, id = -1, size = wxDefaultSize):
1126          if parent is not None:          if parent is not None:
1127              wxWindow.__init__(self, parent, id, size=size)              wxWindow.__init__(self, parent, id, (0, 0), size)
1128              EVT_PAINT(self, self._OnPaint)              EVT_PAINT(self, self._OnPaint)
1129    
1130          self.rect = rect          self.rect = rect
1131    
1132          self.prop = prop          self.prop = prop
1133          self.shapeType = shapeType          self.shapeType = shapeType
1134            self.previewer = ClassDataPreviewer()
1135    
1136      def _OnPaint(self, event):      def _OnPaint(self, event):
1137          dc = wxPaintDC(self)          dc = wxPaintDC(self)
# Line 1007  class ClassDataPreviewer(wxWindow): Line 1139  class ClassDataPreviewer(wxWindow):
1139          # XXX: this doesn't seem to be having an effect:          # XXX: this doesn't seem to be having an effect:
1140          dc.DestroyClippingRegion()          dc.DestroyClippingRegion()
1141    
1142          self.Draw(dc, None)          if self.rect is None:
1143                w, h = self.GetSize()
1144                rect = wxRect(0, 0, w, h)
1145            else:
1146                rect = self.rect
1147    
1148            self.previewer.Draw(dc, rect, self.prop, self.shapeType)
1149    
1150    class ClassDataPreviewer:
1151    
1152      def Draw(self, dc, rect, prop = None, shapeType = None):      def Draw(self, dc, rect, prop, shapeType):
1153    
1154          if prop is None: prop = self.prop          assert(dc is not None)
1155          if shapeType is None: shapeType = self.shapeType          assert(isinstance(prop, ClassGroupProperties))
1156    
1157          if rect is None:          if rect is None:
1158              x = y = 0              x = 0
1159              w, h = self.GetClientSizeTuple()              y = 0
1160                w, h = dc.GetSize()
1161          else:          else:
1162              x = rect.GetX()              x = rect.GetX()
1163              y = rect.GetY()              y = rect.GetY()
# Line 1046  class ClassDataPreviewer(wxWindow): Line 1187  class ClassDataPreviewer(wxWindow):
1187                             wxPoint(x + w/2, y + h/4*3),                             wxPoint(x + w/2, y + h/4*3),
1188                             wxPoint(x + w, y)])                             wxPoint(x + w, y)])
1189    
1190          elif shapeType == SHAPETYPE_POINT or \          elif shapeType == SHAPETYPE_POINT:
              shapeType == SHAPETYPE_POLYGON:  
1191    
1192              dc.DrawCircle(x + w/2, y + h/2,              dc.DrawCircle(x + w/2, y + h/2,
1193                            (min(w, h) - prop.GetLineWidth())/2)                            (min(w, h) - prop.GetLineWidth())/2)
1194    
1195            elif shapeType == SHAPETYPE_POLYGON:
1196                dc.DrawRectangle(x, y, w, h)
1197    
1198  class ClassRenderer(wxPyGridCellRenderer):  class ClassRenderer(wxPyGridCellRenderer):
1199    
1200      def __init__(self, shapeType):      def __init__(self, shapeType):
1201          wxPyGridCellRenderer.__init__(self)          wxPyGridCellRenderer.__init__(self)
1202          self.previewer = ClassDataPreviewer(None, None, shapeType)          self.shapeType = shapeType
1203            self.previewer = ClassDataPreviewer()
1204    
1205      def Draw(self, grid, attr, dc, rect, row, col, isSelected):      def Draw(self, grid, attr, dc, rect, row, col, isSelected):
1206          data = grid.GetTable().GetClassGroup(row)          data = grid.GetTable().GetClassGroup(row)
# Line 1069  class ClassRenderer(wxPyGridCellRenderer Line 1213  class ClassRenderer(wxPyGridCellRenderer
1213                           rect.GetWidth(), rect.GetHeight())                           rect.GetWidth(), rect.GetHeight())
1214    
1215          if not isinstance(data, ClassGroupMap):          if not isinstance(data, ClassGroupMap):
1216              self.previewer.Draw(dc, rect, data.GetProperties())              self.previewer.Draw(dc, rect, data.GetProperties(), self.shapeType)
1217    
1218          if isSelected:          if isSelected:
1219              dc.SetPen(wxPen(wxColour(0 * 255, 0 * 255, 0 * 255),              dc.SetPen(wxPen(wxColour(0 * 255, 0 * 255, 0 * 255),

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26