/[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 877 by bh, Tue May 6 15:52:41 2003 UTC revision 878 by jonathan, Fri May 9 16:32:31 2003 UTC
# Line 18  from wxPython.wx import * Line 18  from wxPython.wx import *
18  from wxPython.grid import *  from wxPython.grid import *
19    
20  from Thuban import _  from Thuban import _
21  from Thuban.UI.common import *  from Thuban.UI.common import Color2wxColour, wxColour2Color
22    
23  from Thuban.Model.classification import *  from Thuban.Model.range import Range
24    from Thuban.Model.classification import \
25        Classification, ClassGroupDefault, \
26        ClassGroupSingleton, ClassGroupRange, ClassGroupMap, \
27        ClassGroupProperties
28    
29  from Thuban.Model.color import Color  from Thuban.Model.color import Color
30    
31  from Thuban.Model.layer import Layer, SHAPETYPE_ARC, SHAPETYPE_POLYGON, SHAPETYPE_POINT  from Thuban.Model.layer import Layer, \
32        SHAPETYPE_ARC, SHAPETYPE_POLYGON, SHAPETYPE_POINT
33    
34  from Thuban.UI.classgen import ClassGenDialog, ClassGenerator  from Thuban.UI.classgen import ClassGenDialog, ClassGenerator
35    
# Line 243  class ClassGrid(wxGrid): Line 248  class ClassGrid(wxGrid):
248    
249      def _OnCellResize(self, event):      def _OnCellResize(self, event):
250          self.FitInside()          self.FitInside()
251            event.Skip()
252    
253  class ClassTable(wxPyGridTableBase):  class ClassTable(wxPyGridTableBase):
254      """Represents the underlying data structure for the grid."""      """Represents the underlying data structure for the grid."""
# Line 457  class ClassTable(wxPyGridTableBase): Line 463  class ClassTable(wxPyGridTableBase):
463          elif isinstance(group, ClassGroupSingleton):          elif isinstance(group, ClassGroupSingleton):
464              return group.GetValue()              return group.GetValue()
465          elif isinstance(group, ClassGroupRange):          elif isinstance(group, ClassGroupRange):
466              return _("%s - %s") % (group.GetMin(), group.GetMax())              return group.GetRange()
467    
468          assert(False) # shouldn't get here          assert False # shouldn't get here
469          return None          return None
470    
471      def __ParseInput(self, value):      def __ParseInput(self, value):
472          """Try to determine what kind of input value is          """Try to determine what kind of input value is
473             (string, number, or range)             (string, number, or range)
474    
475          Returns a tuple of length one if there is a single          Returns a tuple (type, data) where type is 0 if data is
476          value, or of length two if it is a range.          a singleton value, or 1 if is a range
477          """          """
478    
479          type = self.fieldType          type = self.fieldType
480    
481          if type == FIELDTYPE_STRING:          if type == FIELDTYPE_STRING:
482              return (value,)              return (0, value)
483          elif type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):          elif type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):
   
484              if type == FIELDTYPE_INT:              if type == FIELDTYPE_INT:
485                  # the float call allows the user to enter 1.0 for 1                  # the float call allows the user to enter 1.0 for 1
486                  conv = lambda p: int(float(p))                  conv = lambda p: int(float(p))
487              else:              else:
488                  conv = lambda p: p                  conv = float
489    
490              #              #
491              # first try to take the input as a single number              # first try to take the input as a single number
492              # if there's an exception try to break it into              # if there's an exception try to break it into
493              # a range seperated by a '-'. take care to ignore              # a range. if there is an exception here, let it
494              # a leading '-' as that could be for a negative number.              # pass up to the calling function.
             # then try to parse the individual parts. if there  
             # is an exception here, let it pass up to the calling  
             # function.  
495              #              #
496              try:              try:
497                  return (conv(value),)                  return (0, conv(value))
498              except ValueError:              except ValueError:
499                  i = value.find('-')                  return (1, Range(value))
                 if i == 0:  
                     i = value.find('-', 1)  
   
                 return (conv(value[:i]), conv(value[i+1:]))  
500    
501          assert False  # shouldn't get here          assert False  # shouldn't get here
502          return (0,)          return (0,None)
               
503    
504      def SetValueAsCustom(self, row, col, typeName, value):      def SetValueAsCustom(self, row, col, typeName, value):
505          """Set the cell specified by 'row' and 'col' to 'value'.          """Set the cell specified by 'row' and 'col' to 'value'.
# Line 556  class ClassTable(wxPyGridTableBase): Line 553  class ClassTable(wxPyGridTableBase):
553                      # changing the underlying group type if the                      # changing the underlying group type if the
554                      # group was a singleton and a range was entered                      # group was a singleton and a range was entered
555                      #                      #
556                      if len(dataInfo) == 1:                      if dataInfo[0] == 0:
557                          if not isinstance(group, ClassGroupSingleton):                          if not isinstance(group, ClassGroupSingleton):
558                              ngroup = ClassGroupSingleton(props = props)                              ngroup = ClassGroupSingleton(props = props)
559                              changed = True                              changed = True
560                          ngroup.SetValue(dataInfo[0])                          ngroup.SetValue(dataInfo[1])
561                      elif len(dataInfo) == 2:                      elif dataInfo[0] == 1:
562                          if not isinstance(group, ClassGroupRange):                          if not isinstance(group, ClassGroupRange):
563                              ngroup = ClassGroupRange(props = props)                              ngroup = ClassGroupRange(props = props)
564                              changed = True                              changed = True
565                          ngroup.SetRange(dataInfo[0], dataInfo[1])                          ngroup.SetRange(dataInfo[1])
566                      else:                      else:
567                          assert False                          assert False
568                          pass                          pass
# Line 970  class Classifier(NonModalDialog): Line 967  class Classifier(NonModalDialog):
967          # only build the classification if there wasn't one to          # only build the classification if there wasn't one to
968          # to begin with or it has been modified          # to begin with or it has been modified
969          #          #
970            self.classGrid.SaveEditControlValue()
971          if clazz is None or self.classGrid.GetTable().IsModified():          if clazz is None or self.classGrid.GetTable().IsModified():
972              clazz = self.__BuildClassification(self.__cur_field, True)              clazz = self.__BuildClassification(self.__cur_field, True)
973    

Legend:
Removed from v.877  
changed lines
  Added in v.878

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26