/[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 610 by jonathan, Fri Apr 4 13:56:59 2003 UTC revision 630 by jonathan, Wed Apr 9 10:10:06 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  
38    
39  # table columns  # table columns
40  COL_SYMBOL = 0  COL_SYMBOL = 0
# Line 86  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    
         #print "123123123: ", ('Show' in dir(self))  
   
     #def Show(self):  
         #print "SHOW!"  
   
     #def Refresh(self):  
         #self.Show()  
     #def Update(self):  
         #self.Show()  
   
80      def CreateTable(self, clazz, shapeType, group = None):      def CreateTable(self, clazz, shapeType, group = None):
81    
82          assert isinstance(clazz, Classification)          assert isinstance(clazz, Classification)
# Line 113  class ClassGrid(wxGrid): Line 94  class ClassGrid(wxGrid):
94          self.SetSelectionMode(wxGrid.wxGridSelectRows)          self.SetSelectionMode(wxGrid.wxGridSelectRows)
95          self.ClearSelection()          self.ClearSelection()
96    
         #print "8------------------"  
97          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)  
98    
99      def GetCurrentSelection(self):      def GetCurrentSelection(self):
100          """Return the currently highlighted rows as an increasing list          """Return the currently highlighted rows as an increasing list
101             of row numbers."""             of row numbers."""
         #print "@@ ", self.currentSelection  
102          sel = copy.copy(self.currentSelection)          sel = copy.copy(self.currentSelection)
103          sel.sort()          sel.sort()
104          return sel          return sel
# Line 215  class ClassGrid(wxGrid): Line 182  class ClassGrid(wxGrid):
182    
183          assert table is not None          assert table is not None
184    
   
         #print "-- ", group  
185          for i in range(table.GetNumberRows()):          for i in range(table.GetNumberRows()):
186              g = table.GetClassGroup(i)              g = table.GetClassGroup(i)
             #print "1", g  
187              if g is group:              if g is group:
                 #print "2"  
188                  self.SelectRow(i)                  self.SelectRow(i)
189                  if makeVisible:                  if makeVisible:
                     #print "3"  
190                      self.MakeCellVisible(i, 0)                      self.MakeCellVisible(i, 0)
191                  break                  break
192    
           
   
193  #  #
194  # 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!
195  #  #
# Line 260  class ClassGrid(wxGrid): Line 220  class ClassGrid(wxGrid):
220          if event.Selecting():          if event.Selecting():
221              for index in range( event.GetTopRow(), event.GetBottomRow()+1):              for index in range( event.GetTopRow(), event.GetBottomRow()+1):
222                  if index not in self.currentSelection:                  if index not in self.currentSelection:
                     #print "    ", index  
223                      self.currentSelection.append( index )                      self.currentSelection.append( index )
224          else:          else:
225              for index in range( event.GetTopRow(), event.GetBottomRow()+1):              for index in range( event.GetTopRow(), event.GetBottomRow()+1):
226                  while index in self.currentSelection:                  while index in self.currentSelection:
                     #print "    ", index  
227                      self.currentSelection.remove( index )                      self.currentSelection.remove( index )
228          #self.ConfigureForSelection()          #self.ConfigureForSelection()
229    
         #print self.GetCurrentSelection()  
230          event.Skip()          event.Skip()
231    
232      def _OnSelectedCell( self, event ):      def _OnSelectedCell( self, event ):
233          """Internal update to the selection tracking list"""          """Internal update to the selection tracking list"""
         #print "selecting cell: ", event.GetRow()  
234          self.currentSelection = [ event.GetRow() ]          self.currentSelection = [ event.GetRow() ]
235          #self.ConfigureForSelection()          #self.ConfigureForSelection()
236          event.Skip()          event.Skip()
# Line 302  class ClassTable(wxPyGridTableBase): Line 258  class ClassTable(wxPyGridTableBase):
258          wxPyGridTableBase.__init__(self)          wxPyGridTableBase.__init__(self)
259    
260          self.SetView(view)          self.SetView(view)
261          self.tdata = []          self.clazz = None
262    
263          #self.Reset(clazz, shapeType)          #self.Reset(clazz, shapeType)
264    
# Line 329  class ClassTable(wxPyGridTableBase): Line 285  class ClassTable(wxPyGridTableBase):
285    
286          self.SetClassification(clazz, group)          self.SetClassification(clazz, group)
287          self.__Modified(-1)          self.__Modified(-1)
         #print "11------------------"  
288    
289          self.GetView().EndBatch()          self.GetView().EndBatch()
290          self.GetView().FitInside()          self.GetView().FitInside()
291    
292        def GetClassification(self):
293            return self.clazz
294    
295      def SetClassification(self, clazz, group = None):      def SetClassification(self, clazz, group = None):
296    
297          self.GetView().BeginBatch()          self.GetView().BeginBatch()
298    
299          old_len = self.GetNumberRows()          old_len = self.GetNumberRows()
         self.tdata = []  
300    
         #print "9------------------"  
301          #          #
302          # copy the data out of the classification and into our          # copy the data out of the classification and into our
303          # array          # array
304          #          #
305          row = -1          row = -1
306          for g in clazz:  #       for g in clazz:
307              ng = copy.deepcopy(g)  #           ng = copy.deepcopy(g)
308              self.__SetRow(None, ng)  #           self.__SetRow(None, ng)
309              if g is group:  #           if g is group:
310                  row = self.GetNumberRows() - 1  #               row = self.GetNumberRows() - 1
311                  #print "selecting row..."  #               #print "selecting row..."
312    
313          #print "10------------------"  
314            #self.clazz = copy.deepcopy(clazz)
315            self.clazz = clazz
316    
317          self.__NotifyRowChanges(old_len, self.GetNumberRows())          self.__NotifyRowChanges(old_len, self.GetNumberRows())
318    
# Line 363  class ClassTable(wxPyGridTableBase): Line 321  class ClassTable(wxPyGridTableBase):
321              self.GetView().SelectRow(row)              self.GetView().SelectRow(row)
322              self.GetView().MakeCellVisible(row, 0)              self.GetView().MakeCellVisible(row, 0)
323    
324            self.__Modified()
325    
326          self.GetView().EndBatch()          self.GetView().EndBatch()
327          self.GetView().FitInside()          self.GetView().FitInside()
328    
# Line 385  class ClassTable(wxPyGridTableBase): Line 345  class ClassTable(wxPyGridTableBase):
345              self.GetView().ProcessTableMessage(msg)              self.GetView().ProcessTableMessage(msg)
346              self.GetView().FitInside()              self.GetView().FitInside()
347    
348    
349      def __SetRow(self, row, group):      def __SetRow(self, row, group):
350          """Set a row's data to that of the group.          """Set a row's data to that of the group.
351    
# Line 398  class ClassTable(wxPyGridTableBase): Line 359  class ClassTable(wxPyGridTableBase):
359    
360          # either append or replace          # either append or replace
361          if row is None or row >= self.GetNumberRows():          if row is None or row >= self.GetNumberRows():
362              self.tdata.append(group)              self.clazz.AppendGroup(group)
363          elif row < 0:          elif row < 0:
364              self.tdata.insert(0, group)              self.clazz.InsertGroup(0, group)
365          else:          else:
366              self.tdata[row] = group              if row == 0:
367                    self.clazz.SetDefaultGroup(group)
368                else:
369                    self.clazz.ReplaceGroup(row - 1, group)
370    
371          self.__Modified()          self.__Modified()
372    
# Line 413  class ClassTable(wxPyGridTableBase): Line 377  class ClassTable(wxPyGridTableBase):
377      def GetRowLabelValue(self, row):      def GetRowLabelValue(self, row):
378          """Return the label for the given row."""          """Return the label for the given row."""
379    
380          group = self.tdata[row]          if row == 0:
381          if isinstance(group, ClassGroupDefault):   return _("Default")              return _("Default")
382          if isinstance(group, ClassGroupSingleton): return _("Singleton")          else:
383          if isinstance(group, ClassGroupRange):     return _("Range")              group = self.clazz.GetGroup(row - 1)
384          if isinstance(group, ClassGroupMap):       return _("Map")              if isinstance(group, ClassGroupDefault):   return _("Default")
385                if isinstance(group, ClassGroupSingleton): return _("Singleton")
386                if isinstance(group, ClassGroupRange):     return _("Range")
387                if isinstance(group, ClassGroupMap):       return _("Map")
388    
389          assert False # shouldn't get here          assert False # shouldn't get here
390          return _("")          return _("")
391    
392      def GetNumberRows(self):      def GetNumberRows(self):
393          """Return the number of rows."""          """Return the number of rows."""
394          return len(self.tdata)          if self.clazz is None:
395                return 0
396    
397            return self.clazz.GetNumGroups() + 1 # +1 for default group
398    
399      def GetNumberCols(self):      def GetNumberCols(self):
400          """Return the number of columns."""          """Return the number of columns."""
# Line 455  class ClassTable(wxPyGridTableBase): Line 425  class ClassTable(wxPyGridTableBase):
425          typeName -- unused, but needed to overload wxPyGridTableBase          typeName -- unused, but needed to overload wxPyGridTableBase
426          """          """
427    
428          group = self.tdata[row]          if row == 0:
429                group = self.clazz.GetDefaultGroup()
430            else:
431                group = self.clazz.GetGroup(row - 1)
432    
433    
434          if col == COL_SYMBOL:          if col == COL_SYMBOL:
435              return group.GetProperties()              return group.GetProperties()
# Line 473  class ClassTable(wxPyGridTableBase): Line 447  class ClassTable(wxPyGridTableBase):
447          elif isinstance(group, ClassGroupRange):          elif isinstance(group, ClassGroupRange):
448              return _("%s - %s") % (group.GetMin(), group.GetMax())              return _("%s - %s") % (group.GetMin(), group.GetMax())
449    
450          assert False  # shouldn't get here          assert(False) # shouldn't get here
451          return None          return None
452    
453      def __ParseInput(self, value):      def __ParseInput(self, value):
# Line 488  class ClassTable(wxPyGridTableBase): Line 462  class ClassTable(wxPyGridTableBase):
462    
463          if type == FIELDTYPE_STRING:          if type == FIELDTYPE_STRING:
464              return (value,)              return (value,)
465          elif type == FIELDTYPE_INT or type == FIELDTYPE_DOUBLE:          elif type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):
466    
467              if type == FIELDTYPE_INT:              if type == FIELDTYPE_INT:
468                  conv = lambda p: int(float(p))                  conv = lambda p: int(float(p))
# Line 532  class ClassTable(wxPyGridTableBase): Line 506  class ClassTable(wxPyGridTableBase):
506          assert col >= 0 and col < self.GetNumberCols()          assert col >= 0 and col < self.GetNumberCols()
507          assert row >= 0 and row < self.GetNumberRows()          assert row >= 0 and row < self.GetNumberRows()
508    
509          group = self.tdata[row]          if row == 0:
510                group = self.clazz.GetDefaultGroup()
511            else:
512                group = self.clazz.GetGroup(row - 1)
513    
514          mod = True # assume the data will change          mod = True # assume the data will change
515    
# Line 606  class ClassTable(wxPyGridTableBase): Line 583  class ClassTable(wxPyGridTableBase):
583      def GetClassGroup(self, row):      def GetClassGroup(self, row):
584          """Return the ClassGroup object representing row 'row'."""          """Return the ClassGroup object representing row 'row'."""
585    
586          return self.tdata[row] # self.GetValueAsCustom(row, COL_SYMBOL, None)          #return self.GetValueAsCustom(row, COL_SYMBOL, None)
587            if row == 0:
588                return self.clazz.GetDefaultGroup()
589            else:
590                return self.clazz.GetGroup(row - 1)
591    
592      def SetClassGroup(self, row, group):      def SetClassGroup(self, row, group):
593          self.__SetRow(row, group)          self.__SetRow(row, group)
# Line 638  class ClassTable(wxPyGridTableBase): Line 619  class ClassTable(wxPyGridTableBase):
619          """          """
620    
621          assert pos >= 0          assert pos >= 0
622          old_len = len(self.tdata)          old_len = self.GetNumberRows()
623          for row in range(pos, pos - numRows, -1):          for row in range(pos, pos - numRows, -1):
624              group = self.GetClassGroup(row)              group = self.GetClassGroup(row)
625              if not isinstance(group, ClassGroupDefault):              if row != 0:
626                  self.tdata.pop(row)                  self.clazz.RemoveGroup(row - 1)
627                  self.__Modified()                  self.__Modified()
628            
629          if self.IsModified():          if self.IsModified():
630              self.__NotifyRowChanges(old_len, len(self.tdata))              self.__NotifyRowChanges(old_len, self.GetNumberRows())
631    
632      def AppendRows(self, numRows = 1):      def AppendRows(self, numRows = 1):
633          """Append 'numRows' empty rows to the end of the table.          """Append 'numRows' empty rows to the end of the table.
# Line 654  class ClassTable(wxPyGridTableBase): Line 635  class ClassTable(wxPyGridTableBase):
635          The table is considered modified if any rows are appended.          The table is considered modified if any rows are appended.
636          """          """
637    
638          old_len = len(self.tdata)          old_len = self.GetNumberRows()
639          for i in range(numRows):          for i in range(numRows):
640              np = ClassGroupSingleton()              np = ClassGroupSingleton()
641              self.__SetRow(None, np)              self.__SetRow(None, np)
642    
643          if self.IsModified():          if self.IsModified():
644              self.__NotifyRowChanges(old_len, len(self.tdata))              self.__NotifyRowChanges(old_len, self.GetNumberRows())
645    
646    
647    ID_CLASSIFY_OK = 4001
648    ID_CLASSIFY_CANCEL = 4002
649    ID_CLASSIFY_ADD = 4003
650    ID_CLASSIFY_GENCLASS = 4004
651    ID_CLASSIFY_REMOVE = 4005
652    ID_CLASSIFY_MOVEUP = 4006
653    ID_CLASSIFY_MOVEDOWN = 4007
654    ID_CLASSIFY_APPLY = 4008
655    ID_CLASSIFY_EDITPROPS = 4009
656    ID_CLASSIFY_CLOSE = 4010
657    
658    BTN_ADD = 0
659    BTN_EDIT = 1
660    BTN_GEN = 2
661    BTN_UP = 3
662    BTN_DOWN = 4
663    BTN_RM = 5
664    
665  class Classifier(NonModalDialog):  class Classifier(NonModalDialog):
666    
667        type2string = {None:             _("None"),
668                       FIELDTYPE_STRING: _("Text"),
669                       FIELDTYPE_INT:    _("Integer"),
670                       FIELDTYPE_DOUBLE: _("Decimal")}
671    
672      def __init__(self, parent, name, layer, group = None):      def __init__(self, parent, name, layer, group = None):
673          NonModalDialog.__init__(self, parent, name,          NonModalDialog.__init__(self, parent, name,
674                                  _("Classifier: %s") % layer.Title())                                  _("Classifier: %s") % layer.Title())
# Line 677  class Classifier(NonModalDialog): Line 681  class Classifier(NonModalDialog):
681          field = self.originalClass.GetField()          field = self.originalClass.GetField()
682          fieldType = self.originalClass.GetFieldType()          fieldType = self.originalClass.GetFieldType()
683    
684            self.genDlg = None
685    
686          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
687          panelBox = wxBoxSizer(wxVERTICAL)          panelBox = wxBoxSizer(wxVERTICAL)
688    
# Line 707  class Classifier(NonModalDialog): Line 713  class Classifier(NonModalDialog):
713    
714              if name == field:              if name == field:
715                  self.__cur_field = i + 1                  self.__cur_field = i + 1
716                  self.fields.SetClientData(i + 1, self.originalClass)                  self.fields.SetClientData(i + 1,
717                                              copy.deepcopy(self.originalClass))
718              else:              else:
719                  self.fields.SetClientData(i + 1, None)                  self.fields.SetClientData(i + 1, None)
720    
# Line 779  class Classifier(NonModalDialog): Line 786  class Classifier(NonModalDialog):
786    
787          # calling __SelectField after creating the classGrid fills in the          # calling __SelectField after creating the classGrid fills in the
788          # grid with the correct information          # grid with the correct information
789          #print "2------------------"          self.fields.SetSelection(self.__cur_field)
790          self.__SelectField(self.__cur_field, group = group)          self.__SelectField(self.__cur_field, group = group)
791    
792          #self.classGrid.SelectGroup(group)          #self.classGrid.SelectGroup(group)
# Line 807  class Classifier(NonModalDialog): Line 814  class Classifier(NonModalDialog):
814          buttonBox.Add(wxButton(panel, ID_CLASSIFY_APPLY, _("Apply")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_APPLY, _("Apply")),
815                        0, wxALL, 4)                        0, wxALL, 4)
816          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
817            buttonBox.Add(wxButton(panel, ID_CLASSIFY_CLOSE, _("Close")),
818                          0, wxALL, 4)
819            buttonBox.Add(60, 20, 0, wxALL, 4)
820          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CANCEL, _("Cancel")),          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CANCEL, _("Cancel")),
821                        0, wxALL, 4)                        0, wxALL, 4)
822          panelBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)          panelBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)
823    
824          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)
825          EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply)          EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply)
826            EVT_BUTTON(self, ID_CLASSIFY_CLOSE, self._OnCloseBtn)
827          EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel)          EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel)
828    
829          ###########          ###########
# Line 827  class Classifier(NonModalDialog): Line 838  class Classifier(NonModalDialog):
838          self.SetAutoLayout(True)          self.SetAutoLayout(True)
839          self.SetSizer(topBox)          self.SetSizer(topBox)
840    
         #print "1------------------"  
841          #self.Fit()          #self.Fit()
842          ######################          ######################
843    
# Line 840  class Classifier(NonModalDialog): Line 850  class Classifier(NonModalDialog):
850          # get a new ClassGroupProperties object and copy the          # get a new ClassGroupProperties object and copy the
851          # values over to our current object          # values over to our current object
852          propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType())          propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType())
853    
854            self.Enable(False)
855          if propDlg.ShowModal() == wxID_OK:          if propDlg.ShowModal() == wxID_OK:
856              new_prop = propDlg.GetClassGroupProperties()              new_prop = propDlg.GetClassGroupProperties()
857              table.SetValueAsCustom(row, COL_SYMBOL, None, new_prop)              table.SetValueAsCustom(row, COL_SYMBOL, None, new_prop)
858            self.Enable(True)
859          propDlg.Destroy()          propDlg.Destroy()
860                    
861        def _SetClassification(self, clazz):
862            
863            self.fields.SetClientData(self.__cur_field, clazz)
864            self.classGrid.GetTable().SetClassification(clazz)
865    
866      def __BuildClassification(self, fieldIndex):      def __BuildClassification(self, fieldIndex, copyClass = False):
867    
868          numRows = self.classGrid.GetNumberRows()  #       numRows = self.classGrid.GetNumberRows()
869          assert numRows > 0  # there should always be a default row  #       assert numRows > 0  # there should always be a default row
870    
871          clazz = Classification()  #       clazz = Classification()
872          if fieldIndex == 0:          if fieldIndex == 0:
873              fieldName = None              fieldName = None
874              fieldType = None              fieldType = None
# Line 859  class Classifier(NonModalDialog): Line 876  class Classifier(NonModalDialog):
876              fieldName = self.fields.GetString(fieldIndex)              fieldName = self.fields.GetString(fieldIndex)
877              fieldType = self.layer.GetFieldType(fieldName)              fieldType = self.layer.GetFieldType(fieldName)
878    
879            clazz = self.classGrid.GetTable().GetClassification()
880    
881            if copyClass:
882                clazz = copy.deepcopy(clazz)
883    
884          clazz.SetField(fieldName)          clazz.SetField(fieldName)
885          clazz.SetFieldType(fieldType)          clazz.SetFieldType(fieldType)
886    
887    
888          table = self.classGrid.GetTable()  #       table = self.classGrid.GetTable()
889          clazz.SetDefaultGroup(table.GetClassGroup(0))  #       clazz.SetDefaultGroup(table.GetClassGroup(0))
890    
891          for i in range(1, numRows):  #       for i in range(1, numRows):
892              clazz.AddGroup(table.GetClassGroup(i))  #           clazz.AppendGroup(table.GetClassGroup(i))
893    
894          return clazz          return clazz
895    
# Line 886  class Classifier(NonModalDialog): Line 908  class Classifier(NonModalDialog):
908              fieldType = self.layer.GetFieldType(fieldName)              fieldType = self.layer.GetFieldType(fieldName)
909              clazz.SetFieldType(fieldType)              clazz.SetFieldType(fieldType)
910                                    
         #print "6------------------"  
911          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")}  
912    
913      def __SetFieldTypeText(self, fieldIndex):      def __SetFieldTypeText(self, fieldIndex):
914          fieldName = self.fields.GetString(fieldIndex)          fieldName = self.fields.GetString(fieldIndex)
# Line 908  class Classifier(NonModalDialog): Line 921  class Classifier(NonModalDialog):
921          self.fieldTypeText.SetLabel(_("Field Type: %s") % text)          self.fieldTypeText.SetLabel(_("Field Type: %s") % text)
922    
923      def __SelectField(self, newIndex, oldIndex = -1, group = None):      def __SelectField(self, newIndex, oldIndex = -1, group = None):
924            """This method assumes that the current selection for the
925          #print "3------------------"          combo has already been set by a call to SetSelection().
926            """
927    
928          assert oldIndex >= -1          assert oldIndex >= -1
929    
         self.fields.SetSelection(newIndex)  
   
930          if oldIndex != -1:          if oldIndex != -1:
931              clazz = self.__BuildClassification(oldIndex)              clazz = self.__BuildClassification(oldIndex)
932              self.fields.SetClientData(oldIndex, clazz)              self.fields.SetClientData(oldIndex, clazz)
933    
         #print "4------------------"  
934          self.__SetGridTable(newIndex, group)          self.__SetGridTable(newIndex, group)
         #print "5------------------"  
935    
936          enabled = newIndex != 0          enabled = newIndex != 0
937    
# Line 954  class Classifier(NonModalDialog): Line 964  class Classifier(NonModalDialog):
964          # to begin with or it has been modified          # to begin with or it has been modified
965          #          #
966          if clazz is None or self.classGrid.GetTable().IsModified():          if clazz is None or self.classGrid.GetTable().IsModified():
967              clazz = self.__BuildClassification(self.__cur_field)              clazz = self.__BuildClassification(self.__cur_field, True)
968    
969          self.layer.SetClassification(clazz)          self.layer.SetClassification(clazz)
970    
# Line 962  class Classifier(NonModalDialog): Line 972  class Classifier(NonModalDialog):
972    
973      def _OnOK(self, event):      def _OnOK(self, event):
974          self._OnApply(event)          self._OnApply(event)
975          self.OnClose(event)          self.Close()
976    
977        def _OnCloseBtn(self, event):
978            """Close is similar to Cancel except that any changes that were
979            made and applied remain applied, but the currently displayed
980            classification is discarded.
981            """
982    
983            self.Close()
984    
985      def _OnCancel(self, event):      def _OnCancel(self, event):
986          """The layer's current classification stays the same."""          """The layer's current classification stays the same."""
987          if self.haveApplied:          if self.haveApplied:
988              self.layer.SetClassification(self.originalClass)              self.layer.SetClassification(self.originalClass)
989    
990          self.OnClose(event)          self.Close()
991    
992      def _OnAdd(self, event):      def _OnAdd(self, event):
993          self.classGrid.AppendRows()          self.classGrid.AppendRows()
# Line 979  class Classifier(NonModalDialog): Line 997  class Classifier(NonModalDialog):
997    
998      def _OnGenClass(self, event):      def _OnGenClass(self, event):
999    
1000          genDlg = ClassGenDialog(self,          #if self.genDlg is None:
1001                                  self.layer.table,          self.genDlg = ClassGenDialog(self, self.layer,
1002                                  self.fields.GetString(self.__cur_field))                            self.fields.GetString(self.__cur_field))
1003    
1004          if genDlg.ShowModal() == wxID_OK:          EVT_CLOSE(self.genDlg, self._OnGenDialogClose)
1005              clazz = genDlg.GetClassification()  
1006              self.fields.SetClientData(self.__cur_field, clazz)          self.fields.Enable(False)
1007              self.classGrid.GetTable().SetClassification(clazz)          self.controlButtons[BTN_EDIT].Enable(False)
1008          genDlg.Destroy()          self.controlButtons[BTN_GEN].Enable(False)
1009    
1010            self.genDlg.Show()
1011            #if self.genDlg.ShowModal() == wxID_OK:
1012            #    clazz = self.genDlg.GetClassification()
1013            #    self.fields.SetClientData(self.__cur_field, clazz)
1014            #    self.classGrid.GetTable().SetClassification(clazz)
1015            #self.Enable(True)
1016            #self.genDlg.Destroy()
1017    
1018        def _OnGenDialogClose(self, event):
1019            self.genDlg.Destroy()
1020    
1021            self.fields.Enable(True)
1022            self.controlButtons[BTN_EDIT].Enable(True)
1023            self.controlButtons[BTN_GEN].Enable(True)
1024    
1025      def _OnMoveUp(self, event):      def _OnMoveUp(self, event):
1026          sel = self.classGrid.GetCurrentSelection()          sel = self.classGrid.GetCurrentSelection()
1027    
         #print "sel: ", sel  
   
1028          if len(sel) == 1:          if len(sel) == 1:
1029              i = sel[0]              i = sel[0]
1030              if i > 1:              if i > 1:
# Line 1047  class SelectPropertiesDialog(wxDialog): Line 1078  class SelectPropertiesDialog(wxDialog):
1078          previewBox = wxBoxSizer(wxVERTICAL)          previewBox = wxBoxSizer(wxVERTICAL)
1079          previewBox.Add(wxStaticText(self, -1, _("Preview:")),          previewBox.Add(wxStaticText(self, -1, _("Preview:")),
1080              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
1081          self.previewWin = ClassDataPreviewWindow(None, self.prop, shapeType,  
1082                                              self, ID_SELPROP_PREVIEW, (40, 40))          self.previewWin = ClassGroupPropertiesCtrl(
1083          previewBox.Add(self.previewWin, 1, wxGROW, 15)              self, ID_SELPROP_PREVIEW, self.prop, shapeType,
1084                (40, 40), wxSIMPLE_BORDER)
1085    
1086            self.previewWin.AllowEdit(False)
1087    
1088            previewBox.Add(self.previewWin, 1, wxGROW | wxALL, 4)
1089    
1090          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)
1091    
# Line 1180  class ClassDataPreviewWindow(wxWindow): Line 1216  class ClassDataPreviewWindow(wxWindow):
1216          self.shapeType = shapeType          self.shapeType = shapeType
1217          self.previewer = ClassDataPreviewer()          self.previewer = ClassDataPreviewer()
1218    
1219        def GetProperties():
1220            return self.prop
1221    
1222      def _OnPaint(self, event):      def _OnPaint(self, event):
1223          dc = wxPaintDC(self)          dc = wxPaintDC(self)
1224    
# Line 1263  class ClassRenderer(wxPyGridCellRenderer Line 1302  class ClassRenderer(wxPyGridCellRenderer
1302              self.previewer.Draw(dc, rect, data.GetProperties(), self.shapeType)              self.previewer.Draw(dc, rect, data.GetProperties(), self.shapeType)
1303    
1304          if isSelected:          if isSelected:
1305              dc.SetPen(wxPen(wxColour(0 * 255, 0 * 255, 0 * 255),              dc.SetPen(wxPen(wxBLACK, 1, wxSOLID))
                       4, wxSOLID))  
1306              dc.SetBrush(wxTRANSPARENT_BRUSH)              dc.SetBrush(wxTRANSPARENT_BRUSH)
1307    
1308              dc.DrawRectangle(rect.GetX(), rect.GetY(),              dc.DrawRectangle(rect.GetX(), rect.GetY(),
1309                               rect.GetWidth(), rect.GetHeight())                               rect.GetWidth(), rect.GetHeight())
1310    
1311          dc.DestroyClippingRegion()          dc.DestroyClippingRegion()
1312    
1313    
1314    class ClassGroupPropertiesCtrl(wxWindow, wxControl):
1315    
1316        def __init__(self, parent, id, props, shapeType,
1317                     size = wxDefaultSize, style = 0):
1318    
1319            wxWindow.__init__(self, parent, id, size = size, style = style)
1320    
1321            self.SetProperties(props)
1322            self.SetShapeType(shapeType)
1323            self.AllowEdit(True)
1324    
1325            EVT_PAINT(self, self._OnPaint)
1326            EVT_LEFT_DCLICK(self, self._OnLeftDClick)
1327    
1328            self.previewer = ClassDataPreviewer()
1329    
1330        def _OnPaint(self, event):
1331            dc = wxPaintDC(self)
1332    
1333            # XXX: this doesn't seem to be having an effect:
1334            dc.DestroyClippingRegion()
1335    
1336            w, h = self.GetClientSize()
1337    
1338            self.previewer.Draw(dc,
1339                                wxRect(0, 0, w, h),
1340                                self.GetProperties(),
1341                                self.GetShapeType())
1342    
1343    
1344        def GetProperties(self):
1345            return self.props
1346    
1347        def SetProperties(self, props):
1348            self.props = props
1349            self.Refresh()
1350    
1351        def GetShapeType(self):
1352            return self.shapeType
1353    
1354        def SetShapeType(self, shapeType):
1355            self.shapeType = shapeType
1356            self.Refresh()
1357    
1358        def AllowEdit(self, allow):
1359            self.allowEdit = allow
1360    
1361        def DoEdit(self):
1362            if not self.allowEdit: return
1363    
1364            propDlg = SelectPropertiesDialog(NULL,
1365                                             self.GetProperties(),
1366                                             self.GetShapeType())
1367    
1368            if propDlg.ShowModal() == wxID_OK:
1369                new_prop = propDlg.GetClassGroupProperties()
1370                self.SetProperties(new_prop)
1371                self.Refresh()
1372    
1373            propDlg.Destroy()
1374    
1375        def _OnLeftDClick(self, event):
1376            self.DoEdit()

Legend:
Removed from v.610  
changed lines
  Added in v.630

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26