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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26