/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/classifier.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/classifier.py

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

revision 615 by jonathan, Mon Apr 7 08:57:20 2003 UTC revision 638 by jonathan, Thu Apr 10 14:35:20 2003 UTC
# Line 35  from dialogs import NonModalDialog Line 35  from dialogs import NonModalDialog
35  ID_PROPERTY_SELECT = 4010  ID_PROPERTY_SELECT = 4010
36  ID_CLASS_TABLE = 40011  ID_CLASS_TABLE = 40011
37    
 ID_CLASSIFY_OK = 4001  
 ID_CLASSIFY_CANCEL = 4002  
 ID_CLASSIFY_ADD = 4003  
 ID_CLASSIFY_GENCLASS = 4004  
 ID_CLASSIFY_REMOVE = 4005  
 ID_CLASSIFY_MOVEUP = 4006  
 ID_CLASSIFY_MOVEDOWN = 4007  
 ID_CLASSIFY_APPLY = 4008  
 ID_CLASSIFY_EDITPROPS = 4009  
 ID_CLASSIFY_CLOSE = 4010  
38    
39  # table columns  # table columns
40  COL_SYMBOL = 0  COL_VISIBLE = 0
41  COL_VALUE  = 1  COL_SYMBOL  = 1
42  COL_LABEL  = 2  COL_VALUE   = 2
43    COL_LABEL   = 3
44    NUM_COLS    = 4
45    
46  # indices into the client data lists in Classifier.fields  # indices into the client data lists in Classifier.fields
47  FIELD_CLASS = 0  FIELD_CLASS = 0
# Line 73  class ClassGrid(wxGrid): Line 65  class ClassGrid(wxGrid):
65                   use for display.                   use for display.
66          """          """
67    
         #wxGrid.__init__(self, parent, ID_CLASS_TABLE, size = (340, 160))  
68          wxGrid.__init__(self, parent, ID_CLASS_TABLE)          wxGrid.__init__(self, parent, ID_CLASS_TABLE)
         #self.SetTable(ClassTable(fieldData, layer.ShapeType(), self), True)  
69    
70          self.classifier = classifier          self.classifier = classifier
71    
# Line 87  class ClassGrid(wxGrid): Line 77  class ClassGrid(wxGrid):
77          EVT_GRID_COL_SIZE(self, self._OnCellResize)          EVT_GRID_COL_SIZE(self, self._OnCellResize)
78          EVT_GRID_ROW_SIZE(self, self._OnCellResize)          EVT_GRID_ROW_SIZE(self, self._OnCellResize)
79    
80          #print "123123123: ", ('Show' in dir(self))      #def GetCellAttr(self, row, col):
81            #print "GetCellAttr ", row, col
82      #def Show(self):          #wxGrid.GetCellAttr(self, row, col)
         #print "SHOW!"  
   
     #def Refresh(self):  
         #self.Show()  
     #def Update(self):  
         #self.Show()  
83    
84      def CreateTable(self, clazz, shapeType, group = None):      def CreateTable(self, clazz, shapeType, group = None):
85    
# Line 114  class ClassGrid(wxGrid): Line 98  class ClassGrid(wxGrid):
98          self.SetSelectionMode(wxGrid.wxGridSelectRows)          self.SetSelectionMode(wxGrid.wxGridSelectRows)
99          self.ClearSelection()          self.ClearSelection()
100    
         #print "8------------------"  
101          table.Reset(clazz, shapeType, group)          table.Reset(clazz, shapeType, group)
         #print "9------------------"  
   
 #   def Show(self, show = True):  
 #       print "SHOW!"  
 #       wxGrid.Show(self, show)  
   
 #       sel = self.GetCurrentSelection()  
   
 #       print "( 1"  
 #       if len(sel) == 1:  
 #           print "( 2"  
 #           self.MakeCellVisible(sel[0], 0)  
102    
103      def GetCurrentSelection(self):      def GetCurrentSelection(self):
104          """Return the currently highlighted rows as an increasing list          """Return the currently highlighted rows as an increasing list
105             of row numbers."""             of row numbers."""
         #print "@@ ", self.currentSelection  
106          sel = copy.copy(self.currentSelection)          sel = copy.copy(self.currentSelection)
107          sel.sort()          sel.sort()
108          return sel          return sel
# Line 140  class ClassGrid(wxGrid): Line 110  class ClassGrid(wxGrid):
110      def GetSelectedRows(self):      def GetSelectedRows(self):
111          return self.GetCurrentSelection()          return self.GetCurrentSelection()
112    
113      def SetCellRenderer(self, row, col):      #def SetCellRenderer(self, row, col, renderer):
114          raise ValueError(_("Must not allow setting of renderer in ClassGrid!"))          #raise ValueError(_("Must not allow setting of renderer in ClassGrid!"))
115    
116      #      #
117      # [Set|Get]Table is taken from http://wiki.wxpython.org      # [Set|Get]Table is taken from http://wiki.wxpython.org
# Line 216  class ClassGrid(wxGrid): Line 186  class ClassGrid(wxGrid):
186    
187          assert table is not None          assert table is not None
188    
   
         #print "-- ", group  
189          for i in range(table.GetNumberRows()):          for i in range(table.GetNumberRows()):
190              g = table.GetClassGroup(i)              g = table.GetClassGroup(i)
             #print "1", g  
191              if g is group:              if g is group:
                 #print "2"  
192                  self.SelectRow(i)                  self.SelectRow(i)
193                  if makeVisible:                  if makeVisible:
                     #print "3"  
194                      self.MakeCellVisible(i, 0)                      self.MakeCellVisible(i, 0)
195                  break                  break
196    
           
   
197  #  #
198  # 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!
199  #  #
# Line 243  class ClassGrid(wxGrid): Line 206  class ClassGrid(wxGrid):
206  #                                  sel = False))  #                                  sel = False))
207    
208      def _OnCellDClick(self, event):      def _OnCellDClick(self, event):
209          """Handle a double on a cell."""          """Handle a double click on a cell."""
210    
211          r = event.GetRow()          r = event.GetRow()
212          c = event.GetCol()          c = event.GetCol()
         if c == COL_SYMBOL:  
             self.classifier.EditGroupProperties(r)  
213    
214            if c == COL_SYMBOL:
215                self.classifier.EditSymbol(r)
216            else:
217                event.Skip()
218    
219      #      #
220      # _OnSelectedRange() and _OnSelectedCell() were borrowed      # _OnSelectedRange() and _OnSelectedCell() were borrowed
# Line 261  class ClassGrid(wxGrid): Line 226  class ClassGrid(wxGrid):
226          if event.Selecting():          if event.Selecting():
227              for index in range( event.GetTopRow(), event.GetBottomRow()+1):              for index in range( event.GetTopRow(), event.GetBottomRow()+1):
228                  if index not in self.currentSelection:                  if index not in self.currentSelection:
                     #print "    ", index  
229                      self.currentSelection.append( index )                      self.currentSelection.append( index )
230          else:          else:
231              for index in range( event.GetTopRow(), event.GetBottomRow()+1):              for index in range( event.GetTopRow(), event.GetBottomRow()+1):
232                  while index in self.currentSelection:                  while index in self.currentSelection:
                     #print "    ", index  
233                      self.currentSelection.remove( index )                      self.currentSelection.remove( index )
234          #self.ConfigureForSelection()          #self.ConfigureForSelection()
235    
         #print self.GetCurrentSelection()  
236          event.Skip()          event.Skip()
237    
238      def _OnSelectedCell( self, event ):      def _OnSelectedCell( self, event ):
239          """Internal update to the selection tracking list"""          """Internal update to the selection tracking list"""
         #print "selecting cell: ", event.GetRow()  
240          self.currentSelection = [ event.GetRow() ]          self.currentSelection = [ event.GetRow() ]
241          #self.ConfigureForSelection()          #self.ConfigureForSelection()
242          event.Skip()          event.Skip()
# Line 286  class ClassGrid(wxGrid): Line 247  class ClassGrid(wxGrid):
247  class ClassTable(wxPyGridTableBase):  class ClassTable(wxPyGridTableBase):
248      """Represents the underlying data structure for the grid."""      """Represents the underlying data structure for the grid."""
249    
250      NUM_COLS = 3      __col_labels = [_("Visible"), _("Symbol"), _("Value"), _("Label")]
   
     __col_labels = [_("Symbol"), _("Value"), _("Label")]  
251    
252    
253      def __init__(self, view = None):      def __init__(self, view = None):
# Line 302  class ClassTable(wxPyGridTableBase): Line 261  class ClassTable(wxPyGridTableBase):
261    
262          wxPyGridTableBase.__init__(self)          wxPyGridTableBase.__init__(self)
263    
264          self.SetView(view)          assert len(ClassTable.__col_labels) == NUM_COLS
265    
266          self.clazz = None          self.clazz = None
267            self.__colAttr = {}
268    
269          #self.Reset(clazz, shapeType)          self.SetView(view)
270    
271      def Reset(self, clazz, shapeType, group = None):      def Reset(self, clazz, shapeType, group = None):
272          """Reset the table with the given data.          """Reset the table with the given data.
# Line 330  class ClassTable(wxPyGridTableBase): Line 291  class ClassTable(wxPyGridTableBase):
291    
292          self.SetClassification(clazz, group)          self.SetClassification(clazz, group)
293          self.__Modified(-1)          self.__Modified(-1)
294          #print "11------------------"  
295            self.__colAttr = {}
296    
297            attr = wxGridCellAttr()
298            attr.SetEditor(wxGridCellBoolEditor())
299            attr.SetRenderer(wxGridCellBoolRenderer())
300            attr.SetAlignment(wxALIGN_CENTER, wxALIGN_CENTER)
301            self.__colAttr[COL_VISIBLE] = attr
302    
303            attr = wxGridCellAttr()
304            attr.SetRenderer(ClassRenderer(self.shapeType))
305            attr.SetReadOnly()
306            self.__colAttr[COL_SYMBOL] = attr
307    
308          self.GetView().EndBatch()          self.GetView().EndBatch()
309          self.GetView().FitInside()          self.GetView().FitInside()
# Line 344  class ClassTable(wxPyGridTableBase): Line 317  class ClassTable(wxPyGridTableBase):
317    
318          old_len = self.GetNumberRows()          old_len = self.GetNumberRows()
319    
         #print "9------------------"  
         #  
         # copy the data out of the classification and into our  
         # array  
         #  
320          row = -1          row = -1
 #       for g in clazz:  
 #           ng = copy.deepcopy(g)  
 #           self.__SetRow(None, ng)  
 #           if g is group:  
 #               row = self.GetNumberRows() - 1  
 #               #print "selecting row..."  
   
         #print "10------------------"  
   
         #self.clazz = copy.deepcopy(clazz)  
321          self.clazz = clazz          self.clazz = clazz
322    
323          self.__NotifyRowChanges(old_len, self.GetNumberRows())          self.__NotifyRowChanges(old_len, self.GetNumberRows())
324    
325            #
326            # XXX: this is dead code at the moment
327            #
328          if row > -1:          if row > -1:
329              self.GetView().ClearSelection()              self.GetView().ClearSelection()
330              self.GetView().SelectRow(row)              self.GetView().SelectRow(row)
# Line 371  class ClassTable(wxPyGridTableBase): Line 332  class ClassTable(wxPyGridTableBase):
332    
333          self.__Modified()          self.__Modified()
334    
335    
336          self.GetView().EndBatch()          self.GetView().EndBatch()
337          self.GetView().FitInside()          self.GetView().FitInside()
338    
# Line 446  class ClassTable(wxPyGridTableBase): Line 408  class ClassTable(wxPyGridTableBase):
408    
409      def GetNumberCols(self):      def GetNumberCols(self):
410          """Return the number of columns."""          """Return the number of columns."""
411          return self.NUM_COLS          return NUM_COLS
412    
413      def IsEmptyCell(self, row, col):      def IsEmptyCell(self, row, col):
414          """Determine if a cell is empty. This is always false."""          """Determine if a cell is empty. This is always false."""
# Line 464  class ClassTable(wxPyGridTableBase): Line 426  class ClassTable(wxPyGridTableBase):
426          """          """
427    
428          self.SetValueAsCustom(row, col, None, value)          self.SetValueAsCustom(row, col, None, value)
         self.__Modified()  
429                
430      def GetValueAsCustom(self, row, col, typeName):      def GetValueAsCustom(self, row, col, typeName):
431          """Return the object that is used to represent the given          """Return the object that is used to represent the given
# Line 479  class ClassTable(wxPyGridTableBase): Line 440  class ClassTable(wxPyGridTableBase):
440              group = self.clazz.GetGroup(row - 1)              group = self.clazz.GetGroup(row - 1)
441    
442    
443            if col == COL_VISIBLE:
444                return group.IsVisible()
445    
446          if col == COL_SYMBOL:          if col == COL_SYMBOL:
447              return group.GetProperties()              return group.GetProperties()
448    
# Line 510  class ClassTable(wxPyGridTableBase): Line 474  class ClassTable(wxPyGridTableBase):
474    
475          if type == FIELDTYPE_STRING:          if type == FIELDTYPE_STRING:
476              return (value,)              return (value,)
477          elif type == FIELDTYPE_INT or type == FIELDTYPE_DOUBLE:          elif type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):
478    
479              if type == FIELDTYPE_INT:              if type == FIELDTYPE_INT:
480                  conv = lambda p: int(float(p))                  conv = lambda p: int(float(p))
# Line 561  class ClassTable(wxPyGridTableBase): Line 525  class ClassTable(wxPyGridTableBase):
525    
526          mod = True # assume the data will change          mod = True # assume the data will change
527    
528          if col == COL_SYMBOL:          if col == COL_VISIBLE:
529                group.SetVisible(value)
530            elif col == COL_SYMBOL:
531              group.SetProperties(value)              group.SetProperties(value)
532          elif col == COL_LABEL:          elif col == COL_LABEL:
533              group.SetLabel(value)              group.SetLabel(value)
# Line 617  class ClassTable(wxPyGridTableBase): Line 583  class ClassTable(wxPyGridTableBase):
583      def GetAttr(self, row, col, someExtraParameter):      def GetAttr(self, row, col, someExtraParameter):
584          """Returns the cell attributes"""          """Returns the cell attributes"""
585    
586          attr = wxGridCellAttr()          return self.__colAttr.get(col, wxGridCellAttr()).Clone()
         #attr = wxPyGridTableBase.GetAttr(self, row, col, someExtraParameter)  
   
         if col == COL_SYMBOL:  
             # we need to create a new renderer each time, because  
             # SetRenderer takes control of the parameter  
             attr.SetRenderer(ClassRenderer(self.shapeType))  
             attr.SetReadOnly()  
   
         return attr  
587    
588      def GetClassGroup(self, row):      def GetClassGroup(self, row):
589          """Return the ClassGroup object representing row 'row'."""          """Return the ClassGroup object representing row 'row'."""
# Line 692  class ClassTable(wxPyGridTableBase): Line 649  class ClassTable(wxPyGridTableBase):
649              self.__NotifyRowChanges(old_len, self.GetNumberRows())              self.__NotifyRowChanges(old_len, self.GetNumberRows())
650    
651    
652    ID_CLASSIFY_OK = 4001
653    ID_CLASSIFY_REVERT = 4002
654    ID_CLASSIFY_ADD = 4003
655    ID_CLASSIFY_GENCLASS = 4004
656    ID_CLASSIFY_REMOVE = 4005
657    ID_CLASSIFY_MOVEUP = 4006
658    ID_CLASSIFY_MOVEDOWN = 4007
659    ID_CLASSIFY_TRY = 4008
660    ID_CLASSIFY_EDITSYM = 4009
661    ID_CLASSIFY_CLOSE = 4010
662    
663    BTN_ADD = 0
664    BTN_EDIT = 1
665    BTN_GEN = 2
666    BTN_UP = 3
667    BTN_DOWN = 4
668    BTN_RM = 5
669    
670  class Classifier(NonModalDialog):  class Classifier(NonModalDialog):
671    
672        type2string = {None:             _("None"),
673                       FIELDTYPE_STRING: _("Text"),
674                       FIELDTYPE_INT:    _("Integer"),
675                       FIELDTYPE_DOUBLE: _("Decimal")}
676    
677      def __init__(self, parent, name, layer, group = None):      def __init__(self, parent, name, layer, group = None):
678          NonModalDialog.__init__(self, parent, name,          NonModalDialog.__init__(self, parent, name,
679                                  _("Classifier: %s") % layer.Title())                                  _("Classifier: %s") % layer.Title())
# Line 706  class Classifier(NonModalDialog): Line 686  class Classifier(NonModalDialog):
686          field = self.originalClass.GetField()          field = self.originalClass.GetField()
687          fieldType = self.originalClass.GetFieldType()          fieldType = self.originalClass.GetFieldType()
688    
689            self.genDlg = None
690    
691          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
692          panelBox = wxBoxSizer(wxVERTICAL)          panelBox = wxBoxSizer(wxVERTICAL)
693    
# Line 771  class Classifier(NonModalDialog): Line 753  class Classifier(NonModalDialog):
753    
754          controlButtonBox = wxBoxSizer(wxVERTICAL)          controlButtonBox = wxBoxSizer(wxVERTICAL)
755    
756          button = wxButton(panel, ID_CLASSIFY_ADD, _("Add"))          button = wxButton(panel, ID_CLASSIFY_GENCLASS, _("Generate Class"))
757          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
758          self.controlButtons.append(button)          self.controlButtons.append(button)
759    
760          button = wxButton(panel, ID_CLASSIFY_EDITPROPS, _("Edit Properties"))          button = wxButton(panel, ID_CLASSIFY_ADD, _("Add"))
761          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
762          self.controlButtons.append(button)          self.controlButtons.append(button)
763    
764          button = wxButton(panel, ID_CLASSIFY_GENCLASS, _("Generate Class"))          button = wxButton(panel, ID_CLASSIFY_MOVEUP, _("Move Up"))
765          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
766          self.controlButtons.append(button)          self.controlButtons.append(button)
767    
768          button = wxButton(panel, ID_CLASSIFY_MOVEUP, _("Move Up"))          button = wxButton(panel, ID_CLASSIFY_MOVEDOWN, _("Move Down"))
769          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
770          self.controlButtons.append(button)          self.controlButtons.append(button)
771    
772          button = wxButton(panel, ID_CLASSIFY_MOVEDOWN, _("Move Down"))          button = wxButton(panel, ID_CLASSIFY_EDITSYM, _("Edit Symbol"))
773          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
774          self.controlButtons.append(button)          self.controlButtons.append(button)
775    
# Line 804  class Classifier(NonModalDialog): Line 786  class Classifier(NonModalDialog):
786          #          #
787    
788          self.classGrid = ClassGrid(panel, self)          self.classGrid = ClassGrid(panel, self)
789          #self.__SetGridTable(self.__cur_field, group)  #       self.classGrid = wxGrid(panel, -1)
790          #self.fields.SetSelection(self.__cur_field)  #       self.classGrid.SetDefaultRenderer(wxGridCellBoolRenderer())
791    #       self.classGrid.SetDefaultEditor(wxGridCellBoolEditor())
792            #self.classGrid.CreateGrid(5, 5)
793            #self.classGrid.SetCellEditor(0, 0, wxGridCellBoolEditor())
794            #self.classGrid.SetCellRenderer(0, 0, wxGridCellBoolRenderer())
795            #print self.classGrid.GetCellEditor(0, 0)
796            #print self.classGrid.GetCellRenderer(0, 0)
797            #self.classGrid = ClassGrid(panel, self)
798    
799            # need these
800            self.__SetGridTable(self.__cur_field, group)
801            self.fields.SetSelection(self.__cur_field)
802            #self.classGrid.SetCellEditor(0, 0, wxGridCellBoolEditor())
803            #self.classGrid.SetCellRenderer(0, 0, wxGridCellBoolRenderer())
804    
805          # calling __SelectField after creating the classGrid fills in the          # calling __SelectField after creating the classGrid fills in the
806          # grid with the correct information          # grid with the correct information
807          #print "2------------------"          #self.fields.SetSelection(self.__cur_field)
808          self.fields.SetSelection(self.__cur_field)          #self.__SelectField(self.__cur_field, group = group)
         self.__SelectField(self.__cur_field, group = group)  
809    
810          #self.classGrid.SelectGroup(group)          #self.classGrid.SelectGroup(group)
811    
# Line 823  class Classifier(NonModalDialog): Line 817  class Classifier(NonModalDialog):
817          panelBox.Add(controlBox, 1, wxGROW, 10)          panelBox.Add(controlBox, 1, wxGROW, 10)
818    
819          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)
820          EVT_BUTTON(self, ID_CLASSIFY_EDITPROPS, self._OnEditGroupProperties)          EVT_BUTTON(self, ID_CLASSIFY_EDITSYM, self._OnEditSymbol)
821          EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove)          EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove)
822          EVT_BUTTON(self, ID_CLASSIFY_GENCLASS, self._OnGenClass)          EVT_BUTTON(self, ID_CLASSIFY_GENCLASS, self._OnGenClass)
823          EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp)          EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp)
# Line 832  class Classifier(NonModalDialog): Line 826  class Classifier(NonModalDialog):
826          ###########          ###########
827    
828          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
829          buttonBox.Add(wxButton(panel, ID_CLASSIFY_OK, _("OK")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_TRY, _("Try")),
830                        0, wxALL, 4)                        0, wxALL, 4)
831          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
832          buttonBox.Add(wxButton(panel, ID_CLASSIFY_APPLY, _("Apply")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_REVERT, _("Revert")),
833                        0, wxALL, 4)                        0, wxALL, 4)
834          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
835          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CLOSE, _("Close")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_OK, _("OK")),
836                        0, wxALL, 4)                        0, wxALL, 4)
837          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
838          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CANCEL, _("Cancel")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CLOSE, _("Close")),
839                        0, wxALL, 4)                        0, wxALL, 4)
840          panelBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)          panelBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)
841    
842          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)
843          EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply)          EVT_BUTTON(self, ID_CLASSIFY_TRY, self._OnTry)
844          EVT_BUTTON(self, ID_CLASSIFY_CLOSE, self._OnCloseBtn)          EVT_BUTTON(self, ID_CLASSIFY_CLOSE, self._OnCloseBtn)
845          EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel)          EVT_BUTTON(self, ID_CLASSIFY_REVERT, self._OnRevert)
846    
847          ###########          ###########
848    
# Line 862  class Classifier(NonModalDialog): Line 856  class Classifier(NonModalDialog):
856          self.SetAutoLayout(True)          self.SetAutoLayout(True)
857          self.SetSizer(topBox)          self.SetSizer(topBox)
858    
         #print "1------------------"  
859          #self.Fit()          #self.Fit()
860          ######################          ######################
861    
862          self.haveApplied = False          self.haveApplied = False
863    
864      def EditGroupProperties(self, row):      def EditSymbol(self, row):
865          table = self.classGrid.GetTable()          table = self.classGrid.GetTable()
866          prop = table.GetValueAsCustom(row, COL_SYMBOL, None)          prop = table.GetValueAsCustom(row, COL_SYMBOL, None)
867    
868          # get a new ClassGroupProperties object and copy the          # get a new ClassGroupProperties object and copy the
869          # values over to our current object          # values over to our current object
870          propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType())          propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType())
871    
872            self.Enable(False)
873          if propDlg.ShowModal() == wxID_OK:          if propDlg.ShowModal() == wxID_OK:
874              new_prop = propDlg.GetClassGroupProperties()              new_prop = propDlg.GetClassGroupProperties()
875              table.SetValueAsCustom(row, COL_SYMBOL, None, new_prop)              table.SetValueAsCustom(row, COL_SYMBOL, None, new_prop)
876            self.Enable(True)
877          propDlg.Destroy()          propDlg.Destroy()
878                    
879        def _SetClassification(self, clazz):
880            
881            self.fields.SetClientData(self.__cur_field, clazz)
882            self.classGrid.GetTable().SetClassification(clazz)
883    
884      def __BuildClassification(self, fieldIndex, copyClass = False):      def __BuildClassification(self, fieldIndex, copyClass = False):
885    
# Line 926  class Classifier(NonModalDialog): Line 926  class Classifier(NonModalDialog):
926              fieldType = self.layer.GetFieldType(fieldName)              fieldType = self.layer.GetFieldType(fieldName)
927              clazz.SetFieldType(fieldType)              clazz.SetFieldType(fieldType)
928                                    
         #print "6------------------"  
929          self.classGrid.CreateTable(clazz, self.layer.ShapeType(), group)          self.classGrid.CreateTable(clazz, self.layer.ShapeType(), group)
         #print "7------------------"  
   
   
   
     type2string = {None:             _("None"),  
                    FIELDTYPE_STRING: _("Text"),  
                    FIELDTYPE_INT:    _("Integer"),  
                    FIELDTYPE_DOUBLE: _("Decimal")}  
930    
931      def __SetFieldTypeText(self, fieldIndex):      def __SetFieldTypeText(self, fieldIndex):
932          fieldName = self.fields.GetString(fieldIndex)          fieldName = self.fields.GetString(fieldIndex)
# Line 952  class Classifier(NonModalDialog): Line 943  class Classifier(NonModalDialog):
943          combo has already been set by a call to SetSelection().          combo has already been set by a call to SetSelection().
944          """          """
945    
         #print "3------------------"  
   
946          assert oldIndex >= -1          assert oldIndex >= -1
947    
948          if oldIndex != -1:          if oldIndex != -1:
949              clazz = self.__BuildClassification(oldIndex)              clazz = self.__BuildClassification(oldIndex)
950              self.fields.SetClientData(oldIndex, clazz)              self.fields.SetClientData(oldIndex, clazz)
951    
         #print "4------------------"  
952          self.__SetGridTable(newIndex, group)          self.__SetGridTable(newIndex, group)
         #print "5------------------"  
953    
954          enabled = newIndex != 0          enabled = newIndex != 0
955    
# Line 972  class Classifier(NonModalDialog): Line 959  class Classifier(NonModalDialog):
959          self.__SetFieldTypeText(newIndex)          self.__SetFieldTypeText(newIndex)
960    
961    
962      def _OnEditGroupProperties(self, event):      def _OnEditSymbol(self, event):
963          sel = self.classGrid.GetCurrentSelection()          sel = self.classGrid.GetCurrentSelection()
964    
965          if len(sel) == 1:          if len(sel) == 1:
966              self.EditGroupProperties(sel[0])              self.EditSymbol(sel[0])
967    
968      def _OnFieldSelect(self, event):      def _OnFieldSelect(self, event):
969          index = self.fields.GetSelection()          index = self.fields.GetSelection()
970          self.__SelectField(index, self.__cur_field)          self.__SelectField(index, self.__cur_field)
971          self.__cur_field = index          self.__cur_field = index
972    
973      def _OnApply(self, event):      def _OnTry(self, event):
974          """Put the data from the table into a new Classification and hand          """Put the data from the table into a new Classification and hand
975             it to the layer.             it to the layer.
976          """          """
# Line 1002  class Classifier(NonModalDialog): Line 989  class Classifier(NonModalDialog):
989          self.haveApplied = True          self.haveApplied = True
990    
991      def _OnOK(self, event):      def _OnOK(self, event):
992          self._OnApply(event)          self._OnTry(event)
993          self.Close()          self.Close()
994    
995      def _OnCloseBtn(self, event):      def _OnCloseBtn(self, event):
# Line 1013  class Classifier(NonModalDialog): Line 1000  class Classifier(NonModalDialog):
1000    
1001          self.Close()          self.Close()
1002    
1003      def _OnCancel(self, event):      def _OnRevert(self, event):
1004          """The layer's current classification stays the same."""          """The layer's current classification stays the same."""
1005          if self.haveApplied:          if self.haveApplied:
1006              self.layer.SetClassification(self.originalClass)              self.layer.SetClassification(self.originalClass)
1007    
1008          self.Close()          #self.Close()
1009    
1010      def _OnAdd(self, event):      def _OnAdd(self, event):
1011          self.classGrid.AppendRows()          self.classGrid.AppendRows()
# Line 1028  class Classifier(NonModalDialog): Line 1015  class Classifier(NonModalDialog):
1015    
1016      def _OnGenClass(self, event):      def _OnGenClass(self, event):
1017    
1018          genDlg = ClassGenDialog(self,          #if self.genDlg is None:
1019                                  self.layer.table,          self.genDlg = ClassGenDialog(self, self.layer,
1020                                  self.fields.GetString(self.__cur_field))                            self.fields.GetString(self.__cur_field))
1021    
1022          if genDlg.ShowModal() == wxID_OK:          EVT_CLOSE(self.genDlg, self._OnGenDialogClose)
1023              clazz = genDlg.GetClassification()  
1024              self.fields.SetClientData(self.__cur_field, clazz)          self.fields.Enable(False)
1025              self.classGrid.GetTable().SetClassification(clazz)          self.controlButtons[BTN_EDIT].Enable(False)
1026          genDlg.Destroy()          self.controlButtons[BTN_GEN].Enable(False)
1027    
1028            self.genDlg.Show()
1029            #if self.genDlg.ShowModal() == wxID_OK:
1030            #    clazz = self.genDlg.GetClassification()
1031            #    self.fields.SetClientData(self.__cur_field, clazz)
1032            #    self.classGrid.GetTable().SetClassification(clazz)
1033            #self.Enable(True)
1034            #self.genDlg.Destroy()
1035    
1036        def _OnGenDialogClose(self, event):
1037            self.genDlg.Destroy()
1038    
1039            self.fields.Enable(True)
1040            self.controlButtons[BTN_EDIT].Enable(True)
1041            self.controlButtons[BTN_GEN].Enable(True)
1042    
1043      def _OnMoveUp(self, event):      def _OnMoveUp(self, event):
1044          sel = self.classGrid.GetCurrentSelection()          sel = self.classGrid.GetCurrentSelection()
1045    
         #print "sel: ", sel  
   
1046          if len(sel) == 1:          if len(sel) == 1:
1047              i = sel[0]              i = sel[0]
1048              if i > 1:              if i > 1:
# Line 1096  class SelectPropertiesDialog(wxDialog): Line 1096  class SelectPropertiesDialog(wxDialog):
1096          previewBox = wxBoxSizer(wxVERTICAL)          previewBox = wxBoxSizer(wxVERTICAL)
1097          previewBox.Add(wxStaticText(self, -1, _("Preview:")),          previewBox.Add(wxStaticText(self, -1, _("Preview:")),
1098              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
1099          self.previewWin = ClassDataPreviewWindow(None, self.prop, shapeType,  
1100                                              self, ID_SELPROP_PREVIEW, (40, 40))          self.previewWin = ClassGroupPropertiesCtrl(
1101                self, ID_SELPROP_PREVIEW, self.prop, shapeType,
1102                (40, 40), wxSIMPLE_BORDER)
1103    
1104            self.previewWin.AllowEdit(False)
1105    
1106          previewBox.Add(self.previewWin, 1, wxGROW | wxALL, 4)          previewBox.Add(self.previewWin, 1, wxGROW | wxALL, 4)
1107    
1108          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)
# Line 1229  class ClassDataPreviewWindow(wxWindow): Line 1234  class ClassDataPreviewWindow(wxWindow):
1234          self.shapeType = shapeType          self.shapeType = shapeType
1235          self.previewer = ClassDataPreviewer()          self.previewer = ClassDataPreviewer()
1236    
1237        def GetProperties():
1238            return self.prop
1239    
1240      def _OnPaint(self, event):      def _OnPaint(self, event):
1241          dc = wxPaintDC(self)          dc = wxPaintDC(self)
1242    
# Line 1320  class ClassRenderer(wxPyGridCellRenderer Line 1328  class ClassRenderer(wxPyGridCellRenderer
1328    
1329          dc.DestroyClippingRegion()          dc.DestroyClippingRegion()
1330    
1331    
1332    class ClassGroupPropertiesCtrl(wxWindow, wxControl):
1333    
1334        def __init__(self, parent, id, props, shapeType,
1335                     size = wxDefaultSize, style = 0):
1336    
1337            wxWindow.__init__(self, parent, id, size = size, style = style)
1338    
1339            self.SetProperties(props)
1340            self.SetShapeType(shapeType)
1341            self.AllowEdit(True)
1342    
1343            EVT_PAINT(self, self._OnPaint)
1344            EVT_LEFT_DCLICK(self, self._OnLeftDClick)
1345    
1346            self.previewer = ClassDataPreviewer()
1347    
1348        def _OnPaint(self, event):
1349            dc = wxPaintDC(self)
1350    
1351            # XXX: this doesn't seem to be having an effect:
1352            dc.DestroyClippingRegion()
1353    
1354            w, h = self.GetClientSize()
1355    
1356            self.previewer.Draw(dc,
1357                                wxRect(0, 0, w, h),
1358                                self.GetProperties(),
1359                                self.GetShapeType())
1360    
1361    
1362        def GetProperties(self):
1363            return self.props
1364    
1365        def SetProperties(self, props):
1366            self.props = props
1367            self.Refresh()
1368    
1369        def GetShapeType(self):
1370            return self.shapeType
1371    
1372        def SetShapeType(self, shapeType):
1373            self.shapeType = shapeType
1374            self.Refresh()
1375    
1376        def AllowEdit(self, allow):
1377            self.allowEdit = allow
1378    
1379        def DoEdit(self):
1380            if not self.allowEdit: return
1381    
1382            propDlg = SelectPropertiesDialog(NULL,
1383                                             self.GetProperties(),
1384                                             self.GetShapeType())
1385    
1386            if propDlg.ShowModal() == wxID_OK:
1387                new_prop = propDlg.GetClassGroupProperties()
1388                self.SetProperties(new_prop)
1389                self.Refresh()
1390    
1391            propDlg.Destroy()
1392    
1393        def _OnLeftDClick(self, event):
1394            self.DoEdit()

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26