/[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 392 - (show annotations)
Mon Feb 10 15:26:30 2003 UTC (22 years ago) by jonathan
File MIME type: text/x-python
File size: 6033 byte(s)
* Thuban/UI/classifier.py (ClassRenderer): New class to
        draw the classifications in the dialog box's table.
        (Classifier): Modified to use the ClassRenderer class.

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 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):
67
68 def __init__(self, parent, layer):
69 wxDialog.__init__(self, parent, -1, _("Classify"),
70 style = wxRESIZE_BORDER)
71
72 topBox = wxBoxSizer(wxVERTICAL)
73
74 propertyBox = wxBoxSizer(wxHORIZONTAL)
75 propertyBox.Add(wxStaticText(self, -1, _("Property")),
76 0, wxALIGN_CENTER | wxALL, 4)
77
78 self.properties = wxComboBox(self, ID_PROPERTY_SELECT, "",
79 style = wxCB_READONLY)
80
81 self.num_cols = layer.table.field_count()
82 cur_hilight = 0
83 for i in range(self.num_cols):
84 type, name, len, decc = layer.table.field_info(i)
85 if name == layer.classification.field:
86 cur_hilight = i
87 self.properties.Append(name)
88
89 self.properties.SetSelection(cur_hilight)
90 propertyBox.Add(self.properties, 1, wxGROW, 4)
91 EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self.OnPropertySelect)
92
93 topBox.Add(propertyBox, 0, wxGROW, 4)
94
95 #
96 # Classification data table
97 #
98
99 self.classTable = wxGrid(self, ID_CLASS_TABLE, size=(300, 150))
100
101 table = ClassTable(layer.classification)
102 self.classTable.SetTable(table, true)
103 self.classTable.EnableEditing(false)
104 cr = ClassRenderer(layer.ShapeType())
105 for i in range(self.classTable.GetNumberRows()):
106 self.classTable.SetCellRenderer(i, 0, cr)
107
108 topBox.Add(self.classTable, 1, wxGROW, 0)
109
110 #
111 # Control buttons:
112 #
113 buttonBox = wxBoxSizer(wxHORIZONTAL)
114 buttonBox.Add(wxButton(self, ID_CLASSIFY_OK, _("OK")),
115 0, wxALL, 4)
116 buttonBox.Add(wxButton(self, ID_CLASSIFY_CANCEL, _("Cancel")),
117 0, wxALL, 4)
118 topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 10)
119
120 EVT_BUTTON(self, ID_CLASSIFY_OK, self.OnOK)
121 EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self.OnCancel)
122
123 self.SetAutoLayout(true)
124 self.SetSizer(topBox)
125 topBox.Fit(self)
126 topBox.SetSizeHints(self)
127
128 def OnPropertySelect(self, event): pass
129
130 def OnOK(self, event):
131 self.EndModal(wxID_OK)
132
133 def OnCancel(self, event):
134 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

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26