5 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
6 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
8 |
|
import sys |
9 |
|
|
10 |
from Thuban import _ |
from Thuban import _ |
11 |
|
|
12 |
from wxPython.wx import * |
from wxPython.wx import * |
23 |
|
|
24 |
import resource |
import resource |
25 |
|
|
|
from Thuban.common import Str2Num |
|
|
|
|
|
ID_CLASSGEN_GEN = 4001 |
|
|
ID_CLASSGEN_CLOSE = 4002 |
|
26 |
ID_CLASSGEN_GENCOMBO = 4007 |
ID_CLASSGEN_GENCOMBO = 4007 |
27 |
ID_CLASSGEN_PROPCOMBO = 4008 |
ID_CLASSGEN_PROPCOMBO = 4008 |
28 |
|
|
42 |
PROPCOMBOSTR_HOT2COLD = _("Hot-to-Cold Ramp") |
PROPCOMBOSTR_HOT2COLD = _("Hot-to-Cold Ramp") |
43 |
|
|
44 |
class ClassGenDialog(wxDialog): |
class ClassGenDialog(wxDialog): |
45 |
|
|
46 |
def __init__(self, parent, layer, fieldName): |
def __init__(self, parent, layer, fieldName): |
47 |
"""Inialize the class generating dialog. |
"""Inialize the class generating dialog. |
48 |
|
|
51 |
|
|
52 |
wxDialog.__init__(self, parent, -1, _("Generate Classification"), |
wxDialog.__init__(self, parent, -1, _("Generate Classification"), |
53 |
style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) |
style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) |
54 |
|
|
55 |
self.parent = parent |
self.parent = parent |
56 |
self.clazz = None |
self.clazz = None |
57 |
|
|
58 |
self.type, name, width, prec = layer.table.field_info_by_name(fieldName) |
col = layer.table.Column(fieldName) |
59 |
|
self.type = col.type |
60 |
|
|
61 |
############# |
############# |
62 |
# we need to create genButton first because when we create the |
# we need to create genButton first because when we create the |
63 |
# panels they will call AllowGenerate() which uses genButton. |
# panels they will call AllowGenerate() which uses genButton. |
64 |
# |
# |
65 |
buttonSizer = wxBoxSizer(wxHORIZONTAL) |
self.genButton = wxButton(self, wxID_OK, _("Generate")) |
66 |
self.genButton = wxButton(self, ID_CLASSGEN_GEN, _("Generate")) |
self.genButton.SetDefault() |
67 |
|
|
68 |
buttonSizer.Add(self.genButton, 0, wxALL, 4) |
self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO) |
69 |
buttonSizer.Add(60, 20, 0, wxALL, 4) |
|
70 |
buttonSizer.Add(wxButton(self, ID_CLASSGEN_CLOSE, _("Close")), |
uniq_panel = GenUniquePanel(self, layer, fieldName, self.type) |
71 |
0, wxALL, 4) |
|
72 |
|
self.genPanel = uniq_panel |
73 |
|
self.genChoice.Append(GENCOMBOSTR_UNIQUE, uniq_panel) |
74 |
|
|
75 |
|
if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE): |
76 |
|
uni_panel = GenUniformPanel(self, layer, fieldName, self.type) |
77 |
|
self.genChoice.Append(GENCOMBOSTR_UNIFORM, uni_panel) |
78 |
|
|
79 |
|
self.genChoice.SetSelection(0) |
80 |
|
|
81 |
|
self.propPanel = None |
82 |
|
custom_ramp_panel = CustomRampPanel(self, layer.ShapeType()) |
83 |
|
|
84 |
|
self.propCombo = wxChoice(self, ID_CLASSGEN_PROPCOMBO) |
85 |
|
self.propCombo.Append(PROPCOMBOSTR_GREY, GreyRamp()) |
86 |
|
self.propCombo.Append(PROPCOMBOSTR_RED, RedRamp()) |
87 |
|
self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp()) |
88 |
|
self.propCombo.Append(PROPCOMBOSTR_BLUE, BlueRamp()) |
89 |
|
self.propCombo.Append(PROPCOMBOSTR_HOT2COLD, HotToColdRamp()) |
90 |
|
self.propCombo.Append(PROPCOMBOSTR_CUSTOM, custom_ramp_panel) |
91 |
|
|
92 |
|
self.propCombo.SetSelection(0) |
93 |
|
|
94 |
############# |
############# |
95 |
|
|
105 |
psizer = wxBoxSizer(wxHORIZONTAL) |
psizer = wxBoxSizer(wxHORIZONTAL) |
106 |
psizer.Add(wxStaticText(self, -1, _("Generate:")), |
psizer.Add(wxStaticText(self, -1, _("Generate:")), |
107 |
0, wxALIGN_CENTER_VERTICAL, 0) |
0, wxALIGN_CENTER_VERTICAL, 0) |
108 |
|
psizer.Add(self.genChoice, 1, wxALL | wxGROW, 4) |
|
self.genCombo = wxComboBox(self, |
|
|
ID_CLASSGEN_GENCOMBO, |
|
|
"", style = wxCB_READONLY) |
|
|
psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4) |
|
|
EVT_COMBOBOX(self, ID_CLASSGEN_GENCOMBO, self._OnGenTypeSelect) |
|
109 |
|
|
110 |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
111 |
|
sizer.Add(self.genPanel, 1, wxGROW | wxALL, 4) |
112 |
|
|
113 |
############# |
sizer.Show(uniq_panel, True) |
|
|
|
|
self.genPanel = None |
|
|
|
|
|
panel = GenUniquePanel(self, layer, fieldName, self.type) |
|
|
self.genCombo.Append(GENCOMBOSTR_UNIQUE, panel) |
|
|
sizer.Add(panel, 1, wxGROW | wxALL, 4) |
|
|
|
|
|
self.genPanel = panel |
|
|
|
|
114 |
if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE): |
if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE): |
115 |
panel = GenUniformPanel(self, layer, fieldName, self.type) |
sizer.Add(uni_panel, 1, wxGROW | wxALL, 4) |
116 |
self.genCombo.Append(GENCOMBOSTR_UNIFORM, panel) |
sizer.Show(uni_panel, False) |
|
sizer.Add(panel, 0, wxGROW | wxALL, 4) |
|
|
sizer.Show(panel, False) |
|
|
|
|
|
############# |
|
117 |
|
|
118 |
psizer = wxBoxSizer(wxHORIZONTAL) |
psizer = wxBoxSizer(wxHORIZONTAL) |
119 |
psizer.Add(wxStaticText(self, -1, _("Color Schemes:")), |
psizer.Add(wxStaticText(self, -1, _("Color Scheme:")), |
120 |
0, wxALIGN_CENTER_VERTICAL, 0) |
0, wxALIGN_CENTER_VERTICAL, 0) |
|
|
|
|
self.propCombo = wxComboBox(self, |
|
|
ID_CLASSGEN_PROPCOMBO, |
|
|
"", style = wxCB_READONLY) |
|
121 |
psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4) |
psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4) |
|
EVT_COMBOBOX(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect) |
|
122 |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
123 |
|
|
124 |
############# |
sizer.Add(custom_ramp_panel, 1, wxGROW | wxALL, 4) |
125 |
|
sizer.Show(custom_ramp_panel, False) |
|
self.propPanel = None |
|
|
panel = CustomRampPanel(self, layer.ShapeType()) |
|
|
sizer.Add(panel, 1, wxALL | wxGROW, 4) |
|
|
sizer.Show(panel, False) |
|
|
|
|
|
self.propCombo.Append(PROPCOMBOSTR_GREY, GreyRamp()) |
|
|
self.propCombo.Append(PROPCOMBOSTR_RED, RedRamp()) |
|
|
self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp()) |
|
|
self.propCombo.Append(PROPCOMBOSTR_BLUE, BlueRamp()) |
|
|
self.propCombo.Append(PROPCOMBOSTR_HOT2COLD, HotToColdRamp()) |
|
|
self.propCombo.Append(PROPCOMBOSTR_CUSTOM, panel) |
|
|
|
|
|
|
|
|
|
|
|
############# |
|
126 |
|
|
127 |
|
buttonSizer = wxBoxSizer(wxHORIZONTAL) |
128 |
|
buttonSizer.Add(self.genButton, 0, wxALL, 4) |
129 |
|
buttonSizer.Add(60, 20, 0, wxALL, 4) |
130 |
|
buttonSizer.Add(wxButton(self, wxID_CANCEL, _("Close")), |
131 |
|
0, wxALL, 4) |
132 |
sizer.Add(buttonSizer, 0, |
sizer.Add(buttonSizer, 0, |
133 |
wxALL | wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL, 4) |
wxALL | wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL, 4) |
134 |
|
|
|
|
|
135 |
self.SetSizer(sizer) |
self.SetSizer(sizer) |
136 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
137 |
sizer.SetSizeHints(self) |
sizer.SetSizeHints(self) |
138 |
|
|
139 |
self.sizer = sizer |
self.sizer = sizer |
140 |
|
|
141 |
EVT_BUTTON(self, ID_CLASSGEN_GEN, self._OnGenerate) |
EVT_CHOICE(self, ID_CLASSGEN_GENCOMBO, self._OnGenTypeSelect) |
142 |
EVT_BUTTON(self, ID_CLASSGEN_CLOSE, self._OnCloseBtn) |
EVT_CHOICE(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect) |
143 |
|
EVT_BUTTON(self, wxID_OK, self.OnOK) |
144 |
|
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
145 |
|
|
146 |
|
|
147 |
|
self.genChoice.SetFocus() |
148 |
|
|
149 |
def GetClassification(self): |
def GetClassification(self): |
150 |
return self.clazz |
return self.clazz |
152 |
def AllowGenerate(self, on): |
def AllowGenerate(self, on): |
153 |
pass #self.genButton.Enable(on) |
pass #self.genButton.Enable(on) |
154 |
|
|
155 |
def _OnGenerate(self, event): |
def OnOK(self, event): |
156 |
|
"""This is really the generate button, but we want to override |
157 |
|
the wxDialog class. |
158 |
|
""" |
159 |
|
|
160 |
index = self.genCombo.GetSelection() |
index = self.genChoice.GetSelection() |
161 |
|
|
162 |
genSel = self.genCombo.GetString(index) |
genSel = self.genChoice.GetString(index) |
163 |
genPanel = self.genCombo.GetClientData(index) |
genPanel = self.genChoice.GetClientData(index) |
164 |
|
|
165 |
propPanel = self.propPanel |
propPanel = self.propPanel |
166 |
|
|
201 |
|
|
202 |
self.parent._SetClassification(self.clazz) |
self.parent._SetClassification(self.clazz) |
203 |
|
|
204 |
def _OnCloseBtn(self, event): |
def OnCancel(self, event): |
205 |
self.Close() |
self.Close() |
206 |
|
|
207 |
def _OnGenTypeSelect(self, event): |
def _OnGenTypeSelect(self, event): |
282 |
sizer = wxBoxSizer(wxHORIZONTAL) |
sizer = wxBoxSizer(wxHORIZONTAL) |
283 |
|
|
284 |
sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4) |
sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4) |
285 |
self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS, style=wxTE_RIGHT) |
self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS, |
286 |
|
style=wxTE_RIGHT) |
287 |
EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
288 |
EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
289 |
sizer.Add(self.numGroupsCtrl, 1, wxALL, 4) |
sizer.Add(self.numGroupsCtrl, 1, wxALL, 4) |
304 |
self.numGroupsChanging = False |
self.numGroupsChanging = False |
305 |
self.steppingChanging = False |
self.steppingChanging = False |
306 |
|
|
307 |
self.numGroupsCtrl.SetRange(1, 100) |
self.numGroupsCtrl.SetRange(1, sys.maxint) |
308 |
|
|
309 |
self.numGroupsCtrl.SetValue(1) |
self.numGroupsCtrl.SetValue(1) |
310 |
self.stepCtrl.SetValue("1") |
self.stepCtrl.SetValue("1") |
354 |
self.numGroupsCtrl.Enable(on) |
self.numGroupsCtrl.Enable(on) |
355 |
self.stepCtrl.Enable(on) |
self.stepCtrl.Enable(on) |
356 |
|
|
|
if on: |
|
|
self.numGroupsCtrl.SetRange(1, abs(max - min) / 0.001) |
|
|
|
|
357 |
ngroups = self.GetNumGroups() |
ngroups = self.GetNumGroups() |
358 |
|
|
359 |
if ngroups is not None \ |
if ngroups is not None \ |
384 |
min = self.GetMin() |
min = self.GetMin() |
385 |
max = self.GetMax() |
max = self.GetMax() |
386 |
|
|
|
if ngroups >= self.numGroupsCtrl.GetMax(): |
|
|
self.numGroupsCtrl.SetRange(1, ngroups + 1) |
|
|
|
|
387 |
if ngroups is not None \ |
if ngroups is not None \ |
388 |
and min is not None \ |
and min is not None \ |
389 |
and max is not None \ |
and max is not None \ |
432 |
def _OnRetrieve(self, event): |
def _OnRetrieve(self, event): |
433 |
|
|
434 |
if self.layer.table is not None: |
if self.layer.table is not None: |
435 |
range = self.layer.table.field_range(self.fieldName) |
wxBeginBusyCursor() |
436 |
self.minCtrl.SetValue(str(range[0][0])) |
min, max = self.layer.table.ValueRange(self.fieldName) |
437 |
self.maxCtrl.SetValue(str(range[1][0])) |
self.minCtrl.SetValue(str(min)) |
438 |
|
self.maxCtrl.SetValue(str(max)) |
439 |
|
wxEndBusyCursor() |
440 |
|
|
441 |
def __GetValidatedTypeEntry(self, win, value, type, badValue = None): |
def __GetValidatedTypeEntry(self, win, value, type, badValue = None): |
442 |
|
|
478 |
return valid |
return valid |
479 |
|
|
480 |
def __CalcStepping(self, min, max, ngroups): |
def __CalcStepping(self, min, max, ngroups): |
481 |
step = Str2Num(str((max - min) / float(ngroups))) |
step = (max - min) / float(ngroups) |
482 |
if self.fieldType == FIELDTYPE_INT: |
if self.fieldType == FIELDTYPE_INT: |
483 |
step = int(step) |
step = int(step) |
484 |
|
|
640 |
self.list_avail.DeleteAllItems() |
self.list_avail.DeleteAllItems() |
641 |
self.list_avail_data = [] |
self.list_avail_data = [] |
642 |
|
|
643 |
list = self.layer.table.GetUniqueValues(self.fieldName) |
list = self.layer.table.UniqueValues(self.fieldName) |
644 |
index = 0 |
index = 0 |
645 |
for v in list: |
for v in list: |
646 |
self.dataList.append(v) |
self.dataList.append(v) |
819 |
clazz = Classification() |
clazz = Classification() |
820 |
|
|
821 |
#step = int((max - min) / float(numGroups)) |
#step = int((max - min) / float(numGroups)) |
|
step = int(Str2Num(str((max - min + 1) / float(numGroups)))) |
|
822 |
|
|
823 |
if numGroups > 0: |
if numGroups > 0: |
824 |
|
|
825 |
|
step = int((max - min + 1) / float(numGroups)) |
826 |
cur_value = min |
cur_value = min |
827 |
|
|
828 |
ramp.SetNumGroups(numGroups) |
ramp.SetNumGroups(numGroups) |
829 |
|
|
830 |
for prop in ramp: |
for prop in ramp: |
831 |
clazz.AppendGroup( |
clazz.AppendGroup(ClassGroupSingleton(cur_value), prop) |
|
ClassGroupSingleton( |
|
|
Str2Num(str(cur_value)), |
|
|
prop)) |
|
832 |
cur_value += step |
cur_value += step |
833 |
|
|
834 |
return clazz |
return clazz |
849 |
|
|
850 |
ramp.SetNumGroups(numGroups) |
ramp.SetNumGroups(numGroups) |
851 |
|
|
852 |
step = Str2Num(str((max - min) / float(numGroups))) |
step = (max - min) / float(numGroups) |
853 |
|
|
854 |
if intStep: |
if intStep: |
855 |
step = int(step) |
step = int(step) |
865 |
|
|
866 |
# this check guards against rounding issues |
# this check guards against rounding issues |
867 |
if cur_min != cur_max: |
if cur_min != cur_max: |
868 |
clazz.AppendGroup( |
clazz.AppendGroup(ClassGroupRange(cur_min, cur_max, prop)) |
|
ClassGroupRange( |
|
|
Str2Num(str(cur_min)), |
|
|
Str2Num(str(cur_max)), |
|
|
prop)) |
|
869 |
|
|
870 |
cur_min = cur_max |
cur_min = cur_max |
871 |
cur_max += step |
cur_max += step |
998 |
|
|
999 |
class GreyRamp(MonochromaticRamp): |
class GreyRamp(MonochromaticRamp): |
1000 |
def __init__(self): |
def __init__(self): |
1001 |
MonochromaticRamp.__init__(self, Color(0, 0, 0), Color(1, 1, 1)) |
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, 0)) |
1002 |
|
|
1003 |
class RedRamp(MonochromaticRamp): |
class RedRamp(MonochromaticRamp): |
1004 |
def __init__(self): |
def __init__(self): |
1005 |
MonochromaticRamp.__init__(self, Color(.2, 0, 0), Color(1, 0, 0)) |
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(.8, 0, 0)) |
1006 |
|
|
1007 |
class GreenRamp(MonochromaticRamp): |
class GreenRamp(MonochromaticRamp): |
1008 |
def __init__(self): |
def __init__(self): |
1009 |
MonochromaticRamp.__init__(self, Color(0, .2, 0), Color(0, 1, 0)) |
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, .8, 0)) |
1010 |
|
|
1011 |
class BlueRamp(MonochromaticRamp): |
class BlueRamp(MonochromaticRamp): |
1012 |
def __init__(self): |
def __init__(self): |
1013 |
MonochromaticRamp.__init__(self, Color(0, 0, .2), Color(0, 0, 1)) |
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, .8)) |
1014 |
|
|
1015 |
class HotToColdRamp: |
class HotToColdRamp: |
1016 |
|
|