/[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 560 by jonathan, Wed Mar 26 11:05:47 2003 UTC revision 783 by jonathan, Tue Apr 29 17:29:32 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 27  from Thuban.Model.color import Color Line 26  from Thuban.Model.color import Color
26    
27  from Thuban.Model.layer import Layer, SHAPETYPE_ARC, SHAPETYPE_POLYGON, SHAPETYPE_POINT  from Thuban.Model.layer import Layer, SHAPETYPE_ARC, SHAPETYPE_POLYGON, SHAPETYPE_POINT
28    
29    from Thuban.UI.classgen import ClassGenDialog, ClassGenerator
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    
 ID_CLASSIFY_OK = 4001  
 ID_CLASSIFY_CANCEL = 4002  
 ID_CLASSIFY_ADD = 4003  
 ID_CLASSIFY_GENRANGE = 4004  
 ID_CLASSIFY_REMOVE = 4005  
 ID_CLASSIFY_MOVEUP = 4006  
 ID_CLASSIFY_MOVEDOWN = 4007  
 ID_CLASSIFY_APPLY = 4008  
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 59  FIELD_NAME = 2 Line 52  FIELD_NAME = 2
52  import weakref  import weakref
53  class ClassGrid(wxGrid):  class ClassGrid(wxGrid):
54    
55      def __init__(self, parent):  
56        def __init__(self, parent, classifier):
57          """Constructor.          """Constructor.
58    
59          parent -- the parent window          parent -- the parent window
# Line 68  class ClassGrid(wxGrid): Line 62  class ClassGrid(wxGrid):
62                   use for display.                   use for display.
63          """          """
64    
         #wxGrid.__init__(self, parent, ID_CLASS_TABLE, size = (340, 160))  
65          wxGrid.__init__(self, parent, ID_CLASS_TABLE)          wxGrid.__init__(self, parent, ID_CLASS_TABLE)
66          #self.SetTable(ClassTable(fieldData, layer.ShapeType(), self), True)  
67            self.classifier = classifier
68    
69            self.currentSelection = []
70    
71          EVT_GRID_CELL_LEFT_DCLICK(self, self._OnCellDClick)          EVT_GRID_CELL_LEFT_DCLICK(self, self._OnCellDClick)
72          EVT_GRID_RANGE_SELECT(self, self._OnSelectedRange)          EVT_GRID_RANGE_SELECT(self, self._OnSelectedRange)
73          EVT_GRID_SELECT_CELL(self, self._OnSelectedCell)          EVT_GRID_SELECT_CELL(self, self._OnSelectedCell)
74            EVT_GRID_COL_SIZE(self, self._OnCellResize)
75            EVT_GRID_ROW_SIZE(self, self._OnCellResize)
76    
77          self.currentSelection = []      #def GetCellAttr(self, row, col):
78            #print "GetCellAttr ", row, col
79            #wxGrid.GetCellAttr(self, row, col)
80    
81      def CreateTable(self, clazz, shapeType):      def CreateTable(self, clazz, shapeType, group = None):
82    
83          assert(isinstance(clazz, Classification))          assert isinstance(clazz, Classification)
84    
         self.shapeType = shapeType  
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              self.SetTable(ClassTable(clazz, self.shapeType, self), True)              table = ClassTable(self)
95          else:              self.SetTable(table, True)
96              table.Reset(clazz, self.shapeType)  
97    
98          self.SetSelectionMode(wxGrid.wxGridSelectRows)          self.SetSelectionMode(wxGrid.wxGridSelectRows)
99          self.ClearSelection()          self.ClearSelection()
100    
101            table.Reset(clazz, shapeType, group)
102    
103      def GetCurrentSelection(self):      def GetCurrentSelection(self):
104          """Return the currently highlighted rows as an increasing list          """Return the currently highlighted rows as an increasing list
105             of row numbers."""             of row numbers."""
# Line 103  class ClassGrid(wxGrid): Line 107  class ClassGrid(wxGrid):
107          sel.sort()          sel.sort()
108          return sel          return sel
109    
110      def SetCellRenderer(self, row, col):      def GetSelectedRows(self):
111          raise ValueError(_("Must not allow setting of renderer in ClassGrid!"))          return self.GetCurrentSelection()
112    
113        #def SetCellRenderer(self, row, col, renderer):
114            #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 169  class ClassGrid(wxGrid): Line 176  class ClassGrid(wxGrid):
176                  r = self.GetNumberRows() - 1                  r = self.GetNumberRows() - 1
177              self.SelectRow(r)              self.SelectRow(r)
178                    
179    
180        def SelectGroup(self, group, makeVisible = True):
181            if group is None: return
182    
183            assert isinstance(group, ClassGroup)
184    
185            table = self.GetTable()
186    
187            assert table is not None
188    
189            for i in range(table.GetNumberRows()):
190                g = table.GetClassGroup(i)
191                if g is group:
192                    self.SelectRow(i)
193                    if makeVisible:
194                        self.MakeCellVisible(i, 0)
195                    break
196    
197  #  #
198  # 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!
199  #  #
# Line 181  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:  
             prop = self.GetTable().GetValueAsCustom(r, c, None)  
             #prop = group.GetProperties()  
213    
214              # get a new ClassGroupProperties object and copy the          if c == COL_SYMBOL:
215              # values over to our current object              self.classifier.EditSymbol(r)
216              propDlg = SelectPropertiesDialog(NULL, prop, self.shapeType)          else:
217              if propDlg.ShowModal() == wxID_OK:              event.Skip()
                 new_prop = propDlg.GetClassGroupProperties()  
                 #prop.SetProperties(new_prop)  
                 self.GetTable().SetValueAsCustom(r, c, None, new_prop)  
             propDlg.Destroy()  
218    
219      #      #
220      # _OnSelectedRange() and _OnSelectedCell() were borrowed      # _OnSelectedRange() and _OnSelectedCell() were borrowed
# Line 223  class ClassGrid(wxGrid): Line 241  class ClassGrid(wxGrid):
241          #self.ConfigureForSelection()          #self.ConfigureForSelection()
242          event.Skip()          event.Skip()
243    
244        def _OnCellResize(self, event):
245            self.FitInside()
246    
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")]
251    
     __col_labels = [_("Symbol"), _("Value"), _("Label")]  
252    
253      def __init__(self, clazz, shapeType, view = None):      def __init__(self, view = None):
254        #def __init__(self, clazz, shapeType, view = None):
255          """Constructor.          """Constructor.
256    
257          shapeType -- the type of shape that the layer uses          shapeType -- the type of shape that the layer uses
# Line 240  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
         self.tdata = []  
265    
266          self.Reset(clazz, shapeType)          self.clazz = None
267            self.__colAttr = {}
268    
269      def Reset(self, clazz, shapeType):          self.SetView(view)
270    
271        def Reset(self, clazz, shapeType, group = None):
272          """Reset the table with the given data.          """Reset the table with the given data.
273    
274          This is necessary because wxWindows does not allow a grid's          This is necessary because wxWindows does not allow a grid's
# Line 259  class ClassTable(wxPyGridTableBase): Line 282  class ClassTable(wxPyGridTableBase):
282          shapeType -- the type of shape that the layer uses          shapeType -- the type of shape that the layer uses
283          """          """
284    
285          assert(isinstance(clazz, Classification))          assert isinstance(clazz, Classification)
286    
287          self.GetView().BeginBatch()          self.GetView().BeginBatch()
288    
289          self.fieldType = clazz.GetFieldType()          self.fieldType = clazz.GetFieldType()
290          self.shapeType = shapeType          self.shapeType = shapeType
291    
292          old_len = len(self.tdata)          self.SetClassification(clazz, group)
293            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()
309            self.GetView().FitInside()
310    
311        def GetClassification(self):
312            return self.clazz
313    
314        def SetClassification(self, clazz, group = None):
315    
316          self.tdata = []          self.GetView().BeginBatch()
317    
318            old_len = self.GetNumberRows()
319    
320            row = -1
321            self.clazz = clazz
322    
323            self.__NotifyRowChanges(old_len, self.GetNumberRows())
324    
325          #          #
326          # copy the data out of the classification and into our          # XXX: this is dead code at the moment
         # array  
327          #          #
328          for p in clazz:          if row > -1:
329              np = copy.deepcopy(p)              self.GetView().ClearSelection()
330              self.__SetRow(-1, np)              self.GetView().SelectRow(row)
331                self.GetView().MakeCellVisible(row, 0)
332    
333            self.__Modified()
         self.__Modified(-1)  
334    
         self.__NotifyRowChanges(old_len, len(self.tdata))  
335    
               
336          self.GetView().EndBatch()          self.GetView().EndBatch()
337            self.GetView().FitInside()
338    
339      def __NotifyRowChanges(self, curRows, newRows):      def __NotifyRowChanges(self, curRows, newRows):
340          #          #
# Line 300  class ClassTable(wxPyGridTableBase): Line 350  class ClassTable(wxPyGridTableBase):
350          elif newRows < curRows:          elif newRows < curRows:
351              msg = wxGridTableMessage(self,              msg = wxGridTableMessage(self,
352                          wxGRIDTABLE_NOTIFY_ROWS_DELETED,                          wxGRIDTABLE_NOTIFY_ROWS_DELETED,
353                          curRows - newRows,    # position                          curRows,              # position
354                          curRows - newRows)    # how many                          curRows - newRows)    # how many
355              self.GetView().ProcessTableMessage(msg)              self.GetView().ProcessTableMessage(msg)
356              self.GetView().FitInside()              self.GetView().FitInside()
357    
358    
359      def __SetRow(self, row, group):      def __SetRow(self, row, group):
360          """Set a row's data to that of the group.          """Set a row's data to that of the group.
361    
362          The table is considered modified after this operation.          The table is considered modified after this operation.
363    
364          row -- if row is -1 or greater than the current number of rows          row -- if row is < 0 'group' is inserted at the top of the table
365                 then group is appended to the end.                 if row is >= GetNumberRows() or None 'group' is append to
366                        the end of the table.
367                   otherwise 'group' replaces row 'row'
368          """          """
369    
370          # either append or replace          # either append or replace
371          if row == -1 or row >= self.GetNumberRows():          if row is None or row >= self.GetNumberRows():
372              self.tdata.append(group)              self.clazz.AppendGroup(group)
373            elif row < 0:
374                self.clazz.InsertGroup(0, group)
375          else:          else:
376              self.tdata[row] = group              if row == 0:
377                    self.clazz.SetDefaultGroup(group)
378                else:
379                    self.clazz.ReplaceGroup(row - 1, group)
380    
381          self.__Modified()          self.__Modified()
382    
# Line 329  class ClassTable(wxPyGridTableBase): Line 387  class ClassTable(wxPyGridTableBase):
387      def GetRowLabelValue(self, row):      def GetRowLabelValue(self, row):
388          """Return the label for the given row."""          """Return the label for the given row."""
389    
390          group = self.tdata[row]          if row == 0:
391          if isinstance(group, ClassGroupDefault):   return _("Default")              return _("Default")
392          if isinstance(group, ClassGroupSingleton): return _("Singleton")          else:
393          if isinstance(group, ClassGroupRange):     return _("Range")              group = self.clazz.GetGroup(row - 1)
394          if isinstance(group, ClassGroupMap):       return _("Map")              if isinstance(group, ClassGroupDefault):   return _("Default")
395                if isinstance(group, ClassGroupSingleton): return _("Singleton")
396                if isinstance(group, ClassGroupRange):     return _("Range")
397                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."""
404          return len(self.tdata)          if self.clazz is None:
405                return 0
406    
407            return self.clazz.GetNumGroups() + 1 # +1 for default group
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 362  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 371  class ClassTable(wxPyGridTableBase): Line 434  class ClassTable(wxPyGridTableBase):
434          typeName -- unused, but needed to overload wxPyGridTableBase          typeName -- unused, but needed to overload wxPyGridTableBase
435          """          """
436    
437          group = self.tdata[row]          if row == 0:
438                group = self.clazz.GetDefaultGroup()
439            else:
440                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()
# Line 380  class ClassTable(wxPyGridTableBase): Line 450  class ClassTable(wxPyGridTableBase):
450              return group.GetLabel()              return group.GetLabel()
451    
452          # col must be COL_VALUE          # col must be COL_VALUE
453          assert(col == COL_VALUE)          assert col == COL_VALUE
454    
455          if isinstance(group, ClassGroupDefault):          if isinstance(group, ClassGroupDefault):
456              return _("DEFAULT")              return _("DEFAULT")
# Line 404  class ClassTable(wxPyGridTableBase): Line 474  class ClassTable(wxPyGridTableBase):
474    
475          if type == FIELDTYPE_STRING:          if type == FIELDTYPE_STRING:
476              return (value,)              return (value,)
477          elif type == FIELDTYPE_INT or type == 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 421  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,)
505                            
506    
# Line 445  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          group = self.tdata[row]          if row == 0:
523                group = self.clazz.GetDefaultGroup()
524            else:
525                group = self.clazz.GetGroup(row - 1)
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 482  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:
570                          assert(False)                          assert False
571                          pass                          pass
572    
573                      if changed:                      if changed:
574                          ngroup.SetLabel(group.GetLabel())                          ngroup.SetLabel(group.GetLabel())
575                          self.SetClassGroup(row, ngroup)                          self.SetClassGroup(row, ngroup)
576          else:          else:
577              assert(False) # shouldn't be here              assert False # shouldn't be here
578              pass              pass
579    
580          if mod:          if mod:
# Line 508  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'."""
591    
592          return self.tdata[row] # self.GetValueAsCustom(row, COL_SYMBOL, None)          #return self.GetValueAsCustom(row, COL_SYMBOL, None)
593            if row == 0:
594                return self.clazz.GetDefaultGroup()
595            else:
596                return self.clazz.GetGroup(row - 1)
597    
598      def SetClassGroup(self, row, group):      def SetClassGroup(self, row, group):
599          self.__SetRow(row, group)          self.__SetRow(row, group)
# Line 553  class ClassTable(wxPyGridTableBase): Line 624  class ClassTable(wxPyGridTableBase):
624          The table is considered modified if any rows are removed.          The table is considered modified if any rows are removed.
625          """          """
626    
627          assert(pos >= 0)          assert pos >= 0
628          old_len = len(self.tdata)          old_len = self.GetNumberRows()
629          for row in range(pos, pos - numRows, -1):          for row in range(pos, pos - numRows, -1):
630              group = self.GetClassGroup(row)              group = self.GetClassGroup(row)
631              if not isinstance(group, ClassGroupDefault):              if row != 0:
632                  self.tdata.pop(row)                  self.clazz.RemoveGroup(row - 1)
633                  self.__Modified()                  self.__Modified()
634            
635          if self.IsModified():          if self.IsModified():
636              self.__NotifyRowChanges(old_len, len(self.tdata))              self.__NotifyRowChanges(old_len, self.GetNumberRows())
637    
638      def AppendRows(self, numRows = 1):      def AppendRows(self, numRows = 1):
639          """Append 'numRows' empty rows to the end of the table.          """Append 'numRows' empty rows to the end of the table.
# Line 570  class ClassTable(wxPyGridTableBase): Line 641  class ClassTable(wxPyGridTableBase):
641          The table is considered modified if any rows are appended.          The table is considered modified if any rows are appended.
642          """          """
643    
644          old_len = len(self.tdata)          old_len = self.GetNumberRows()
645          for i in range(numRows):          for i in range(numRows):
646              np = ClassGroupSingleton()              np = ClassGroupSingleton()
647              self.__SetRow(-1, np)              self.__SetRow(None, np)
648    
649          if self.IsModified():          if self.IsModified():
650              self.__NotifyRowChanges(old_len, len(self.tdata))              self.__NotifyRowChanges(old_len, self.GetNumberRows())
651    
652    
653    ID_PROPERTY_OK = 4001
654    ID_PROPERTY_REVERT = 4002
655    ID_PROPERTY_ADD = 4003
656    ID_PROPERTY_GENCLASS = 4004
657    ID_PROPERTY_REMOVE = 4005
658    ID_PROPERTY_MOVEUP = 4006
659    ID_PROPERTY_MOVEDOWN = 4007
660    ID_PROPERTY_TRY = 4008
661    ID_PROPERTY_EDITSYM = 4009
662    ID_PROPERTY_CLOSE = 4010
663    ID_PROPERTY_SELECT = 4011
664    ID_PROPERTY_TITLE = 4012
665    ID_PROPERTY_FIELDTEXT = 4013
666    
667    BTN_ADD = 0
668    BTN_EDIT = 1
669    BTN_GEN = 2
670    BTN_UP = 3
671    BTN_DOWN = 4
672    BTN_RM = 5
673    
674    EB_LAYER_TITLE = 0
675    EB_SELECT_FIELD = 1
676    EB_GEN_CLASS = 2
677    
678  class Classifier(NonModalDialog):  class Classifier(NonModalDialog):
679    
680      def __init__(self, parent, name, layer):      type2string = {None:             _("None"),
681          NonModalDialog.__init__(self, parent, name,                     FIELDTYPE_STRING: _("Text"),
682                                  _("Classifier: %s") % layer.Title())                     FIELDTYPE_INT:    _("Integer"),
683                       FIELDTYPE_DOUBLE: _("Decimal")}
684    
685        def __init__(self, parent, name, layer, group = None):
686            NonModalDialog.__init__(self, parent, name, "")
687    
688          panel = wxPanel(self, -1, size=(100, 100))          self.__SetTitle(layer.Title())
689    
690          self.layer = layer          self.layer = layer
691    
# Line 593  class Classifier(NonModalDialog): Line 693  class Classifier(NonModalDialog):
693          field = self.originalClass.GetField()          field = self.originalClass.GetField()
694          fieldType = self.originalClass.GetFieldType()          fieldType = self.originalClass.GetFieldType()
695    
696            self.genDlg = None
697    
698          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
699    
700            panel = wxPanel(self, -1, size=(100, 100))
701    
702          panelBox = wxBoxSizer(wxVERTICAL)          panelBox = wxBoxSizer(wxVERTICAL)
703    
704          #panelBox.Add(wxStaticText(panel, -1, _("Layer: %s") % layer.Title()),          sizer = wxBoxSizer(wxHORIZONTAL)
705              #0, wxALIGN_LEFT | wxALL, 4)          sizer.Add(wxStaticText(panel, -1, _("Title: ")),
706                0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 4)
707            sizer.Add(wxTextCtrl(panel, ID_PROPERTY_TITLE, layer.Title()),
708                      1, wxGROW | wxALL, 4)
709            EVT_TEXT(self, ID_PROPERTY_TITLE, self._OnTitleChanged)
710    
711            panelBox.Add(sizer, 0, wxGROW, 4)
712    
713          panelBox.Add(wxStaticText(panel, -1,          panelBox.Add(wxStaticText(panel, -1,
714                                  _("Layer Type: %s") % layer.ShapeType()),                                  _("Type: %s") % layer.ShapeType()),
715              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
716    
717    
718            #####################
719    
720            #panelBox = wxBoxSizer(wxVERTICAL)
721            classBox = wxStaticBoxSizer(
722                        wxStaticBox(panel, -1, _("Classification")), wxVERTICAL)
723    
724    
725          #          #
726          # make field combo box          # make field choice box
727          #          #
728          self.fields = wxComboBox(panel, ID_PROPERTY_SELECT, "",          self.fields = wxChoice(panel, ID_PROPERTY_SELECT,)
729                                       style = wxCB_READONLY)          #self.fields = wxComboBox(panel, ID_PROPERTY_SELECT, "",
730            #                             style = wxCB_READONLY)
731    
732          self.num_cols = layer.table.field_count()          self.num_cols = layer.table.field_count()
733          # just assume the first field in case one hasn't been          # just assume the first field in case one hasn't been
# Line 615  class Classifier(NonModalDialog): Line 735  class Classifier(NonModalDialog):
735          self.__cur_field = 0          self.__cur_field = 0
736    
737          self.fields.Append("<None>")          self.fields.Append("<None>")
738          self.fields.SetClientData(0, None)  
739            if self.originalClass.GetFieldType() is None:
740                self.fields.SetClientData(0, copy.deepcopy(self.originalClass))
741            else:
742                self.fields.SetClientData(0, None)
743    
744          for i in range(self.num_cols):          for i in range(self.num_cols):
745              type, name, len, decc = layer.table.field_info(i)              type, name, len, decc = layer.table.field_info(i)
# Line 623  class Classifier(NonModalDialog): Line 747  class Classifier(NonModalDialog):
747    
748              if name == field:              if name == field:
749                  self.__cur_field = i + 1                  self.__cur_field = i + 1
750                  self.fields.SetClientData(i + 1, self.originalClass)                  self.fields.SetClientData(i + 1,
751                                              copy.deepcopy(self.originalClass))
752              else:              else:
753                  self.fields.SetClientData(i + 1, None)                  self.fields.SetClientData(i + 1, None)
754    
755    
756          ###########          ###########
757    
758    
759            sizer = wxBoxSizer(wxHORIZONTAL)
760            sizer.Add(wxStaticText(panel, ID_PROPERTY_FIELDTEXT, _("Field: ")),
761                0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 4)
762            sizer.Add(self.fields, 1, wxGROW | wxALL, 4)
763            EVT_CHOICE(self, ID_PROPERTY_SELECT, self._OnFieldSelect)
764            #EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self._OnFieldSelect)
765    
766            classBox.Add(sizer, 0, wxGROW, 4)
767    
768          self.fieldTypeText = wxStaticText(panel, -1, "")          self.fieldTypeText = wxStaticText(panel, -1, "")
769          panelBox.Add(self.fieldTypeText, 0,          classBox.Add(self.fieldTypeText, 0,
770                       wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4)                       wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4)
771    
         propertyBox = wxBoxSizer(wxHORIZONTAL)  
         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)  
   
         panelBox.Add(propertyBox, 0, wxGROW, 4)  
772    
         ###########  
773          #          #
774          # Classification data table          # Control Box
775          #          #
   
776          controlBox = wxBoxSizer(wxHORIZONTAL)          controlBox = wxBoxSizer(wxHORIZONTAL)
777    
         self.classGrid = ClassGrid(panel)  
         self.__SetGridTable(self.__cur_field)  
   
         controlBox.Add(self.classGrid, 1, wxGROW, 0)  
778    
779          ###########          ###########
780          #          #
781          # Control buttons:          # Control buttons:
782          #          #
         self.controlButtons = []  
   
783          controlButtonBox = wxBoxSizer(wxVERTICAL)          controlButtonBox = wxBoxSizer(wxVERTICAL)
784    
785          button = wxButton(panel, ID_CLASSIFY_ADD, _("Add"))          button = wxButton(panel, ID_PROPERTY_GENCLASS, _("Generate Class"))
786          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
787    
788          #button = wxButton(panel, ID_CLASSIFY_GENRANGE, _("Generate Ranges"))          button = wxButton(panel, ID_PROPERTY_ADD, _("Add"))
789          #controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
790          #self.controlButtons.append(button)  
791            button = wxButton(panel, ID_PROPERTY_MOVEUP, _("Move Up"))
792            controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
793    
794          button = wxButton(panel, ID_CLASSIFY_MOVEUP, _("Move Up"))          button = wxButton(panel, ID_PROPERTY_MOVEDOWN, _("Move Down"))
795          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
796    
797          button = wxButton(panel, ID_CLASSIFY_MOVEDOWN, _("Move Down"))          button = wxButton(panel, ID_PROPERTY_EDITSYM, _("Edit Symbol"))
798          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL, 4)
         self.controlButtons.append(button)  
799    
800          controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)          controlButtonBox.Add(60, 20, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)
801    
802          button = wxButton(panel, ID_CLASSIFY_REMOVE, _("Remove"))          button = wxButton(panel, ID_PROPERTY_REMOVE, _("Remove"))
803          controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)          controlButtonBox.Add(button, 0, wxGROW | wxALL | wxALIGN_BOTTOM, 4)
         self.controlButtons.append(button)  
804    
805    
806            ###########
807            #
808            # Classification data table
809            #
810    
811            self.classGrid = ClassGrid(panel, self)
812    
813            # calling __SelectField after creating the classGrid fills in the
814            # grid with the correct information
815            self.fields.SetSelection(self.__cur_field)
816            self.__SelectField(self.__cur_field, group = group)
817    
818            controlBox.Add(self.classGrid, 1, wxGROW, 0)
819          controlBox.Add(controlButtonBox, 0, wxGROW, 10)          controlBox.Add(controlButtonBox, 0, wxGROW, 10)
         panelBox.Add(controlBox, 1, wxGROW, 10)  
820    
821          EVT_BUTTON(self, ID_CLASSIFY_ADD, self._OnAdd)          classBox.Add(controlBox, 1, wxGROW, 10)
822          EVT_BUTTON(self, ID_CLASSIFY_REMOVE, self._OnRemove)          panelBox.Add(classBox, 1, wxGROW, 0)
823          EVT_BUTTON(self, ID_CLASSIFY_GENRANGE, self._OnGenRange)  
824          EVT_BUTTON(self, ID_CLASSIFY_MOVEUP, self._OnMoveUp)          EVT_BUTTON(self, ID_PROPERTY_ADD, self._OnAdd)
825          EVT_BUTTON(self, ID_CLASSIFY_MOVEDOWN, self._OnMoveDown)          EVT_BUTTON(self, ID_PROPERTY_EDITSYM, self._OnEditSymbol)
826            EVT_BUTTON(self, ID_PROPERTY_REMOVE, self._OnRemove)
827            EVT_BUTTON(self, ID_PROPERTY_GENCLASS, self._OnGenClass)
828            EVT_BUTTON(self, ID_PROPERTY_MOVEUP, self._OnMoveUp)
829            EVT_BUTTON(self, ID_PROPERTY_MOVEDOWN, self._OnMoveDown)
830    
831            ###########
832    
833    
834            panel.SetAutoLayout(True)
835            panel.SetSizer(panelBox)
836            panelBox.SetSizeHints(panel)
837    
838            topBox.Add(panel, 1, wxGROW | wxALL, 4)
839    
840          ###########          ###########
841    
842          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
843          buttonBox.Add(wxButton(panel, ID_CLASSIFY_OK, _("OK")),          buttonBox.Add(wxButton(self, ID_PROPERTY_TRY, _("Try")),
844                          0, wxALL, 4)
845            buttonBox.Add(60, 20, 0, wxALL, 4)
846            buttonBox.Add(wxButton(self, ID_PROPERTY_REVERT, _("Revert")),
847                        0, wxALL, 4)                        0, wxALL, 4)
848          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
849          buttonBox.Add(wxButton(panel, ID_CLASSIFY_APPLY, _("Apply")),          buttonBox.Add(wxButton(self, ID_PROPERTY_OK, _("OK")),
850                        0, wxALL, 4)                        0, wxALL, 4)
851          buttonBox.Add(60, 20, 0, wxALL, 4)          buttonBox.Add(60, 20, 0, wxALL, 4)
852          buttonBox.Add(wxButton(panel, ID_CLASSIFY_CANCEL, _("Cancel")),          buttonBox.Add(wxButton(self, ID_PROPERTY_CLOSE, _("Close")),
853                        0, wxALL, 4)                        0, wxALL, 4)
854          panelBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0)
855    
856          EVT_BUTTON(self, ID_CLASSIFY_OK, self._OnOK)          EVT_BUTTON(self, ID_PROPERTY_OK, self._OnOK)
857          EVT_BUTTON(self, ID_CLASSIFY_APPLY, self._OnApply)          EVT_BUTTON(self, ID_PROPERTY_TRY, self._OnTry)
858          EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self._OnCancel)          EVT_BUTTON(self, ID_PROPERTY_CLOSE, self._OnCloseBtn)
859            EVT_BUTTON(self, ID_PROPERTY_REVERT, self._OnRevert)
860    
861          ###########          ###########
862    
863          self.fields.SetSelection(self.__cur_field)          topBox.SetSizeHints(self)
         self.__SelectField(self.__cur_field)  
   
         panel.SetAutoLayout(True)  
         panel.SetSizer(panelBox)  
         panelBox.SetSizeHints(panel)  
   
         topBox.Add(panel, 1, wxGROW, 0)  
         panelBox.SetSizeHints(self)  
864          self.SetAutoLayout(True)          self.SetAutoLayout(True)
865          self.SetSizer(topBox)          self.SetSizer(topBox)
866    
867            #self.Fit()
868          ######################          ######################
869    
870          self.haveApplied = False          self.haveApplied = False
871    
872      def __BuildClassification(self, fieldIndex):      def EditSymbol(self, row):
873            table = self.classGrid.GetTable()
874            prop = table.GetValueAsCustom(row, COL_SYMBOL, None)
875    
876            # get a new ClassGroupProperties object and copy the
877            # values over to our current object
878            propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType())
879    
880            self.Enable(False)
881            if propDlg.ShowModal() == wxID_OK:
882                new_prop = propDlg.GetClassGroupProperties()
883                table.SetValueAsCustom(row, COL_SYMBOL, None, new_prop)
884            self.Enable(True)
885            propDlg.Destroy()
886            
887        def _SetClassification(self, clazz):
888            
889            self.fields.SetClientData(self.__cur_field, clazz)
890            self.classGrid.GetTable().SetClassification(clazz)
891    
892        def __BuildClassification(self, fieldIndex, copyClass = False):
893    
894          numRows = self.classGrid.GetNumberRows()  #       numRows = self.classGrid.GetNumberRows()
895          assert(numRows > 0) # there should always be a default row  #       assert numRows > 0  # there should always be a default row
896    
897          clazz = Classification()  #       clazz = Classification()
898          if fieldIndex == 0:          if fieldIndex == 0:
899              fieldName = None              fieldName = None
900              fieldType = None              fieldType = None
# Line 741  class Classifier(NonModalDialog): Line 902  class Classifier(NonModalDialog):
902              fieldName = self.fields.GetString(fieldIndex)              fieldName = self.fields.GetString(fieldIndex)
903              fieldType = self.layer.GetFieldType(fieldName)              fieldType = self.layer.GetFieldType(fieldName)
904    
905            clazz = self.classGrid.GetTable().GetClassification()
906    
907            if copyClass:
908                clazz = copy.deepcopy(clazz)
909    
910          clazz.SetField(fieldName)          clazz.SetField(fieldName)
911          clazz.SetFieldType(fieldType)          clazz.SetFieldType(fieldType)
912    
913    
914          table = self.classGrid.GetTable()  #       table = self.classGrid.GetTable()
915          clazz.SetDefaultGroup(table.GetClassGroup(0))  #       clazz.SetDefaultGroup(table.GetClassGroup(0))
916    
917          for i in range(1, numRows):  #       for i in range(1, numRows):
918              clazz.AddGroup(table.GetClassGroup(i))  #           clazz.AppendGroup(table.GetClassGroup(i))
919    
920          return clazz          return clazz
921    
922      def __SetGridTable(self, fieldIndex):      def __SetGridTable(self, fieldIndex, group = None):
923    
924          clazz = self.fields.GetClientData(fieldIndex)          clazz = self.fields.GetClientData(fieldIndex)
925    
# Line 768  class Classifier(NonModalDialog): Line 934  class Classifier(NonModalDialog):
934              fieldType = self.layer.GetFieldType(fieldName)              fieldType = self.layer.GetFieldType(fieldName)
935              clazz.SetFieldType(fieldType)              clazz.SetFieldType(fieldType)
936                                    
937          self.classGrid.CreateTable(clazz, self.layer.ShapeType())          self.classGrid.CreateTable(clazz, self.layer.ShapeType(), group)
   
   
   
     type2string = {None:             _("None"),  
                    FIELDTYPE_STRING: _("Text"),  
                    FIELDTYPE_INT:    _("Integer"),  
                    FIELDTYPE_DOUBLE: _("Decimal")}  
938    
939      def __SetFieldTypeText(self, fieldIndex):      def __SetFieldTypeText(self, fieldIndex):
940          fieldName = self.fields.GetString(fieldIndex)          fieldName = self.fields.GetString(fieldIndex)
941          fieldType = self.layer.GetFieldType(fieldName)          fieldType = self.layer.GetFieldType(fieldName)
942    
943          assert(Classifier.type2string.has_key(fieldType))          assert Classifier.type2string.has_key(fieldType)
944    
945          text = Classifier.type2string[fieldType]          text = Classifier.type2string[fieldType]
946    
947          self.fieldTypeText.SetLabel(_("Field Type: %s") % text)          self.fieldTypeText.SetLabel(_("Data Type: %s") % text)
948    
949      def __SelectField(self, newIndex, oldIndex = -1):      def __SelectField(self, newIndex, oldIndex = -1, group = None):
950            """This method assumes that the current selection for the
951            combo has already been set by a call to SetSelection().
952            """
953    
954          assert(oldIndex >= -1)          assert oldIndex >= -1
955    
956          if oldIndex != -1:          if oldIndex != -1:
957              clazz = self.__BuildClassification(oldIndex)              clazz = self.__BuildClassification(oldIndex)
958              self.fields.SetClientData(oldIndex, clazz)              self.fields.SetClientData(oldIndex, clazz)
959    
960          self.__SetGridTable(newIndex)          self.__SetGridTable(newIndex, group)
961    
962          enabled = newIndex != 0          self.__EnableButtons(EB_SELECT_FIELD, newIndex != 0)
   
         for b in self.controlButtons:  
             b.Enable(enabled)  
963    
964          self.__SetFieldTypeText(newIndex)          self.__SetFieldTypeText(newIndex)
965    
966        def __SetTitle(self, title):
967            if title != "":
968                title = ": " + title
969    
970            self.SetTitle(_("Layer Properties") + title)
971    
972        def _OnEditSymbol(self, event):
973            sel = self.classGrid.GetCurrentSelection()
974    
975            if len(sel) == 1:
976                self.EditSymbol(sel[0])
977    
978      def _OnFieldSelect(self, event):      def _OnFieldSelect(self, event):
979          index = self.fields.GetSelection()          index = self.fields.GetSelection()
980          self.__SelectField(index, self.__cur_field)          self.__SelectField(index, self.__cur_field)
981          self.__cur_field = index          self.__cur_field = index
982    
983      def _OnApply(self, event):      def _OnTry(self, event):
984          """Put the data from the table into a new Classification and hand          """Put the data from the table into a new Classification and hand
985             it to the layer.             it to the layer.
986          """          """
# Line 822  class Classifier(NonModalDialog): Line 992  class Classifier(NonModalDialog):
992          # to begin with or it has been modified          # to begin with or it has been modified
993          #          #
994          if clazz is None or self.classGrid.GetTable().IsModified():          if clazz is None or self.classGrid.GetTable().IsModified():
995              clazz = self.__BuildClassification(self.__cur_field)              clazz = self.__BuildClassification(self.__cur_field, True)
996    
997          self.layer.SetClassification(clazz)          self.layer.SetClassification(clazz)
998    
999          self.haveApplied = True          self.haveApplied = True
1000    
1001      def _OnOK(self, event):      def _OnOK(self, event):
1002          self._OnApply(event)          self._OnTry(event)
1003          self.OnClose(event)          self.Close()
1004    
1005      def _OnCancel(self, event):      def _OnCloseBtn(self, event):
1006            """Close is similar to Cancel except that any changes that were
1007            made and applied remain applied, but the currently displayed
1008            classification is discarded.
1009            """
1010    
1011            self.Close()
1012    
1013        def _OnRevert(self, event):
1014          """The layer's current classification stays the same."""          """The layer's current classification stays the same."""
1015          if self.haveApplied:          if self.haveApplied:
1016              self.layer.SetClassification(self.originalClass)              self.layer.SetClassification(self.originalClass)
1017    
1018          self.OnClose(event)          #self.Close()
1019    
1020      def _OnAdd(self, event):      def _OnAdd(self, event):
1021          self.classGrid.AppendRows()          self.classGrid.AppendRows()
# Line 845  class Classifier(NonModalDialog): Line 1023  class Classifier(NonModalDialog):
1023      def _OnRemove(self, event):      def _OnRemove(self, event):
1024          self.classGrid.DeleteSelectedRows()          self.classGrid.DeleteSelectedRows()
1025    
1026      def _OnGenRange(self, event):      def _OnGenClass(self, event):
1027          print "Classifier._OnGenRange()"  
1028            self.genDlg = ClassGenDialog(self, self.layer,
1029                              self.fields.GetString(self.__cur_field))
1030    
1031            EVT_CLOSE(self.genDlg, self._OnGenDialogClose)
1032    
1033            self.__EnableButtons(EB_GEN_CLASS, False)
1034    
1035            self.genDlg.Show()
1036    
1037        def _OnGenDialogClose(self, event):
1038            self.genDlg.Destroy()
1039            self.__EnableButtons(EB_GEN_CLASS, True)
1040    
1041      def _OnMoveUp(self, event):      def _OnMoveUp(self, event):
1042          sel = self.classGrid.GetCurrentSelection()          sel = self.classGrid.GetCurrentSelection()
# Line 861  class Classifier(NonModalDialog): Line 1051  class Classifier(NonModalDialog):
1051                  table.SetClassGroup(i, x)                  table.SetClassGroup(i, x)
1052                  self.classGrid.ClearSelection()                  self.classGrid.ClearSelection()
1053                  self.classGrid.SelectRow(i - 1)                  self.classGrid.SelectRow(i - 1)
1054                    self.classGrid.MakeCellVisible(i - 1, 0)
1055    
1056      def _OnMoveDown(self, event):      def _OnMoveDown(self, event):
1057          sel = self.classGrid.GetCurrentSelection()          sel = self.classGrid.GetCurrentSelection()
# Line 875  class Classifier(NonModalDialog): Line 1066  class Classifier(NonModalDialog):
1066                  table.SetClassGroup(i + 1, x)                  table.SetClassGroup(i + 1, x)
1067                  self.classGrid.ClearSelection()                  self.classGrid.ClearSelection()
1068                  self.classGrid.SelectRow(i + 1)                  self.classGrid.SelectRow(i + 1)
1069                    self.classGrid.MakeCellVisible(i + 1, 0)
1070    
1071        def _OnTitleChanged(self, event):
1072            obj = event.GetEventObject()
1073    
1074            self.layer.SetTitle(obj.GetValue())
1075            self.__SetTitle(self.layer.Title())
1076    
1077            self.__EnableButtons(EB_LAYER_TITLE, self.layer.Title() != "")
1078    
1079        def __EnableButtons(self, case, enable):
1080    
1081            if case == EB_LAYER_TITLE:  
1082                list = (ID_PROPERTY_OK,
1083                        ID_PROPERTY_CLOSE)
1084    
1085            elif case == EB_SELECT_FIELD:
1086                list = (ID_PROPERTY_GENCLASS,
1087                        ID_PROPERTY_ADD,
1088                        ID_PROPERTY_MOVEUP,
1089                        ID_PROPERTY_MOVEDOWN,
1090                        ID_PROPERTY_EDITSYM,
1091                        ID_PROPERTY_REMOVE)
1092    
1093            elif case == EB_GEN_CLASS:
1094                list = (ID_PROPERTY_SELECT,
1095                        ID_PROPERTY_FIELDTEXT,
1096                        ID_PROPERTY_GENCLASS,
1097                        ID_PROPERTY_EDITSYM)
1098    
1099            for id in list:
1100                self.FindWindowById(id).Enable(enable)
1101    
1102  ID_SELPROP_OK = 4001  ID_SELPROP_OK = 4001
1103  ID_SELPROP_CANCEL = 4002  ID_SELPROP_CANCEL = 4002
# Line 902  class SelectPropertiesDialog(wxDialog): Line 1124  class SelectPropertiesDialog(wxDialog):
1124          previewBox = wxBoxSizer(wxVERTICAL)          previewBox = wxBoxSizer(wxVERTICAL)
1125          previewBox.Add(wxStaticText(self, -1, _("Preview:")),          previewBox.Add(wxStaticText(self, -1, _("Preview:")),
1126              0, wxALIGN_LEFT | wxALL, 4)              0, wxALIGN_LEFT | wxALL, 4)
1127          self.previewWin = ClassDataPreviewWindow(None, self.prop, shapeType,  
1128                                              self, ID_SELPROP_PREVIEW, (40, 40))          self.previewWin = ClassGroupPropertiesCtrl(
1129          previewBox.Add(self.previewWin, 1, wxGROW, 15)              self, ID_SELPROP_PREVIEW, self.prop, shapeType,
1130                (40, 40), wxSIMPLE_BORDER)
1131    
1132            self.previewWin.AllowEdit(False)
1133    
1134            previewBox.Add(self.previewWin, 1, wxGROW | wxALL, 4)
1135    
1136          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)          itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)
1137    
# Line 986  class SelectPropertiesDialog(wxDialog): Line 1213  class SelectPropertiesDialog(wxDialog):
1213    
1214      def __GetColor(self, cur):      def __GetColor(self, cur):
1215          dialog = wxColourDialog(self)          dialog = wxColourDialog(self)
1216          dialog.GetColourData().SetColour(Color2wxColour(cur))          if cur is not Color.Transparent:
1217                dialog.GetColourData().SetColour(Color2wxColour(cur))
1218    
1219          ret = None          ret = None
1220          if dialog.ShowModal() == wxID_OK:          if dialog.ShowModal() == wxID_OK:
1221              ret = wxColour2Color(dialog.GetColourData().GetColour())              ret = wxColour2Color(dialog.GetColourData().GetColour())
# Line 1002  class SelectPropertiesDialog(wxDialog): Line 1231  class SelectPropertiesDialog(wxDialog):
1231          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1232    
1233      def _OnChangeLineColorTrans(self, event):      def _OnChangeLineColorTrans(self, event):
1234          self.prop.SetLineColor(Color.None)          self.prop.SetLineColor(Color.Transparent)
1235          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1236                    
1237      def _OnChangeFillColor(self, event):      def _OnChangeFillColor(self, event):
# Line 1012  class SelectPropertiesDialog(wxDialog): Line 1241  class SelectPropertiesDialog(wxDialog):
1241          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1242    
1243      def _OnChangeFillColorTrans(self, event):      def _OnChangeFillColorTrans(self, event):
1244          self.prop.SetFill(Color.None)          self.prop.SetFill(Color.Transparent)
1245          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer          self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer
1246    
1247      def GetClassGroupProperties(self):      def GetClassGroupProperties(self):
# Line 1033  class ClassDataPreviewWindow(wxWindow): Line 1262  class ClassDataPreviewWindow(wxWindow):
1262          self.shapeType = shapeType          self.shapeType = shapeType
1263          self.previewer = ClassDataPreviewer()          self.previewer = ClassDataPreviewer()
1264    
1265        def GetProperties():
1266            return self.prop
1267    
1268      def _OnPaint(self, event):      def _OnPaint(self, event):
1269          dc = wxPaintDC(self)          dc = wxPaintDC(self)
1270    
# Line 1051  class ClassDataPreviewer: Line 1283  class ClassDataPreviewer:
1283    
1284      def Draw(self, dc, rect, prop, shapeType):      def Draw(self, dc, rect, prop, shapeType):
1285    
1286          assert(dc is not None)          assert dc is not None
1287          assert(isinstance(prop, ClassGroupProperties))          assert isinstance(prop, ClassGroupProperties)
1288    
1289          if rect is None:          if rect is None:
1290              x = 0              x = 0
# Line 1065  class ClassDataPreviewer: Line 1297  class ClassDataPreviewer:
1297              h = rect.GetHeight()              h = rect.GetHeight()
1298    
1299          stroke = prop.GetLineColor()          stroke = prop.GetLineColor()
1300          if stroke is Color.None:          if stroke is Color.Transparent:
1301              pen = wxTRANSPARENT_PEN              pen = wxTRANSPARENT_PEN
1302          else:          else:
1303              pen = wxPen(Color2wxColour(stroke),              pen = wxPen(Color2wxColour(stroke),
# Line 1073  class ClassDataPreviewer: Line 1305  class ClassDataPreviewer:
1305                          wxSOLID)                          wxSOLID)
1306    
1307          stroke = prop.GetFill()          stroke = prop.GetFill()
1308          if stroke is Color.None:          if stroke is Color.Transparent:
1309              brush = wxTRANSPARENT_BRUSH              brush = wxTRANSPARENT_BRUSH
1310          else:          else:
1311              brush = wxBrush(Color2wxColour(stroke), wxSOLID)              brush = wxBrush(Color2wxColour(stroke), wxSOLID)
# Line 1087  class ClassDataPreviewer: Line 1319  class ClassDataPreviewer:
1319                             wxPoint(x + w/2, y + h/4*3),                             wxPoint(x + w/2, y + h/4*3),
1320                             wxPoint(x + w, y)])                             wxPoint(x + w, y)])
1321    
1322          elif shapeType == SHAPETYPE_POINT or \          elif shapeType == SHAPETYPE_POINT:
              shapeType == SHAPETYPE_POLYGON:  
1323    
1324              dc.DrawCircle(x + w/2, y + h/2,              dc.DrawCircle(x + w/2, y + h/2,
1325                            (min(w, h) - prop.GetLineWidth())/2)                            (min(w, h) - prop.GetLineWidth())/2)
1326    
1327            elif shapeType == SHAPETYPE_POLYGON:
1328                dc.DrawRectangle(x, y, w, h)
1329    
1330  class ClassRenderer(wxPyGridCellRenderer):  class ClassRenderer(wxPyGridCellRenderer):
1331    
1332      def __init__(self, shapeType):      def __init__(self, shapeType):
# Line 1114  class ClassRenderer(wxPyGridCellRenderer Line 1348  class ClassRenderer(wxPyGridCellRenderer
1348              self.previewer.Draw(dc, rect, data.GetProperties(), self.shapeType)              self.previewer.Draw(dc, rect, data.GetProperties(), self.shapeType)
1349    
1350          if isSelected:          if isSelected:
1351              dc.SetPen(wxPen(wxColour(0 * 255, 0 * 255, 0 * 255),              dc.SetPen(wxPen(wxBLACK, 1, wxSOLID))
                       4, wxSOLID))  
1352              dc.SetBrush(wxTRANSPARENT_BRUSH)              dc.SetBrush(wxTRANSPARENT_BRUSH)
1353    
1354              dc.DrawRectangle(rect.GetX(), rect.GetY(),              dc.DrawRectangle(rect.GetX(), rect.GetY(),
1355                               rect.GetWidth(), rect.GetHeight())                               rect.GetWidth(), rect.GetHeight())
1356    
1357          dc.DestroyClippingRegion()          dc.DestroyClippingRegion()
1358    
1359    
1360    class ClassGroupPropertiesCtrl(wxWindow, wxControl):
1361    
1362        def __init__(self, parent, id, props, shapeType,
1363                     size = wxDefaultSize, style = 0):
1364    
1365            wxWindow.__init__(self, parent, id, size = size, style = style)
1366    
1367            self.SetProperties(props)
1368            self.SetShapeType(shapeType)
1369            self.AllowEdit(True)
1370    
1371            EVT_PAINT(self, self._OnPaint)
1372            EVT_LEFT_DCLICK(self, self._OnLeftDClick)
1373    
1374            self.previewer = ClassDataPreviewer()
1375    
1376        def _OnPaint(self, event):
1377            dc = wxPaintDC(self)
1378    
1379            # XXX: this doesn't seem to be having an effect:
1380            dc.DestroyClippingRegion()
1381    
1382            w, h = self.GetClientSize()
1383    
1384            self.previewer.Draw(dc,
1385                                wxRect(0, 0, w, h),
1386                                self.GetProperties(),
1387                                self.GetShapeType())
1388    
1389    
1390        def GetProperties(self):
1391            return self.props
1392    
1393        def SetProperties(self, props):
1394            self.props = props
1395            self.Refresh()
1396    
1397        def GetShapeType(self):
1398            return self.shapeType
1399    
1400        def SetShapeType(self, shapeType):
1401            self.shapeType = shapeType
1402            self.Refresh()
1403    
1404        def AllowEdit(self, allow):
1405            self.allowEdit = allow
1406    
1407        def DoEdit(self):
1408            if not self.allowEdit: return
1409    
1410            propDlg = SelectPropertiesDialog(NULL,
1411                                             self.GetProperties(),
1412                                             self.GetShapeType())
1413    
1414            if propDlg.ShowModal() == wxID_OK:
1415                new_prop = propDlg.GetClassGroupProperties()
1416                self.SetProperties(new_prop)
1417                self.Refresh()
1418    
1419            propDlg.Destroy()
1420    
1421        def _OnLeftDClick(self, event):
1422            self.DoEdit()

Legend:
Removed from v.560  
changed lines
  Added in v.783

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26