/[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 372 by jonathan, Mon Jan 27 13:50:58 2003 UTC revision 398 by jonathan, Tue Feb 11 14:23:45 2003 UTC
# Line 9  Line 9 
9    
10  __version__ = "$Revision$"  __version__ = "$Revision$"
11    
12    import copy
13    
14  from wxPython.wx import *  from wxPython.wx import *
15  from wxPython.grid import *  from wxPython.grid import *
16    
17    from Thuban import _
18    
19    from Thuban.Model.classification import Classification
20    
21    from Thuban.Model.layer import SHAPETYPE_ARC, SHAPETYPE_POLYGON, SHAPETYPE_POINT
22    
23  ID_PROPERTY_SELECT = 4010  ID_PROPERTY_SELECT = 4010
24  ID_CLASS_TABLE = 40011  ID_CLASS_TABLE = 40011
25    
26  ID_CLASSIFY_OK = 4001  ID_CLASSIFY_OK = 4001
27  ID_CLASSIFY_CANCEL = 4002  ID_CLASSIFY_CANCEL = 4002
28    
29    class ClassTable(wxPyGridTableBase):
30    
31        def __init__(self, clinfo):
32            wxPyGridTableBase.__init__(self)
33    
34            self.tdata = []
35    
36            self.tdata.append([clinfo.DefaultData, 'DEFAULT'])
37    
38            for value, data in clinfo.points.items():
39                self.tdata.append([data, value])
40    
41            for range in self.clinfo.ranges:
42                self.tdata.append([range[2], '%s-%s' % range[0], range[1]])
43    
44            self.SetColLabelValue(1, _("Data Values"))
45    
46        def GetNumberRows(self):
47            return len(self.tdata)
48    
49        def GetNumberCols(self):
50            return 2
51    
52        def IsEmptyCell(self, row, col):
53            return false
54    
55        def GetValue(self, row, col):
56            return self.tdata[row][col]
57    
58        def SetValue(self, row, col, value):
59            self.tdata[row][col] = value
60    
61        def GetValueAsCustom(self, row, col, typeName):
62            return self.tdata[row][col]
63    
64    
65  class Classifier(wxDialog):  class Classifier(wxDialog):
66            
67      def __init__(self, parent, layer):      def __init__(self, parent, layer):
68          wxDialog.__init__(self, parent, -1, "Classify",          wxDialog.__init__(self, parent, -1, _("Classify"),
69                            style = wxRESIZE_BORDER)                            style = wxRESIZE_BORDER)
70    
71          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
72    
73          propertyBox = wxBoxSizer(wxHORIZONTAL)          propertyBox = wxBoxSizer(wxHORIZONTAL)
74          propertyBox.Add(wxStaticText(self, -1, "Property"),          propertyBox.Add(wxStaticText(self, -1, _("Property")),
75              0, wxALIGN_CENTER | wxALL, 4)              0, wxALIGN_CENTER | wxALL, 4)
76    
77          self.properties = wxComboBox(self, ID_PROPERTY_SELECT, "",          self.properties = wxComboBox(self, ID_PROPERTY_SELECT, "",
78                                       style = wxCB_READONLY)                                       style = wxCB_READONLY)
79    
80          self.num_cols = layer.table.field_count()          self.num_cols = layer.table.field_count()
81            cur_hilight = 0
82          for i in range(self.num_cols):          for i in range(self.num_cols):
83              type, name, len, decc = layer.table.field_info(i)              type, name, len, decc = layer.table.field_info(i)
84                if name == layer.classification.field:
85                    cur_hilight = i
86              self.properties.Append(name)              self.properties.Append(name)
87    
88          propertyBox.Add(self.properties, 0, wxALL, 4)          self.properties.SetSelection(cur_hilight)
89            propertyBox.Add(self.properties, 1, wxGROW, 4)
90          EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self.OnPropertySelect)          EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self.OnPropertySelect)
91    
92          topBox.Add(propertyBox, 0, 0)          topBox.Add(propertyBox, 0, wxGROW, 4)
93    
94          #          #
95          # Classification data table          # Classification data table
96          #          #
97    
98          table = wxPyGridTableBase()          self.classTable = wxGrid(self, ID_CLASS_TABLE, size=(300, 150))
99          tableBox = wxGridSizer(25)  
100          self.classTable = wxGrid(self, ID_CLASS_TABLE)          table = ClassTable(layer.classification)
         self.classTable.CreateGrid(10, 2)  
101          self.classTable.SetTable(table, true)          self.classTable.SetTable(table, true)
102          #table.SetNumberRows(10)          self.classTable.EnableEditing(false)
103          #table.SetNumberCols(2)          cr = ClassRenderer(layer.ShapeType())
104          table.SetColLabelValue(0, "Class")          for i in range(self.classTable.GetNumberRows()):
105          table.SetColLabelValue(1, "Value")              self.classTable.SetCellRenderer(i, 0, cr)
106          #self.classTable.SetColLabelValue(0, "Class")  
107          #self.classTable.SetColLabelValue(1, "Value")          topBox.Add(self.classTable, 1, wxGROW, 0)
         #self.classTable.SetCellValue(1, 1, "Value")  
   
         tableBox.Add(self.classTable, 0, wxALL, 4)  
           
         topBox.Add(self.classTable, 0, 0)  
108    
109          #          #
110          # Control buttons:          # Control buttons:
111          #          #
112          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
113          buttonBox.Add(wxButton(self, ID_CLASSIFY_OK, "OK"),          buttonBox.Add(wxButton(self, ID_CLASSIFY_OK, _("OK")),
114                        0, wxALL, 4)                        0, wxALL, 4)
115          buttonBox.Add(wxButton(self, ID_CLASSIFY_CANCEL, "Cancel"),          buttonBox.Add(wxButton(self, ID_CLASSIFY_CANCEL, _("Cancel")),
116                        0, wxALL, 4)                        0, wxALL, 4)
117          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 10)          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 10)
118    
# Line 90  class Classifier(wxDialog): Line 132  class Classifier(wxDialog):
132      def OnCancel(self, event):      def OnCancel(self, event):
133          self.EndModal(wxID_CANCEL)          self.EndModal(wxID_CANCEL)
134    
135    
136    class ClassRenderer(wxPyGridCellRenderer):
137    
138        def __init__(self, shapeType):
139            wxPyGridCellRenderer.__init__(self)
140            self.shapeType = shapeType
141    
142        def Draw(self, grid, attr, dc, rect, row, col, isSelected):
143            value = grid.GetTable().GetValueAsCustom(row, col, "")
144            # XXX: check if value is a dictionary
145            stroke = value.GetStroke()
146            if stroke is None:
147                pen = wxTRANSPARENT_PEN
148            else:
149                pen = wxPen(wxColour(stroke.red * 255,
150                                     stroke.green * 255,
151                                     stroke.blue * 255),
152                            value.GetStrokeWidth(),
153                            wxSOLID)
154    
155            stroke = value.GetFill()
156            if stroke is None:
157                brush = wxTRANSPARENT_BRUSH
158            else:
159                brush = wxBrush(wxColour(stroke.red * 255,
160                                         stroke.green * 255,
161                                         stroke.blue * 255), wxSOLID)
162    
163            dc.SetClippingRegion(rect.GetX(), rect.GetY(),
164                                 rect.GetWidth(), rect.GetHeight())
165            dc.SetPen(wxPen(wxLIGHT_GREY))
166            dc.SetBrush(wxBrush(wxLIGHT_GREY, wxSOLID))
167            dc.DrawRectangle(rect.GetX(), rect.GetY(),
168                             rect.GetWidth(), rect.GetHeight())
169    
170            dc.SetPen(pen)
171            dc.SetBrush(brush)
172    
173            if self.shapeType == SHAPETYPE_ARC:
174                dc.DrawSpline([wxPoint(rect.GetX(), rect.GetY() + rect.GetHeight()),
175                               wxPoint(rect.GetX() + rect.GetWidth()/2,
176                                       rect.GetY() + rect.GetHeight()/4),
177                               wxPoint(rect.GetX() + rect.GetWidth()/2,
178                                       rect.GetY() + rect.GetHeight()/4*3),
179                               wxPoint(rect.GetX() + rect.GetWidth(), rect.GetY())])
180    
181            elif self.shapeType == SHAPETYPE_POINT or self.shapeType == SHAPETYPE_POLYGON:
182                dc.DrawCircle(rect.GetX() + rect.GetWidth()/2,
183                              rect.GetY() + rect.GetHeight()/2,
184                              (min(rect.GetWidth(), rect.GetHeight())
185                               - value.GetStrokeWidth())/2)
186    
187            dc.DestroyClippingRegion()
188    
189    

Legend:
Removed from v.372  
changed lines
  Added in v.398

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26