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 |
|
import resource |
25 |
|
|
26 |
from Thuban.common import Str2Num |
from Thuban.common import Str2Num |
27 |
|
|
28 |
ID_CLASSGEN_GEN = 4001 |
ID_CLASSGEN_GEN = 4001 |
29 |
ID_CLASSGEN_CLOSE = 4002 |
ID_CLASSGEN_CLOSE = 4002 |
30 |
ID_CLASSGEN_COMBO = 4007 |
ID_CLASSGEN_GENCOMBO = 4007 |
31 |
|
ID_CLASSGEN_PROPCOMBO = 4008 |
32 |
|
|
33 |
COMBOSTR_UNIFORM = _("Uniform Distribution") |
USEALL_BMP = "group_use_all" |
34 |
COMBOSTR_UNIQUE = _("Unique Values") |
USE_BMP = "group_use" |
35 |
|
USENOT_BMP = "group_use_not" |
36 |
|
USENONE_BMP = "group_use_none" |
37 |
|
|
38 |
|
GENCOMBOSTR_UNIFORM = _("Uniform Distribution") |
39 |
|
GENCOMBOSTR_UNIQUE = _("Unique Values") |
40 |
|
|
41 |
|
PROPCOMBOSTR_CUSTOM = _("Custom Ramp") |
42 |
|
PROPCOMBOSTR_GREY = _("Grey Ramp") |
43 |
|
PROPCOMBOSTR_RED = _("Red Ramp") |
44 |
|
PROPCOMBOSTR_GREEN = _("Green Ramp") |
45 |
|
PROPCOMBOSTR_BLUE = _("Blue Ramp") |
46 |
|
PROPCOMBOSTR_HOT2COLD = _("Hot-to-Cold Ramp") |
47 |
|
|
48 |
class ClassGenDialog(wxDialog): |
class ClassGenDialog(wxDialog): |
49 |
|
|
81 |
0, wxALL, 4) |
0, wxALL, 4) |
82 |
sizer.Add(wxStaticText( |
sizer.Add(wxStaticText( |
83 |
self, -1, |
self, -1, |
84 |
_("Field Type: %s") % classifier.Classifier.type2string[self.type]), |
_("Data Type: %s") % classifier.Classifier.type2string[self.type]), |
85 |
0, wxALL, 4) |
0, wxALL, 4) |
86 |
|
|
87 |
psizer = wxBoxSizer(wxHORIZONTAL) |
psizer = wxBoxSizer(wxHORIZONTAL) |
88 |
psizer.Add(wxStaticText( |
psizer.Add(wxStaticText(self, -1, _("Generate:")), |
|
self, -1, |
|
|
_("Generate:")), |
|
89 |
0, wxALIGN_CENTER_VERTICAL, 0) |
0, wxALIGN_CENTER_VERTICAL, 0) |
90 |
|
|
91 |
self.genCombo = wxComboBox(self, |
self.genCombo = wxChoice(self, ID_CLASSGEN_GENCOMBO) |
|
ID_CLASSGEN_COMBO, |
|
|
"", style = wxCB_READONLY) |
|
92 |
psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4) |
psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4) |
93 |
EVT_COMBOBOX(self, ID_CLASSGEN_COMBO, self._OnGenTypeSelect) |
EVT_CHOICE(self, ID_CLASSGEN_GENCOMBO, self._OnGenTypeSelect) |
94 |
|
|
95 |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
96 |
|
|
99 |
self.genPanel = None |
self.genPanel = None |
100 |
|
|
101 |
panel = GenUniquePanel(self, layer, fieldName, self.type) |
panel = GenUniquePanel(self, layer, fieldName, self.type) |
102 |
self.genCombo.Append(COMBOSTR_UNIQUE) |
self.genCombo.Append(GENCOMBOSTR_UNIQUE, panel) |
|
self.genCombo.SetClientData(self.genCombo.GetCount() - 1, panel) |
|
103 |
sizer.Add(panel, 1, wxGROW | wxALL, 4) |
sizer.Add(panel, 1, wxGROW | wxALL, 4) |
104 |
|
|
105 |
self.genPanel = panel |
self.genPanel = panel |
106 |
|
|
107 |
if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE): |
if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE): |
108 |
panel = GenUniformPanel(self, layer, fieldName, self.type) |
panel = GenUniformPanel(self, layer, fieldName, self.type) |
109 |
self.genCombo.Append(COMBOSTR_UNIFORM) |
self.genCombo.Append(GENCOMBOSTR_UNIFORM, panel) |
110 |
self.genCombo.SetClientData(self.genCombo.GetCount() - 1, panel) |
sizer.Add(panel, 1, wxGROW | wxALL, 4) |
|
sizer.Add(panel, 0, wxGROW | wxALL, 4) |
|
111 |
sizer.Show(panel, False) |
sizer.Show(panel, False) |
112 |
|
|
113 |
|
self.genCombo.SetSelection(0) |
114 |
|
|
115 |
############# |
############# |
116 |
|
|
117 |
self.propPanel = None |
psizer = wxBoxSizer(wxHORIZONTAL) |
118 |
|
psizer.Add(wxStaticText(self, -1, _("Color Scheme:")), |
119 |
|
0, wxALIGN_CENTER_VERTICAL, 0) |
120 |
|
|
121 |
panel = CustomRampPanel(self, layer.ShapeType()) |
self.propCombo = wxChoice(self, ID_CLASSGEN_PROPCOMBO) |
122 |
|
psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4) |
123 |
|
EVT_CHOICE(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect) |
124 |
|
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
125 |
|
|
126 |
self.propPanel = panel |
############# |
127 |
|
|
128 |
|
self.propPanel = None |
129 |
|
panel = CustomRampPanel(self, layer.ShapeType()) |
130 |
sizer.Add(panel, 1, wxALL | wxGROW, 4) |
sizer.Add(panel, 1, wxALL | wxGROW, 4) |
131 |
|
sizer.Show(panel, False) |
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_HOT2COLD, HotToColdRamp()) |
138 |
|
self.propCombo.Append(PROPCOMBOSTR_CUSTOM, panel) |
139 |
|
|
140 |
|
self.propCombo.SetSelection(0) |
141 |
|
|
142 |
|
|
143 |
############# |
############# |
144 |
|
|
163 |
|
|
164 |
def _OnGenerate(self, event): |
def _OnGenerate(self, event): |
165 |
|
|
166 |
selIndex = self.genCombo.GetSelection() |
index = self.genCombo.GetSelection() |
167 |
|
|
168 |
sel = self.genCombo.GetString(selIndex) |
genSel = self.genCombo.GetString(index) |
169 |
genPanel = self.genCombo.GetClientData(selIndex) |
genPanel = self.genCombo.GetClientData(index) |
|
propPanel = self.propPanel |
|
170 |
|
|
171 |
if sel == COMBOSTR_UNIFORM: |
propPanel = self.propPanel |
172 |
|
|
173 |
min = genPanel.GetMin() |
if genSel in (GENCOMBOSTR_UNIFORM, GENCOMBOSTR_UNIQUE): |
|
max = genPanel.GetMax() |
|
174 |
numGroups = genPanel.GetNumGroups() |
numGroups = genPanel.GetNumGroups() |
|
sp = propPanel.GetStartProperties() |
|
|
ep = propPanel.GetEndProperties() |
|
175 |
|
|
176 |
if min is not None \ |
index = self.propCombo.GetSelection() |
|
and max is not None \ |
|
|
and numGroups is not None: |
|
177 |
|
|
178 |
self.clazz = ClassGenerator().GenUnifromDistribution( |
propSel = self.propCombo.GetString(index) |
179 |
min, max, numGroups, sp, ep, |
propPanel = self.propCombo.GetClientData(index) |
|
self.type == FIELDTYPE_INT) |
|
180 |
|
|
181 |
self.parent._SetClassification(self.clazz) |
ramp = propPanel.GetRamp() |
182 |
|
|
183 |
elif sel == COMBOSTR_UNIQUE: |
if genSel == GENCOMBOSTR_UNIFORM: |
184 |
|
|
185 |
list = genPanel.GetValueList() |
min = genPanel.GetMin() |
186 |
numGroups = genPanel.GetNumGroups() |
max = genPanel.GetMax() |
|
sp = propPanel.GetStartProperties() |
|
|
ep = propPanel.GetEndProperties() |
|
187 |
|
|
188 |
if len(list) > 0 \ |
if min is not None \ |
189 |
and numGroups is not None: |
and max is not None \ |
190 |
|
and numGroups is not None: |
191 |
|
|
192 |
self.clazz = ClassGenerator().GenSingletonsFromList( |
self.clazz = ClassGenerator().GenUnifromDistribution( |
193 |
list, numGroups, sp, ep) |
min, max, numGroups, ramp, |
194 |
|
self.type == FIELDTYPE_INT) |
195 |
|
|
196 |
self.parent._SetClassification(self.clazz) |
self.parent._SetClassification(self.clazz) |
197 |
|
|
198 |
else: |
elif genSel == GENCOMBOSTR_UNIQUE: |
199 |
pass |
|
200 |
|
list = genPanel.GetValueList() |
201 |
|
|
202 |
|
if len(list) > 0 \ |
203 |
|
and numGroups is not None: |
204 |
|
|
205 |
|
self.clazz = ClassGenerator().GenSingletonsFromList( |
206 |
|
list, numGroups, ramp) |
207 |
|
|
208 |
|
self.parent._SetClassification(self.clazz) |
209 |
|
|
210 |
def _OnCloseBtn(self, event): |
def _OnCloseBtn(self, event): |
211 |
self.Close() |
self.Close() |
226 |
self.sizer.SetSizeHints(self) |
self.sizer.SetSizeHints(self) |
227 |
self.sizer.Layout() |
self.sizer.Layout() |
228 |
|
|
229 |
|
def _OnPropTypeSelect(self, event): |
230 |
|
combo = event.GetEventObject() |
231 |
|
|
232 |
|
selIndex = combo.GetSelection() |
233 |
|
sel = combo.GetString(selIndex) |
234 |
|
|
235 |
|
if isinstance(self.propPanel, wxPanel): |
236 |
|
self.sizer.Show(self.propPanel, False) |
237 |
|
|
238 |
|
self.propPanel = combo.GetClientData(selIndex) |
239 |
|
|
240 |
|
if isinstance(self.propPanel, wxPanel): |
241 |
|
self.sizer.Show(self.propPanel, True) |
242 |
|
|
243 |
|
self.sizer.SetSizeHints(self) |
244 |
|
self.sizer.Layout() |
245 |
|
|
246 |
|
|
247 |
ID_UNIFORM_MIN = 4001 |
ID_UNIFORM_MIN = 4001 |
248 |
ID_UNIFORM_MAX = 4002 |
ID_UNIFORM_MAX = 4002 |
288 |
sizer = wxBoxSizer(wxHORIZONTAL) |
sizer = wxBoxSizer(wxHORIZONTAL) |
289 |
|
|
290 |
sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4) |
sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4) |
291 |
self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS, style=wxTE_RIGHT) |
self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS, |
292 |
|
style=wxTE_RIGHT) |
293 |
EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
294 |
EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged) |
295 |
sizer.Add(self.numGroupsCtrl, 1, wxALL, 4) |
sizer.Add(self.numGroupsCtrl, 1, wxALL, 4) |
310 |
self.numGroupsChanging = False |
self.numGroupsChanging = False |
311 |
self.steppingChanging = False |
self.steppingChanging = False |
312 |
|
|
313 |
self.numGroupsCtrl.SetRange(1, 100) |
self.numGroupsCtrl.SetRange(1, sys.maxint) |
314 |
|
|
315 |
self.numGroupsCtrl.SetValue(1) |
self.numGroupsCtrl.SetValue(1) |
316 |
self.stepCtrl.SetValue("1") |
self.stepCtrl.SetValue("1") |
360 |
self.numGroupsCtrl.Enable(on) |
self.numGroupsCtrl.Enable(on) |
361 |
self.stepCtrl.Enable(on) |
self.stepCtrl.Enable(on) |
362 |
|
|
|
if on: |
|
|
self.numGroupsCtrl.SetRange(1, abs(max - min) / 0.001) |
|
|
|
|
363 |
ngroups = self.GetNumGroups() |
ngroups = self.GetNumGroups() |
364 |
|
|
365 |
if ngroups is not None \ |
if ngroups is not None \ |
390 |
min = self.GetMin() |
min = self.GetMin() |
391 |
max = self.GetMax() |
max = self.GetMax() |
392 |
|
|
|
if ngroups >= self.numGroupsCtrl.GetMax(): |
|
|
self.numGroupsCtrl.SetRange(1, ngroups + 1) |
|
|
|
|
393 |
if ngroups is not None \ |
if ngroups is not None \ |
394 |
and min is not None \ |
and min is not None \ |
395 |
and max is not None \ |
and max is not None \ |
506 |
ID_UNIQUE_USENONE = 4005 |
ID_UNIQUE_USENONE = 4005 |
507 |
ID_UNIQUE_SORTAVAIL = 4006 |
ID_UNIQUE_SORTAVAIL = 4006 |
508 |
ID_UNIQUE_SORTUSE = 4007 |
ID_UNIQUE_SORTUSE = 4007 |
509 |
|
ID_UNIQUE_REVAVAIL = 4008 |
510 |
|
ID_UNIQUE_REVUSE = 4009 |
511 |
|
|
512 |
class GenUniquePanel(wxPanel): |
class GenUniquePanel(wxPanel): |
513 |
|
|
523 |
wxVERTICAL) |
wxVERTICAL) |
524 |
|
|
525 |
|
|
526 |
|
#bsizer = wxBoxSizer(wxVERTICAL) |
527 |
|
topSizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE, |
528 |
|
_("Retrieve From Table")), |
529 |
|
0, wxALL | wxALIGN_RIGHT, 4) |
530 |
|
|
531 |
|
EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve) |
532 |
|
|
533 |
|
#topSizer.Add(bsizer, 0, wxALL, 4) |
534 |
|
|
535 |
sizer = wxBoxSizer(wxHORIZONTAL) |
sizer = wxBoxSizer(wxHORIZONTAL) |
536 |
|
|
537 |
self.dataList = [] |
self.dataList = [] |
543 |
self.list_avail_data = [] |
self.list_avail_data = [] |
544 |
psizer.Add(self.list_avail, 1, wxGROW, 0) |
psizer.Add(self.list_avail, 1, wxGROW, 0) |
545 |
|
|
546 |
psizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort"))) |
bsizer = wxBoxSizer(wxHORIZONTAL) |
547 |
|
bsizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort"))) |
548 |
|
EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortList) |
549 |
|
|
550 |
EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortAvailList) |
bsizer.Add(wxButton(self, ID_UNIQUE_REVAVAIL, _("Reverse"))) |
551 |
|
EVT_BUTTON(self, ID_UNIQUE_REVAVAIL, self._OnReverseList) |
552 |
|
|
553 |
|
psizer.Add(bsizer, 0, wxGROW, 0) |
554 |
sizer.Add(psizer, 1, wxGROW, 0) |
sizer.Add(psizer, 1, wxGROW, 0) |
555 |
|
|
556 |
|
|
557 |
bsizer = wxBoxSizer(wxVERTICAL) |
bsizer = wxBoxSizer(wxVERTICAL) |
558 |
bsizer.Add(wxButton(self, ID_UNIQUE_USEALL, _("Use All")), |
|
559 |
|
bmp = resource.GetBitmapResource(USEALL_BMP, wxBITMAP_TYPE_XPM) |
560 |
|
bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USEALL, bmp), |
561 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
562 |
bsizer.Add(wxButton(self, ID_UNIQUE_USE, _("Use >>")), |
bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM) |
563 |
|
bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USE, bmp), |
564 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
565 |
bsizer.Add(wxButton(self, ID_UNIQUE_DONTUSE, _("<< Don't Use")), |
bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM) |
566 |
|
bsizer.Add(wxBitmapButton(self, ID_UNIQUE_DONTUSE, bmp), |
567 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
568 |
bsizer.Add(wxButton(self, ID_UNIQUE_USENONE, _("Use None")), |
bmp = resource.GetBitmapResource(USENONE_BMP, wxBITMAP_TYPE_XPM) |
569 |
|
bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USENONE, bmp), |
570 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
571 |
|
|
572 |
EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll) |
EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll) |
583 |
self.list_use_data = [] |
self.list_use_data = [] |
584 |
psizer.Add(self.list_use, 1, wxGROW, 0) |
psizer.Add(self.list_use, 1, wxGROW, 0) |
585 |
|
|
586 |
psizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort"))) |
bsizer = wxBoxSizer(wxHORIZONTAL) |
587 |
|
bsizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort"))) |
588 |
|
EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortList) |
589 |
|
|
590 |
EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortUseList) |
bsizer.Add(wxButton(self, ID_UNIQUE_REVUSE, _("Reverse"))) |
591 |
|
EVT_BUTTON(self, ID_UNIQUE_REVUSE, self._OnReverseList) |
592 |
|
|
593 |
sizer.Add(psizer, 1, wxGROW, 0) |
psizer.Add(bsizer, 0, wxGROW, 0) |
|
|
|
|
bsizer = wxBoxSizer(wxVERTICAL) |
|
|
bsizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE, |
|
|
_("Retrieve From Table")), |
|
|
0, wxGROW | wxALL, 4) |
|
594 |
|
|
595 |
EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve) |
sizer.Add(psizer, 1, wxGROW, 0) |
596 |
|
|
|
sizer.Add(bsizer, 0, wxALL, 4) |
|
597 |
|
|
598 |
topSizer.Add(sizer, 1, wxGROW, 0) |
topSizer.Add(sizer, 1, wxGROW, 0) |
599 |
|
|
614 |
list.append(self.dataList[self.list_use.GetItemData(i)]) |
list.append(self.dataList[self.list_use.GetItemData(i)]) |
615 |
return list |
return list |
616 |
|
|
617 |
def _OnSortAvailList(self, event): |
def _OnSortList(self, event): |
618 |
self.list_avail.SortItems(lambda i1, i2: |
id = event.GetId() |
619 |
cmp(self.dataList[i1], |
|
620 |
self.dataList[i2])) |
if id == ID_UNIQUE_SORTUSE: |
621 |
|
list = self.list_use |
622 |
def _OnSortUseList(self, event): |
else: |
623 |
self.list_use.SortItems(lambda i1, i2: |
list = self.list_avail |
624 |
cmp(self.dataList[i1], |
|
625 |
self.dataList[i2])) |
list.SortItems(lambda i1, i2: cmp(self.dataList[i1], |
626 |
|
self.dataList[i2])) |
627 |
|
|
628 |
|
def _OnReverseList(self, event): |
629 |
|
id = event.GetId() |
630 |
|
|
631 |
|
if id == ID_UNIQUE_REVUSE: |
632 |
|
list = self.list_use |
633 |
|
else: |
634 |
|
list = self.list_avail |
635 |
|
|
636 |
|
# |
637 |
|
# always returning 1 reverses the list |
638 |
|
# |
639 |
|
list.SortItems(lambda i1, i2: 1) |
640 |
|
|
641 |
def _OnRetrieve(self, event): |
def _OnRetrieve(self, event): |
642 |
self.list_use.DeleteAllItems() |
self.list_use.DeleteAllItems() |
659 |
self.__MoveListItem(0, self.list_avail, self.list_use) |
self.__MoveListItem(0, self.list_avail, self.list_use) |
660 |
|
|
661 |
def _OnUse(self, event): |
def _OnUse(self, event): |
|
print "_OnUse" |
|
662 |
self.__MoveSelectedItems(self.list_avail, self.list_use) |
self.__MoveSelectedItems(self.list_avail, self.list_use) |
663 |
|
|
664 |
def _OnDontUse(self, event): |
def _OnDontUse(self, event): |
|
print "_OnDontUse" |
|
665 |
self.__MoveSelectedItems(self.list_use, self.list_avail) |
self.__MoveSelectedItems(self.list_use, self.list_avail) |
666 |
|
|
667 |
def _OnUseNone(self, event): |
def _OnUseNone(self, event): |
|
print "_OnUseNone" |
|
668 |
|
|
669 |
for i in range(self.list_use.GetItemCount()): |
for i in range(self.list_use.GetItemCount()): |
670 |
self.__MoveListItem(0, self.list_use, self.list_avail) |
self.__MoveListItem(0, self.list_use, self.list_avail) |
730 |
| wxALIGN_CENTER_VERTICAL, \ |
| wxALIGN_CENTER_VERTICAL, \ |
731 |
4) |
4) |
732 |
|
|
733 |
|
bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM) |
734 |
bsizer = wxBoxSizer(wxVERTICAL) |
bsizer = wxBoxSizer(wxVERTICAL) |
735 |
bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYSTART, _("Copy >>")), |
bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYSTART, bmp), |
736 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
737 |
bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYEND, _("<< Copy")), |
bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM) |
738 |
|
bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYEND, bmp), |
739 |
0, wxGROW | wxALL, 4) |
0, wxGROW | wxALL, 4) |
740 |
|
|
741 |
topSizer.Add(bsizer, |
topSizer.Add(bsizer, |
771 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
772 |
topSizer.SetSizeHints(self) |
topSizer.SetSizeHints(self) |
773 |
|
|
774 |
def GetStartProperties(self): |
def GetRamp(self): |
775 |
return self.startPropCtrl.GetProperties() |
return CustomRamp(self.startPropCtrl.GetProperties(), |
776 |
|
self.endPropCtrl.GetProperties()) |
|
def GetEndProperties(self): |
|
|
return self.endPropCtrl.GetProperties() |
|
777 |
|
|
778 |
def _OnCopyStart(self, event): |
def _OnCopyStart(self, event): |
779 |
self.endPropCtrl.SetProperties(self.startPropCtrl.GetProperties()) |
self.endPropCtrl.SetProperties(self.startPropCtrl.GetProperties()) |
789 |
|
|
790 |
class ClassGenerator: |
class ClassGenerator: |
791 |
|
|
792 |
def GenSingletonsFromList(self, list, numGroups, prop1, prop2): |
def GenSingletonsFromList(self, list, numGroups, ramp): |
793 |
"""Generate a new classification consisting solely of singletons. |
"""Generate a new classification consisting solely of singletons. |
794 |
|
|
795 |
The resulting classification will consist of at most 'numGroups' |
The resulting classification will consist of at most 'numGroups' |
811 |
clazz = Classification() |
clazz = Classification() |
812 |
if numGroups == 0: return clazz |
if numGroups == 0: return clazz |
813 |
|
|
814 |
for value, prop in zip(list, CustomRamp(numGroups, prop1, prop2)): |
ramp.SetNumGroups(numGroups) |
815 |
|
|
816 |
|
for value, prop in zip(list, ramp): |
817 |
clazz.AppendGroup(ClassGroupSingleton(value, prop)) |
clazz.AppendGroup(ClassGroupSingleton(value, prop)) |
818 |
|
|
819 |
return clazz |
return clazz |
820 |
|
|
821 |
def GenSingletons(self, min, max, numGroups, prop1, prop2): |
def GenSingletons(self, min, max, numGroups, ramp): |
822 |
|
|
823 |
clazz = Classification() |
clazz = Classification() |
824 |
|
|
828 |
if numGroups > 0: |
if numGroups > 0: |
829 |
cur_value = min |
cur_value = min |
830 |
|
|
831 |
for prop in CustomRamp(numGroups, prop1, prop2): |
ramp.SetNumGroups(numGroups) |
832 |
|
|
833 |
|
for prop in ramp: |
834 |
clazz.AppendGroup( |
clazz.AppendGroup( |
835 |
ClassGroupSingleton( |
ClassGroupSingleton( |
836 |
Str2Num(str(cur_value)), |
Str2Num(str(cur_value)), |
840 |
return clazz |
return clazz |
841 |
|
|
842 |
def GenUnifromDistribution(self, min, max, numGroups, |
def GenUnifromDistribution(self, min, max, numGroups, |
843 |
prop1, prop2, intStep = False): |
ramp, intStep = False): |
844 |
"""Generate a classification with numGroups range groups |
"""Generate a classification with numGroups range groups |
845 |
each with the same interval. |
each with the same interval. |
846 |
|
|
853 |
clazz = Classification() |
clazz = Classification() |
854 |
if numGroups == 0: return clazz |
if numGroups == 0: return clazz |
855 |
|
|
856 |
|
ramp.SetNumGroups(numGroups) |
857 |
|
|
858 |
step = Str2Num(str((max - min) / float(numGroups))) |
step = Str2Num(str((max - min) / float(numGroups))) |
859 |
|
|
860 |
if intStep: |
if intStep: |
864 |
cur_max = cur_min + step |
cur_max = cur_min + step |
865 |
|
|
866 |
i = 0 |
i = 0 |
867 |
for prop in CustomRamp(numGroups, prop1, prop2): |
for prop in ramp: |
868 |
|
|
869 |
if i == (numGroups - 1): |
if i == (numGroups - 1): |
870 |
cur_max = max |
cur_max = max |
887 |
STEP = 1 |
STEP = 1 |
888 |
class CustomRamp: |
class CustomRamp: |
889 |
|
|
890 |
def __init__(self, num, prop1, prop2): |
def __init__(self, prop1, prop2): |
891 |
|
self.prop1 = prop1 |
892 |
|
self.prop2 = prop2 |
893 |
|
|
894 |
|
self.count = 0 |
895 |
|
|
896 |
|
def __iter__(self): |
897 |
|
return self |
898 |
|
|
899 |
|
def GetRamp(self): |
900 |
|
return self |
901 |
|
|
902 |
|
def SetNumGroups(self, num): |
903 |
|
|
904 |
|
if num <= 0: |
905 |
|
return False |
906 |
|
|
907 |
self.count = int(num) |
self.count = int(num) |
908 |
num = float(num) |
num = float(num) |
909 |
|
|
910 |
|
prop1 = self.prop1 |
911 |
|
prop2 = self.prop2 |
912 |
|
|
913 |
clr = prop1.GetLineColor() |
clr = prop1.GetLineColor() |
914 |
lineColor2 = prop2.GetLineColor() |
lineColor2 = prop2.GetLineColor() |
915 |
|
|
928 |
self.lineWidth = prop1.GetLineWidth() |
self.lineWidth = prop1.GetLineWidth() |
929 |
self.lineWidthStep = (prop2.GetLineWidth() - self.lineWidth) / num |
self.lineWidthStep = (prop2.GetLineWidth() - self.lineWidth) / num |
930 |
|
|
931 |
def __iter__(self): |
return True |
|
return self |
|
932 |
|
|
933 |
def next(self): |
def next(self): |
934 |
if self.count == 0: |
if self.count == 0: |
993 |
|
|
994 |
|
|
995 |
return (color, step) |
return (color, step) |
996 |
|
|
997 |
|
class MonochromaticRamp(CustomRamp): |
998 |
|
def __init__(self, start, end): |
999 |
|
sp = ClassGroupProperties() |
1000 |
|
sp.SetLineColor(start) |
1001 |
|
sp.SetFill(start) |
1002 |
|
|
1003 |
|
ep = ClassGroupProperties() |
1004 |
|
ep.SetLineColor(end) |
1005 |
|
ep.SetFill(end) |
1006 |
|
|
1007 |
|
CustomRamp.__init__(self, sp, ep) |
1008 |
|
|
1009 |
|
class GreyRamp(MonochromaticRamp): |
1010 |
|
def __init__(self): |
1011 |
|
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, 0)) |
1012 |
|
|
1013 |
|
class RedRamp(MonochromaticRamp): |
1014 |
|
def __init__(self): |
1015 |
|
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(.8, 0, 0)) |
1016 |
|
|
1017 |
|
class GreenRamp(MonochromaticRamp): |
1018 |
|
def __init__(self): |
1019 |
|
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, .8, 0)) |
1020 |
|
|
1021 |
|
class BlueRamp(MonochromaticRamp): |
1022 |
|
def __init__(self): |
1023 |
|
MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, .8)) |
1024 |
|
|
1025 |
|
class HotToColdRamp: |
1026 |
|
|
1027 |
|
def __iter__(self): |
1028 |
|
return self |
1029 |
|
|
1030 |
|
def GetRamp(self): |
1031 |
|
return self |
1032 |
|
|
1033 |
|
def SetNumGroups(self, num): |
1034 |
|
if num < 0: |
1035 |
|
return False |
1036 |
|
|
1037 |
|
self.num = float(num) |
1038 |
|
self.index = 0 |
1039 |
|
|
1040 |
|
return True |
1041 |
|
|
1042 |
|
def next(self): |
1043 |
|
if self.index == self.num: |
1044 |
|
raise StopIteration |
1045 |
|
|
1046 |
|
clr = [1.0, 1.0, 1.0] |
1047 |
|
|
1048 |
|
if self.index < (.25 * self.num): |
1049 |
|
clr[0] = 0 |
1050 |
|
clr[1] = 4 * self.index / self.num |
1051 |
|
elif self.index < (.5 * self.num): |
1052 |
|
clr[0] = 0 |
1053 |
|
clr[2] = 1 + 4 * (.25 * self.num - self.index) / self.num |
1054 |
|
elif self.index < (.75 * self.num): |
1055 |
|
clr[0] = 4 * (self.index - .5 * self.num) / self.num |
1056 |
|
clr[2] = 0 |
1057 |
|
else: |
1058 |
|
clr[1] = 1 + 4 * (.75 * self.num - self.index) / self.num |
1059 |
|
clr[2] = 0 |
1060 |
|
|
1061 |
|
self.index += 1 |
1062 |
|
|
1063 |
|
prop = ClassGroupProperties() |
1064 |
|
prop.SetLineColor(Color(clr[0], clr[1], clr[2])) |
1065 |
|
prop.SetFill(Color(clr[0], clr[1], clr[2])) |
1066 |
|
|
1067 |
|
return prop |
1068 |
|
|
1069 |
|
#class Colors16Ramp: |
1070 |
|
# |
1071 |
|
#def __iter__(self): |
1072 |
|
#return self |
1073 |
|
# |
1074 |
|
#def GetRamp(self): |
1075 |
|
#return self |
1076 |
|
# |
1077 |
|
#def SetNumGroups(self, num): |
1078 |
|
#if num < 0: |
1079 |
|
#return False |
1080 |
|
# |
1081 |
|
#self.index = 0 |
1082 |
|
# |
1083 |
|
#return True |
1084 |
|
|
1085 |
|
|