/[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 630 by jonathan, Wed Apr 9 10:10:06 2003 UTC revision 835 by bh, Tue May 6 15:52:41 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 _
 from Thuban.common import *  
21  from Thuban.UI.common import *  from Thuban.UI.common import *
22    
23  from Thuban.Model.classification import *  from Thuban.Model.classification import *
# Line 31  from Thuban.UI.classgen import ClassGenD Line 30  from Thuban.UI.classgen import ClassGenD
30    
31  from dialogs import NonModalDialog  from dialogs import NonModalDialog
32    
 # widget id's  
 ID_PROPERTY_SELECT = 4010  
33  ID_CLASS_TABLE = 40011  ID_CLASS_TABLE = 40011
34    
35    
36  # table columns  # table columns
37  COL_SYMBOL = 0  COL_VISIBLE = 0
38  COL_VALUE  = 1  COL_SYMBOL  = 1
39  COL_LABEL  = 2  COL_VALUE   = 2
40    COL_LABEL   = 3
41    NUM_COLS    = 4
42    
43  # indices into the client data lists in Classifier.fields  # indices into the client data lists in Classifier.fields
44  FIELD_CLASS = 0  FIELD_CLASS = 0
# Line 63  class ClassGrid(wxGrid): Line 62  class ClassGrid(wxGrid):
62                   use for display.                   use for display.
63          """          """
64    
65          #wxGrid.__init__(self, parent, ID_CLASS_TABLE, size = (340, 160))          wxGrid.__init__(self, parent, ID_CLASS_TABLE, style = 0)
         wxGrid.__init__(self, parent, ID_CLASS_TABLE)  
         #self.SetTable(ClassTable(fieldData, layer.ShapeType(), self), True)  
66    
67          self.classifier = classifier          self.classifier = classifier
68    
# Line 77  class ClassGrid(wxGrid): Line 74  class ClassGrid(wxGrid):
74          EVT_GRID_COL_SIZE(self, self._OnCellResize)          EVT_GRID_COL_SIZE(self, self._OnCellResize)
75          EVT_GRID_ROW_SIZE(self, self._OnCellResize)          EVT_GRID_ROW_SIZE(self, self._OnCellResize)
76    
77        #def GetCellAttr(self, row, col):
78            #print "GetCellAttr ", row, col
79            #wxGrid.GetCellAttr(self, row, col)
80    
81      def CreateTable(self, clazz, shapeType, group = None):      def CreateTable(self, clazz, shapeType, group = None):
82    
83          assert isinstance(clazz, Classification)          assert isinstance(clazz, Classification)
84    
85          table = self.GetTable()          table = self.GetTable()
86          if table is None:          if table is None:
87              w = self.GetDefaultColSize() * 3 + self.GetDefaultRowLabelSize()              w = self.GetDefaultColSize() * NUM_COLS \
88              h = self.GetDefaultRowSize() * 4 + self.GetDefaultColLabelSize()                  + self.GetDefaultRowLabelSize()
89                h = self.GetDefaultRowSize() * 4 \
90                    + self.GetDefaultColLabelSize()
91    
92              self.SetDimensions(-1, -1, w, h)              self.SetDimensions(-1, -1, w, h)
93              self.SetSizeHints(w, h, -1, -1)              self.SetSizeHints(w, h, -1, -1)
94              table = ClassTable(self)              table = ClassTable(self)
# Line 106  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 202  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 241  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 257  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 286  class ClassTable(wxPyGridTableBase): Line 292  class ClassTable(wxPyGridTableBase):
292          self.SetClassification(clazz, group)          self.SetClassification(clazz, group)
293          self.__Modified(-1)          self.__Modified(-1)
294    
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()
310    
# Line 298  class ClassTable(wxPyGridTableBase): Line 317  class ClassTable(wxPyGridTableBase):
317    
318          old_len = self.GetNumberRows()          old_len = self.GetNumberRows()
319    
         #  
         # 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..."  
   
   
         #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 323  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 387  class ClassTable(wxPyGridTableBase): Line 397  class ClassTable(wxPyGridTableBase):
397              if isinstance(group, ClassGroupMap):       return _("Map")              if isinstance(group, ClassGroupMap):       return _("Map")
398    
399          assert False # shouldn't get here          assert False # shouldn't get here
400          return _("")          return ""
401    
402      def GetNumberRows(self):      def GetNumberRows(self):
403          """Return the number of rows."""          """Return the number of rows."""
# Line 398  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 416  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 431  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 465  class ClassTable(wxPyGridTableBase): Line 477  class ClassTable(wxPyGridTableBase):
477          elif type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):          elif type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):
478    
479              if type == FIELDTYPE_INT:              if type == FIELDTYPE_INT:
480                    # the float call allows the user to enter 1.0 for 1
481                  conv = lambda p: int(float(p))                  conv = lambda p: int(float(p))
482              else:              else:
483                  conv = lambda p: p                  conv = lambda p: p
# Line 479  class ClassTable(wxPyGridTableBase): Line 492  class ClassTable(wxPyGridTableBase):
492              # function.              # function.
493              #              #
494              try:              try:
495                  return (conv(Str2Num(value)),)                  return (conv(value),)
496              except ValueError:              except ValueError:
497                  i = value.find('-')                  i = value.find('-')
498                  if i == 0:                  if i == 0:
499                      i = value.find('-', 1)                      i = value.find('-', 1)
500    
501                  return (conv(Str2Num(value[:i])), conv(Str2Num(value[i+1:])))                  return (conv(value[:i]), conv(value[i+1:]))
502    
503          assert False  # shouldn't get here          assert False  # shouldn't get here
504          return (0,)          return (0,)
# Line 503  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 513  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 543  class ClassTable(wxPyGridTableBase): Line 558  class ClassTable(wxPyGridTableBase):
558                      #                      #
559                      if len(dataInfo) == 1:                      if len(dataInfo) == 1:
560                          if not isinstance(group, ClassGroupSingleton):                          if not isinstance(group, ClassGroupSingleton):
561                              ngroup = ClassGroupSingleton(prop = props)                              ngroup = ClassGroupSingleton(props = props)
562                              changed = True                              changed = True
563                          ngroup.SetValue(dataInfo[0])                          ngroup.SetValue(dataInfo[0])
564                      elif len(dataInfo) == 2:                      elif len(dataInfo) == 2:
565                          if not isinstance(group, ClassGroupRange):                          if not isinstance(group, ClassGroupRange):
566                              ngroup = ClassGroupRange(prop = props)                              ngroup = ClassGroupRange(props = props)
567                              changed = True                              changed = True
568                          ngroup.SetRange(dataInfo[0], dataInfo[1])                          ngroup.SetRange(dataInfo[0], dataInfo[1])
569                      else:                      else:
# Line 569  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 644  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_CLASSIFY_OK = 4001  ID_PROPERTY_REVERT = 4002
654  ID_CLASSIFY_CANCEL = 4002  ID_PROPERTY_ADD = 4003
655  ID_CLASSIFY_ADD = 4003  ID_PROPERTY_GENCLASS = 4004
656  ID_CLASSIFY_GENCLASS = 4004  ID_PROPERTY_REMOVE = 4005
657  ID_CLASSIFY_REMOVE = 4005  ID_PROPERTY_MOVEUP = 4006
658  ID_CLASSIFY_MOVEUP = 4006  ID_PROPERTY_MOVEDOWN = 4007
659  ID_CLASSIFY_MOVEDOWN = 4007  ID_PROPERTY_TRY = 4008
660  ID_CLASSIFY_APPLY = 4008  ID_PROPERTY_EDITSYM = 4009
661  ID_CLASSIFY_EDITPROPS = 4009  ID_PROPERTY_SELECT = 4011
662  ID_CLASSIFY_CLOSE = 4010  ID_PROPERTY_TITLE = 4012
663    ID_PROPERTY_FIELDTEXT = 4013
664    
665  BTN_ADD = 0  BTN_ADD = 0
666  BTN_EDIT = 1  BTN_EDIT = 1
# Line 662  BTN_UP = 3 Line 669  BTN_UP = 3
669  BTN_DOWN = 4  BTN_DOWN = 4
670  BTN_RM = 5  BTN_RM = 5
671    
672    EB_LAYER_TITLE = 0
673    EB_SELECT_FIELD = 1
674    EB_GEN_CLASS = 2
675    
676  class Classifier(NonModalDialog):  class Classifier(NonModalDialog):
677    
678      type2string = {None:             _("None"),      type2string = {None:             _("None"),
# Line 670  class Classifier(NonModalDialog): Line 681  class Classifier(NonModalDialog):
681                     FIELDTYPE_DOUBLE: _("Decimal")}                     FIELDTYPE_DOUBLE: _("Decimal")}
682    
683      def __init__(self, parent, name, layer, group = None):      def __init__(self, parent, name, layer, group = None):
684          NonModalDialog.__init__(self, parent, name,          NonModalDialog.__init__(self, parent, name, "")
                                 _("Classifier: %s") % layer.Title())  
685    
686          panel = wxPanel(self, -1, size=(100, 100))          self.__SetTitle(layer.Title())
687    
688          self.layer = layer          self.layer = layer
689    
# Line 683  class Classifier(NonModalDialog): Line 693  class Classifier(NonModalDialog):
693    
694          self.genDlg = None          self.genDlg = None
695    
696          topBox = wxBoxSizer(wxVERTICAL)          ############################
697          panelBox = wxBoxSizer(wxVERTICAL)          # Create the controls
698            #
         #panelBox.Add(wxStaticText(panel, -1, _("Layer: %s") % layer.Title()),  
             #0, wxALIGN_LEFT | wxALL, 4)  
         panelBox.Add(wxStaticText(panel, -1,  
                                 _("Layer Type: %s") % layer.ShapeType()),  
             0, wxALIGN_LEFT | wxALL, 4)  
699    
700            panel = wxPanel(self, -1)
701    
702            text_title = wxTextCtrl(panel, ID_PROPERTY_TITLE, layer.Title())
703          #          #
704          # make field combo box          # make field choice box
705          #          #
706          self.fields = wxComboBox(panel, ID_PROPERTY_SELECT, "",          self.fields = wxChoice(panel, ID_PROPERTY_SELECT,)
                                      style = wxCB_READONLY)  
707    
708          self.num_cols = layer.table.field_count()          self.num_cols = layer.table.NumColumns()
709          # just assume the first field in case one hasn't been          # just assume the first field in case one hasn't been
710          # specified in the file.          # specified in the file.
711          self.__cur_field = 0          self.__cur_field = 0
712    
713          self.fields.Append("<None>")          self.fields.Append("<None>")
714          self.fields.SetClientData(0, None)  
715            if self.originalClass.GetFieldType() is None:
716                self.fields.SetClientData(0, copy.deepcopy(self.originalClass))
717            else:
718                self.fields.SetClientData(0, None)
719    
720          for i in range(self.num_cols):          for i in range(self.num_cols):
721              type, name, len, decc = layer.table.field_info(i)              name = layer.table.Column(i).name
722              self.fields.Append(name)              self.fields.Append(name)
723    
724              if name == field:              if name == field:
# Line 719  class Classifier(NonModalDialog): Line 729  class Classifier(NonModalDialog):
729                  self.fields.SetClientData(i + 1, None)                  self.fields.SetClientData(i + 1, None)
730    
731    
         ###########  
   
732          self.fieldTypeText = wxStaticText(panel, -1, "")          self.fieldTypeText = wxStaticText(panel, -1, "")
         panelBox.Add(self.fieldTypeText, 0,  
                      wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4)  
733    
734          propertyBox = wxBoxSizer(wxHORIZONTAL)          button_gen = wxButton(panel, ID_PROPERTY_GENCLASS, _("Generate Class"))
         propertyBox.Add(wxStaticText(panel, -1, _("Field: ")),  
             0, wxALIGN_LEFT | wxALL, 4)  
         propertyBox.Add(self.fields, 1, wxGROW|wxALL, 4)  
         EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect)  
735    
736          panelBox.Add(propertyBox, 0, wxGROW, 4)          button_add = wxButton(panel, ID_PROPERTY_ADD, _("Add"))
737            button_moveup = wxButton(panel, ID_PROPERTY_MOVEUP, _("Move Up"))
738            button_movedown = wxButton(panel, ID_PROPERTY_MOVEDOWN, _("Move Down"))
739            button_edit = wxButton(panel, ID_PROPERTY_EDITSYM, _("Edit Symbol"))
740            button_remove = wxButton(panel, ID_PROPERTY_REMOVE, _("Remove"))
741    
742    
743          #          button_try = wxButton(panel, ID_PROPERTY_TRY, _("Try"))
744          # Control Box          button_revert = wxButton(panel, ID_PROPERTY_REVERT, _("Revert"))
745          #          button_ok = wxButton(panel, wxID_OK, _("OK"))
746          controlBox = wxBoxSizer(wxHORIZONTAL)          button_ok.SetDefault()
747            button_close = wxButton(panel, wxID_CANCEL, _("Close"))
748    
749            self.classGrid = ClassGrid(panel, self)
750    
751          ###########          # calling __SelectField after creating the classGrid fills in the
752          #          # grid with the correct information
753          # Control buttons:          self.fields.SetSelection(self.__cur_field)
754            self.__SelectField(self.__cur_field, group = group)
755    
756            ############################
757            # Layout the controls
758          #          #
         self.controlButtons = []  
759    
760          controlButtonBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
761            panelBox = wxBoxSizer(wxVERTICAL)
762    
763          button = wxButton(panel, ID_CLASSIFY_ADD, _("Add"))          sizer = wxBoxSizer(wxHORIZONTAL)
764          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          sizer.Add(wxStaticText(panel, -1, _("Title: ")),
765          self.controlButtons.append(button)              0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 4)
766            sizer.Add(text_title, 1, wxGROW, 0)
         button = wxButton(panel, ID_CLASSIFY_EDITPROPS, _("Edit Properties"))  
         controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)  
         self.controlButtons.append(button)  
   
         button = wxButton(panel, ID_CLASSIFY_GENCLASS, _("Generate Class"))  
         controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)  
         self.controlButtons.append(button)  
   
         button = wxButton(panel, ID_CLASSIFY_MOVEUP, _("Move Up"))  
         controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)  
         self.controlButtons.append(button)  
   
         button = wxButton(panel, ID_CLASSIFY_MOVEDOWN, _("Move Down"))  
         controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)  
         self.controlButtons.append(button)  
   
         controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)  
   
         button = wxButton(panel, ID_CLASSIFY_REMOVE, _("Remove"))  
         controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)  
         self.controlButtons.append(button)  
767    
768            panelBox.Add(sizer, 0, wxGROW, 4)
769    
770          ###########          panelBox.Add(wxStaticText(panel, -1,
771          #                                  _("Type: %s") % layer.ShapeType()),
772          # Classification data table              0, wxALIGN_LEFT | wxALL, 4)
         #  
773    
774          self.classGrid = ClassGrid(panel, self)          classBox = wxStaticBoxSizer(
775          #self.__SetGridTable(self.__cur_field, group)                      wxStaticBox(panel, -1, _("Classification")), wxVERTICAL)
         #self.fields.SetSelection(self.__cur_field)  
776    
         # calling __SelectField after creating the classGrid fills in the  
         # grid with the correct information  
         self.fields.SetSelection(self.__cur_field)  
         self.__SelectField(self.__cur_field, group = group)  
777    
778          #self.classGrid.SelectGroup(group)          sizer = wxBoxSizer(wxHORIZONTAL)
779            sizer.Add(wxStaticText(panel, ID_PROPERTY_FIELDTEXT, _("Field: ")),
780                0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 4)
781            sizer.Add(self.fields, 1, wxGROW | wxALL, 4)
782    
783          controlBox.Add(self.classGrid, 1, wxGROW, 0)          classBox.Add(sizer, 0, wxGROW, 4)
784    
785            classBox.Add(self.fieldTypeText, 0,
786                         wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4)
787    
788            controlBox = wxBoxSizer(wxHORIZONTAL)
789            controlButtonBox = wxBoxSizer(wxVERTICAL)
790    
791            controlButtonBox.Add(button_gen, 0, wxGROW|wxALL, 4)
792            controlButtonBox.Add(button_add, 0, wxGROW|wxALL, 4)
793            controlButtonBox.Add(button_moveup, 0, wxGROW|wxALL, 4)
794            controlButtonBox.Add(button_movedown, 0, wxGROW|wxALL, 4)
795            controlButtonBox.Add(button_edit, 0, wxGROW|wxALL, 4)
796            controlButtonBox.Add(60, 20, 0, wxGROW|wxALL|wxALIGN_BOTTOM, 4)
797            controlButtonBox.Add(button_remove, 0, wxGROW|wxALL|wxALIGN_BOTTOM, 4)
798    
799            controlBox.Add(self.classGrid, 1, wxGROW, 0)
800          controlBox.Add(controlButtonBox, 0, wxGROW, 10)          controlBox.Add(controlButtonBox, 0, wxGROW, 10)
         panelBox.Add(controlBox, 1, wxGROW, 10)  
801    
802          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)          classBox.Add(controlBox, 1, wxGROW, 10)
803          EVT_BUTTON(self, ID_CLASSIFY_EDITPROPS, self._OnEditGroupProperties)          panelBox.Add(classBox, 1, wxGROW, 0)
         EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove)  
         EVT_BUTTON(self, ID_CLASSIFY_GENCLASS, self._OnGenClass)  
         EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp)  
         EVT_BUTTON(self, ID_CLASSIFY_MOVEDOWN, self._OnMoveDown)  
804    
         ###########  
805    
806          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
807          buttonBox.Add(wxButton(panel, ID_CLASSIFY_OK, _("OK")),          buttonBox.Add(button_try, 0, wxALL, 4)
                       0, wxALL, 4)  
808          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
809          buttonBox.Add(wxButton(panel, ID_CLASSIFY_APPLY, _("Apply")),          buttonBox.Add(button_revert, 0, wxALL, 4)
                       0, wxALL, 4)  
810          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
811          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CLOSE, _("Close")),          buttonBox.Add(button_ok, 0, wxALL, 4)
                       0, wxALL, 4)  
812          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
813          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CANCEL, _("Cancel")),          buttonBox.Add(button_close, 0, wxALL, 4)
814                        0, wxALL, 4)          panelBox.Add(buttonBox, 0,
815          panelBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)              wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)
   
         EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)  
         EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply)  
         EVT_BUTTON(self, ID_CLASSIFY_CLOSE, self._OnCloseBtn)  
         EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel)  
   
         ###########  
   
816    
817          panel.SetAutoLayout(True)          panel.SetAutoLayout(True)
818          panel.SetSizer(panelBox)          panel.SetSizer(panelBox)
819            panelBox.Fit(panel)
820          panelBox.SetSizeHints(panel)          panelBox.SetSizeHints(panel)
821    
822          topBox.Add(panel, 1, wxGROW, 0)          topBox.Add(panel, 1, wxGROW | wxALL, 4)
823          panelBox.SetSizeHints(self)  
824          self.SetAutoLayout(True)          self.SetAutoLayout(True)
825          self.SetSizer(topBox)          self.SetSizer(topBox)
826            topBox.Fit(self)
827            topBox.SetSizeHints(self)
828            self.Layout()
829    
830            ###########
831    
832            EVT_CHOICE(self, ID_PROPERTY_SELECT, self._OnFieldSelect)
833            EVT_TEXT(self, ID_PROPERTY_TITLE, self._OnTitleChanged)
834            EVT_BUTTON(self, wxID_OK, self._OnOK)
835            EVT_BUTTON(self, ID_PROPERTY_TRY, self._OnTry)
836            EVT_BUTTON(self, wxID_CANCEL, self._OnCloseBtn)
837            EVT_BUTTON(self, ID_PROPERTY_REVERT, self._OnRevert)
838    
839            EVT_BUTTON(self, ID_PROPERTY_ADD, self._OnAdd)
840            EVT_BUTTON(self, ID_PROPERTY_EDITSYM, self._OnEditSymbol)
841            EVT_BUTTON(self, ID_PROPERTY_REMOVE, self._OnRemove)
842            EVT_BUTTON(self, ID_PROPERTY_GENCLASS, self._OnGenClass)
843            EVT_BUTTON(self, ID_PROPERTY_MOVEUP, self._OnMoveUp)
844            EVT_BUTTON(self, ID_PROPERTY_MOVEDOWN, self._OnMoveDown)
845    
         #self.Fit()  
846          ######################          ######################
847    
848            self.fields.SetFocus()
849          self.haveApplied = False          self.haveApplied = False
850    
851      def EditGroupProperties(self, row):      def EditSymbol(self, row):
852          table = self.classGrid.GetTable()          table = self.classGrid.GetTable()
853          prop = table.GetValueAsCustom(row, COL_SYMBOL, None)          prop = table.GetValueAsCustom(row, COL_SYMBOL, None)
854    
# Line 918  class Classifier(NonModalDialog): Line 923  class Classifier(NonModalDialog):
923    
924          text = Classifier.type2string[fieldType]          text = Classifier.type2string[fieldType]
925    
926          self.fieldTypeText.SetLabel(_("Field Type: %s") % text)          self.fieldTypeText.SetLabel(_("Data Type: %s") % text)
927    
928      def __SelectField(self, newIndex, oldIndex = -1, group = None):      def __SelectField(self, newIndex, oldIndex = -1, group = None):
929          """This method assumes that the current selection for the          """This method assumes that the current selection for the
# Line 933  class Classifier(NonModalDialog): Line 938  class Classifier(NonModalDialog):
938    
939          self.__SetGridTable(newIndex, group)          self.__SetGridTable(newIndex, group)
940    
941          enabled = newIndex != 0          self.__EnableButtons(EB_SELECT_FIELD, newIndex != 0)
   
         for b in self.controlButtons:  
             b.Enable(enabled)  
942    
943          self.__SetFieldTypeText(newIndex)          self.__SetFieldTypeText(newIndex)
944    
945        def __SetTitle(self, title):
946            if title != "":
947                title = ": " + title
948    
949            self.SetTitle(_("Layer Properties") + title)
950    
951      def _OnEditGroupProperties(self, event):      def _OnEditSymbol(self, event):
952          sel = self.classGrid.GetCurrentSelection()          sel = self.classGrid.GetCurrentSelection()
953    
954          if len(sel) == 1:          if len(sel) == 1:
955              self.EditGroupProperties(sel[0])              self.EditSymbol(sel[0])
956    
957      def _OnFieldSelect(self, event):      def _OnFieldSelect(self, event):
958          index = self.fields.GetSelection()          index = self.fields.GetSelection()
959          self.__SelectField(index, self.__cur_field)          self.__SelectField(index, self.__cur_field)
960          self.__cur_field = index          self.__cur_field = index
961    
962      def _OnApply(self, event):      def _OnTry(self, event):
963          """Put the data from the table into a new Classification and hand          """Put the data from the table into a new Classification and hand
964             it to the layer.             it to the layer.
965          """          """
# Line 971  class Classifier(NonModalDialog): Line 978  class Classifier(NonModalDialog):
978          self.haveApplied = True          self.haveApplied = True
979    
980      def _OnOK(self, event):      def _OnOK(self, event):
981          self._OnApply(event)          self._OnTry(event)
982          self.Close()          self.Close()
983    
984        def OnClose(self, event):
985            NonModalDialog.OnClose(self, event)
986    
987      def _OnCloseBtn(self, event):      def _OnCloseBtn(self, event):
988          """Close is similar to Cancel except that any changes that were          """Close is similar to Cancel except that any changes that were
989          made and applied remain applied, but the currently displayed          made and applied remain applied, but the currently displayed
# Line 982  class Classifier(NonModalDialog): Line 992  class Classifier(NonModalDialog):
992    
993          self.Close()          self.Close()
994    
995      def _OnCancel(self, event):      def _OnRevert(self, event):
996          """The layer's current classification stays the same."""          """The layer's current classification stays the same."""
997          if self.haveApplied:          if self.haveApplied:
998              self.layer.SetClassification(self.originalClass)              self.layer.SetClassification(self.originalClass)
999    
1000          self.Close()          #self.Close()
1001    
1002      def _OnAdd(self, event):      def _OnAdd(self, event):
1003          self.classGrid.AppendRows()          self.classGrid.AppendRows()
# Line 997  class Classifier(NonModalDialog): Line 1007  class Classifier(NonModalDialog):
1007    
1008      def _OnGenClass(self, event):      def _OnGenClass(self, event):
1009    
         #if self.genDlg is None:  
1010          self.genDlg = ClassGenDialog(self, self.layer,          self.genDlg = ClassGenDialog(self, self.layer,
1011                            self.fields.GetString(self.__cur_field))                            self.fields.GetString(self.__cur_field))
1012    
1013          EVT_CLOSE(self.genDlg, self._OnGenDialogClose)          EVT_CLOSE(self.genDlg, self._OnGenDialogClose)
1014    
1015          self.fields.Enable(False)          self.__EnableButtons(EB_GEN_CLASS, False)
         self.controlButtons[BTN_EDIT].Enable(False)  
         self.controlButtons[BTN_GEN].Enable(False)  
1016    
1017          self.genDlg.Show()          self.genDlg.Show()
         #if self.genDlg.ShowModal() == wxID_OK:  
         #    clazz = self.genDlg.GetClassification()  
         #    self.fields.SetClientData(self.__cur_field, clazz)  
         #    self.classGrid.GetTable().SetClassification(clazz)  
         #self.Enable(True)  
         #self.genDlg.Destroy()  
1018    
1019      def _OnGenDialogClose(self, event):      def _OnGenDialogClose(self, event):
1020          self.genDlg.Destroy()          self.genDlg.Destroy()
1021            self.__EnableButtons(EB_GEN_CLASS, True)
         self.fields.Enable(True)  
         self.controlButtons[BTN_EDIT].Enable(True)  
         self.controlButtons[BTN_GEN].Enable(True)  
1022    
1023      def _OnMoveUp(self, event):      def _OnMoveUp(self, event):
1024          sel = self.classGrid.GetCurrentSelection()          sel = self.classGrid.GetCurrentSelection()
# Line 1052  class Classifier(NonModalDialog): Line 1050  class Classifier(NonModalDialog):
1050                  self.classGrid.SelectRow(i + 1)                  self.classGrid.SelectRow(i + 1)
1051                  self.classGrid.MakeCellVisible(i + 1, 0)                  self.classGrid.MakeCellVisible(i + 1, 0)
1052    
1053        def _OnTitleChanged(self, event):
1054            obj = event.GetEventObject()
1055    
1056            self.layer.SetTitle(obj.GetValue())
1057            self.__SetTitle(self.layer.Title())
1058    
1059            self.__EnableButtons(EB_LAYER_TITLE, self.layer.Title() != "")
1060    
1061        def __EnableButtons(self, case, enable):
1062    
1063            if case == EB_LAYER_TITLE:  
1064                list = (wxID_OK,
1065                        wxID_CANCEL)
1066    
1067            elif case == EB_SELECT_FIELD:
1068                list = (ID_PROPERTY_GENCLASS,
1069                        ID_PROPERTY_ADD,
1070                        ID_PROPERTY_MOVEUP,
1071                        ID_PROPERTY_MOVEDOWN,
1072                        ID_PROPERTY_EDITSYM,
1073                        ID_PROPERTY_REMOVE)
1074    
1075            elif case == EB_GEN_CLASS:
1076                list = (ID_PROPERTY_SELECT,
1077                        ID_PROPERTY_FIELDTEXT,
1078                        ID_PROPERTY_GENCLASS,
1079                        ID_PROPERTY_EDITSYM)
1080    
1081            for id in list:
1082                self.FindWindowById(id).Enable(enable)
1083    
 ID_SELPROP_OK = 4001  
 ID_SELPROP_CANCEL = 4002  
1084  ID_SELPROP_SPINCTRL = 4002  ID_SELPROP_SPINCTRL = 4002
1085  ID_SELPROP_PREVIEW = 4003  ID_SELPROP_PREVIEW = 4003
1086  ID_SELPROP_STROKECLR = 4004  ID_SELPROP_STROKECLR = 4004
# Line 1093  class SelectPropertiesDialog(wxDialog): Line 1119  class SelectPropertiesDialog(wxDialog):
1119          ctrlBox = wxBoxSizer(wxVERTICAL)          ctrlBox = wxBoxSizer(wxVERTICAL)
1120    
1121          lineColorBox = wxBoxSizer(wxHORIZONTAL)          lineColorBox = wxBoxSizer(wxHORIZONTAL)
1122          lineColorBox.Add(          button = wxButton(self, ID_SELPROP_STROKECLR, _("Change Line Color"))
1123              wxButton(self, ID_SELPROP_STROKECLR, _("Change Line Color")),          button.SetFocus()
1124              1, wxALL | wxGROW, 4)          lineColorBox.Add(button, 1, wxALL | wxGROW, 4)
1125          EVT_BUTTON(self, ID_SELPROP_STROKECLR, self._OnChangeLineColor)          EVT_BUTTON(self, ID_SELPROP_STROKECLR, self._OnChangeLineColor)
1126    
1127          lineColorBox.Add(          lineColorBox.Add(
# Line 1141  class SelectPropertiesDialog(wxDialog): Line 1167  class SelectPropertiesDialog(wxDialog):
1167          # Control buttons:          # Control buttons:
1168          #          #
1169          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
1170          buttonBox.Add(wxButton(self, ID_SELPROP_OK, _("OK")),          button_ok = wxButton(self, wxID_OK, _("OK"))
1171                        0, wxALL, 4)          button_ok.SetDefault()
1172          buttonBox.Add(wxButton(self, ID_SELPROP_CANCEL, _("Cancel")),          buttonBox.Add(button_ok, 0, wxALL, 4)
1173            buttonBox.Add(wxButton(self, wxID_CANCEL, _("Cancel")),
1174                        0, wxALL, 4)                        0, wxALL, 4)
1175          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 10)          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 10)
1176                                                                                                                                                                    
1177          EVT_BUTTON(self, ID_SELPROP_OK, self._OnOK)          #EVT_BUTTON(self, wxID_OK, self._OnOK)
1178          EVT_BUTTON(self, ID_SELPROP_CANCEL, self._OnCancel)          #EVT_BUTTON(self, ID_SELPROP_CANCEL, self._OnCancel)
1179                                                                                                                                                                    
1180          self.SetAutoLayout(True)          self.SetAutoLayout(True)
1181          self.SetSizer(topBox)          self.SetSizer(topBox)
1182          topBox.Fit(self)          topBox.Fit(self)
1183          topBox.SetSizeHints(self)          topBox.SetSizeHints(self)
1184    
1185      def _OnOK(self, event):      def OnOK(self, event):
1186          self.EndModal(wxID_OK)          self.EndModal(wxID_OK)
1187    
1188      def _OnCancel(self, event):      def OnCancel(self, event):
1189          self.EndModal(wxID_CANCEL)          self.EndModal(wxID_CANCEL)
1190    
1191      def _OnSpin(self, event):      def _OnSpin(self, event):

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26