1 |
jonathan |
372 |
# 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 |
jonathan |
376 |
import copy |
13 |
|
|
|
14 |
jonathan |
372 |
from wxPython.wx import * |
15 |
|
|
from wxPython.grid import * |
16 |
|
|
|
17 |
jan |
374 |
from Thuban import _ |
18 |
|
|
|
19 |
jonathan |
372 |
ID_PROPERTY_SELECT = 4010 |
20 |
|
|
ID_CLASS_TABLE = 40011 |
21 |
|
|
|
22 |
|
|
ID_CLASSIFY_OK = 4001 |
23 |
|
|
ID_CLASSIFY_CANCEL = 4002 |
24 |
|
|
|
25 |
jonathan |
376 |
class ClassTable(wxPyGridTableBase): |
26 |
|
|
|
27 |
|
|
def __init__(self, clinfo): |
28 |
|
|
wxPyGridTableBase.__init__(self) |
29 |
|
|
self.clinfo = copy.deepcopy(clinfo) |
30 |
|
|
|
31 |
|
|
self.tdata = [] |
32 |
|
|
|
33 |
|
|
for value, data in self.clinfo.points.items(): |
34 |
|
|
self.tdata.append([data, value]) |
35 |
|
|
|
36 |
|
|
for range in self.clinfo.ranges: |
37 |
|
|
self.tdata.append([range[2], '%s-%s' % range[0], range[1]]) |
38 |
|
|
|
39 |
|
|
self.SetColLabelValue(1, "Data Values") |
40 |
|
|
|
41 |
|
|
def GetNumberRows(self): |
42 |
|
|
return len(self.tdata) |
43 |
|
|
|
44 |
|
|
def GetNumberCols(self): |
45 |
|
|
return 2 |
46 |
|
|
|
47 |
|
|
def IsEmptyCell(self, row, col): |
48 |
|
|
return false |
49 |
|
|
|
50 |
|
|
def GetValue(self, row, col): |
51 |
|
|
return self.tdata[row][col] |
52 |
|
|
|
53 |
|
|
def SetValue(self, row, col, value): |
54 |
|
|
pass |
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
jonathan |
372 |
class Classifier(wxDialog): |
59 |
|
|
|
60 |
|
|
def __init__(self, parent, layer): |
61 |
jan |
374 |
wxDialog.__init__(self, parent, -1, _("Classify"), |
62 |
jonathan |
372 |
style = wxRESIZE_BORDER) |
63 |
|
|
|
64 |
|
|
topBox = wxBoxSizer(wxVERTICAL) |
65 |
|
|
|
66 |
|
|
propertyBox = wxBoxSizer(wxHORIZONTAL) |
67 |
jan |
374 |
propertyBox.Add(wxStaticText(self, -1, _("Property")), |
68 |
jonathan |
372 |
0, wxALIGN_CENTER | wxALL, 4) |
69 |
|
|
|
70 |
|
|
self.properties = wxComboBox(self, ID_PROPERTY_SELECT, "", |
71 |
|
|
style = wxCB_READONLY) |
72 |
|
|
|
73 |
|
|
self.num_cols = layer.table.field_count() |
74 |
jonathan |
376 |
cur_hilight = 0 |
75 |
jonathan |
372 |
for i in range(self.num_cols): |
76 |
|
|
type, name, len, decc = layer.table.field_info(i) |
77 |
jonathan |
376 |
if name == layer.classification.field: |
78 |
|
|
cur_hilight = i |
79 |
jonathan |
372 |
self.properties.Append(name) |
80 |
|
|
|
81 |
jonathan |
376 |
self.properties.SetSelection(cur_hilight) |
82 |
|
|
propertyBox.Add(self.properties, 0, wxGROW, 4) |
83 |
jonathan |
372 |
EVT_COMBOBOX(self, ID_PROPERTY_SELECT, self.OnPropertySelect) |
84 |
|
|
|
85 |
jonathan |
376 |
topBox.Add(propertyBox, 0, wxGROW, 4) |
86 |
jonathan |
372 |
|
87 |
|
|
# |
88 |
|
|
# Classification data table |
89 |
|
|
# |
90 |
|
|
|
91 |
jonathan |
376 |
self.classTable = wxGrid(self, ID_CLASS_TABLE, size=(300, 150)) |
92 |
|
|
|
93 |
|
|
table = ClassTable(layer.classification) |
94 |
jonathan |
372 |
self.classTable.SetTable(table, true) |
95 |
jonathan |
376 |
|
96 |
|
|
topBox.Add(self.classTable, 0, wxGROW, 0) |
97 |
jonathan |
372 |
|
98 |
|
|
# |
99 |
|
|
# Control buttons: |
100 |
|
|
# |
101 |
|
|
buttonBox = wxBoxSizer(wxHORIZONTAL) |
102 |
jan |
374 |
buttonBox.Add(wxButton(self, ID_CLASSIFY_OK, _("OK")), |
103 |
jonathan |
372 |
0, wxALL, 4) |
104 |
jan |
374 |
buttonBox.Add(wxButton(self, ID_CLASSIFY_CANCEL, _("Cancel")), |
105 |
jonathan |
372 |
0, wxALL, 4) |
106 |
|
|
topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 10) |
107 |
|
|
|
108 |
|
|
EVT_BUTTON(self, ID_CLASSIFY_OK, self.OnOK) |
109 |
|
|
EVT_BUTTON(self, ID_CLASSIFY_CANCEL, self.OnCancel) |
110 |
|
|
|
111 |
|
|
self.SetAutoLayout(true) |
112 |
|
|
self.SetSizer(topBox) |
113 |
|
|
topBox.Fit(self) |
114 |
|
|
topBox.SetSizeHints(self) |
115 |
|
|
|
116 |
|
|
def OnPropertySelect(self, event): pass |
117 |
|
|
|
118 |
|
|
def OnOK(self, event): |
119 |
|
|
self.EndModal(wxID_OK) |
120 |
|
|
|
121 |
|
|
def OnCancel(self, event): |
122 |
|
|
self.EndModal(wxID_CANCEL) |
123 |
|
|
|