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 * |
21 |
|
|
22 |
import classifier |
import classifier |
23 |
|
|
24 |
from Thuban.common import Str2Num |
import resource |
25 |
|
|
26 |
ID_CLASSGEN_GEN = 4001 |
ID_CLASSGEN_GENCOMBO = 4007 |
27 |
ID_CLASSGEN_CLOSE = 4002 |
ID_CLASSGEN_PROPCOMBO = 4008 |
|
ID_CLASSGEN_COMBO = 4007 |
|
28 |
|
|
29 |
COMBOSTR_UNIFORM = _("Uniform Distribution") |
USEALL_BMP = "group_use_all" |
30 |
COMBOSTR_UNIQUE = _("Unique Values") |
USE_BMP = "group_use" |
31 |
|
USENOT_BMP = "group_use_not" |
32 |
|
USENONE_BMP = "group_use_none" |
33 |
|
|
34 |
|
GENCOMBOSTR_UNIFORM = _("Uniform Distribution") |
35 |
|
GENCOMBOSTR_UNIQUE = _("Unique Values") |
36 |
|
|
37 |
|
PROPCOMBOSTR_CUSTOM = _("Custom Ramp") |
38 |
|
PROPCOMBOSTR_GREY = _("Grey Ramp") |
39 |
|
PROPCOMBOSTR_RED = _("Red Ramp") |
40 |
|
PROPCOMBOSTR_GREEN = _("Green Ramp") |
41 |
|
PROPCOMBOSTR_BLUE = _("Blue Ramp") |
42 |
|
PROPCOMBOSTR_HOT2COLD = _("Hot-to-Cold Ramp") |
43 |
|
|
44 |
class ClassGenDialog(wxDialog): |
class ClassGenDialog(wxDialog): |
45 |
|
|
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 |
|
|
98 |
0, wxALL, 4) |
0, wxALL, 4) |
99 |
sizer.Add(wxStaticText( |
sizer.Add(wxStaticText( |
100 |
self, -1, |
self, -1, |
101 |
_("Field Type: %s") % classifier.Classifier.type2string[self.type]), |
_("Data Type: %s") % classifier.Classifier.type2string[self.type]), |
102 |
0, wxALL, 4) |
0, wxALL, 4) |
103 |
|
|
104 |
psizer = wxBoxSizer(wxHORIZONTAL) |
psizer = wxBoxSizer(wxHORIZONTAL) |
105 |
psizer.Add(wxStaticText( |
psizer.Add(wxStaticText(self, -1, _("Generate:")), |
|
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 = wxComboBox(self, |
|
|
ID_CLASSGEN_COMBO, |
|
|
"", style = wxCB_READONLY) |
|
|
psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4) |
|
|
EVT_COMBOBOX(self, ID_CLASSGEN_COMBO, 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(COMBOSTR_UNIQUE) |
|
|
self.genCombo.SetClientData(self.genCombo.GetCount() - 1, 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(COMBOSTR_UNIFORM) |
sizer.Show(uni_panel, False) |
|
self.genCombo.SetClientData(self.genCombo.GetCount() - 1, panel) |
|
|
sizer.Add(panel, 0, wxGROW | wxALL, 4) |
|
|
sizer.Show(panel, False) |
|
|
|
|
|
############# |
|
116 |
|
|
117 |
self.propPanel = None |
psizer = wxBoxSizer(wxHORIZONTAL) |
118 |
|
psizer.Add(wxStaticText(self, -1, _("Color Scheme:")), |
119 |
panel = CustomRampPanel(self, layer.ShapeType()) |
0, wxALIGN_CENTER_VERTICAL, 0) |
120 |
|
psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4) |
121 |
self.propPanel = panel |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
|
|
|
|
sizer.Add(panel, 1, wxALL | wxGROW, 4) |
|
122 |
|
|
123 |
############# |
sizer.Add(custom_ramp_panel, 1, wxGROW | wxALL, 4) |
124 |
|
sizer.Show(custom_ramp_panel, False) |
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 |
selIndex = self.genCombo.GetSelection() |
index = self.genChoice.GetSelection() |
160 |
|
|
161 |
sel = self.genCombo.GetString(selIndex) |
genSel = self.genChoice.GetString(index) |
162 |
genPanel = self.genCombo.GetClientData(selIndex) |
genPanel = self.genChoice.GetClientData(index) |
|
propPanel = self.propPanel |
|
163 |
|
|
164 |
if sel == COMBOSTR_UNIFORM: |
propPanel = self.propPanel |
165 |
|
|
166 |
min = genPanel.GetMin() |
if genSel in (GENCOMBOSTR_UNIFORM, GENCOMBOSTR_UNIQUE): |
|
max = genPanel.GetMax() |
|
167 |
numGroups = genPanel.GetNumGroups() |
numGroups = genPanel.GetNumGroups() |
|
sp = propPanel.GetStartProperties() |
|
|
ep = propPanel.GetEndProperties() |
|
168 |
|
|
169 |
if min is not None \ |
index = self.propCombo.GetSelection() |
|
and max is not None \ |
|
|
and numGroups is not None: |
|
170 |
|
|
171 |
self.clazz = ClassGenerator().GenUnifromDistribution( |
propSel = self.propCombo.GetString(index) |
172 |
min, max, numGroups, sp, ep, |
propPanel = self.propCombo.GetClientData(index) |
|
self.type == FIELDTYPE_INT) |
|
173 |
|
|
174 |
self.parent._SetClassification(self.clazz) |
ramp = propPanel.GetRamp() |
175 |
|
|
176 |
elif sel == COMBOSTR_UNIQUE: |
if genSel == GENCOMBOSTR_UNIFORM: |
177 |
|
|
178 |
list = genPanel.GetValueList() |
min = genPanel.GetMin() |
179 |
numGroups = genPanel.GetNumGroups() |
max = genPanel.GetMax() |
|
sp = propPanel.GetStartProperties() |
|
|
ep = propPanel.GetEndProperties() |
|
180 |
|
|
181 |
if len(list) > 0 \ |
if min is not None \ |
182 |
and numGroups is not None: |
and max is not None \ |
183 |
|
and numGroups is not None: |
184 |
|
|
185 |
self.clazz = ClassGenerator().GenSingletonsFromList( |
self.clazz = ClassGenerator().GenUnifromDistribution( |
186 |
list, numGroups, sp, ep) |
min, max, numGroups, ramp, |
187 |
|
self.type == FIELDTYPE_INT) |
188 |
|
|
189 |
self.parent._SetClassification(self.clazz) |
self.parent._SetClassification(self.clazz) |
190 |
|
|
191 |
else: |
elif genSel == GENCOMBOSTR_UNIQUE: |
192 |
pass |
|
193 |
|
list = genPanel.GetValueList() |
194 |
|
|
195 |
|
if len(list) > 0 \ |
196 |
|
and numGroups is not None: |
197 |
|
|
198 |
def _OnCloseBtn(self, event): |
self.clazz = ClassGenerator().GenSingletonsFromList( |
199 |
|
list, numGroups, ramp) |
200 |
|
|
201 |
|
self.parent._SetClassification(self.clazz) |
202 |
|
|
203 |
|
def OnCancel(self, event): |
204 |
self.Close() |
self.Close() |
205 |
|
|
206 |
def _OnGenTypeSelect(self, event): |
def _OnGenTypeSelect(self, event): |
219 |
self.sizer.SetSizeHints(self) |
self.sizer.SetSizeHints(self) |
220 |
self.sizer.Layout() |
self.sizer.Layout() |
221 |
|
|
222 |
|
def _OnPropTypeSelect(self, event): |
223 |
|
combo = event.GetEventObject() |
224 |
|
|
225 |
|
selIndex = combo.GetSelection() |
226 |
|
sel = combo.GetString(selIndex) |
227 |
|
|
228 |
|
if isinstance(self.propPanel, wxPanel): |
229 |
|
self.sizer.Show(self.propPanel, False) |
230 |
|
|
231 |
|
self.propPanel = combo.GetClientData(selIndex) |
232 |
|
|
233 |
|
if isinstance(self.propPanel, wxPanel): |
234 |
|
self.sizer.Show(self.propPanel, True) |
235 |
|
|
236 |
|
self.sizer.SetSizeHints(self) |
237 |
|
self.sizer.Layout() |
238 |
|
|
239 |
|
|
240 |
ID_UNIFORM_MIN = 4001 |
ID_UNIFORM_MIN = 4001 |
241 |
ID_UNIFORM_MAX = 4002 |
ID_UNIFORM_MAX = 4002 |
281 |
sizer = wxBoxSizer(wxHORIZONTAL) |
sizer = wxBoxSizer(wxHORIZONTAL) |
282 |
|
|
283 |
sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4) |
sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4) |
284 |
self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS, style=wxTE_RIGHT) |
self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS, |
285 |
|
style=wxTE_RIGHT) |
286 |
EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
287 |
EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
288 |
sizer.Add(self.numGroupsCtrl, 1, wxALL, 4) |
sizer.Add(self.numGroupsCtrl, 1, wxALL, 4) |
303 |
self.numGroupsChanging = False |
self.numGroupsChanging = False |
304 |
self.steppingChanging = False |
self.steppingChanging = False |
305 |
|
|
306 |
self.numGroupsCtrl.SetRange(1, 100) |
self.numGroupsCtrl.SetRange(1, sys.maxint) |
307 |
|
|
308 |
self.numGroupsCtrl.SetValue(1) |
self.numGroupsCtrl.SetValue(1) |
309 |
self.stepCtrl.SetValue("1") |
self.stepCtrl.SetValue("1") |
353 |
self.numGroupsCtrl.Enable(on) |
self.numGroupsCtrl.Enable(on) |
354 |
self.stepCtrl.Enable(on) |
self.stepCtrl.Enable(on) |
355 |
|
|
|
if on: |
|
|
self.numGroupsCtrl.SetRange(1, abs(max - min) / 0.001) |
|
|
|
|
356 |
ngroups = self.GetNumGroups() |
ngroups = self.GetNumGroups() |
357 |
|
|
358 |
if ngroups is not None \ |
if ngroups is not None \ |
383 |
min = self.GetMin() |
min = self.GetMin() |
384 |
max = self.GetMax() |
max = self.GetMax() |
385 |
|
|
|
if ngroups >= self.numGroupsCtrl.GetMax(): |
|
|
self.numGroupsCtrl.SetRange(1, ngroups + 1) |
|
|
|
|
386 |
if ngroups is not None \ |
if ngroups is not None \ |
387 |
and min is not None \ |
and min is not None \ |
388 |
and max is not None \ |
and max is not None \ |
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 |
|
|
501 |
ID_UNIQUE_USENONE = 4005 |
ID_UNIQUE_USENONE = 4005 |
502 |
ID_UNIQUE_SORTAVAIL = 4006 |
ID_UNIQUE_SORTAVAIL = 4006 |
503 |
ID_UNIQUE_SORTUSE = 4007 |
ID_UNIQUE_SORTUSE = 4007 |
504 |
|
ID_UNIQUE_REVAVAIL = 4008 |
505 |
|
ID_UNIQUE_REVUSE = 4009 |
506 |
|
|
507 |
class GenUniquePanel(wxPanel): |
class GenUniquePanel(wxPanel): |
508 |
|
|
518 |
wxVERTICAL) |
wxVERTICAL) |
519 |
|
|
520 |
|
|
521 |
|
#bsizer = wxBoxSizer(wxVERTICAL) |
522 |
|
topSizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE, |
523 |
|
_("Retrieve From Table")), |
524 |
|
0, wxALL | wxALIGN_RIGHT, 4) |
525 |
|
|
526 |
|
EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve) |
527 |
|
|
528 |
|
#topSizer.Add(bsizer, 0, wxALL, 4) |
529 |
|
|
530 |
sizer = wxBoxSizer(wxHORIZONTAL) |
sizer = wxBoxSizer(wxHORIZONTAL) |
531 |
|
|
532 |
self.dataList = [] |
self.dataList = [] |
538 |
self.list_avail_data = [] |
self.list_avail_data = [] |
539 |
psizer.Add(self.list_avail, 1, wxGROW, 0) |
psizer.Add(self.list_avail, 1, wxGROW, 0) |
540 |
|
|
541 |
psizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort"))) |
bsizer = wxBoxSizer(wxHORIZONTAL) |
542 |
|
bsizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort"))) |
543 |
|
EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortList) |
544 |
|
|
545 |
EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortAvailList) |
bsizer.Add(wxButton(self, ID_UNIQUE_REVAVAIL, _("Reverse"))) |
546 |
|
EVT_BUTTON(self, ID_UNIQUE_REVAVAIL, self._OnReverseList) |
547 |
|
|
548 |
|
psizer.Add(bsizer, 0, wxGROW, 0) |
549 |
sizer.Add(psizer, 1, wxGROW, 0) |
sizer.Add(psizer, 1, wxGROW, 0) |
550 |
|
|
551 |
|
|
552 |
bsizer = wxBoxSizer(wxVERTICAL) |
bsizer = wxBoxSizer(wxVERTICAL) |
553 |
bsizer.Add(wxButton(self, ID_UNIQUE_USEALL, _("Use All")), |
|
554 |
|
bmp = resource.GetBitmapResource(USEALL_BMP, wxBITMAP_TYPE_XPM) |
555 |
|
bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USEALL, bmp), |
556 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
557 |
bsizer.Add(wxButton(self, ID_UNIQUE_USE, _("Use >>")), |
bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM) |
558 |
|
bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USE, bmp), |
559 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
560 |
bsizer.Add(wxButton(self, ID_UNIQUE_DONTUSE, _("<< Don't Use")), |
bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM) |
561 |
|
bsizer.Add(wxBitmapButton(self, ID_UNIQUE_DONTUSE, bmp), |
562 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
563 |
bsizer.Add(wxButton(self, ID_UNIQUE_USENONE, _("Use None")), |
bmp = resource.GetBitmapResource(USENONE_BMP, wxBITMAP_TYPE_XPM) |
564 |
|
bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USENONE, bmp), |
565 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
566 |
|
|
567 |
EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll) |
EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll) |
578 |
self.list_use_data = [] |
self.list_use_data = [] |
579 |
psizer.Add(self.list_use, 1, wxGROW, 0) |
psizer.Add(self.list_use, 1, wxGROW, 0) |
580 |
|
|
581 |
psizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort"))) |
bsizer = wxBoxSizer(wxHORIZONTAL) |
582 |
|
bsizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort"))) |
583 |
|
EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortList) |
584 |
|
|
585 |
EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortUseList) |
bsizer.Add(wxButton(self, ID_UNIQUE_REVUSE, _("Reverse"))) |
586 |
|
EVT_BUTTON(self, ID_UNIQUE_REVUSE, self._OnReverseList) |
587 |
|
|
588 |
sizer.Add(psizer, 1, wxGROW, 0) |
psizer.Add(bsizer, 0, wxGROW, 0) |
589 |
|
|
590 |
bsizer = wxBoxSizer(wxVERTICAL) |
sizer.Add(psizer, 1, wxGROW, 0) |
|
bsizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE, |
|
|
_("Retrieve From Table")), |
|
|
0, wxGROW | wxALL, 4) |
|
|
|
|
|
EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve) |
|
591 |
|
|
|
sizer.Add(bsizer, 0, wxALL, 4) |
|
592 |
|
|
593 |
topSizer.Add(sizer, 1, wxGROW, 0) |
topSizer.Add(sizer, 1, wxGROW, 0) |
594 |
|
|
609 |
list.append(self.dataList[self.list_use.GetItemData(i)]) |
list.append(self.dataList[self.list_use.GetItemData(i)]) |
610 |
return list |
return list |
611 |
|
|
612 |
def _OnSortAvailList(self, event): |
def _OnSortList(self, event): |
613 |
self.list_avail.SortItems(lambda i1, i2: |
id = event.GetId() |
614 |
cmp(self.dataList[i1], |
|
615 |
self.dataList[i2])) |
if id == ID_UNIQUE_SORTUSE: |
616 |
|
list = self.list_use |
617 |
def _OnSortUseList(self, event): |
else: |
618 |
self.list_use.SortItems(lambda i1, i2: |
list = self.list_avail |
619 |
cmp(self.dataList[i1], |
|
620 |
self.dataList[i2])) |
list.SortItems(lambda i1, i2: cmp(self.dataList[i1], |
621 |
|
self.dataList[i2])) |
622 |
|
|
623 |
|
def _OnReverseList(self, event): |
624 |
|
id = event.GetId() |
625 |
|
|
626 |
|
if id == ID_UNIQUE_REVUSE: |
627 |
|
list = self.list_use |
628 |
|
else: |
629 |
|
list = self.list_avail |
630 |
|
|
631 |
|
# |
632 |
|
# always returning 1 reverses the list |
633 |
|
# |
634 |
|
list.SortItems(lambda i1, i2: 1) |
635 |
|
|
636 |
def _OnRetrieve(self, event): |
def _OnRetrieve(self, event): |
637 |
self.list_use.DeleteAllItems() |
self.list_use.DeleteAllItems() |
654 |
self.__MoveListItem(0, self.list_avail, self.list_use) |
self.__MoveListItem(0, self.list_avail, self.list_use) |
655 |
|
|
656 |
def _OnUse(self, event): |
def _OnUse(self, event): |
|
print "_OnUse" |
|
657 |
self.__MoveSelectedItems(self.list_avail, self.list_use) |
self.__MoveSelectedItems(self.list_avail, self.list_use) |
658 |
|
|
659 |
def _OnDontUse(self, event): |
def _OnDontUse(self, event): |
|
print "_OnDontUse" |
|
660 |
self.__MoveSelectedItems(self.list_use, self.list_avail) |
self.__MoveSelectedItems(self.list_use, self.list_avail) |
661 |
|
|
662 |
def _OnUseNone(self, event): |
def _OnUseNone(self, event): |
|
print "_OnUseNone" |
|
663 |
|
|
664 |
for i in range(self.list_use.GetItemCount()): |
for i in range(self.list_use.GetItemCount()): |
665 |
self.__MoveListItem(0, self.list_use, self.list_avail) |
self.__MoveListItem(0, self.list_use, self.list_avail) |
725 |
| wxALIGN_CENTER_VERTICAL, \ |
| wxALIGN_CENTER_VERTICAL, \ |
726 |
4) |
4) |
727 |
|
|
728 |
|
bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM) |
729 |
bsizer = wxBoxSizer(wxVERTICAL) |
bsizer = wxBoxSizer(wxVERTICAL) |
730 |
bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYSTART, _("Copy >>")), |
bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYSTART, bmp), |
731 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
732 |
bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYEND, _("<< Copy")), |
bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM) |
733 |
|
bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYEND, bmp), |
734 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
735 |
|
|
736 |
topSizer.Add(bsizer, |
topSizer.Add(bsizer, |
766 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
767 |
topSizer.SetSizeHints(self) |
topSizer.SetSizeHints(self) |
768 |
|
|
769 |
def GetStartProperties(self): |
def GetRamp(self): |
770 |
return self.startPropCtrl.GetProperties() |
return CustomRamp(self.startPropCtrl.GetProperties(), |
771 |
|
self.endPropCtrl.GetProperties()) |
|
def GetEndProperties(self): |
|
|
return self.endPropCtrl.GetProperties() |
|
772 |
|
|
773 |
def _OnCopyStart(self, event): |
def _OnCopyStart(self, event): |
774 |
self.endPropCtrl.SetProperties(self.startPropCtrl.GetProperties()) |
self.endPropCtrl.SetProperties(self.startPropCtrl.GetProperties()) |
784 |
|
|
785 |
class ClassGenerator: |
class ClassGenerator: |
786 |
|
|
787 |
def GenSingletonsFromList(self, list, numGroups, prop1, prop2): |
def GenSingletonsFromList(self, list, numGroups, ramp): |
788 |
"""Generate a new classification consisting solely of singletons. |
"""Generate a new classification consisting solely of singletons. |
789 |
|
|
790 |
The resulting classification will consist of at most 'numGroups' |
The resulting classification will consist of at most 'numGroups' |
806 |
clazz = Classification() |
clazz = Classification() |
807 |
if numGroups == 0: return clazz |
if numGroups == 0: return clazz |
808 |
|
|
809 |
for value, prop in zip(list, CustomRamp(numGroups, prop1, prop2)): |
ramp.SetNumGroups(numGroups) |
810 |
|
|
811 |
|
for value, prop in zip(list, ramp): |
812 |
clazz.AppendGroup(ClassGroupSingleton(value, prop)) |
clazz.AppendGroup(ClassGroupSingleton(value, prop)) |
813 |
|
|
814 |
return clazz |
return clazz |
815 |
|
|
816 |
def GenSingletons(self, min, max, numGroups, prop1, prop2): |
def GenSingletons(self, min, max, numGroups, ramp): |
817 |
|
|
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 |
for prop in CustomRamp(numGroups, prop1, prop2): |
ramp.SetNumGroups(numGroups) |
828 |
clazz.AppendGroup( |
|
829 |
ClassGroupSingleton( |
for prop in ramp: |
830 |
Str2Num(str(cur_value)), |
clazz.AppendGroup(ClassGroupSingleton(cur_value), prop) |
|
prop)) |
|
831 |
cur_value += step |
cur_value += step |
832 |
|
|
833 |
return clazz |
return clazz |
834 |
|
|
835 |
def GenUnifromDistribution(self, min, max, numGroups, |
def GenUnifromDistribution(self, min, max, numGroups, |
836 |
prop1, prop2, intStep = False): |
ramp, intStep = False): |
837 |
"""Generate a classification with numGroups range groups |
"""Generate a classification with numGroups range groups |
838 |
each with the same interval. |
each with the same interval. |
839 |
|
|
846 |
clazz = Classification() |
clazz = Classification() |
847 |
if numGroups == 0: return clazz |
if numGroups == 0: return clazz |
848 |
|
|
849 |
step = Str2Num(str((max - min) / float(numGroups))) |
ramp.SetNumGroups(numGroups) |
850 |
|
|
851 |
|
step = (max - min) / float(numGroups) |
852 |
|
|
853 |
if intStep: |
if intStep: |
854 |
step = int(step) |
step = int(step) |
857 |
cur_max = cur_min + step |
cur_max = cur_min + step |
858 |
|
|
859 |
i = 0 |
i = 0 |
860 |
for prop in CustomRamp(numGroups, prop1, prop2): |
for prop in ramp: |
861 |
|
|
862 |
if i == (numGroups - 1): |
if i == (numGroups - 1): |
863 |
cur_max = max |
cur_max = max |
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 |
876 |
STEP = 1 |
STEP = 1 |
877 |
class CustomRamp: |
class CustomRamp: |
878 |
|
|
879 |
def __init__(self, num, prop1, prop2): |
def __init__(self, prop1, prop2): |
880 |
|
self.prop1 = prop1 |
881 |
|
self.prop2 = prop2 |
882 |
|
|
883 |
|
self.count = 0 |
884 |
|
|
885 |
|
def __iter__(self): |
886 |
|
return self |
887 |
|
|
888 |
|
def GetRamp(self): |
889 |
|
return self |
890 |
|
|
891 |
|
def SetNumGroups(self, num): |
892 |
|
|
893 |
|
if num <= 0: |
894 |
|
return False |
895 |
|
|
896 |
self.count = int(num) |
self.count = int(num) |
897 |
num = float(num) |
num = float(num) |
898 |
|
|
899 |
|
prop1 = self.prop1 |
900 |
|
prop2 = self.prop2 |
901 |
|
|
902 |
clr = prop1.GetLineColor() |
clr = prop1.GetLineColor() |
903 |
lineColor2 = prop2.GetLineColor() |
lineColor2 = prop2.GetLineColor() |
904 |
|
|
917 |
self.lineWidth = prop1.GetLineWidth() |
self.lineWidth = prop1.GetLineWidth() |
918 |
self.lineWidthStep = (prop2.GetLineWidth() - self.lineWidth) / num |
self.lineWidthStep = (prop2.GetLineWidth() - self.lineWidth) / num |
919 |
|
|
920 |
def __iter__(self): |
return True |
|
return self |
|
921 |
|
|
922 |
def next(self): |
def next(self): |
923 |
if self.count == 0: |
if self.count == 0: |
982 |
|
|
983 |
|
|
984 |
return (color, step) |
return (color, step) |
985 |
|
|
986 |
|
class MonochromaticRamp(CustomRamp): |
987 |
|
def __init__(self, start, end): |
988 |
|
sp = ClassGroupProperties() |
989 |
|
sp.SetLineColor(start) |
990 |
|
sp.SetFill(start) |
991 |
|
|
992 |
|
ep = ClassGroupProperties() |
993 |
|
ep.SetLineColor(end) |
994 |
|
ep.SetFill(end) |
995 |
|
|
996 |
|
CustomRamp.__init__(self, sp, ep) |
997 |
|
|
998 |
|
class GreyRamp(MonochromaticRamp): |
999 |
|
def __init__(self): |
1000 |
|
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, 0)) |
1001 |
|
|
1002 |
|
class RedRamp(MonochromaticRamp): |
1003 |
|
def __init__(self): |
1004 |
|
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(.8, 0, 0)) |
1005 |
|
|
1006 |
|
class GreenRamp(MonochromaticRamp): |
1007 |
|
def __init__(self): |
1008 |
|
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, .8, 0)) |
1009 |
|
|
1010 |
|
class BlueRamp(MonochromaticRamp): |
1011 |
|
def __init__(self): |
1012 |
|
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, .8)) |
1013 |
|
|
1014 |
|
class HotToColdRamp: |
1015 |
|
|
1016 |
|
def __iter__(self): |
1017 |
|
return self |
1018 |
|
|
1019 |
|
def GetRamp(self): |
1020 |
|
return self |
1021 |
|
|
1022 |
|
def SetNumGroups(self, num): |
1023 |
|
if num < 0: |
1024 |
|
return False |
1025 |
|
|
1026 |
|
self.num = float(num) |
1027 |
|
self.index = 0 |
1028 |
|
|
1029 |
|
return True |
1030 |
|
|
1031 |
|
def next(self): |
1032 |
|
if self.index == self.num: |
1033 |
|
raise StopIteration |
1034 |
|
|
1035 |
|
clr = [1.0, 1.0, 1.0] |
1036 |
|
|
1037 |
|
if self.index < (.25 * self.num): |
1038 |
|
clr[0] = 0 |
1039 |
|
clr[1] = 4 * self.index / self.num |
1040 |
|
elif self.index < (.5 * self.num): |
1041 |
|
clr[0] = 0 |
1042 |
|
clr[2] = 1 + 4 * (.25 * self.num - self.index) / self.num |
1043 |
|
elif self.index < (.75 * self.num): |
1044 |
|
clr[0] = 4 * (self.index - .5 * self.num) / self.num |
1045 |
|
clr[2] = 0 |
1046 |
|
else: |
1047 |
|
clr[1] = 1 + 4 * (.75 * self.num - self.index) / self.num |
1048 |
|
clr[2] = 0 |
1049 |
|
|
1050 |
|
self.index += 1 |
1051 |
|
|
1052 |
|
prop = ClassGroupProperties() |
1053 |
|
prop.SetLineColor(Color(clr[0], clr[1], clr[2])) |
1054 |
|
prop.SetFill(Color(clr[0], clr[1], clr[2])) |
1055 |
|
|
1056 |
|
return prop |
1057 |
|
|
1058 |
|
#class Colors16Ramp: |
1059 |
|
# |
1060 |
|
#def __iter__(self): |
1061 |
|
#return self |
1062 |
|
# |
1063 |
|
#def GetRamp(self): |
1064 |
|
#return self |
1065 |
|
# |
1066 |
|
#def SetNumGroups(self, num): |
1067 |
|
#if num < 0: |
1068 |
|
#return False |
1069 |
|
# |
1070 |
|
#self.index = 0 |
1071 |
|
# |
1072 |
|
#return True |
1073 |
|
|
1074 |
|
|