/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/classgen.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/classgen.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 629 by jonathan, Wed Apr 9 10:09:44 2003 UTC revision 834 by bh, Tue May 6 15:52:36 2003 UTC
# Line 5  Line 5 
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 *
# Line 19  from Thuban.Model.color import Color Line 21  from Thuban.Model.color import Color
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                                                                                    
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    
# Line 38  class ClassGenDialog(wxDialog): Line 51  class ClassGenDialog(wxDialog):
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    
# Line 64  class ClassGenDialog(wxDialog): Line 99  class ClassGenDialog(wxDialog):
99                    0, wxALL, 4)                    0, wxALL, 4)
100          sizer.Add(wxStaticText(          sizer.Add(wxStaticText(
101              self, -1,              self, -1,
102              _("Field Type: %s") % classifier.Classifier.type2string[self.type]),              _("Data Type: %s") % classifier.Classifier.type2string[self.type]),
103              0, wxALL, 4)              0, wxALL, 4)
104    
105          psizer = wxBoxSizer(wxHORIZONTAL)          psizer = wxBoxSizer(wxHORIZONTAL)
106          psizer.Add(wxStaticText(          psizer.Add(wxStaticText(self, -1, _("Generate:")),
             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_COMBO,  
                                 "", style = wxCB_READONLY)  
         psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4)  
         EVT_COMBOBOX(self, ID_CLASSGEN_COMBO, 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(COMBOSTR_UNIQUE)  
         self.genCombo.SetClientData(self.genCombo.GetCount() - 1, 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(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)  
117    
118          #############          psizer = wxBoxSizer(wxHORIZONTAL)
119            psizer.Add(wxStaticText(self, -1, _("Color Scheme:")),
120          self.propPanel = None              0, wxALIGN_CENTER_VERTICAL, 0)
121            psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4)
122          panel = CustomRampPanel(self, layer.ShapeType())          sizer.Add(psizer, 0, wxALL | wxGROW, 4)
   
         self.propPanel = panel  
   
         sizer.Add(panel, 1, wxALL | wxGROW, 4)  
123    
124          #############          sizer.Add(custom_ramp_panel, 1, wxGROW | wxALL, 4)
125            sizer.Show(custom_ramp_panel, False)
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
# Line 130  class ClassGenDialog(wxDialog): Line 152  class ClassGenDialog(wxDialog):
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.genChoice.GetSelection()
161    
162          selIndex = self.genCombo.GetSelection()          genSel = self.genChoice.GetString(index)
163            genPanel = self.genChoice.GetClientData(index)
164    
         sel = self.genCombo.GetString(selIndex)  
         genPanel = self.genCombo.GetClientData(selIndex)  
165          propPanel = self.propPanel          propPanel = self.propPanel
166    
167          if sel == COMBOSTR_UNIFORM:          if genSel in (GENCOMBOSTR_UNIFORM, GENCOMBOSTR_UNIQUE):
   
             min = genPanel.GetMin()  
             max = genPanel.GetMax()  
168              numGroups = genPanel.GetNumGroups()              numGroups = genPanel.GetNumGroups()
             sp = propPanel.GetStartProperties()  
             ep = propPanel.GetEndProperties()  
169    
170              if min is not None \              index = self.propCombo.GetSelection()
                 and max is not None \  
                 and numGroups is not None:  
171    
172                  self.clazz = ClassGenerator().GenUnifromDistribution(              propSel = self.propCombo.GetString(index)
173                               min, max, numGroups, sp, ep,              propPanel = self.propCombo.GetClientData(index)
                              self.type == FIELDTYPE_INT)  
174    
175                  self.parent._SetClassification(self.clazz)              ramp = propPanel.GetRamp()
176    
177          elif sel == COMBOSTR_UNIQUE:              if genSel == GENCOMBOSTR_UNIFORM:
178    
179              list = genPanel.GetValueList()                  min = genPanel.GetMin()
180              numGroups = genPanel.GetNumGroups()                  max = genPanel.GetMax()
             sp = propPanel.GetStartProperties()  
             ep = propPanel.GetEndProperties()  
181    
182              if len(list) > 0 \                  if min is not None \
183                  and numGroups is not None:                      and max is not None \
184                        and numGroups is not None:
185    
186                  self.clazz = ClassGenerator().GenSingletonsFromList(                      self.clazz = ClassGenerator().GenUnifromDistribution(
187                                  list, numGroups, sp, ep)                                  min, max, numGroups, ramp,
188                                    self.type == FIELDTYPE_INT)
189    
190                  self.parent._SetClassification(self.clazz)                      self.parent._SetClassification(self.clazz)
191    
192          else:              elif genSel == GENCOMBOSTR_UNIQUE:
193              pass  
194                    list = genPanel.GetValueList()
195    
196      def _OnCloseBtn(self, event):                  if len(list) > 0 \
197                        and numGroups is not None:
198    
199                        self.clazz = ClassGenerator().GenSingletonsFromList(
200                                        list, numGroups, ramp)
201    
202                        self.parent._SetClassification(self.clazz)
203    
204        def OnCancel(self, event):
205          self.Close()          self.Close()
206    
207      def _OnGenTypeSelect(self, event):      def _OnGenTypeSelect(self, event):
# Line 193  class ClassGenDialog(wxDialog): Line 220  class ClassGenDialog(wxDialog):
220          self.sizer.SetSizeHints(self)          self.sizer.SetSizeHints(self)
221          self.sizer.Layout()          self.sizer.Layout()
222    
223        def _OnPropTypeSelect(self, event):
224            combo = event.GetEventObject()
225    
226            selIndex = combo.GetSelection()
227            sel = combo.GetString(selIndex)
228    
229            if isinstance(self.propPanel, wxPanel):
230                self.sizer.Show(self.propPanel, False)
231    
232            self.propPanel = combo.GetClientData(selIndex)
233    
234            if isinstance(self.propPanel, wxPanel):
235                self.sizer.Show(self.propPanel, True)
236    
237            self.sizer.SetSizeHints(self)
238            self.sizer.Layout()
239    
240    
241  ID_UNIFORM_MIN = 4001  ID_UNIFORM_MIN = 4001
242  ID_UNIFORM_MAX = 4002  ID_UNIFORM_MAX = 4002
# Line 238  class GenUniformPanel(wxPanel): Line 282  class GenUniformPanel(wxPanel):
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)
# Line 259  class GenUniformPanel(wxPanel): Line 304  class GenUniformPanel(wxPanel):
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")
# Line 309  class GenUniformPanel(wxPanel): Line 354  class GenUniformPanel(wxPanel):
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  \
# Line 342  class GenUniformPanel(wxPanel): Line 384  class GenUniformPanel(wxPanel):
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 \
# Line 393  class GenUniformPanel(wxPanel): Line 432  class GenUniformPanel(wxPanel):
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    
# Line 437  class GenUniformPanel(wxPanel): Line 478  class GenUniformPanel(wxPanel):
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    
# Line 461  ID_UNIQUE_DONTUSE = 4004 Line 502  ID_UNIQUE_DONTUSE = 4004
502  ID_UNIQUE_USENONE = 4005  ID_UNIQUE_USENONE = 4005
503  ID_UNIQUE_SORTAVAIL = 4006  ID_UNIQUE_SORTAVAIL = 4006
504  ID_UNIQUE_SORTUSE = 4007  ID_UNIQUE_SORTUSE = 4007
505    ID_UNIQUE_REVAVAIL = 4008
506    ID_UNIQUE_REVUSE = 4009
507    
508  class GenUniquePanel(wxPanel):  class GenUniquePanel(wxPanel):
509    
# Line 476  class GenUniquePanel(wxPanel): Line 519  class GenUniquePanel(wxPanel):
519                                      wxVERTICAL)                                      wxVERTICAL)
520    
521    
522            #bsizer = wxBoxSizer(wxVERTICAL)
523            topSizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE,
524                                _("Retrieve From Table")),
525                       0, wxALL | wxALIGN_RIGHT, 4)
526    
527            EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve)
528    
529            #topSizer.Add(bsizer, 0, wxALL, 4)
530    
531          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
532    
533          self.dataList = []          self.dataList = []
# Line 487  class GenUniquePanel(wxPanel): Line 539  class GenUniquePanel(wxPanel):
539          self.list_avail_data = []          self.list_avail_data = []
540          psizer.Add(self.list_avail, 1, wxGROW, 0)          psizer.Add(self.list_avail, 1, wxGROW, 0)
541    
542          psizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort")))          bsizer = wxBoxSizer(wxHORIZONTAL)
543            bsizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort")))
544            EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortList)
545    
546          EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortAvailList)          bsizer.Add(wxButton(self, ID_UNIQUE_REVAVAIL, _("Reverse")))
547            EVT_BUTTON(self, ID_UNIQUE_REVAVAIL, self._OnReverseList)
548    
549            psizer.Add(bsizer, 0, wxGROW, 0)
550          sizer.Add(psizer, 1, wxGROW, 0)          sizer.Add(psizer, 1, wxGROW, 0)
551    
552                    
553          bsizer = wxBoxSizer(wxVERTICAL)          bsizer = wxBoxSizer(wxVERTICAL)
554          bsizer.Add(wxButton(self, ID_UNIQUE_USEALL, _("Use All")),  
555            bmp = resource.GetBitmapResource(USEALL_BMP, wxBITMAP_TYPE_XPM)
556            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USEALL, bmp),
557                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
558          bsizer.Add(wxButton(self, ID_UNIQUE_USE, _("Use >>")),          bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM)
559            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USE, bmp),
560                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
561          bsizer.Add(wxButton(self, ID_UNIQUE_DONTUSE, _("<< Don't Use")),          bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM)
562            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_DONTUSE, bmp),
563                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
564          bsizer.Add(wxButton(self, ID_UNIQUE_USENONE, _("Use None")),          bmp = resource.GetBitmapResource(USENONE_BMP, wxBITMAP_TYPE_XPM)
565            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USENONE, bmp),
566                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
567    
568          EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll)          EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll)
# Line 518  class GenUniquePanel(wxPanel): Line 579  class GenUniquePanel(wxPanel):
579          self.list_use_data = []          self.list_use_data = []
580          psizer.Add(self.list_use, 1, wxGROW, 0)          psizer.Add(self.list_use, 1, wxGROW, 0)
581    
582          psizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort")))          bsizer = wxBoxSizer(wxHORIZONTAL)
583            bsizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort")))
584            EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortList)
585    
586          EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortUseList)          bsizer.Add(wxButton(self, ID_UNIQUE_REVUSE, _("Reverse")))
587            EVT_BUTTON(self, ID_UNIQUE_REVUSE, self._OnReverseList)
         sizer.Add(psizer, 1, wxGROW, 0)  
588    
589          bsizer = wxBoxSizer(wxVERTICAL)          psizer.Add(bsizer, 0, wxGROW, 0)
         bsizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE,  
                             _("Retrieve From Table")),  
                    0, wxGROW | wxALL, 4)  
590    
591          EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve)          sizer.Add(psizer, 1, wxGROW, 0)
592    
         sizer.Add(bsizer, 0, wxALL, 4)  
593    
594          topSizer.Add(sizer, 1, wxGROW, 0)          topSizer.Add(sizer, 1, wxGROW, 0)
595    
# Line 552  class GenUniquePanel(wxPanel): Line 610  class GenUniquePanel(wxPanel):
610              list.append(self.dataList[self.list_use.GetItemData(i)])              list.append(self.dataList[self.list_use.GetItemData(i)])
611          return list          return list
612    
613      def _OnSortAvailList(self, event):      def _OnSortList(self, event):
614          self.list_avail.SortItems(lambda i1, i2:          id = event.GetId()
615                                      cmp(self.dataList[i1],  
616                                          self.dataList[i2]))          if id == ID_UNIQUE_SORTUSE:
617                list = self.list_use
618      def _OnSortUseList(self, event):          else:
619          self.list_use.SortItems(lambda i1, i2:              list = self.list_avail
620                                      cmp(self.dataList[i1],  
621                                          self.dataList[i2]))          list.SortItems(lambda i1, i2: cmp(self.dataList[i1],
622                                              self.dataList[i2]))
623    
624        def _OnReverseList(self, event):
625            id = event.GetId()
626    
627            if id == ID_UNIQUE_REVUSE:
628                list = self.list_use
629            else:
630                list = self.list_avail
631    
632            #
633            # always returning 1 reverses the list
634            #
635            list.SortItems(lambda i1, i2: 1)
636    
637      def _OnRetrieve(self, event):      def _OnRetrieve(self, event):
638          self.list_use.DeleteAllItems()          self.list_use.DeleteAllItems()
# Line 568  class GenUniquePanel(wxPanel): Line 640  class GenUniquePanel(wxPanel):
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)
# Line 583  class GenUniquePanel(wxPanel): Line 655  class GenUniquePanel(wxPanel):
655              self.__MoveListItem(0, self.list_avail, self.list_use)              self.__MoveListItem(0, self.list_avail, self.list_use)
656    
657      def _OnUse(self, event):      def _OnUse(self, event):
         print "_OnUse"  
658          self.__MoveSelectedItems(self.list_avail, self.list_use)          self.__MoveSelectedItems(self.list_avail, self.list_use)
659    
660      def _OnDontUse(self, event):      def _OnDontUse(self, event):
         print "_OnDontUse"  
661          self.__MoveSelectedItems(self.list_use, self.list_avail)          self.__MoveSelectedItems(self.list_use, self.list_avail)
662    
663      def _OnUseNone(self, event):      def _OnUseNone(self, event):
         print "_OnUseNone"  
664    
665          for i in range(self.list_use.GetItemCount()):          for i in range(self.list_use.GetItemCount()):
666              self.__MoveListItem(0, self.list_use, self.list_avail)              self.__MoveListItem(0, self.list_use, self.list_avail)
# Line 657  class CustomRampPanel(wxPanel): Line 726  class CustomRampPanel(wxPanel):
726                        | wxALIGN_CENTER_VERTICAL, \                        | wxALIGN_CENTER_VERTICAL, \
727                     4)                     4)
728    
729            bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM)
730          bsizer = wxBoxSizer(wxVERTICAL)          bsizer = wxBoxSizer(wxVERTICAL)
731          bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYSTART, _("Copy >>")),          bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYSTART, bmp),
732                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
733          bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYEND, _("<< Copy")),          bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM)
734            bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYEND, bmp),
735                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
736    
737          topSizer.Add(bsizer,          topSizer.Add(bsizer,
# Line 696  class CustomRampPanel(wxPanel): Line 767  class CustomRampPanel(wxPanel):
767          self.SetAutoLayout(True)          self.SetAutoLayout(True)
768          topSizer.SetSizeHints(self)          topSizer.SetSizeHints(self)
769    
770      def GetStartProperties(self):      def GetRamp(self):
771          return self.startPropCtrl.GetProperties()          return CustomRamp(self.startPropCtrl.GetProperties(),
772                              self.endPropCtrl.GetProperties())
     def GetEndProperties(self):  
         return self.endPropCtrl.GetProperties()  
773    
774      def _OnCopyStart(self, event):      def _OnCopyStart(self, event):
775          self.endPropCtrl.SetProperties(self.startPropCtrl.GetProperties())          self.endPropCtrl.SetProperties(self.startPropCtrl.GetProperties())
# Line 716  class CustomRampPanel(wxPanel): Line 785  class CustomRampPanel(wxPanel):
785    
786  class ClassGenerator:  class ClassGenerator:
787    
788      def GenSingletonsFromList(self, list, numGroups, prop1, prop2):      def GenSingletonsFromList(self, list, numGroups, ramp):
789          """Generate a new classification consisting solely of singletons.          """Generate a new classification consisting solely of singletons.
790    
791          The resulting classification will consist of at most 'numGroups'          The resulting classification will consist of at most 'numGroups'
# Line 738  class ClassGenerator: Line 807  class ClassGenerator:
807          clazz = Classification()          clazz = Classification()
808          if numGroups == 0: return clazz          if numGroups == 0: return clazz
809    
810          for value, prop in zip(list, CustomRamp(numGroups, prop1, prop2)):          ramp.SetNumGroups(numGroups)
811    
812            for value, prop in zip(list, ramp):
813              clazz.AppendGroup(ClassGroupSingleton(value, prop))              clazz.AppendGroup(ClassGroupSingleton(value, prop))
814    
815          return clazz          return clazz
816    
817      def GenSingletons(self, min, max, numGroups, prop1, prop2):      def GenSingletons(self, min, max, numGroups, ramp):
818    
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              for prop in CustomRamp(numGroups, prop1, prop2):              ramp.SetNumGroups(numGroups)
829                  clazz.AppendGroup(  
830                      ClassGroupSingleton(              for prop in ramp:
831                          Str2Num(str(cur_value)),                  clazz.AppendGroup(ClassGroupSingleton(cur_value), prop)
                         prop))  
832                  cur_value += step                  cur_value += step
833    
834          return clazz          return clazz
835    
836      def GenUnifromDistribution(self, min, max, numGroups,      def GenUnifromDistribution(self, min, max, numGroups,
837                                 prop1, prop2, intStep = False):                                 ramp, intStep = False):
838          """Generate a classification with numGroups range groups          """Generate a classification with numGroups range groups
839          each with the same interval.          each with the same interval.
840    
# Line 776  class ClassGenerator: Line 847  class ClassGenerator:
847          clazz = Classification()          clazz = Classification()
848          if numGroups == 0: return clazz          if numGroups == 0: return clazz
849    
850          step = Str2Num(str((max - min) / float(numGroups)))          ramp.SetNumGroups(numGroups)
851    
852            step = (max - min) / float(numGroups)
853    
854          if intStep:          if intStep:
855              step = int(step)              step = int(step)
# Line 785  class ClassGenerator: Line 858  class ClassGenerator:
858          cur_max = cur_min + step          cur_max = cur_min + step
859    
860          i = 0          i = 0
861          for prop in CustomRamp(numGroups, prop1, prop2):          for prop in ramp:
862    
863              if i == (numGroups - 1):              if i == (numGroups - 1):
864                  cur_max = max                  cur_max = max
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
# Line 808  CLR  = 0 Line 877  CLR  = 0
877  STEP = 1  STEP = 1
878  class CustomRamp:  class CustomRamp:
879    
880      def __init__(self, num, prop1, prop2):      def __init__(self, prop1, prop2):
881            self.prop1 = prop1
882            self.prop2 = prop2
883    
884            self.count = 0
885    
886        def __iter__(self):
887            return self
888    
889        def GetRamp(self):
890            return self
891    
892        def SetNumGroups(self, num):
893    
894            if num <= 0:
895                return False
896    
897          self.count = int(num)          self.count = int(num)
898          num = float(num)          num = float(num)
899    
900            prop1 = self.prop1
901            prop2 = self.prop2
902    
903          clr = prop1.GetLineColor()          clr = prop1.GetLineColor()
904          lineColor2 = prop2.GetLineColor()          lineColor2 = prop2.GetLineColor()
905                    
# Line 831  class CustomRamp: Line 918  class CustomRamp:
918          self.lineWidth = prop1.GetLineWidth()          self.lineWidth = prop1.GetLineWidth()
919          self.lineWidthStep = (prop2.GetLineWidth() - self.lineWidth) / num          self.lineWidthStep = (prop2.GetLineWidth() - self.lineWidth) / num
920    
921      def __iter__(self):          return True
         return self  
922    
923      def next(self):      def next(self):
924          if self.count == 0:          if self.count == 0:
# Line 897  class CustomRamp: Line 983  class CustomRamp:
983    
984    
985          return (color, step)          return (color, step)
986    
987    class MonochromaticRamp(CustomRamp):
988        def __init__(self, start, end):
989            sp = ClassGroupProperties()
990            sp.SetLineColor(start)
991            sp.SetFill(start)
992    
993            ep = ClassGroupProperties()
994            ep.SetLineColor(end)
995            ep.SetFill(end)
996    
997            CustomRamp.__init__(self, sp, ep)
998    
999    class GreyRamp(MonochromaticRamp):
1000        def __init__(self):
1001            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, 0))
1002    
1003    class RedRamp(MonochromaticRamp):
1004        def __init__(self):
1005            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(.8, 0, 0))
1006    
1007    class GreenRamp(MonochromaticRamp):
1008        def __init__(self):
1009            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, .8, 0))
1010    
1011    class BlueRamp(MonochromaticRamp):
1012        def __init__(self):
1013            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, .8))
1014    
1015    class HotToColdRamp:
1016    
1017        def __iter__(self):
1018            return self
1019            
1020        def GetRamp(self):
1021            return self
1022    
1023        def SetNumGroups(self, num):
1024            if num < 0:
1025                return False
1026    
1027            self.num = float(num)
1028            self.index = 0
1029    
1030            return True
1031    
1032        def next(self):
1033            if self.index == self.num:
1034                raise StopIteration
1035    
1036            clr = [1.0, 1.0, 1.0]
1037    
1038            if self.index < (.25 * self.num):
1039                clr[0] = 0
1040                clr[1] = 4 * self.index / self.num
1041            elif self.index < (.5 * self.num):
1042                clr[0] = 0
1043                clr[2] = 1 + 4 * (.25 * self.num - self.index) / self.num
1044            elif self.index < (.75 * self.num):
1045                clr[0] = 4 * (self.index - .5 * self.num) / self.num
1046                clr[2] = 0
1047            else:
1048                clr[1] = 1 + 4 * (.75 * self.num - self.index) / self.num
1049                clr[2] = 0
1050    
1051            self.index += 1
1052    
1053            prop = ClassGroupProperties()
1054            prop.SetLineColor(Color(clr[0], clr[1], clr[2]))
1055            prop.SetFill(Color(clr[0], clr[1], clr[2]))
1056    
1057            return prop
1058    
1059    #class Colors16Ramp:
1060    #
1061        #def __iter__(self):
1062            #return self
1063    #
1064        #def GetRamp(self):
1065            #return self
1066    #
1067        #def SetNumGroups(self, num):
1068            #if num < 0:
1069                #return False
1070    #
1071            #self.index = 0
1072    #
1073            #return True
1074    
1075        

Legend:
Removed from v.629  
changed lines
  Added in v.834

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26