/[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 615 by jonathan, Mon Apr 7 08:57:20 2003 UTC revision 661 by jonathan, Mon Apr 14 14:16:00 2003 UTC
# Line 31  from Thuban.UI.classgen import ClassGenD Line 31  from Thuban.UI.classgen import ClassGenD
31    
32  from dialogs import NonModalDialog  from dialogs import NonModalDialog
33    
 # widget id's  
 ID_PROPERTY_SELECT = 4010  
34  ID_CLASS_TABLE = 40011  ID_CLASS_TABLE = 40011
35    
 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  
36    
37  # table columns  # table columns
38  COL_SYMBOL = 0  COL_VISIBLE = 0
39  COL_VALUE  = 1  COL_SYMBOL  = 1
40  COL_LABEL  = 2  COL_VALUE   = 2
41    COL_LABEL   = 3
42    NUM_COLS    = 4
43    
44  # indices into the client data lists in Classifier.fields  # indices into the client data lists in Classifier.fields
45  FIELD_CLASS = 0  FIELD_CLASS = 0
# Line 73  class ClassGrid(wxGrid): Line 63  class ClassGrid(wxGrid):
63                   use for display.                   use for display.
64          """          """
65    
         #wxGrid.__init__(self, parent, ID_CLASS_TABLE, size = (340, 160))  
66          wxGrid.__init__(self, parent, ID_CLASS_TABLE)          wxGrid.__init__(self, parent, ID_CLASS_TABLE)
         #self.SetTable(ClassTable(fieldData, layer.ShapeType(), self), True)  
67    
68          self.classifier = classifier          self.classifier = classifier
69    
# Line 87  class ClassGrid(wxGrid): Line 75  class ClassGrid(wxGrid):
75          EVT_GRID_COL_SIZE(self, self._OnCellResize)          EVT_GRID_COL_SIZE(self, self._OnCellResize)
76          EVT_GRID_ROW_SIZE(self, self._OnCellResize)          EVT_GRID_ROW_SIZE(self, self._OnCellResize)
77    
78          #print "123123123: ", ('Show' in dir(self))      #def GetCellAttr(self, row, col):
79            #print "GetCellAttr ", row, col
80      #def Show(self):          #wxGrid.GetCellAttr(self, row, col)
         #print "SHOW!"  
   
     #def Refresh(self):  
         #self.Show()  
     #def Update(self):  
         #self.Show()  
81    
82      def CreateTable(self, clazz, shapeType, group = None):      def CreateTable(self, clazz, shapeType, group = None):
83    
# Line 103  class ClassGrid(wxGrid): Line 85  class ClassGrid(wxGrid):
85    
86          table = self.GetTable()          table = self.GetTable()
87          if table is None:          if table is None:
88              w = self.GetDefaultColSize() * 3 + self.GetDefaultRowLabelSize()              w = self.GetDefaultColSize() * NUM_COLS \
89              h = self.GetDefaultRowSize() * 4 + self.GetDefaultColLabelSize()                  + self.GetDefaultRowLabelSize()
90                h = self.GetDefaultRowSize() * 4 \
91                    + self.GetDefaultColLabelSize()
92    
93              self.SetDimensions(-1, -1, w, h)              self.SetDimensions(-1, -1, w, h)
94              self.SetSizeHints(w, h, -1, -1)              self.SetSizeHints(w, h, -1, -1)
95              table = ClassTable(self)              table = ClassTable(self)
# Line 114  class ClassGrid(wxGrid): Line 99  class ClassGrid(wxGrid):
99          self.SetSelectionMode(wxGrid.wxGridSelectRows)          self.SetSelectionMode(wxGrid.wxGridSelectRows)
100          self.ClearSelection()          self.ClearSelection()
101    
         #print "8------------------"  
102          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)  
103    
104      def GetCurrentSelection(self):      def GetCurrentSelection(self):
105          """Return the currently highlighted rows as an increasing list          """Return the currently highlighted rows as an increasing list
106             of row numbers."""             of row numbers."""
         #print "@@ ", self.currentSelection  
107          sel = copy.copy(self.currentSelection)          sel = copy.copy(self.currentSelection)
108          sel.sort()          sel.sort()
109          return sel          return sel
# Line 140  class ClassGrid(wxGrid): Line 111  class ClassGrid(wxGrid):
111      def GetSelectedRows(self):      def GetSelectedRows(self):
112          return self.GetCurrentSelection()          return self.GetCurrentSelection()
113    
114      def SetCellRenderer(self, row, col):      #def SetCellRenderer(self, row, col, renderer):
115          raise ValueError(_("Must not allow setting of renderer in ClassGrid!"))          #raise ValueError(_("Must not allow setting of renderer in ClassGrid!"))
116    
117      #      #
118      # [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 187  class ClassGrid(wxGrid):
187    
188          assert table is not None          assert table is not None
189    
   
         #print "-- ", group  
190          for i in range(table.GetNumberRows()):          for i in range(table.GetNumberRows()):
191              g = table.GetClassGroup(i)              g = table.GetClassGroup(i)
             #print "1", g  
192              if g is group:              if g is group:
                 #print "2"  
193                  self.SelectRow(i)                  self.SelectRow(i)
194                  if makeVisible:                  if makeVisible:
                     #print "3"  
195                      self.MakeCellVisible(i, 0)                      self.MakeCellVisible(i, 0)
196                  break                  break
197    
           
   
198  #  #
199  # 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!
200  #  #
# Line 243  class ClassGrid(wxGrid): Line 207  class ClassGrid(wxGrid):
207  #                                  sel = False))  #                                  sel = False))
208    
209      def _OnCellDClick(self, event):      def _OnCellDClick(self, event):
210          """Handle a double on a cell."""          """Handle a double click on a cell."""
211    
212          r = event.GetRow()          r = event.GetRow()
213          c = event.GetCol()          c = event.GetCol()
         if c == COL_SYMBOL:  
             self.classifier.EditGroupProperties(r)  
214    
215            if c == COL_SYMBOL:
216                self.classifier.EditSymbol(r)
217            else:
218                event.Skip()
219    
220      #      #
221      # _OnSelectedRange() and _OnSelectedCell() were borrowed      # _OnSelectedRange() and _OnSelectedCell() were borrowed
# Line 261  class ClassGrid(wxGrid): Line 227  class ClassGrid(wxGrid):
227          if event.Selecting():          if event.Selecting():
228              for index in range( event.GetTopRow(), event.GetBottomRow()+1):              for index in range( event.GetTopRow(), event.GetBottomRow()+1):
229                  if index not in self.currentSelection:                  if index not in self.currentSelection:
                     #print "    ", index  
230                      self.currentSelection.append( index )                      self.currentSelection.append( index )
231          else:          else:
232              for index in range( event.GetTopRow(), event.GetBottomRow()+1):              for index in range( event.GetTopRow(), event.GetBottomRow()+1):
233                  while index in self.currentSelection:                  while index in self.currentSelection:
                     #print "    ", index  
234                      self.currentSelection.remove( index )                      self.currentSelection.remove( index )
235          #self.ConfigureForSelection()          #self.ConfigureForSelection()
236    
         #print self.GetCurrentSelection()  
237          event.Skip()          event.Skip()
238    
239      def _OnSelectedCell( self, event ):      def _OnSelectedCell( self, event ):
240          """Internal update to the selection tracking list"""          """Internal update to the selection tracking list"""
         #print "selecting cell: ", event.GetRow()  
241          self.currentSelection = [ event.GetRow() ]          self.currentSelection = [ event.GetRow() ]
242          #self.ConfigureForSelection()          #self.ConfigureForSelection()
243          event.Skip()          event.Skip()
# Line 286  class ClassGrid(wxGrid): Line 248  class ClassGrid(wxGrid):
248  class ClassTable(wxPyGridTableBase):  class ClassTable(wxPyGridTableBase):
249      """Represents the underlying data structure for the grid."""      """Represents the underlying data structure for the grid."""
250    
251      NUM_COLS = 3      __col_labels = [_("Visible"), _("Symbol"), _("Value"), _("Label")]
   
     __col_labels = [_("Symbol"), _("Value"), _("Label")]  
252    
253    
254      def __init__(self, view = None):      def __init__(self, view = None):
# Line 302  class ClassTable(wxPyGridTableBase): Line 262  class ClassTable(wxPyGridTableBase):
262    
263          wxPyGridTableBase.__init__(self)          wxPyGridTableBase.__init__(self)
264    
265          self.SetView(view)          assert len(ClassTable.__col_labels) == NUM_COLS
266    
267          self.clazz = None          self.clazz = None
268            self.__colAttr = {}
269    
270          #self.Reset(clazz, shapeType)          self.SetView(view)
271    
272      def Reset(self, clazz, shapeType, group = None):      def Reset(self, clazz, shapeType, group = None):
273          """Reset the table with the given data.          """Reset the table with the given data.
# Line 330  class ClassTable(wxPyGridTableBase): Line 292  class ClassTable(wxPyGridTableBase):
292    
293          self.SetClassification(clazz, group)          self.SetClassification(clazz, group)
294          self.__Modified(-1)          self.__Modified(-1)
295          #print "11------------------"  
296            self.__colAttr = {}
297    
298            attr = wxGridCellAttr()
299            attr.SetEditor(wxGridCellBoolEditor())
300            attr.SetRenderer(wxGridCellBoolRenderer())
301            attr.SetAlignment(wxALIGN_CENTER, wxALIGN_CENTER)
302            self.__colAttr[COL_VISIBLE] = attr
303    
304            attr = wxGridCellAttr()
305            attr.SetRenderer(ClassRenderer(self.shapeType))
306            attr.SetReadOnly()
307            self.__colAttr[COL_SYMBOL] = attr
308    
309          self.GetView().EndBatch()          self.GetView().EndBatch()
310          self.GetView().FitInside()          self.GetView().FitInside()
# Line 344  class ClassTable(wxPyGridTableBase): Line 318  class ClassTable(wxPyGridTableBase):
318    
319          old_len = self.GetNumberRows()          old_len = self.GetNumberRows()
320    
         #print "9------------------"  
         #  
         # copy the data out of the classification and into our  
         # array  
         #  
321          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)  
322          self.clazz = clazz          self.clazz = clazz
323    
324          self.__NotifyRowChanges(old_len, self.GetNumberRows())          self.__NotifyRowChanges(old_len, self.GetNumberRows())
325    
326            #
327            # XXX: this is dead code at the moment
328            #
329          if row > -1:          if row > -1:
330              self.GetView().ClearSelection()              self.GetView().ClearSelection()
331              self.GetView().SelectRow(row)              self.GetView().SelectRow(row)
# Line 371  class ClassTable(wxPyGridTableBase): Line 333  class ClassTable(wxPyGridTableBase):
333    
334          self.__Modified()          self.__Modified()
335    
336    
337          self.GetView().EndBatch()          self.GetView().EndBatch()
338          self.GetView().FitInside()          self.GetView().FitInside()
339    
# Line 446  class ClassTable(wxPyGridTableBase): Line 409  class ClassTable(wxPyGridTableBase):
409    
410      def GetNumberCols(self):      def GetNumberCols(self):
411          """Return the number of columns."""          """Return the number of columns."""
412          return self.NUM_COLS          return NUM_COLS
413    
414      def IsEmptyCell(self, row, col):      def IsEmptyCell(self, row, col):
415          """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 427  class ClassTable(wxPyGridTableBase):
427          """          """
428    
429          self.SetValueAsCustom(row, col, None, value)          self.SetValueAsCustom(row, col, None, value)
         self.__Modified()  
430                
431      def GetValueAsCustom(self, row, col, typeName):      def GetValueAsCustom(self, row, col, typeName):
432          """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 441  class ClassTable(wxPyGridTableBase):
441              group = self.clazz.GetGroup(row - 1)              group = self.clazz.GetGroup(row - 1)
442    
443    
444            if col == COL_VISIBLE:
445                return group.IsVisible()
446    
447          if col == COL_SYMBOL:          if col == COL_SYMBOL:
448              return group.GetProperties()              return group.GetProperties()
449    
# Line 510  class ClassTable(wxPyGridTableBase): Line 475  class ClassTable(wxPyGridTableBase):
475    
476          if type == FIELDTYPE_STRING:          if type == FIELDTYPE_STRING:
477              return (value,)              return (value,)
478          elif type == FIELDTYPE_INT or type == FIELDTYPE_DOUBLE:          elif type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):
479    
480              if type == FIELDTYPE_INT:              if type == FIELDTYPE_INT:
481                  conv = lambda p: int(float(p))                  conv = lambda p: int(float(p))
# Line 551  class ClassTable(wxPyGridTableBase): Line 516  class ClassTable(wxPyGridTableBase):
516          typeName -- unused, but needed to overload wxPyGridTableBase          typeName -- unused, but needed to overload wxPyGridTableBase
517          """          """
518    
519          assert col >= 0 and col < self.GetNumberCols()          assert 0 <= col < self.GetNumberCols()
520          assert row >= 0 and row < self.GetNumberRows()          assert 0 <= row < self.GetNumberRows()
521    
522          if row == 0:          if row == 0:
523              group = self.clazz.GetDefaultGroup()              group = self.clazz.GetDefaultGroup()
# Line 561  class ClassTable(wxPyGridTableBase): Line 526  class ClassTable(wxPyGridTableBase):
526    
527          mod = True # assume the data will change          mod = True # assume the data will change
528    
529          if col == COL_SYMBOL:          if col == COL_VISIBLE:
530                group.SetVisible(value)
531            elif col == COL_SYMBOL:
532              group.SetProperties(value)              group.SetProperties(value)
533          elif col == COL_LABEL:          elif col == COL_LABEL:
534              group.SetLabel(value)              group.SetLabel(value)
# Line 617  class ClassTable(wxPyGridTableBase): Line 584  class ClassTable(wxPyGridTableBase):
584      def GetAttr(self, row, col, someExtraParameter):      def GetAttr(self, row, col, someExtraParameter):
585          """Returns the cell attributes"""          """Returns the cell attributes"""
586    
587          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  
588    
589      def GetClassGroup(self, row):      def GetClassGroup(self, row):
590          """Return the ClassGroup object representing row 'row'."""          """Return the ClassGroup object representing row 'row'."""
# Line 692  class ClassTable(wxPyGridTableBase): Line 650  class ClassTable(wxPyGridTableBase):
650              self.__NotifyRowChanges(old_len, self.GetNumberRows())              self.__NotifyRowChanges(old_len, self.GetNumberRows())
651    
652    
653    ID_PROPERTY_OK = 4001
654    ID_PROPERTY_REVERT = 4002
655    ID_PROPERTY_ADD = 4003
656    ID_PROPERTY_GENCLASS = 4004
657    ID_PROPERTY_REMOVE = 4005
658    ID_PROPERTY_MOVEUP = 4006
659    ID_PROPERTY_MOVEDOWN = 4007
660    ID_PROPERTY_TRY = 4008
661    ID_PROPERTY_EDITSYM = 4009
662    ID_PROPERTY_CLOSE = 4010
663    ID_PROPERTY_SELECT = 4011
664    ID_PROPERTY_TITLE = 4012
665    ID_PROPERTY_FIELDTEXT = 4013
666    
667    BTN_ADD = 0
668    BTN_EDIT = 1
669    BTN_GEN = 2
670    BTN_UP = 3
671    BTN_DOWN = 4
672    BTN_RM = 5
673    
674    EB_LAYER_TITLE = 0
675    EB_SELECT_FIELD = 1
676    EB_GEN_CLASS = 2
677    
678  class Classifier(NonModalDialog):  class Classifier(NonModalDialog):
679    
680        type2string = {None:             _("None"),
681                       FIELDTYPE_STRING: _("Text"),
682                       FIELDTYPE_INT:    _("Integer"),
683                       FIELDTYPE_DOUBLE: _("Decimal")}
684    
685      def __init__(self, parent, name, layer, group = None):      def __init__(self, parent, name, layer, group = None):
686          NonModalDialog.__init__(self, parent, name,          NonModalDialog.__init__(self, parent, name, "")
                                 _("Classifier: %s") % layer.Title())  
687    
688          panel = wxPanel(self, -1, size=(100, 100))          self.__SetTitle(layer.Title())
689    
690          self.layer = layer          self.layer = layer
691    
# Line 706  class Classifier(NonModalDialog): Line 693  class Classifier(NonModalDialog):
693          field = self.originalClass.GetField()          field = self.originalClass.GetField()
694          fieldType = self.originalClass.GetFieldType()          fieldType = self.originalClass.GetFieldType()
695    
696            self.genDlg = None
697    
698          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
699    
700            panel = wxPanel(self, -1, size=(100, 100))
701    
702          panelBox = wxBoxSizer(wxVERTICAL)          panelBox = wxBoxSizer(wxVERTICAL)
703    
704          #panelBox.Add(wxStaticText(panel, -1, _("Layer: %s") % layer.Title()),          sizer = wxBoxSizer(wxHORIZONTAL)
705              #0, wxALIGN_LEFT | wxALL, 4)          sizer.Add(wxStaticText(panel, -1, _("Title: ")),
706                0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 4)
707            sizer.Add(wxTextCtrl(panel, ID_PROPERTY_TITLE, layer.Title()),
708                      1, wxGROW | wxALL, 4)
709            EVT_TEXT(self, ID_PROPERTY_TITLE, self._OnTitleChanged)
710    
711            panelBox.Add(sizer, 0, wxGROW, 4)
712    
713          panelBox.Add(wxStaticText(panel, -1,          panelBox.Add(wxStaticText(panel, -1,
714                                  _("Layer Type: %s") % layer.ShapeType()),                                  _("Type: %s") % layer.ShapeType()),
715              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
716    
717    
718            #####################
719    
720            #panelBox = wxBoxSizer(wxVERTICAL)
721            classBox = wxStaticBoxSizer(
722                        wxStaticBox(panel, -1, _("Classification")), wxVERTICAL)
723    
724    
725          #          #
726          # make field combo box          # make field combo box
727          #          #
# Line 728  class Classifier(NonModalDialog): Line 734  class Classifier(NonModalDialog):
734          self.__cur_field = 0          self.__cur_field = 0
735    
736          self.fields.Append("<None>")          self.fields.Append("<None>")
737          self.fields.SetClientData(0, None)  
738            if self.originalClass.GetFieldType() is None:
739                self.fields.SetClientData(0, copy.deepcopy(self.originalClass))
740            else:
741                self.fields.SetClientData(0, None)
742    
743          for i in range(self.num_cols):          for i in range(self.num_cols):
744              type, name, len, decc = layer.table.field_info(i)              type, name, len, decc = layer.table.field_info(i)
# Line 744  class Classifier(NonModalDialog): Line 754  class Classifier(NonModalDialog):
754    
755          ###########          ###########
756    
         self.fieldTypeText = wxStaticText(panel, -1, "")  
         panelBox.Add(self.fieldTypeText, 0,  
                      wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4)  
757    
758          propertyBox = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
759          propertyBox.Add(wxStaticText(panel, -1, _("Field: ")),          sizer.Add(wxStaticText(panel, ID_PROPERTY_FIELDTEXT, _("Field: ")),
760              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 4)
761          propertyBox.Add(self.fields, 1, wxGROW|wxALL, 4)          sizer.Add(self.fields, 1, wxGROW | wxALL, 4)
762          EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect)          EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect)
763    
764          panelBox.Add(propertyBox, 0, wxGROW, 4)          classBox.Add(sizer, 0, wxGROW, 4)
765    
766            self.fieldTypeText = wxStaticText(panel, -1, "")
767            classBox.Add(self.fieldTypeText, 0,
768                         wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4)
769    
770    
771          #          #
# Line 767  class Classifier(NonModalDialog): Line 778  class Classifier(NonModalDialog):
778          #          #
779          # Control buttons:          # Control buttons:
780          #          #
         self.controlButtons = []  
   
781          controlButtonBox = wxBoxSizer(wxVERTICAL)          controlButtonBox = wxBoxSizer(wxVERTICAL)
782    
783          button = wxButton(panel, ID_CLASSIFY_ADD, _("Add"))          button = wxButton(panel, ID_PROPERTY_GENCLASS, _("Generate Class"))
784          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
785    
786          button = wxButton(panel, ID_CLASSIFY_EDITPROPS, _("Edit Properties"))          button = wxButton(panel, ID_PROPERTY_ADD, _("Add"))
787          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
788    
789          button = wxButton(panel, ID_CLASSIFY_GENCLASS, _("Generate Class"))          button = wxButton(panel, ID_PROPERTY_MOVEUP, _("Move Up"))
790          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
791    
792          button = wxButton(panel, ID_CLASSIFY_MOVEUP, _("Move Up"))          button = wxButton(panel, ID_PROPERTY_MOVEDOWN, _("Move Down"))
793          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
794    
795          button = wxButton(panel, ID_CLASSIFY_MOVEDOWN, _("Move Down"))          button = wxButton(panel, ID_PROPERTY_EDITSYM, _("Edit Symbol"))
796          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
797    
798          controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)          controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)
799    
800          button = wxButton(panel, ID_CLASSIFY_REMOVE, _("Remove"))          button = wxButton(panel, ID_PROPERTY_REMOVE, _("Remove"))
801          controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)
         self.controlButtons.append(button)  
802    
803    
804          ###########          ###########
# Line 804  class Classifier(NonModalDialog): Line 807  class Classifier(NonModalDialog):
807          #          #
808    
809          self.classGrid = ClassGrid(panel, self)          self.classGrid = ClassGrid(panel, self)
         #self.__SetGridTable(self.__cur_field, group)  
         #self.fields.SetSelection(self.__cur_field)  
810    
811          # calling __SelectField after creating the classGrid fills in the          # calling __SelectField after creating the classGrid fills in the
812          # grid with the correct information          # grid with the correct information
         #print "2------------------"  
813          self.fields.SetSelection(self.__cur_field)          self.fields.SetSelection(self.__cur_field)
814          self.__SelectField(self.__cur_field, group = group)          self.__SelectField(self.__cur_field, group = group)
815    
         #self.classGrid.SelectGroup(group)  
   
816          controlBox.Add(self.classGrid, 1, wxGROW, 0)          controlBox.Add(self.classGrid, 1, wxGROW, 0)
817            controlBox.Add(controlButtonBox, 0, wxGROW, 10)
818    
819            classBox.Add(controlBox, 1, wxGROW, 10)
820            panelBox.Add(classBox, 1, wxGROW, 0)
821    
822            EVT_BUTTON(self, ID_PROPERTY_ADD, self._OnAdd)
823            EVT_BUTTON(self, ID_PROPERTY_EDITSYM, self._OnEditSymbol)
824            EVT_BUTTON(self, ID_PROPERTY_REMOVE, self._OnRemove)
825            EVT_BUTTON(self, ID_PROPERTY_GENCLASS, self._OnGenClass)
826            EVT_BUTTON(self, ID_PROPERTY_MOVEUP, self._OnMoveUp)
827            EVT_BUTTON(self, ID_PROPERTY_MOVEDOWN, self._OnMoveDown)
828    
829          controlBox.Add(controlButtonBox, 0, wxGROW, 10)          ###########
         panelBox.Add(controlBox, 1, wxGROW, 10)  
830    
831          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)  
832          EVT_BUTTON(self, ID_CLASSIFY_EDITPROPS, self._OnEditGroupProperties)          panel.SetAutoLayout(True)
833          EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove)          panel.SetSizer(panelBox)
834          EVT_BUTTON(self, ID_CLASSIFY_GENCLASS, self._OnGenClass)          panelBox.SetSizeHints(panel)
835          EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp)  
836          EVT_BUTTON(self, ID_CLASSIFY_MOVEDOWN, self._OnMoveDown)          topBox.Add(panel, 1, wxGROW | wxALL, 4)
837    
838          ###########          ###########
839    
840          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
841          buttonBox.Add(wxButton(panel, ID_CLASSIFY_OK, _("OK")),          buttonBox.Add(wxButton(self, ID_PROPERTY_TRY, _("Try")),
842                        0, wxALL, 4)                        0, wxALL, 4)
843          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
844          buttonBox.Add(wxButton(panel, ID_CLASSIFY_APPLY, _("Apply")),          buttonBox.Add(wxButton(self, ID_PROPERTY_REVERT, _("Revert")),
845                        0, wxALL, 4)                        0, wxALL, 4)
846          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
847          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CLOSE, _("Close")),          buttonBox.Add(wxButton(self, ID_PROPERTY_OK, _("OK")),
848                        0, wxALL, 4)                        0, wxALL, 4)
849          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
850          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CANCEL, _("Cancel")),          buttonBox.Add(wxButton(self, ID_PROPERTY_CLOSE, _("Close")),
851                        0, wxALL, 4)                        0, wxALL, 4)
852          panelBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)
853    
854          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)          EVT_BUTTON(self, ID_PROPERTY_OK, self._OnOK)
855          EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply)          EVT_BUTTON(self, ID_PROPERTY_TRY, self._OnTry)
856          EVT_BUTTON(self, ID_CLASSIFY_CLOSE, self._OnCloseBtn)          EVT_BUTTON(self, ID_PROPERTY_CLOSE, self._OnCloseBtn)
857          EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel)          EVT_BUTTON(self, ID_PROPERTY_REVERT, self._OnRevert)
858    
859          ###########          ###########
860    
861            topBox.SetSizeHints(self)
         panel.SetAutoLayout(True)  
         panel.SetSizer(panelBox)  
         panelBox.SetSizeHints(panel)  
   
         topBox.Add(panel, 1, wxGROW, 0)  
         panelBox.SetSizeHints(self)  
862          self.SetAutoLayout(True)          self.SetAutoLayout(True)
863          self.SetSizer(topBox)          self.SetSizer(topBox)
864    
         #print "1------------------"  
865          #self.Fit()          #self.Fit()
866          ######################          ######################
867    
868          self.haveApplied = False          self.haveApplied = False
869    
870      def EditGroupProperties(self, row):      def EditSymbol(self, row):
871          table = self.classGrid.GetTable()          table = self.classGrid.GetTable()
872          prop = table.GetValueAsCustom(row, COL_SYMBOL, None)          prop = table.GetValueAsCustom(row, COL_SYMBOL, None)
873    
874          # get a new ClassGroupProperties object and copy the          # get a new ClassGroupProperties object and copy the
875          # values over to our current object          # values over to our current object
876          propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType())          propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType())
877    
878            self.Enable(False)
879          if propDlg.ShowModal() == wxID_OK:          if propDlg.ShowModal() == wxID_OK:
880              new_prop = propDlg.GetClassGroupProperties()              new_prop = propDlg.GetClassGroupProperties()
881              table.SetValueAsCustom(row, COL_SYMBOL, None, new_prop)              table.SetValueAsCustom(row, COL_SYMBOL, None, new_prop)
882            self.Enable(True)
883          propDlg.Destroy()          propDlg.Destroy()
884                    
885        def _SetClassification(self, clazz):
886            
887            self.fields.SetClientData(self.__cur_field, clazz)
888            self.classGrid.GetTable().SetClassification(clazz)
889    
890      def __BuildClassification(self, fieldIndex, copyClass = False):      def __BuildClassification(self, fieldIndex, copyClass = False):
891    
# Line 926  class Classifier(NonModalDialog): Line 932  class Classifier(NonModalDialog):
932              fieldType = self.layer.GetFieldType(fieldName)              fieldType = self.layer.GetFieldType(fieldName)
933              clazz.SetFieldType(fieldType)              clazz.SetFieldType(fieldType)
934                                    
         #print "6------------------"  
935          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")}  
936    
937      def __SetFieldTypeText(self, fieldIndex):      def __SetFieldTypeText(self, fieldIndex):
938          fieldName = self.fields.GetString(fieldIndex)          fieldName = self.fields.GetString(fieldIndex)
# Line 945  class Classifier(NonModalDialog): Line 942  class Classifier(NonModalDialog):
942    
943          text = Classifier.type2string[fieldType]          text = Classifier.type2string[fieldType]
944    
945          self.fieldTypeText.SetLabel(_("Field Type: %s") % text)          self.fieldTypeText.SetLabel(_("Data Type: %s") % text)
946    
947      def __SelectField(self, newIndex, oldIndex = -1, group = None):      def __SelectField(self, newIndex, oldIndex = -1, group = None):
948          """This method assumes that the current selection for the          """This method assumes that the current selection for the
949          combo has already been set by a call to SetSelection().          combo has already been set by a call to SetSelection().
950          """          """
951    
         #print "3------------------"  
   
952          assert oldIndex >= -1          assert oldIndex >= -1
953    
954          if oldIndex != -1:          if oldIndex != -1:
955              clazz = self.__BuildClassification(oldIndex)              clazz = self.__BuildClassification(oldIndex)
956              self.fields.SetClientData(oldIndex, clazz)              self.fields.SetClientData(oldIndex, clazz)
957    
         #print "4------------------"  
958          self.__SetGridTable(newIndex, group)          self.__SetGridTable(newIndex, group)
         #print "5------------------"  
959    
960          enabled = newIndex != 0          self.__EnableButtons(EB_SELECT_FIELD, newIndex != 0)
   
         for b in self.controlButtons:  
             b.Enable(enabled)  
961    
962          self.__SetFieldTypeText(newIndex)          self.__SetFieldTypeText(newIndex)
963    
964        def __SetTitle(self, title):
965            if title != "":
966                title = ": " + title
967    
968            self.SetTitle(_("Layer Properties") + title)
969    
970      def _OnEditGroupProperties(self, event):      def _OnEditSymbol(self, event):
971          sel = self.classGrid.GetCurrentSelection()          sel = self.classGrid.GetCurrentSelection()
972    
973          if len(sel) == 1:          if len(sel) == 1:
974              self.EditGroupProperties(sel[0])              self.EditSymbol(sel[0])
975    
976      def _OnFieldSelect(self, event):      def _OnFieldSelect(self, event):
977          index = self.fields.GetSelection()          index = self.fields.GetSelection()
978          self.__SelectField(index, self.__cur_field)          self.__SelectField(index, self.__cur_field)
979          self.__cur_field = index          self.__cur_field = index
980    
981      def _OnApply(self, event):      def _OnTry(self, event):
982          """Put the data from the table into a new Classification and hand          """Put the data from the table into a new Classification and hand
983             it to the layer.             it to the layer.
984          """          """
# Line 1002  class Classifier(NonModalDialog): Line 997  class Classifier(NonModalDialog):
997          self.haveApplied = True          self.haveApplied = True
998    
999      def _OnOK(self, event):      def _OnOK(self, event):
1000          self._OnApply(event)          self._OnTry(event)
1001          self.Close()          self.Close()
1002    
1003      def _OnCloseBtn(self, event):      def _OnCloseBtn(self, event):
# Line 1013  class Classifier(NonModalDialog): Line 1008  class Classifier(NonModalDialog):
1008    
1009          self.Close()          self.Close()
1010    
1011      def _OnCancel(self, event):      def _OnRevert(self, event):
1012          """The layer's current classification stays the same."""          """The layer's current classification stays the same."""
1013          if self.haveApplied:          if self.haveApplied:
1014              self.layer.SetClassification(self.originalClass)              self.layer.SetClassification(self.originalClass)
1015    
1016          self.Close()          #self.Close()
1017    
1018      def _OnAdd(self, event):      def _OnAdd(self, event):
1019          self.classGrid.AppendRows()          self.classGrid.AppendRows()
# Line 1028  class Classifier(NonModalDialog): Line 1023  class Classifier(NonModalDialog):
1023    
1024      def _OnGenClass(self, event):      def _OnGenClass(self, event):
1025    
1026          genDlg = ClassGenDialog(self,          self.genDlg = ClassGenDialog(self, self.layer,
1027                                  self.layer.table,                            self.fields.GetString(self.__cur_field))
1028                                  self.fields.GetString(self.__cur_field))  
1029            EVT_CLOSE(self.genDlg, self._OnGenDialogClose)
1030          if genDlg.ShowModal() == wxID_OK:  
1031              clazz = genDlg.GetClassification()          self.__EnableButtons(EB_GEN_CLASS, False)
1032              self.fields.SetClientData(self.__cur_field, clazz)  
1033              self.classGrid.GetTable().SetClassification(clazz)          self.genDlg.Show()
1034          genDlg.Destroy()  
1035        def _OnGenDialogClose(self, event):
1036            self.genDlg.Destroy()
1037            self.__EnableButtons(EB_GEN_CLASS, True)
1038    
1039      def _OnMoveUp(self, event):      def _OnMoveUp(self, event):
1040          sel = self.classGrid.GetCurrentSelection()          sel = self.classGrid.GetCurrentSelection()
1041    
         #print "sel: ", sel  
   
1042          if len(sel) == 1:          if len(sel) == 1:
1043              i = sel[0]              i = sel[0]
1044              if i > 1:              if i > 1:
# Line 1070  class Classifier(NonModalDialog): Line 1066  class Classifier(NonModalDialog):
1066                  self.classGrid.SelectRow(i + 1)                  self.classGrid.SelectRow(i + 1)
1067                  self.classGrid.MakeCellVisible(i + 1, 0)                  self.classGrid.MakeCellVisible(i + 1, 0)
1068    
1069        def _OnTitleChanged(self, event):
1070            obj = event.GetEventObject()
1071    
1072            self.layer.SetTitle(obj.GetValue())
1073            self.__SetTitle(self.layer.Title())
1074    
1075            self.__EnableButtons(EB_LAYER_TITLE, self.layer.Title() != "")
1076    
1077        def __EnableButtons(self, case, enable):
1078    
1079            if case == EB_LAYER_TITLE:  
1080                list = (ID_PROPERTY_OK,
1081                        ID_PROPERTY_CLOSE)
1082    
1083            elif case == EB_SELECT_FIELD:
1084                list = (ID_PROPERTY_GENCLASS,
1085                        ID_PROPERTY_ADD,
1086                        ID_PROPERTY_MOVEUP,
1087                        ID_PROPERTY_MOVEDOWN,
1088                        ID_PROPERTY_EDITSYM,
1089                        ID_PROPERTY_REMOVE)
1090    
1091            elif case == EB_GEN_CLASS:
1092                list = (ID_PROPERTY_SELECT,
1093                        ID_PROPERTY_FIELDTEXT,
1094                        ID_PROPERTY_GENCLASS,
1095                        ID_PROPERTY_EDITSYM)
1096    
1097            for id in list:
1098                self.FindWindowById(id).Enable(enable)
1099    
1100  ID_SELPROP_OK = 4001  ID_SELPROP_OK = 4001
1101  ID_SELPROP_CANCEL = 4002  ID_SELPROP_CANCEL = 4002
# Line 1096  class SelectPropertiesDialog(wxDialog): Line 1122  class SelectPropertiesDialog(wxDialog):
1122          previewBox = wxBoxSizer(wxVERTICAL)          previewBox = wxBoxSizer(wxVERTICAL)
1123          previewBox.Add(wxStaticText(self, -1, _("Preview:")),          previewBox.Add(wxStaticText(self, -1, _("Preview:")),
1124              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
1125          self.previewWin = ClassDataPreviewWindow(None, self.prop, shapeType,  
1126                                              self, ID_SELPROP_PREVIEW, (40, 40))          self.previewWin = ClassGroupPropertiesCtrl(
1127                self, ID_SELPROP_PREVIEW, self.prop, shapeType,
1128                (40, 40), wxSIMPLE_BORDER)
1129    
1130            self.previewWin.AllowEdit(False)
1131    
1132          previewBox.Add(self.previewWin, 1, wxGROW | wxALL, 4)          previewBox.Add(self.previewWin, 1, wxGROW | wxALL, 4)
1133    
1134          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)
# Line 1229  class ClassDataPreviewWindow(wxWindow): Line 1260  class ClassDataPreviewWindow(wxWindow):
1260          self.shapeType = shapeType          self.shapeType = shapeType
1261          self.previewer = ClassDataPreviewer()          self.previewer = ClassDataPreviewer()
1262    
1263        def GetProperties():
1264            return self.prop
1265    
1266      def _OnPaint(self, event):      def _OnPaint(self, event):
1267          dc = wxPaintDC(self)          dc = wxPaintDC(self)
1268    
# Line 1320  class ClassRenderer(wxPyGridCellRenderer Line 1354  class ClassRenderer(wxPyGridCellRenderer
1354    
1355          dc.DestroyClippingRegion()          dc.DestroyClippingRegion()
1356    
1357    
1358    class ClassGroupPropertiesCtrl(wxWindow, wxControl):
1359    
1360        def __init__(self, parent, id, props, shapeType,
1361                     size = wxDefaultSize, style = 0):
1362    
1363            wxWindow.__init__(self, parent, id, size = size, style = style)
1364    
1365            self.SetProperties(props)
1366            self.SetShapeType(shapeType)
1367            self.AllowEdit(True)
1368    
1369            EVT_PAINT(self, self._OnPaint)
1370            EVT_LEFT_DCLICK(self, self._OnLeftDClick)
1371    
1372            self.previewer = ClassDataPreviewer()
1373    
1374        def _OnPaint(self, event):
1375            dc = wxPaintDC(self)
1376    
1377            # XXX: this doesn't seem to be having an effect:
1378            dc.DestroyClippingRegion()
1379    
1380            w, h = self.GetClientSize()
1381    
1382            self.previewer.Draw(dc,
1383                                wxRect(0, 0, w, h),
1384                                self.GetProperties(),
1385                                self.GetShapeType())
1386    
1387    
1388        def GetProperties(self):
1389            return self.props
1390    
1391        def SetProperties(self, props):
1392            self.props = props
1393            self.Refresh()
1394    
1395        def GetShapeType(self):
1396            return self.shapeType
1397    
1398        def SetShapeType(self, shapeType):
1399            self.shapeType = shapeType
1400            self.Refresh()
1401    
1402        def AllowEdit(self, allow):
1403            self.allowEdit = allow
1404    
1405        def DoEdit(self):
1406            if not self.allowEdit: return
1407    
1408            propDlg = SelectPropertiesDialog(NULL,
1409                                             self.GetProperties(),
1410                                             self.GetShapeType())
1411    
1412            if propDlg.ShowModal() == wxID_OK:
1413                new_prop = propDlg.GetClassGroupProperties()
1414                self.SetProperties(new_prop)
1415                self.Refresh()
1416    
1417            propDlg.Destroy()
1418    
1419        def _OnLeftDClick(self, event):
1420            self.DoEdit()

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26