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 |
|
|
61 |
# we need to create genButton first because when we create the |
# we need to create genButton first because when we create the |
62 |
# panels they will call AllowGenerate() which uses genButton. |
# panels they will call AllowGenerate() which uses genButton. |
63 |
# |
# |
64 |
buttonSizer = wxBoxSizer(wxHORIZONTAL) |
self.genButton = wxButton(self, wxID_OK, _("Generate")) |
65 |
self.genButton = wxButton(self, ID_CLASSGEN_GEN, _("Generate")) |
self.genButton.SetDefault() |
66 |
|
|
67 |
buttonSizer.Add(self.genButton, 0, wxALL, 4) |
self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO) |
68 |
buttonSizer.Add(60, 20, 0, wxALL, 4) |
|
69 |
buttonSizer.Add(wxButton(self, ID_CLASSGEN_CLOSE, _("Close")), |
uniq_panel = GenUniquePanel(self, layer, fieldName, self.type) |
70 |
0, wxALL, 4) |
|
71 |
|
self.genPanel = uniq_panel |
72 |
|
self.genChoice.Append(GENCOMBOSTR_UNIQUE, uniq_panel) |
73 |
|
|
74 |
|
if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE): |
75 |
|
uni_panel = GenUniformPanel(self, layer, fieldName, self.type) |
76 |
|
self.genChoice.Append(GENCOMBOSTR_UNIFORM, uni_panel) |
77 |
|
|
78 |
|
self.genChoice.SetSelection(0) |
79 |
|
|
80 |
|
self.propPanel = None |
81 |
|
custom_ramp_panel = CustomRampPanel(self, layer.ShapeType()) |
82 |
|
|
83 |
|
self.propCombo = wxChoice(self, ID_CLASSGEN_PROPCOMBO) |
84 |
|
self.propCombo.Append(PROPCOMBOSTR_GREY, GreyRamp()) |
85 |
|
self.propCombo.Append(PROPCOMBOSTR_RED, RedRamp()) |
86 |
|
self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp()) |
87 |
|
self.propCombo.Append(PROPCOMBOSTR_BLUE, BlueRamp()) |
88 |
|
self.propCombo.Append(PROPCOMBOSTR_HOT2COLD, HotToColdRamp()) |
89 |
|
self.propCombo.Append(PROPCOMBOSTR_CUSTOM, custom_ramp_panel) |
90 |
|
|
91 |
|
self.propCombo.SetSelection(0) |
92 |
|
|
93 |
############# |
############# |
94 |
|
|
104 |
psizer = wxBoxSizer(wxHORIZONTAL) |
psizer = wxBoxSizer(wxHORIZONTAL) |
105 |
psizer.Add(wxStaticText(self, -1, _("Generate:")), |
psizer.Add(wxStaticText(self, -1, _("Generate:")), |
106 |
0, wxALIGN_CENTER_VERTICAL, 0) |
0, wxALIGN_CENTER_VERTICAL, 0) |
107 |
|
psizer.Add(self.genChoice, 1, wxALL | wxGROW, 4) |
|
self.genCombo = wxChoice(self, ID_CLASSGEN_GENCOMBO) |
|
|
psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4) |
|
|
EVT_CHOICE(self, ID_CLASSGEN_GENCOMBO, self._OnGenTypeSelect) |
|
108 |
|
|
109 |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
110 |
|
sizer.Add(self.genPanel, 1, wxGROW | wxALL, 4) |
111 |
|
|
112 |
############# |
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 |
|
|
|
|
113 |
if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE): |
if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE): |
114 |
panel = GenUniformPanel(self, layer, fieldName, self.type) |
sizer.Add(uni_panel, 1, wxGROW | wxALL, 4) |
115 |
self.genCombo.Append(GENCOMBOSTR_UNIFORM, panel) |
sizer.Show(uni_panel, False) |
|
sizer.Add(panel, 1, wxGROW | wxALL, 4) |
|
|
sizer.Show(panel, False) |
|
|
|
|
|
self.genCombo.SetSelection(0) |
|
|
|
|
|
############# |
|
116 |
|
|
117 |
psizer = wxBoxSizer(wxHORIZONTAL) |
psizer = wxBoxSizer(wxHORIZONTAL) |
118 |
psizer.Add(wxStaticText(self, -1, _("Color Scheme:")), |
psizer.Add(wxStaticText(self, -1, _("Color Scheme:")), |
119 |
0, wxALIGN_CENTER_VERTICAL, 0) |
0, wxALIGN_CENTER_VERTICAL, 0) |
|
|
|
|
self.propCombo = wxChoice(self, ID_CLASSGEN_PROPCOMBO) |
|
120 |
psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4) |
psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4) |
|
EVT_CHOICE(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect) |
|
121 |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
122 |
|
|
123 |
############# |
sizer.Add(custom_ramp_panel, 1, wxGROW | wxALL, 4) |
124 |
|
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) |
|
|
|
|
|
self.propCombo.SetSelection(0) |
|
|
|
|
|
|
|
|
############# |
|
125 |
|
|
126 |
|
buttonSizer = wxBoxSizer(wxHORIZONTAL) |
127 |
|
buttonSizer.Add(self.genButton, 0, wxALL, 4) |
128 |
|
buttonSizer.Add(60, 20, 0, wxALL, 4) |
129 |
|
buttonSizer.Add(wxButton(self, wxID_CANCEL, _("Close")), |
130 |
|
0, wxALL, 4) |
131 |
sizer.Add(buttonSizer, 0, |
sizer.Add(buttonSizer, 0, |
132 |
wxALL | wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL, 4) |
wxALL | wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL, 4) |
133 |
|
|
|
|
|
134 |
self.SetSizer(sizer) |
self.SetSizer(sizer) |
135 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
136 |
sizer.SetSizeHints(self) |
sizer.SetSizeHints(self) |
137 |
|
|
138 |
self.sizer = sizer |
self.sizer = sizer |
139 |
|
|
140 |
EVT_BUTTON(self, ID_CLASSGEN_GEN, self._OnGenerate) |
EVT_CHOICE(self, ID_CLASSGEN_GENCOMBO, self._OnGenTypeSelect) |
141 |
EVT_BUTTON(self, ID_CLASSGEN_CLOSE, self._OnCloseBtn) |
EVT_CHOICE(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect) |
142 |
|
EVT_BUTTON(self, wxID_OK, self.OnOK) |
143 |
|
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
144 |
|
|
145 |
|
|
146 |
|
self.genChoice.SetFocus() |
147 |
|
|
148 |
def GetClassification(self): |
def GetClassification(self): |
149 |
return self.clazz |
return self.clazz |
151 |
def AllowGenerate(self, on): |
def AllowGenerate(self, on): |
152 |
pass #self.genButton.Enable(on) |
pass #self.genButton.Enable(on) |
153 |
|
|
154 |
def _OnGenerate(self, event): |
def OnOK(self, event): |
155 |
|
"""This is really the generate button, but we want to override |
156 |
|
the wxDialog class. |
157 |
|
""" |
158 |
|
|
159 |
index = self.genCombo.GetSelection() |
index = self.genChoice.GetSelection() |
160 |
|
|
161 |
genSel = self.genCombo.GetString(index) |
genSel = self.genChoice.GetString(index) |
162 |
genPanel = self.genCombo.GetClientData(index) |
genPanel = self.genChoice.GetClientData(index) |
163 |
|
|
164 |
propPanel = self.propPanel |
propPanel = self.propPanel |
165 |
|
|
200 |
|
|
201 |
self.parent._SetClassification(self.clazz) |
self.parent._SetClassification(self.clazz) |
202 |
|
|
203 |
def _OnCloseBtn(self, event): |
def OnCancel(self, event): |
204 |
self.Close() |
self.Close() |
205 |
|
|
206 |
def _OnGenTypeSelect(self, event): |
def _OnGenTypeSelect(self, event): |
431 |
def _OnRetrieve(self, event): |
def _OnRetrieve(self, event): |
432 |
|
|
433 |
if self.layer.table is not None: |
if self.layer.table is not None: |
434 |
|
wxBeginBusyCursor() |
435 |
range = self.layer.table.field_range(self.fieldName) |
range = self.layer.table.field_range(self.fieldName) |
436 |
self.minCtrl.SetValue(str(range[0][0])) |
self.minCtrl.SetValue(str(range[0][0])) |
437 |
self.maxCtrl.SetValue(str(range[1][0])) |
self.maxCtrl.SetValue(str(range[1][0])) |
438 |
|
wxEndBusyCursor() |
439 |
|
|
440 |
def __GetValidatedTypeEntry(self, win, value, type, badValue = None): |
def __GetValidatedTypeEntry(self, win, value, type, badValue = None): |
441 |
|
|
477 |
return valid |
return valid |
478 |
|
|
479 |
def __CalcStepping(self, min, max, ngroups): |
def __CalcStepping(self, min, max, ngroups): |
480 |
step = Str2Num(str((max - min) / float(ngroups))) |
step = (max - min) / float(ngroups) |
481 |
if self.fieldType == FIELDTYPE_INT: |
if self.fieldType == FIELDTYPE_INT: |
482 |
step = int(step) |
step = int(step) |
483 |
|
|
818 |
clazz = Classification() |
clazz = Classification() |
819 |
|
|
820 |
#step = int((max - min) / float(numGroups)) |
#step = int((max - min) / float(numGroups)) |
|
step = int(Str2Num(str((max - min + 1) / float(numGroups)))) |
|
821 |
|
|
822 |
if numGroups > 0: |
if numGroups > 0: |
823 |
|
|
824 |
|
step = int((max - min + 1) / float(numGroups)) |
825 |
cur_value = min |
cur_value = min |
826 |
|
|
827 |
ramp.SetNumGroups(numGroups) |
ramp.SetNumGroups(numGroups) |
828 |
|
|
829 |
for prop in ramp: |
for prop in ramp: |
830 |
clazz.AppendGroup( |
clazz.AppendGroup(ClassGroupSingleton(cur_value), prop) |
|
ClassGroupSingleton( |
|
|
Str2Num(str(cur_value)), |
|
|
prop)) |
|
831 |
cur_value += step |
cur_value += step |
832 |
|
|
833 |
return clazz |
return clazz |
848 |
|
|
849 |
ramp.SetNumGroups(numGroups) |
ramp.SetNumGroups(numGroups) |
850 |
|
|
851 |
step = Str2Num(str((max - min) / float(numGroups))) |
step = (max - min) / float(numGroups) |
852 |
|
|
853 |
if intStep: |
if intStep: |
854 |
step = int(step) |
step = int(step) |
864 |
|
|
865 |
# this check guards against rounding issues |
# this check guards against rounding issues |
866 |
if cur_min != cur_max: |
if cur_min != cur_max: |
867 |
clazz.AppendGroup( |
clazz.AppendGroup(ClassGroupRange(cur_min, cur_max, prop)) |
|
ClassGroupRange( |
|
|
Str2Num(str(cur_min)), |
|
|
Str2Num(str(cur_max)), |
|
|
prop)) |
|
868 |
|
|
869 |
cur_min = cur_max |
cur_min = cur_max |
870 |
cur_max += step |
cur_max += step |