11 |
|
|
12 |
from wxPython.wx import * |
from wxPython.wx import * |
13 |
|
|
14 |
from Thuban.Model.classification import Classification, ClassGroupRange, \ |
from Thuban.Model.classification import ClassGroupProperties |
|
ClassGroupSingleton, ClassGroupProperties |
|
15 |
|
|
16 |
from Thuban.Model.table import Table, FIELDTYPE_INT, FIELDTYPE_DOUBLE, \ |
from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \ |
17 |
FIELDTYPE_STRING |
FIELDTYPE_STRING |
18 |
|
|
|
from Thuban.Model.color import Color |
|
19 |
from Thuban.Model.range import Range |
from Thuban.Model.range import Range |
20 |
|
|
21 |
import classifier, resource |
import classifier, resource |
22 |
|
|
23 |
from Thuban.Model.classgen import ClassGenerator, \ |
from Thuban.Model.classgen import \ |
24 |
|
generate_uniform_distribution, generate_singletons, generate_quantiles, \ |
25 |
CustomRamp, GreyRamp, RedRamp, GreenRamp, BlueRamp, GreenToRedRamp, \ |
CustomRamp, GreyRamp, RedRamp, GreenRamp, BlueRamp, GreenToRedRamp, \ |
26 |
HotToColdRamp |
HotToColdRamp |
27 |
|
|
76 |
# |
# |
77 |
self.genButton = wxButton(self, wxID_OK, _("Generate")) |
self.genButton = wxButton(self, wxID_OK, _("Generate")) |
78 |
self.genButton.SetDefault() |
self.genButton.SetDefault() |
79 |
|
self.cancelButton = wxButton(self, wxID_CANCEL, _("Close")) |
80 |
|
|
81 |
self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO) |
self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO) |
82 |
|
|
83 |
self.genpanels.append((GENCOMBOSTR_UNIQUE, GenUniquePanel)) |
self.genpanels.append((GENCOMBOSTR_UNIQUE, GenUniquePanel)) |
90 |
|
|
91 |
self.genChoice.SetSelection(0) |
self.genChoice.SetSelection(0) |
92 |
|
|
93 |
self.propPanel = None |
for i in range(self.genChoice.GetCount()): |
94 |
custom_ramp_panel = CustomRampPanel(self, layer.ShapeType()) |
clazz, obj = self.genChoice.GetClientData(i) |
95 |
|
|
96 |
self.propCombo = wxChoice(self, ID_CLASSGEN_PROPCOMBO) |
if obj is None: |
97 |
self.propCombo.Append(PROPCOMBOSTR_GREY, GreyRamp()) |
obj = clazz(self, self.layer, self.fieldName, self.fieldType) |
98 |
self.propCombo.Append(PROPCOMBOSTR_RED, RedRamp()) |
obj.Hide() |
99 |
self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp()) |
self.genChoice.SetClientData(i, [clazz, obj]) |
|
self.propCombo.Append(PROPCOMBOSTR_BLUE, BlueRamp()) |
|
|
self.propCombo.Append(PROPCOMBOSTR_GREEN2RED, GreenToRedRamp()) |
|
|
self.propCombo.Append(PROPCOMBOSTR_HOT2COLD, HotToColdRamp()) |
|
|
self.propCombo.Append(PROPCOMBOSTR_CUSTOM, custom_ramp_panel) |
|
100 |
|
|
|
self.propCombo.SetSelection(0) |
|
101 |
|
|
102 |
############# |
############# |
103 |
|
|
123 |
psizer = wxBoxSizer(wxHORIZONTAL) |
psizer = wxBoxSizer(wxHORIZONTAL) |
124 |
psizer.Add(wxStaticText(self, -1, _("Color Scheme:")), |
psizer.Add(wxStaticText(self, -1, _("Color Scheme:")), |
125 |
0, wxALIGN_CENTER_VERTICAL, 0) |
0, wxALIGN_CENTER_VERTICAL, 0) |
126 |
|
|
127 |
|
# Properties (Ramp) ComboBox |
128 |
|
self.propCombo = wxChoice(self, ID_CLASSGEN_PROPCOMBO) |
129 |
|
|
130 |
|
self.propPanel = None |
131 |
|
custom_ramp_panel = CustomRampPanel(self, layer.ShapeType()) |
132 |
|
|
133 |
|
self.propCombo.Append(PROPCOMBOSTR_GREY, GreyRamp()) |
134 |
|
self.propCombo.Append(PROPCOMBOSTR_RED, RedRamp()) |
135 |
|
self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp()) |
136 |
|
self.propCombo.Append(PROPCOMBOSTR_BLUE, BlueRamp()) |
137 |
|
self.propCombo.Append(PROPCOMBOSTR_GREEN2RED, GreenToRedRamp()) |
138 |
|
self.propCombo.Append(PROPCOMBOSTR_HOT2COLD, HotToColdRamp()) |
139 |
|
self.propCombo.Append(PROPCOMBOSTR_CUSTOM, custom_ramp_panel) |
140 |
|
|
141 |
|
self.propCombo.SetSelection(0) |
142 |
|
|
143 |
psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4) |
psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4) |
144 |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
145 |
|
|
146 |
sizer.Add(custom_ramp_panel, 1, wxGROW | wxALL, 4) |
sizer.Add(custom_ramp_panel, 1, wxGROW | wxALL, 4) |
147 |
sizer.Show(custom_ramp_panel, False) |
sizer.Show(custom_ramp_panel, False) |
148 |
|
|
149 |
|
# Finally place the main buttons |
150 |
buttonSizer = wxBoxSizer(wxHORIZONTAL) |
buttonSizer = wxBoxSizer(wxHORIZONTAL) |
151 |
buttonSizer.Add(self.genButton, 0, wxALL, 4) |
buttonSizer.Add(self.genButton, 0, wxRIGHT|wxEXPAND, 10) |
152 |
buttonSizer.Add(60, 20, 0, wxALL, 4) |
buttonSizer.Add(self.cancelButton, 0, wxRIGHT|wxEXPAND, 10) |
153 |
buttonSizer.Add(wxButton(self, wxID_CANCEL, _("Close")), |
sizer.Add(buttonSizer, 0, wxALIGN_RIGHT|wxBOTTOM|wxTOP, 10) |
|
0, wxALL, 4) |
|
|
sizer.Add(buttonSizer, 0, |
|
|
wxALL | wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL, 4) |
|
154 |
|
|
155 |
self.SetSizer(sizer) |
self.SetSizer(sizer) |
156 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
211 |
and max is not None \ |
and max is not None \ |
212 |
and numGroups is not None: |
and numGroups is not None: |
213 |
|
|
214 |
self.clazz = ClassGenerator().GenUnifromDistribution( |
self.clazz = generate_uniform_distribution( |
215 |
min, max, numGroups, ramp, |
min, max, numGroups, ramp, |
216 |
self.type == FIELDTYPE_INT) |
self.type == FIELDTYPE_INT) |
217 |
|
|
224 |
if len(list) > 0 \ |
if len(list) > 0 \ |
225 |
and numGroups is not None: |
and numGroups is not None: |
226 |
|
|
227 |
self.clazz = ClassGenerator().GenSingletonsFromList( |
self.clazz = generate_singletons( |
228 |
list, numGroups, ramp) |
list, numGroups, ramp) |
229 |
|
|
230 |
self.parent._SetClassification(self.clazz) |
self.parent._SetClassification(self.clazz) |
238 |
delta = 1 / float(numGroups) |
delta = 1 / float(numGroups) |
239 |
percents = [delta * i for i in range(1, numGroups + 1)] |
percents = [delta * i for i in range(1, numGroups + 1)] |
240 |
adjusted, self.clazz = \ |
adjusted, self.clazz = \ |
241 |
ClassGenerator().GenQuantiles(_list, percents, ramp, _range) |
generate_quantiles(_list, percents, ramp, _range) |
242 |
|
|
243 |
if adjusted: |
if adjusted: |
244 |
dlg = wxMessageDialog(self, |
dlg = wxMessageDialog(self, |
299 |
|
|
300 |
clazz, obj = choice.GetClientData(sel) |
clazz, obj = choice.GetClientData(sel) |
301 |
|
|
|
if obj is None: |
|
|
obj = clazz(self, self.layer, self.fieldName, self.fieldType) |
|
|
choice.SetClientData(sel, [clazz, obj]) |
|
|
|
|
302 |
if self.curGenPanel is not None: |
if self.curGenPanel is not None: |
303 |
self.curGenPanel.Hide() |
self.curGenPanel.Hide() |
304 |
self.sizer_genPanel.Remove(self.curGenPanel) |
self.sizer_genPanel.Remove(self.curGenPanel) |
507 |
|
|
508 |
if self.layer.table is not None: |
if self.layer.table is not None: |
509 |
wxBeginBusyCursor() |
wxBeginBusyCursor() |
510 |
min, max = self.layer.table.ValueRange(self.fieldName) |
try: |
511 |
self.minCtrl.SetValue(str(min)) |
min, max = self.layer.table.ValueRange(self.fieldName) |
512 |
self.maxCtrl.SetValue(str(max)) |
self.minCtrl.SetValue(str(min)) |
513 |
wxEndBusyCursor() |
self.maxCtrl.SetValue(str(max)) |
514 |
|
finally: |
515 |
|
wxEndBusyCursor() |
516 |
|
|
517 |
def __GetValidatedTypeEntry(self, win, value, type, badValue = None): |
def __GetValidatedTypeEntry(self, win, value, type, badValue = None): |
518 |
|
|
554 |
return valid |
return valid |
555 |
|
|
556 |
def __CalcStepping(self, min, max, ngroups): |
def __CalcStepping(self, min, max, ngroups): |
|
step = (max - min) / float(ngroups) |
|
557 |
if self.fieldType == FIELDTYPE_INT: |
if self.fieldType == FIELDTYPE_INT: |
558 |
step = int(step) |
step = int((max - min + 1) / float(ngroups)) |
559 |
|
else: |
560 |
|
step = (max - min) / float(ngroups) |
561 |
|
|
562 |
return step |
return step |
563 |
|
|
674 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
675 |
topSizer.SetSizeHints(self) |
topSizer.SetSizeHints(self) |
676 |
|
|
677 |
|
width, height = self.list_avail.GetSizeTuple() |
678 |
|
self.list_avail.SetColumnWidth(0,width) |
679 |
|
width, height = self.list_use.GetSizeTuple() |
680 |
|
self.list_use.SetColumnWidth(0,width) |
681 |
|
|
682 |
self.parent.AllowGenerate(False) |
self.parent.AllowGenerate(False) |
683 |
|
|
684 |
def GetNumGroups(self): |
def GetNumGroups(self): |
837 |
|
|
838 |
if self.layer.table is not None: |
if self.layer.table is not None: |
839 |
wxBeginBusyCursor() |
wxBeginBusyCursor() |
840 |
|
try: |
841 |
# |
# |
842 |
# FIXME: Replace with a call to table when the method |
# FIXME: Replace with a call to table when the method |
843 |
# has been written to get all the values |
# has been written to get all the values |
844 |
# |
# |
845 |
table = self.layer.table |
table = self.layer.table |
846 |
for i in range(table.NumRows()): |
for i in range(table.NumRows()): |
847 |
_list.append(table.ReadValue(i, self.fieldName)) |
_list.append(table.ReadValue(i, self.fieldName)) |
848 |
|
finally: |
849 |
wxEndBusyCursor() |
wxEndBusyCursor() |
850 |
|
|
851 |
return _list |
return _list |
852 |
|
|
866 |
|
|
867 |
if self.layer.table is not None: |
if self.layer.table is not None: |
868 |
wxBeginBusyCursor() |
wxBeginBusyCursor() |
869 |
min, max = self.layer.table.ValueRange(self.fieldName) |
try: |
870 |
self.text_range.SetValue("[" + str(min) + ";" + str(max) + "]") |
min, max = self.layer.table.ValueRange(self.fieldName) |
871 |
wxEndBusyCursor() |
self.text_range.SetValue("[" + str(min) + ";" + str(max) + "]") |
872 |
|
finally: |
873 |
|
wxEndBusyCursor() |
874 |
|
|
875 |
ID_CUSTOMRAMP_COPYSTART = 4001 |
ID_CUSTOMRAMP_COPYSTART = 4001 |
876 |
ID_CUSTOMRAMP_COPYEND = 4002 |
ID_CUSTOMRAMP_COPYEND = 4002 |