/[thuban]/trunk/thuban/Thuban/UI/classifier.py
ViewVC logotype

Contents of /trunk/thuban/Thuban/UI/classifier.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 398 - (show annotations)
Tue Feb 11 14:23:45 2003 UTC (22 years ago) by jonathan
File MIME type: text/x-python
File size: 5979 byte(s)
* Thuban/UI/classifier.py (ClassTable): Didn't need to hang
        onto the clinfo parameter, so removed the deepcopy().

1 # Copyright (c) 2001 by Intevation GmbH
2 # Authors:
3 # Jonathan Coles <[email protected]>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with Thuban for details.
7
8 """Dialog for classifying how layers are displayed"""
9
10 __version__ = "$Revision$"
11
12 import copy
13
14 from wxPython.wx import *
15 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
24 ID_CLASS_TABLE = 40011
25
26 ID_CLASSIFY_OK = 4001
27 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):
66
67 def __init__(self, parent, layer):
68 wxDialog.__init__(self, parent, -1, _("Classify"),
69 style = wxRESIZE_BORDER)
70
71 topBox = wxBoxSizer(wxVERTICAL)
72
73 propertyBox = wxBoxSizer(wxHORIZONTAL)
74 propertyBox.Add(wxStaticText(self, -1, _("Property")),
75 0, wxALIGN_CENTER | wxALL, 4)
76
77 self.properties = wxComboBox(self, ID_PROPERTY_SELECT, "",
78 style = wxCB_READONLY)
79
80 self.num_cols = layer.table.field_count()
81 cur_hilight = 0
82 for i in range(self.num_cols):
83 type, name, len, decc = layer.table.field_info(i)
84 if name == layer.classification.field:
85 cur_hilight = i
86 self.properties.Append(name)
87
88 self.properties.SetSelection(cur_hilight)
89 propertyBox.Add(self.properties, 1, wxGROW, 4)
90 EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self.OnPropertySelect)
91
92 topBox.Add(propertyBox, 0, wxGROW, 4)
93
94 #
95 # Classification data table
96 #
97
98 self.classTable = wxGrid(self, ID_CLASS_TABLE, size=(300, 150))
99
100 table = ClassTable(layer.classification)
101 self.classTable.SetTable(table, true)
102 self.classTable.EnableEditing(false)
103 cr = ClassRenderer(layer.ShapeType())
104 for i in range(self.classTable.GetNumberRows()):
105 self.classTable.SetCellRenderer(i, 0, cr)
106
107 topBox.Add(self.classTable, 1, wxGROW, 0)
108
109 #
110 # Control buttons:
111 #
112 buttonBox = wxBoxSizer(wxHORIZONTAL)
113 buttonBox.Add(wxButton(self, ID_CLASSIFY_OK, _("OK")),
114 0, wxALL, 4)
115 buttonBox.Add(wxButton(self, ID_CLASSIFY_CANCEL, _("Cancel")),
116 0, wxALL, 4)
117 topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 10)
118
119 EVT_BUTTON(self, ID_CLASSIFY_OK, self.OnOK)
120 EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self.OnCancel)
121
122 self.SetAutoLayout(true)
123 self.SetSizer(topBox)
124 topBox.Fit(self)
125 topBox.SetSizeHints(self)
126
127 def OnPropertySelect(self, event): pass
128
129 def OnOK(self, event):
130 self.EndModal(wxID_OK)
131
132 def OnCancel(self, event):
133 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

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26