/[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 606 by jonathan, Fri Apr 4 12:16:39 2003 UTC revision 782 by jonathan, Tue Apr 29 16:53:55 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  
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 72  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 86  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 102  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 113  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 139  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 215  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 242  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 260  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 285  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 301  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
         self.tdata = []  
266    
267          #self.Reset(clazz, shapeType)          self.clazz = None
268            self.__colAttr = {}
269    
270            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 329  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()
311    
312        def GetClassification(self):
313            return self.clazz
314    
315      def SetClassification(self, clazz, group = None):      def SetClassification(self, clazz, group = None):
316    
317          self.GetView().BeginBatch()          self.GetView().BeginBatch()
318    
319          old_len = self.GetNumberRows()          old_len = self.GetNumberRows()
         self.tdata = []  
320    
         #print "9------------------"  
         #  
         # copy the data out of the classification and into our  
         # array  
         #  
321          row = -1          row = -1
322          for g in clazz:          self.clazz = clazz
             ng = copy.deepcopy(g)  
             self.__SetRow(None, ng)  
             if g is group:  
                 row = self.GetNumberRows() - 1  
                 #print "selecting row..."  
   
         #print "10------------------"  
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)
332              self.GetView().MakeCellVisible(row, 0)              self.GetView().MakeCellVisible(row, 0)
333    
334            self.__Modified()
335    
336    
337          self.GetView().EndBatch()          self.GetView().EndBatch()
338          self.GetView().FitInside()          self.GetView().FitInside()
339    
# Line 385  class ClassTable(wxPyGridTableBase): Line 356  class ClassTable(wxPyGridTableBase):
356              self.GetView().ProcessTableMessage(msg)              self.GetView().ProcessTableMessage(msg)
357              self.GetView().FitInside()              self.GetView().FitInside()
358    
359    
360      def __SetRow(self, row, group):      def __SetRow(self, row, group):
361          """Set a row's data to that of the group.          """Set a row's data to that of the group.
362    
# Line 398  class ClassTable(wxPyGridTableBase): Line 370  class ClassTable(wxPyGridTableBase):
370    
371          # either append or replace          # either append or replace
372          if row is None or row >= self.GetNumberRows():          if row is None or row >= self.GetNumberRows():
373              self.tdata.append(group)              self.clazz.AppendGroup(group)
374          elif row < 0:          elif row < 0:
375              self.tdata.insert(0, group)              self.clazz.InsertGroup(0, group)
376          else:          else:
377              self.tdata[row] = group              if row == 0:
378                    self.clazz.SetDefaultGroup(group)
379                else:
380                    self.clazz.ReplaceGroup(row - 1, group)
381    
382          self.__Modified()          self.__Modified()
383    
# Line 413  class ClassTable(wxPyGridTableBase): Line 388  class ClassTable(wxPyGridTableBase):
388      def GetRowLabelValue(self, row):      def GetRowLabelValue(self, row):
389          """Return the label for the given row."""          """Return the label for the given row."""
390    
391          group = self.tdata[row]          if row == 0:
392          if isinstance(group, ClassGroupDefault):   return _("Default")              return _("Default")
393          if isinstance(group, ClassGroupSingleton): return _("Singleton")          else:
394          if isinstance(group, ClassGroupRange):     return _("Range")              group = self.clazz.GetGroup(row - 1)
395          if isinstance(group, ClassGroupMap):       return _("Map")              if isinstance(group, ClassGroupDefault):   return _("Default")
396                if isinstance(group, ClassGroupSingleton): return _("Singleton")
397                if isinstance(group, ClassGroupRange):     return _("Range")
398                if isinstance(group, ClassGroupMap):       return _("Map")
399    
400          assert False # shouldn't get here          assert False # shouldn't get here
401          return _("")          return ""
402    
403      def GetNumberRows(self):      def GetNumberRows(self):
404          """Return the number of rows."""          """Return the number of rows."""
405          return len(self.tdata)          if self.clazz is None:
406                return 0
407    
408            return self.clazz.GetNumGroups() + 1 # +1 for default group
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 446  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 455  class ClassTable(wxPyGridTableBase): Line 435  class ClassTable(wxPyGridTableBase):
435          typeName -- unused, but needed to overload wxPyGridTableBase          typeName -- unused, but needed to overload wxPyGridTableBase
436          """          """
437    
438          group = self.tdata[row]          if row == 0:
439                group = self.clazz.GetDefaultGroup()
440            else:
441                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()
# Line 473  class ClassTable(wxPyGridTableBase): Line 460  class ClassTable(wxPyGridTableBase):
460          elif isinstance(group, ClassGroupRange):          elif isinstance(group, ClassGroupRange):
461              return _("%s - %s") % (group.GetMin(), group.GetMax())              return _("%s - %s") % (group.GetMin(), group.GetMax())
462    
463          assert False  # shouldn't get here          assert(False) # shouldn't get here
464          return None          return None
465    
466      def __ParseInput(self, value):      def __ParseInput(self, value):
# Line 488  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                    # the float call allows the user to enter 1.0 for 1
482                  conv = lambda p: int(float(p))                  conv = lambda p: int(float(p))
483              else:              else:
484                  conv = lambda p: p                  conv = lambda p: p
# Line 505  class ClassTable(wxPyGridTableBase): Line 493  class ClassTable(wxPyGridTableBase):
493              # function.              # function.
494              #              #
495              try:              try:
496                  return (conv(Str2Num(value)),)                  return (conv(value),)
497              except ValueError:              except ValueError:
498                  i = value.find('-')                  i = value.find('-')
499                  if i == 0:                  if i == 0:
500                      i = value.find('-', 1)                      i = value.find('-', 1)
501    
502                  return (conv(Str2Num(value[:i])), conv(Str2Num(value[i+1:])))                  return (conv(value[:i]), conv(value[i+1:]))
503    
504          assert False  # shouldn't get here          assert False  # shouldn't get here
505          return (0,)          return (0,)
# Line 529  class ClassTable(wxPyGridTableBase): Line 517  class ClassTable(wxPyGridTableBase):
517          typeName -- unused, but needed to overload wxPyGridTableBase          typeName -- unused, but needed to overload wxPyGridTableBase
518          """          """
519    
520          assert col >= 0 and col < self.GetNumberCols()          assert 0 <= col < self.GetNumberCols()
521          assert row >= 0 and row < self.GetNumberRows()          assert 0 <= row < self.GetNumberRows()
522    
523          group = self.tdata[row]          if row == 0:
524                group = self.clazz.GetDefaultGroup()
525            else:
526                group = self.clazz.GetGroup(row - 1)
527    
528          mod = True # assume the data will change          mod = True # assume the data will change
529    
530          if col == COL_SYMBOL:          if col == COL_VISIBLE:
531                group.SetVisible(value)
532            elif col == COL_SYMBOL:
533              group.SetProperties(value)              group.SetProperties(value)
534          elif col == COL_LABEL:          elif col == COL_LABEL:
535              group.SetLabel(value)              group.SetLabel(value)
# Line 566  class ClassTable(wxPyGridTableBase): Line 559  class ClassTable(wxPyGridTableBase):
559                      #                      #
560                      if len(dataInfo) == 1:                      if len(dataInfo) == 1:
561                          if not isinstance(group, ClassGroupSingleton):                          if not isinstance(group, ClassGroupSingleton):
562                              ngroup = ClassGroupSingleton(prop = props)                              ngroup = ClassGroupSingleton(props = props)
563                              changed = True                              changed = True
564                          ngroup.SetValue(dataInfo[0])                          ngroup.SetValue(dataInfo[0])
565                      elif len(dataInfo) == 2:                      elif len(dataInfo) == 2:
566                          if not isinstance(group, ClassGroupRange):                          if not isinstance(group, ClassGroupRange):
567                              ngroup = ClassGroupRange(prop = props)                              ngroup = ClassGroupRange(props = props)
568                              changed = True                              changed = True
569                          ngroup.SetRange(dataInfo[0], dataInfo[1])                          ngroup.SetRange(dataInfo[0], dataInfo[1])
570                      else:                      else:
# Line 592  class ClassTable(wxPyGridTableBase): Line 585  class ClassTable(wxPyGridTableBase):
585      def GetAttr(self, row, col, someExtraParameter):      def GetAttr(self, row, col, someExtraParameter):
586          """Returns the cell attributes"""          """Returns the cell attributes"""
587    
588          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  
589    
590      def GetClassGroup(self, row):      def GetClassGroup(self, row):
591          """Return the ClassGroup object representing row 'row'."""          """Return the ClassGroup object representing row 'row'."""
592    
593          return self.tdata[row] # self.GetValueAsCustom(row, COL_SYMBOL, None)          #return self.GetValueAsCustom(row, COL_SYMBOL, None)
594            if row == 0:
595                return self.clazz.GetDefaultGroup()
596            else:
597                return self.clazz.GetGroup(row - 1)
598    
599      def SetClassGroup(self, row, group):      def SetClassGroup(self, row, group):
600          self.__SetRow(row, group)          self.__SetRow(row, group)
# Line 638  class ClassTable(wxPyGridTableBase): Line 626  class ClassTable(wxPyGridTableBase):
626          """          """
627    
628          assert pos >= 0          assert pos >= 0
629          old_len = len(self.tdata)          old_len = self.GetNumberRows()
630          for row in range(pos, pos - numRows, -1):          for row in range(pos, pos - numRows, -1):
631              group = self.GetClassGroup(row)              group = self.GetClassGroup(row)
632              if not isinstance(group, ClassGroupDefault):              if row != 0:
633                  self.tdata.pop(row)                  self.clazz.RemoveGroup(row - 1)
634                  self.__Modified()                  self.__Modified()
635            
636          if self.IsModified():          if self.IsModified():
637              self.__NotifyRowChanges(old_len, len(self.tdata))              self.__NotifyRowChanges(old_len, self.GetNumberRows())
638    
639      def AppendRows(self, numRows = 1):      def AppendRows(self, numRows = 1):
640          """Append 'numRows' empty rows to the end of the table.          """Append 'numRows' empty rows to the end of the table.
# Line 654  class ClassTable(wxPyGridTableBase): Line 642  class ClassTable(wxPyGridTableBase):
642          The table is considered modified if any rows are appended.          The table is considered modified if any rows are appended.
643          """          """
644    
645          old_len = len(self.tdata)          old_len = self.GetNumberRows()
646          for i in range(numRows):          for i in range(numRows):
647              np = ClassGroupSingleton()              np = ClassGroupSingleton()
648              self.__SetRow(None, np)              self.__SetRow(None, np)
649    
650          if self.IsModified():          if self.IsModified():
651              self.__NotifyRowChanges(old_len, len(self.tdata))              self.__NotifyRowChanges(old_len, self.GetNumberRows())
652    
653    
654    ID_PROPERTY_OK = 4001
655    ID_PROPERTY_REVERT = 4002
656    ID_PROPERTY_ADD = 4003
657    ID_PROPERTY_GENCLASS = 4004
658    ID_PROPERTY_REMOVE = 4005
659    ID_PROPERTY_MOVEUP = 4006
660    ID_PROPERTY_MOVEDOWN = 4007
661    ID_PROPERTY_TRY = 4008
662    ID_PROPERTY_EDITSYM = 4009
663    ID_PROPERTY_CLOSE = 4010
664    ID_PROPERTY_SELECT = 4011
665    ID_PROPERTY_TITLE = 4012
666    ID_PROPERTY_FIELDTEXT = 4013
667    
668    BTN_ADD = 0
669    BTN_EDIT = 1
670    BTN_GEN = 2
671    BTN_UP = 3
672    BTN_DOWN = 4
673    BTN_RM = 5
674    
675    EB_LAYER_TITLE = 0
676    EB_SELECT_FIELD = 1
677    EB_GEN_CLASS = 2
678    
679  class Classifier(NonModalDialog):  class Classifier(NonModalDialog):
680    
681        type2string = {None:             _("None"),
682                       FIELDTYPE_STRING: _("Text"),
683                       FIELDTYPE_INT:    _("Integer"),
684                       FIELDTYPE_DOUBLE: _("Decimal")}
685    
686      def __init__(self, parent, name, layer, group = None):      def __init__(self, parent, name, layer, group = None):
687          NonModalDialog.__init__(self, parent, name,          NonModalDialog.__init__(self, parent, name, "")
                                 _("Classifier: %s") % layer.Title())  
688    
689          panel = wxPanel(self, -1, size=(100, 100))          self.__SetTitle(layer.Title())
690    
691          self.layer = layer          self.layer = layer
692    
# Line 677  class Classifier(NonModalDialog): Line 694  class Classifier(NonModalDialog):
694          field = self.originalClass.GetField()          field = self.originalClass.GetField()
695          fieldType = self.originalClass.GetFieldType()          fieldType = self.originalClass.GetFieldType()
696    
697            self.genDlg = None
698    
699          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
700    
701            panel = wxPanel(self, -1, size=(100, 100))
702    
703          panelBox = wxBoxSizer(wxVERTICAL)          panelBox = wxBoxSizer(wxVERTICAL)
704    
705          #panelBox.Add(wxStaticText(panel, -1, _("Layer: %s") % layer.Title()),          sizer = wxBoxSizer(wxHORIZONTAL)
706              #0, wxALIGN_LEFT | wxALL, 4)          sizer.Add(wxStaticText(panel, -1, _("Title: ")),
707                0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 4)
708            sizer.Add(wxTextCtrl(panel, ID_PROPERTY_TITLE, layer.Title()),
709                      1, wxGROW | wxALL, 4)
710            EVT_TEXT(self, ID_PROPERTY_TITLE, self._OnTitleChanged)
711    
712            panelBox.Add(sizer, 0, wxGROW, 4)
713    
714          panelBox.Add(wxStaticText(panel, -1,          panelBox.Add(wxStaticText(panel, -1,
715                                  _("Layer Type: %s") % layer.ShapeType()),                                  _("Type: %s") % layer.ShapeType()),
716              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
717    
718    
719            #####################
720    
721            #panelBox = wxBoxSizer(wxVERTICAL)
722            classBox = wxStaticBoxSizer(
723                        wxStaticBox(panel, -1, _("Classification")), wxVERTICAL)
724    
725    
726          #          #
727          # make field combo box          # make field choice box
728          #          #
729          self.fields = wxComboBox(panel, ID_PROPERTY_SELECT, "",          self.fields = wxChoice(panel, ID_PROPERTY_SELECT,)
730                                       style = wxCB_READONLY)          #self.fields = wxComboBox(panel, ID_PROPERTY_SELECT, "",
731            #                             style = wxCB_READONLY)
732    
733          self.num_cols = layer.table.field_count()          self.num_cols = layer.table.field_count()
734          # just assume the first field in case one hasn't been          # just assume the first field in case one hasn't been
# Line 699  class Classifier(NonModalDialog): Line 736  class Classifier(NonModalDialog):
736          self.__cur_field = 0          self.__cur_field = 0
737    
738          self.fields.Append("<None>")          self.fields.Append("<None>")
739          self.fields.SetClientData(0, None)  
740            if self.originalClass.GetFieldType() is None:
741                self.fields.SetClientData(0, copy.deepcopy(self.originalClass))
742            else:
743                self.fields.SetClientData(0, None)
744    
745          for i in range(self.num_cols):          for i in range(self.num_cols):
746              type, name, len, decc = layer.table.field_info(i)              type, name, len, decc = layer.table.field_info(i)
# Line 707  class Classifier(NonModalDialog): Line 748  class Classifier(NonModalDialog):
748    
749              if name == field:              if name == field:
750                  self.__cur_field = i + 1                  self.__cur_field = i + 1
751                  self.fields.SetClientData(i + 1, self.originalClass)                  self.fields.SetClientData(i + 1,
752                                              copy.deepcopy(self.originalClass))
753              else:              else:
754                  self.fields.SetClientData(i + 1, None)                  self.fields.SetClientData(i + 1, None)
755    
756    
757          ###########          ###########
758    
         self.fieldTypeText = wxStaticText(panel, -1, "")  
         panelBox.Add(self.fieldTypeText, 0,  
                      wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4)  
759    
760          propertyBox = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
761          propertyBox.Add(wxStaticText(panel, -1, _("Field: ")),          sizer.Add(wxStaticText(panel, ID_PROPERTY_FIELDTEXT, _("Field: ")),
762              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 4)
763          propertyBox.Add(self.fields, 1, wxGROW|wxALL, 4)          sizer.Add(self.fields, 1, wxGROW | wxALL, 4)
764          EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect)          EVT_CHOICE(self, ID_PROPERTY_SELECT, self._OnFieldSelect)
765            #EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect)
766    
767          panelBox.Add(propertyBox, 0, wxGROW, 4)          classBox.Add(sizer, 0, wxGROW, 4)
768    
769            self.fieldTypeText = wxStaticText(panel, -1, "")
770            classBox.Add(self.fieldTypeText, 0,
771                         wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4)
772    
773    
774          #          #
# Line 737  class Classifier(NonModalDialog): Line 781  class Classifier(NonModalDialog):
781          #          #
782          # Control buttons:          # Control buttons:
783          #          #
         self.controlButtons = []  
   
784          controlButtonBox = wxBoxSizer(wxVERTICAL)          controlButtonBox = wxBoxSizer(wxVERTICAL)
785    
786          button = wxButton(panel, ID_CLASSIFY_ADD, _("Add"))          button = wxButton(panel, ID_PROPERTY_GENCLASS, _("Generate Class"))
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_EDITPROPS, _("Edit Properties"))          button = wxButton(panel, ID_PROPERTY_ADD, _("Add"))
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_GENCLASS, _("Generate Class"))          button = wxButton(panel, ID_PROPERTY_MOVEUP, _("Move Up"))
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_MOVEUP, _("Move Up"))          button = wxButton(panel, ID_PROPERTY_MOVEDOWN, _("Move Down"))
796          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
797    
798          button = wxButton(panel, ID_CLASSIFY_MOVEDOWN, _("Move Down"))          button = wxButton(panel, ID_PROPERTY_EDITSYM, _("Edit Symbol"))
799          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
800    
801          controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)          controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)
802    
803          button = wxButton(panel, ID_CLASSIFY_REMOVE, _("Remove"))          button = wxButton(panel, ID_PROPERTY_REMOVE, _("Remove"))
804          controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)
         self.controlButtons.append(button)  
805    
806    
807          ###########          ###########
# Line 774  class Classifier(NonModalDialog): Line 810  class Classifier(NonModalDialog):
810          #          #
811    
812          self.classGrid = ClassGrid(panel, self)          self.classGrid = ClassGrid(panel, self)
         #self.__SetGridTable(self.__cur_field, group)  
         #self.fields.SetSelection(self.__cur_field)  
813    
814          # calling __SelectField after creating the classGrid fills in the          # calling __SelectField after creating the classGrid fills in the
815          # grid with the correct information          # grid with the correct information
816          #print "2------------------"          self.fields.SetSelection(self.__cur_field)
817          self.__SelectField(self.__cur_field, group = group)          self.__SelectField(self.__cur_field, group = group)
818    
         #self.classGrid.SelectGroup(group)  
   
819          controlBox.Add(self.classGrid, 1, wxGROW, 0)          controlBox.Add(self.classGrid, 1, wxGROW, 0)
820            controlBox.Add(controlButtonBox, 0, wxGROW, 10)
821    
822            classBox.Add(controlBox, 1, wxGROW, 10)
823            panelBox.Add(classBox, 1, wxGROW, 0)
824    
825            EVT_BUTTON(self, ID_PROPERTY_ADD, self._OnAdd)
826            EVT_BUTTON(self, ID_PROPERTY_EDITSYM, self._OnEditSymbol)
827            EVT_BUTTON(self, ID_PROPERTY_REMOVE, self._OnRemove)
828            EVT_BUTTON(self, ID_PROPERTY_GENCLASS, self._OnGenClass)
829            EVT_BUTTON(self, ID_PROPERTY_MOVEUP, self._OnMoveUp)
830            EVT_BUTTON(self, ID_PROPERTY_MOVEDOWN, self._OnMoveDown)
831    
832          controlBox.Add(controlButtonBox, 0, wxGROW, 10)          ###########
833          panelBox.Add(controlBox, 1, wxGROW, 10)  
834    
835            panel.SetAutoLayout(True)
836            panel.SetSizer(panelBox)
837            panelBox.SetSizeHints(panel)
838    
839          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)          topBox.Add(panel, 1, wxGROW | wxALL, 4)
         EVT_BUTTON(self, ID_CLASSIFY_EDITPROPS, self._OnEditGroupProperties)  
         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)  
840    
841          ###########          ###########
842    
843          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
844          buttonBox.Add(wxButton(panel, ID_CLASSIFY_OK, _("OK")),          buttonBox.Add(wxButton(self, ID_PROPERTY_TRY, _("Try")),
845                          0, wxALL, 4)
846            buttonBox.Add(60, 20, 0, wxALL, 4)
847            buttonBox.Add(wxButton(self, ID_PROPERTY_REVERT, _("Revert")),
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_APPLY, _("Apply")),          buttonBox.Add(wxButton(self, ID_PROPERTY_OK, _("OK")),
851                        0, wxALL, 4)                        0, wxALL, 4)
852          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
853          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CANCEL, _("Cancel")),          buttonBox.Add(wxButton(self, ID_PROPERTY_CLOSE, _("Close")),
854                        0, wxALL, 4)                        0, wxALL, 4)
855          panelBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)
856    
857          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)          EVT_BUTTON(self, ID_PROPERTY_OK, self._OnOK)
858          EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply)          EVT_BUTTON(self, ID_PROPERTY_TRY, self._OnTry)
859          EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel)          EVT_BUTTON(self, ID_PROPERTY_CLOSE, self._OnCloseBtn)
860            EVT_BUTTON(self, ID_PROPERTY_REVERT, self._OnRevert)
861    
862          ###########          ###########
863    
864            topBox.SetSizeHints(self)
         panel.SetAutoLayout(True)  
         panel.SetSizer(panelBox)  
         panelBox.SetSizeHints(panel)  
   
         topBox.Add(panel, 1, wxGROW, 0)  
         panelBox.SetSizeHints(self)  
865          self.SetAutoLayout(True)          self.SetAutoLayout(True)
866          self.SetSizer(topBox)          self.SetSizer(topBox)
867    
         #print "1------------------"  
868          #self.Fit()          #self.Fit()
869          ######################          ######################
870    
871          self.haveApplied = False          self.haveApplied = False
872    
873      def EditGroupProperties(self, row):      def EditSymbol(self, row):
874          table = self.classGrid.GetTable()          table = self.classGrid.GetTable()
875          prop = table.GetValueAsCustom(row, COL_SYMBOL, None)          prop = table.GetValueAsCustom(row, COL_SYMBOL, None)
876    
877          # get a new ClassGroupProperties object and copy the          # get a new ClassGroupProperties object and copy the
878          # values over to our current object          # values over to our current object
879          propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType())          propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType())
880    
881            self.Enable(False)
882          if propDlg.ShowModal() == wxID_OK:          if propDlg.ShowModal() == wxID_OK:
883              new_prop = propDlg.GetClassGroupProperties()              new_prop = propDlg.GetClassGroupProperties()
884              table.SetValueAsCustom(row, COL_SYMBOL, None, new_prop)              table.SetValueAsCustom(row, COL_SYMBOL, None, new_prop)
885            self.Enable(True)
886          propDlg.Destroy()          propDlg.Destroy()
887                    
888        def _SetClassification(self, clazz):
889            
890            self.fields.SetClientData(self.__cur_field, clazz)
891            self.classGrid.GetTable().SetClassification(clazz)
892    
893      def __BuildClassification(self, fieldIndex):      def __BuildClassification(self, fieldIndex, copyClass = False):
894    
895          numRows = self.classGrid.GetNumberRows()  #       numRows = self.classGrid.GetNumberRows()
896          assert numRows > 0  # there should always be a default row  #       assert numRows > 0  # there should always be a default row
897    
898          clazz = Classification()  #       clazz = Classification()
899          if fieldIndex == 0:          if fieldIndex == 0:
900              fieldName = None              fieldName = None
901              fieldType = None              fieldType = None
# Line 859  class Classifier(NonModalDialog): Line 903  class Classifier(NonModalDialog):
903              fieldName = self.fields.GetString(fieldIndex)              fieldName = self.fields.GetString(fieldIndex)
904              fieldType = self.layer.GetFieldType(fieldName)              fieldType = self.layer.GetFieldType(fieldName)
905    
906            clazz = self.classGrid.GetTable().GetClassification()
907    
908            if copyClass:
909                clazz = copy.deepcopy(clazz)
910    
911          clazz.SetField(fieldName)          clazz.SetField(fieldName)
912          clazz.SetFieldType(fieldType)          clazz.SetFieldType(fieldType)
913    
914    
915          table = self.classGrid.GetTable()  #       table = self.classGrid.GetTable()
916          clazz.SetDefaultGroup(table.GetClassGroup(0))  #       clazz.SetDefaultGroup(table.GetClassGroup(0))
917    
918          for i in range(1, numRows):  #       for i in range(1, numRows):
919              clazz.AddGroup(table.GetClassGroup(i))  #           clazz.AppendGroup(table.GetClassGroup(i))
920    
921          return clazz          return clazz
922    
# Line 886  class Classifier(NonModalDialog): Line 935  class Classifier(NonModalDialog):
935              fieldType = self.layer.GetFieldType(fieldName)              fieldType = self.layer.GetFieldType(fieldName)
936              clazz.SetFieldType(fieldType)              clazz.SetFieldType(fieldType)
937                                    
         #print "6------------------"  
938          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")}  
939    
940      def __SetFieldTypeText(self, fieldIndex):      def __SetFieldTypeText(self, fieldIndex):
941          fieldName = self.fields.GetString(fieldIndex)          fieldName = self.fields.GetString(fieldIndex)
# Line 905  class Classifier(NonModalDialog): Line 945  class Classifier(NonModalDialog):
945    
946          text = Classifier.type2string[fieldType]          text = Classifier.type2string[fieldType]
947    
948          self.fieldTypeText.SetLabel(_("Field Type: %s") % text)          self.fieldTypeText.SetLabel(_("Data Type: %s") % text)
949    
950      def __SelectField(self, newIndex, oldIndex = -1, group = None):      def __SelectField(self, newIndex, oldIndex = -1, group = None):
951            """This method assumes that the current selection for the
952          #print "3------------------"          combo has already been set by a call to SetSelection().
953            """
954    
955          assert oldIndex >= -1          assert oldIndex >= -1
956    
         self.fields.SetSelection(newIndex)  
   
957          if oldIndex != -1:          if oldIndex != -1:
958              clazz = self.__BuildClassification(oldIndex)              clazz = self.__BuildClassification(oldIndex)
959              self.fields.SetClientData(oldIndex, clazz)              self.fields.SetClientData(oldIndex, clazz)
960    
         #print "4------------------"  
961          self.__SetGridTable(newIndex, group)          self.__SetGridTable(newIndex, group)
         #print "5------------------"  
   
         enabled = newIndex != 0  
962    
963          for b in self.controlButtons:          self.__EnableButtons(EB_SELECT_FIELD, newIndex != 0)
             b.Enable(enabled)  
964    
965          self.__SetFieldTypeText(newIndex)          self.__SetFieldTypeText(newIndex)
966    
967        def __SetTitle(self, title):
968            if title != "":
969                title = ": " + title
970    
971            self.SetTitle(_("Layer Properties") + title)
972    
973      def _OnEditGroupProperties(self, event):      def _OnEditSymbol(self, event):
974          sel = self.classGrid.GetCurrentSelection()          sel = self.classGrid.GetCurrentSelection()
975    
976          if len(sel) == 1:          if len(sel) == 1:
977              self.EditGroupProperties(sel[0])              self.EditSymbol(sel[0])
978    
979      def _OnFieldSelect(self, event):      def _OnFieldSelect(self, event):
980          index = self.fields.GetSelection()          index = self.fields.GetSelection()
981          self.__SelectField(index, self.__cur_field)          self.__SelectField(index, self.__cur_field)
982          self.__cur_field = index          self.__cur_field = index
983    
984      def _OnApply(self, event):      def _OnTry(self, event):
985          """Put the data from the table into a new Classification and hand          """Put the data from the table into a new Classification and hand
986             it to the layer.             it to the layer.
987          """          """
# Line 954  class Classifier(NonModalDialog): Line 993  class Classifier(NonModalDialog):
993          # to begin with or it has been modified          # to begin with or it has been modified
994          #          #
995          if clazz is None or self.classGrid.GetTable().IsModified():          if clazz is None or self.classGrid.GetTable().IsModified():
996              clazz = self.__BuildClassification(self.__cur_field)              clazz = self.__BuildClassification(self.__cur_field, True)
997    
998          self.layer.SetClassification(clazz)          self.layer.SetClassification(clazz)
999    
1000          self.haveApplied = True          self.haveApplied = True
1001    
1002      def _OnOK(self, event):      def _OnOK(self, event):
1003          self._OnApply(event)          self._OnTry(event)
1004          self.OnClose(event)          self.Close()
1005    
1006      def _OnCancel(self, event):      def _OnCloseBtn(self, event):
1007            """Close is similar to Cancel except that any changes that were
1008            made and applied remain applied, but the currently displayed
1009            classification is discarded.
1010            """
1011    
1012            self.Close()
1013    
1014        def _OnRevert(self, event):
1015          """The layer's current classification stays the same."""          """The layer's current classification stays the same."""
1016          if self.haveApplied:          if self.haveApplied:
1017              self.layer.SetClassification(self.originalClass)              self.layer.SetClassification(self.originalClass)
1018    
1019          self.OnClose(event)          #self.Close()
1020    
1021      def _OnAdd(self, event):      def _OnAdd(self, event):
1022          self.classGrid.AppendRows()          self.classGrid.AppendRows()
# Line 979  class Classifier(NonModalDialog): Line 1026  class Classifier(NonModalDialog):
1026    
1027      def _OnGenClass(self, event):      def _OnGenClass(self, event):
1028    
1029          genDlg = ClassGenDialog(self,          self.genDlg = ClassGenDialog(self, self.layer,
1030                                  self.layer.table,                            self.fields.GetString(self.__cur_field))
1031                                  self.fields.GetString(self.__cur_field))  
1032            EVT_CLOSE(self.genDlg, self._OnGenDialogClose)
1033          if genDlg.ShowModal() == wxID_OK:  
1034              clazz = genDlg.GetClassification()          self.__EnableButtons(EB_GEN_CLASS, False)
1035              self.fields.SetClientData(self.__cur_field, clazz)  
1036              self.classGrid.GetTable().SetClassification(clazz)          self.genDlg.Show()
1037          genDlg.Destroy()  
1038        def _OnGenDialogClose(self, event):
1039            self.genDlg.Destroy()
1040            self.__EnableButtons(EB_GEN_CLASS, True)
1041    
1042      def _OnMoveUp(self, event):      def _OnMoveUp(self, event):
1043          sel = self.classGrid.GetCurrentSelection()          sel = self.classGrid.GetCurrentSelection()
1044    
         #print "sel: ", sel  
   
1045          if len(sel) == 1:          if len(sel) == 1:
1046              i = sel[0]              i = sel[0]
1047              if i > 1:              if i > 1:
# Line 1021  class Classifier(NonModalDialog): Line 1069  class Classifier(NonModalDialog):
1069                  self.classGrid.SelectRow(i + 1)                  self.classGrid.SelectRow(i + 1)
1070                  self.classGrid.MakeCellVisible(i + 1, 0)                  self.classGrid.MakeCellVisible(i + 1, 0)
1071    
1072        def _OnTitleChanged(self, event):
1073            obj = event.GetEventObject()
1074    
1075            self.layer.SetTitle(obj.GetValue())
1076            self.__SetTitle(self.layer.Title())
1077    
1078            self.__EnableButtons(EB_LAYER_TITLE, self.layer.Title() != "")
1079    
1080        def __EnableButtons(self, case, enable):
1081    
1082            if case == EB_LAYER_TITLE:  
1083                list = (ID_PROPERTY_OK,
1084                        ID_PROPERTY_CLOSE)
1085    
1086            elif case == EB_SELECT_FIELD:
1087                list = (ID_PROPERTY_GENCLASS,
1088                        ID_PROPERTY_ADD,
1089                        ID_PROPERTY_MOVEUP,
1090                        ID_PROPERTY_MOVEDOWN,
1091                        ID_PROPERTY_EDITSYM,
1092                        ID_PROPERTY_REMOVE)
1093    
1094            elif case == EB_GEN_CLASS:
1095                list = (ID_PROPERTY_SELECT,
1096                        ID_PROPERTY_FIELDTEXT,
1097                        ID_PROPERTY_GENCLASS,
1098                        ID_PROPERTY_EDITSYM)
1099    
1100            for id in list:
1101                self.FindWindowById(id).Enable(enable)
1102    
1103  ID_SELPROP_OK = 4001  ID_SELPROP_OK = 4001
1104  ID_SELPROP_CANCEL = 4002  ID_SELPROP_CANCEL = 4002
# Line 1047  class SelectPropertiesDialog(wxDialog): Line 1125  class SelectPropertiesDialog(wxDialog):
1125          previewBox = wxBoxSizer(wxVERTICAL)          previewBox = wxBoxSizer(wxVERTICAL)
1126          previewBox.Add(wxStaticText(self, -1, _("Preview:")),          previewBox.Add(wxStaticText(self, -1, _("Preview:")),
1127              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
1128          self.previewWin = ClassDataPreviewWindow(None, self.prop, shapeType,  
1129                                              self, ID_SELPROP_PREVIEW, (40, 40))          self.previewWin = ClassGroupPropertiesCtrl(
1130          previewBox.Add(self.previewWin, 1, wxGROW, 15)              self, ID_SELPROP_PREVIEW, self.prop, shapeType,
1131                (40, 40), wxSIMPLE_BORDER)
1132    
1133            self.previewWin.AllowEdit(False)
1134    
1135            previewBox.Add(self.previewWin, 1, wxGROW | wxALL, 4)
1136    
1137          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)
1138    
# Line 1131  class SelectPropertiesDialog(wxDialog): Line 1214  class SelectPropertiesDialog(wxDialog):
1214    
1215      def __GetColor(self, cur):      def __GetColor(self, cur):
1216          dialog = wxColourDialog(self)          dialog = wxColourDialog(self)
1217          if cur is not Color.None:          if cur is not Color.Transparent:
1218              dialog.GetColourData().SetColour(Color2wxColour(cur))              dialog.GetColourData().SetColour(Color2wxColour(cur))
1219    
1220          ret = None          ret = None
# Line 1149  class SelectPropertiesDialog(wxDialog): Line 1232  class SelectPropertiesDialog(wxDialog):
1232          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1233    
1234      def _OnChangeLineColorTrans(self, event):      def _OnChangeLineColorTrans(self, event):
1235          self.prop.SetLineColor(Color.None)          self.prop.SetLineColor(Color.Transparent)
1236          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1237                    
1238      def _OnChangeFillColor(self, event):      def _OnChangeFillColor(self, event):
# Line 1159  class SelectPropertiesDialog(wxDialog): Line 1242  class SelectPropertiesDialog(wxDialog):
1242          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1243    
1244      def _OnChangeFillColorTrans(self, event):      def _OnChangeFillColorTrans(self, event):
1245          self.prop.SetFill(Color.None)          self.prop.SetFill(Color.Transparent)
1246          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1247    
1248      def GetClassGroupProperties(self):      def GetClassGroupProperties(self):
# Line 1180  class ClassDataPreviewWindow(wxWindow): Line 1263  class ClassDataPreviewWindow(wxWindow):
1263          self.shapeType = shapeType          self.shapeType = shapeType
1264          self.previewer = ClassDataPreviewer()          self.previewer = ClassDataPreviewer()
1265    
1266        def GetProperties():
1267            return self.prop
1268    
1269      def _OnPaint(self, event):      def _OnPaint(self, event):
1270          dc = wxPaintDC(self)          dc = wxPaintDC(self)
1271    
# Line 1212  class ClassDataPreviewer: Line 1298  class ClassDataPreviewer:
1298              h = rect.GetHeight()              h = rect.GetHeight()
1299    
1300          stroke = prop.GetLineColor()          stroke = prop.GetLineColor()
1301          if stroke is Color.None:          if stroke is Color.Transparent:
1302              pen = wxTRANSPARENT_PEN              pen = wxTRANSPARENT_PEN
1303          else:          else:
1304              pen = wxPen(Color2wxColour(stroke),              pen = wxPen(Color2wxColour(stroke),
# Line 1220  class ClassDataPreviewer: Line 1306  class ClassDataPreviewer:
1306                          wxSOLID)                          wxSOLID)
1307    
1308          stroke = prop.GetFill()          stroke = prop.GetFill()
1309          if stroke is Color.None:          if stroke is Color.Transparent:
1310              brush = wxTRANSPARENT_BRUSH              brush = wxTRANSPARENT_BRUSH
1311          else:          else:
1312              brush = wxBrush(Color2wxColour(stroke), wxSOLID)              brush = wxBrush(Color2wxColour(stroke), wxSOLID)
# Line 1263  class ClassRenderer(wxPyGridCellRenderer Line 1349  class ClassRenderer(wxPyGridCellRenderer
1349              self.previewer.Draw(dc, rect, data.GetProperties(), self.shapeType)              self.previewer.Draw(dc, rect, data.GetProperties(), self.shapeType)
1350    
1351          if isSelected:          if isSelected:
1352              dc.SetPen(wxPen(wxColour(0 * 255, 0 * 255, 0 * 255),              dc.SetPen(wxPen(wxBLACK, 1, wxSOLID))
                       4, wxSOLID))  
1353              dc.SetBrush(wxTRANSPARENT_BRUSH)              dc.SetBrush(wxTRANSPARENT_BRUSH)
1354    
1355              dc.DrawRectangle(rect.GetX(), rect.GetY(),              dc.DrawRectangle(rect.GetX(), rect.GetY(),
1356                               rect.GetWidth(), rect.GetHeight())                               rect.GetWidth(), rect.GetHeight())
1357    
1358          dc.DestroyClippingRegion()          dc.DestroyClippingRegion()
1359    
1360    
1361    class ClassGroupPropertiesCtrl(wxWindow, wxControl):
1362    
1363        def __init__(self, parent, id, props, shapeType,
1364                     size = wxDefaultSize, style = 0):
1365    
1366            wxWindow.__init__(self, parent, id, size = size, style = style)
1367    
1368            self.SetProperties(props)
1369            self.SetShapeType(shapeType)
1370            self.AllowEdit(True)
1371    
1372            EVT_PAINT(self, self._OnPaint)
1373            EVT_LEFT_DCLICK(self, self._OnLeftDClick)
1374    
1375            self.previewer = ClassDataPreviewer()
1376    
1377        def _OnPaint(self, event):
1378            dc = wxPaintDC(self)
1379    
1380            # XXX: this doesn't seem to be having an effect:
1381            dc.DestroyClippingRegion()
1382    
1383            w, h = self.GetClientSize()
1384    
1385            self.previewer.Draw(dc,
1386                                wxRect(0, 0, w, h),
1387                                self.GetProperties(),
1388                                self.GetShapeType())
1389    
1390    
1391        def GetProperties(self):
1392            return self.props
1393    
1394        def SetProperties(self, props):
1395            self.props = props
1396            self.Refresh()
1397    
1398        def GetShapeType(self):
1399            return self.shapeType
1400    
1401        def SetShapeType(self, shapeType):
1402            self.shapeType = shapeType
1403            self.Refresh()
1404    
1405        def AllowEdit(self, allow):
1406            self.allowEdit = allow
1407    
1408        def DoEdit(self):
1409            if not self.allowEdit: return
1410    
1411            propDlg = SelectPropertiesDialog(NULL,
1412                                             self.GetProperties(),
1413                                             self.GetShapeType())
1414    
1415            if propDlg.ShowModal() == wxID_OK:
1416                new_prop = propDlg.GetClassGroupProperties()
1417                self.SetProperties(new_prop)
1418                self.Refresh()
1419    
1420            propDlg.Destroy()
1421    
1422        def _OnLeftDClick(self, event):
1423            self.DoEdit()

Legend:
Removed from v.606  
changed lines
  Added in v.782

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26