/[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 781 by jonathan, Tue Apr 29 16:53:38 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_GEN = 4001
27  ID_CLASSGEN_CLOSE = 4002  ID_CLASSGEN_CLOSE = 4002
28  ID_CLASSGEN_COMBO = 4007  ID_CLASSGEN_GENCOMBO = 4007
29    ID_CLASSGEN_PROPCOMBO = 4008
30    
31  COMBOSTR_UNIFORM = _("Uniform Distribution")  USEALL_BMP  = "group_use_all"
32  COMBOSTR_UNIQUE = _("Unique Values")  USE_BMP     = "group_use"
33    USENOT_BMP  = "group_use_not"
34    USENONE_BMP = "group_use_none"
35    
36    GENCOMBOSTR_UNIFORM = _("Uniform Distribution")
37    GENCOMBOSTR_UNIQUE = _("Unique Values")
38    
39    PROPCOMBOSTR_CUSTOM     = _("Custom Ramp")
40    PROPCOMBOSTR_GREY       = _("Grey Ramp")
41    PROPCOMBOSTR_RED        = _("Red Ramp")
42    PROPCOMBOSTR_GREEN      = _("Green Ramp")
43    PROPCOMBOSTR_BLUE       = _("Blue Ramp")
44    PROPCOMBOSTR_HOT2COLD   = _("Hot-to-Cold Ramp")
45    
46  class ClassGenDialog(wxDialog):  class ClassGenDialog(wxDialog):
47                                                                                                                                                                    
# Line 64  class ClassGenDialog(wxDialog): Line 79  class ClassGenDialog(wxDialog):
79                    0, wxALL, 4)                    0, wxALL, 4)
80          sizer.Add(wxStaticText(          sizer.Add(wxStaticText(
81              self, -1,              self, -1,
82              _("Field Type: %s") % classifier.Classifier.type2string[self.type]),              _("Data Type: %s") % classifier.Classifier.type2string[self.type]),
83              0, wxALL, 4)              0, wxALL, 4)
84    
85          psizer = wxBoxSizer(wxHORIZONTAL)          psizer = wxBoxSizer(wxHORIZONTAL)
86          psizer.Add(wxStaticText(          psizer.Add(wxStaticText(self, -1, _("Generate:")),
             self, -1,  
             _("Generate:")),  
87              0, wxALIGN_CENTER_VERTICAL, 0)              0, wxALIGN_CENTER_VERTICAL, 0)
88    
89          self.genCombo = wxComboBox(self,          self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO)
90                                  ID_CLASSGEN_COMBO,          psizer.Add(self.genChoice, 1, wxALL | wxGROW, 4)
91                                  "", style = wxCB_READONLY)          EVT_CHOICE(self, ID_CLASSGEN_GENCOMBO, self._OnGenTypeSelect)
         psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4)  
         EVT_COMBOBOX(self, ID_CLASSGEN_COMBO, self._OnGenTypeSelect)  
92    
93          sizer.Add(psizer, 0, wxALL | wxGROW, 4)          sizer.Add(psizer, 0, wxALL | wxGROW, 4)
94    
# Line 86  class ClassGenDialog(wxDialog): Line 97  class ClassGenDialog(wxDialog):
97          self.genPanel = None          self.genPanel = None
98    
99          panel = GenUniquePanel(self, layer, fieldName, self.type)          panel = GenUniquePanel(self, layer, fieldName, self.type)
100          self.genCombo.Append(COMBOSTR_UNIQUE)          self.genChoice.Append(GENCOMBOSTR_UNIQUE, panel)
         self.genCombo.SetClientData(self.genCombo.GetCount() - 1, panel)  
101          sizer.Add(panel, 1, wxGROW | wxALL, 4)          sizer.Add(panel, 1, wxGROW | wxALL, 4)
102    
103          self.genPanel = panel          self.genPanel = panel
104    
105          if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):          if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):
106              panel = GenUniformPanel(self, layer, fieldName, self.type)              panel = GenUniformPanel(self, layer, fieldName, self.type)
107              self.genCombo.Append(COMBOSTR_UNIFORM)              self.genChoice.Append(GENCOMBOSTR_UNIFORM, panel)
108              self.genCombo.SetClientData(self.genCombo.GetCount() - 1, panel)              sizer.Add(panel, 1, wxGROW | wxALL, 4)
             sizer.Add(panel, 0, wxGROW | wxALL, 4)  
109              sizer.Show(panel, False)              sizer.Show(panel, False)
110    
111            self.genChoice.SetSelection(0)
112    
113          #############          #############
114    
115          self.propPanel = None          psizer = wxBoxSizer(wxHORIZONTAL)
116            psizer.Add(wxStaticText(self, -1, _("Color Scheme:")),
117                0, wxALIGN_CENTER_VERTICAL, 0)
118    
119          panel = CustomRampPanel(self, layer.ShapeType())          self.propCombo = wxChoice(self, ID_CLASSGEN_PROPCOMBO)
120            psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4)
121            EVT_CHOICE(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect)
122            sizer.Add(psizer, 0, wxALL | wxGROW, 4)
123    
124          self.propPanel = panel          #############
125    
126            self.propPanel = None
127            panel = CustomRampPanel(self, layer.ShapeType())
128          sizer.Add(panel, 1, wxALL | wxGROW, 4)          sizer.Add(panel, 1, wxALL | wxGROW, 4)
129            sizer.Show(panel, False)
130    
131            self.propCombo.Append(PROPCOMBOSTR_GREY,  GreyRamp())
132            self.propCombo.Append(PROPCOMBOSTR_RED,   RedRamp())
133            self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp())
134            self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp())
135            self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())
136            self.propCombo.Append(PROPCOMBOSTR_CUSTOM, panel)
137    
138            self.propCombo.SetSelection(0)
139    
140    
141          #############          #############
142    
# Line 132  class ClassGenDialog(wxDialog): Line 161  class ClassGenDialog(wxDialog):
161    
162      def _OnGenerate(self, event):      def _OnGenerate(self, event):
163    
164          selIndex = self.genCombo.GetSelection()          index = self.genChoice.GetSelection()
165    
166          sel = self.genCombo.GetString(selIndex)          genSel = self.genChoice.GetString(index)
167          genPanel = self.genCombo.GetClientData(selIndex)          genPanel = self.genChoice.GetClientData(index)
         propPanel = self.propPanel  
168    
169          if sel == COMBOSTR_UNIFORM:          propPanel = self.propPanel
170    
171              min = genPanel.GetMin()          if genSel in (GENCOMBOSTR_UNIFORM, GENCOMBOSTR_UNIQUE):
             max = genPanel.GetMax()  
172              numGroups = genPanel.GetNumGroups()              numGroups = genPanel.GetNumGroups()
             sp = propPanel.GetStartProperties()  
             ep = propPanel.GetEndProperties()  
173    
174              if min is not None \              index = self.propCombo.GetSelection()
                 and max is not None \  
                 and numGroups is not None:  
175    
176                  self.clazz = ClassGenerator().GenUnifromDistribution(              propSel = self.propCombo.GetString(index)
177                               min, max, numGroups, sp, ep,              propPanel = self.propCombo.GetClientData(index)
                              self.type == FIELDTYPE_INT)  
178    
179                  self.parent._SetClassification(self.clazz)              ramp = propPanel.GetRamp()
180    
181          elif sel == COMBOSTR_UNIQUE:              if genSel == GENCOMBOSTR_UNIFORM:
182    
183              list = genPanel.GetValueList()                  min = genPanel.GetMin()
184              numGroups = genPanel.GetNumGroups()                  max = genPanel.GetMax()
             sp = propPanel.GetStartProperties()  
             ep = propPanel.GetEndProperties()  
185    
186              if len(list) > 0 \                  if min is not None \
187                  and numGroups is not None:                      and max is not None \
188                        and numGroups is not None:
189    
190                  self.clazz = ClassGenerator().GenSingletonsFromList(                      self.clazz = ClassGenerator().GenUnifromDistribution(
191                                  list, numGroups, sp, ep)                                  min, max, numGroups, ramp,
192                                    self.type == FIELDTYPE_INT)
193    
194                  self.parent._SetClassification(self.clazz)                      self.parent._SetClassification(self.clazz)
195    
196          else:              elif genSel == GENCOMBOSTR_UNIQUE:
197              pass  
198                    list = genPanel.GetValueList()
199    
200                    if len(list) > 0 \
201                        and numGroups is not None:
202    
203                        self.clazz = ClassGenerator().GenSingletonsFromList(
204                                        list, numGroups, ramp)
205    
206                        self.parent._SetClassification(self.clazz)
207    
208      def _OnCloseBtn(self, event):      def _OnCloseBtn(self, event):
209          self.Close()          self.Close()
# Line 193  class ClassGenDialog(wxDialog): Line 224  class ClassGenDialog(wxDialog):
224          self.sizer.SetSizeHints(self)          self.sizer.SetSizeHints(self)
225          self.sizer.Layout()          self.sizer.Layout()
226    
227        def _OnPropTypeSelect(self, event):
228            combo = event.GetEventObject()
229    
230            selIndex = combo.GetSelection()
231            sel = combo.GetString(selIndex)
232    
233            if isinstance(self.propPanel, wxPanel):
234                self.sizer.Show(self.propPanel, False)
235    
236            self.propPanel = combo.GetClientData(selIndex)
237    
238            if isinstance(self.propPanel, wxPanel):
239                self.sizer.Show(self.propPanel, True)
240    
241            self.sizer.SetSizeHints(self)
242            self.sizer.Layout()
243    
244    
245  ID_UNIFORM_MIN = 4001  ID_UNIFORM_MIN = 4001
246  ID_UNIFORM_MAX = 4002  ID_UNIFORM_MAX = 4002
# Line 238  class GenUniformPanel(wxPanel): Line 286  class GenUniformPanel(wxPanel):
286          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
287    
288          sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4)          sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4)
289          self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS, style=wxTE_RIGHT)          self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS,
290                                            style=wxTE_RIGHT)
291          EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)          EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)
292          EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)          EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)
293          sizer.Add(self.numGroupsCtrl, 1, wxALL, 4)          sizer.Add(self.numGroupsCtrl, 1, wxALL, 4)
# Line 259  class GenUniformPanel(wxPanel): Line 308  class GenUniformPanel(wxPanel):
308          self.numGroupsChanging = False          self.numGroupsChanging = False
309          self.steppingChanging = False          self.steppingChanging = False
310    
311          self.numGroupsCtrl.SetRange(1, 100)          self.numGroupsCtrl.SetRange(1, sys.maxint)
312    
313          self.numGroupsCtrl.SetValue(1)          self.numGroupsCtrl.SetValue(1)
314          self.stepCtrl.SetValue("1")          self.stepCtrl.SetValue("1")
# Line 309  class GenUniformPanel(wxPanel): Line 358  class GenUniformPanel(wxPanel):
358          self.numGroupsCtrl.Enable(on)          self.numGroupsCtrl.Enable(on)
359          self.stepCtrl.Enable(on)          self.stepCtrl.Enable(on)
360    
         if on:  
             self.numGroupsCtrl.SetRange(1, abs(max - min) / 0.001)  
   
361          ngroups = self.GetNumGroups()          ngroups = self.GetNumGroups()
362    
363          if ngroups is not None  \          if ngroups is not None  \
# Line 342  class GenUniformPanel(wxPanel): Line 388  class GenUniformPanel(wxPanel):
388          min = self.GetMin()          min = self.GetMin()
389          max = self.GetMax()          max = self.GetMax()
390    
         if ngroups >= self.numGroupsCtrl.GetMax():  
             self.numGroupsCtrl.SetRange(1, ngroups + 1)  
   
391          if ngroups is not None  \          if ngroups is not None  \
392              and min is not None \              and min is not None \
393              and max is not None \              and max is not None \
# Line 437  class GenUniformPanel(wxPanel): Line 480  class GenUniformPanel(wxPanel):
480          return valid          return valid
481    
482      def __CalcStepping(self, min, max, ngroups):      def __CalcStepping(self, min, max, ngroups):
483          step = Str2Num(str((max - min) / float(ngroups)))          step = (max - min) / float(ngroups)
484          if self.fieldType == FIELDTYPE_INT:          if self.fieldType == FIELDTYPE_INT:
485              step = int(step)              step = int(step)
486    
# Line 461  ID_UNIQUE_DONTUSE = 4004 Line 504  ID_UNIQUE_DONTUSE = 4004
504  ID_UNIQUE_USENONE = 4005  ID_UNIQUE_USENONE = 4005
505  ID_UNIQUE_SORTAVAIL = 4006  ID_UNIQUE_SORTAVAIL = 4006
506  ID_UNIQUE_SORTUSE = 4007  ID_UNIQUE_SORTUSE = 4007
507    ID_UNIQUE_REVAVAIL = 4008
508    ID_UNIQUE_REVUSE = 4009
509    
510  class GenUniquePanel(wxPanel):  class GenUniquePanel(wxPanel):
511    
# Line 476  class GenUniquePanel(wxPanel): Line 521  class GenUniquePanel(wxPanel):
521                                      wxVERTICAL)                                      wxVERTICAL)
522    
523    
524            #bsizer = wxBoxSizer(wxVERTICAL)
525            topSizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE,
526                                _("Retrieve From Table")),
527                       0, wxALL | wxALIGN_RIGHT, 4)
528    
529            EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve)
530    
531            #topSizer.Add(bsizer, 0, wxALL, 4)
532    
533          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
534    
535          self.dataList = []          self.dataList = []
# Line 487  class GenUniquePanel(wxPanel): Line 541  class GenUniquePanel(wxPanel):
541          self.list_avail_data = []          self.list_avail_data = []
542          psizer.Add(self.list_avail, 1, wxGROW, 0)          psizer.Add(self.list_avail, 1, wxGROW, 0)
543    
544          psizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort")))          bsizer = wxBoxSizer(wxHORIZONTAL)
545            bsizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort")))
546            EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortList)
547    
548          EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortAvailList)          bsizer.Add(wxButton(self, ID_UNIQUE_REVAVAIL, _("Reverse")))
549            EVT_BUTTON(self, ID_UNIQUE_REVAVAIL, self._OnReverseList)
550    
551            psizer.Add(bsizer, 0, wxGROW, 0)
552          sizer.Add(psizer, 1, wxGROW, 0)          sizer.Add(psizer, 1, wxGROW, 0)
553    
554                    
555          bsizer = wxBoxSizer(wxVERTICAL)          bsizer = wxBoxSizer(wxVERTICAL)
556          bsizer.Add(wxButton(self, ID_UNIQUE_USEALL, _("Use All")),  
557            bmp = resource.GetBitmapResource(USEALL_BMP, wxBITMAP_TYPE_XPM)
558            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USEALL, bmp),
559                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
560          bsizer.Add(wxButton(self, ID_UNIQUE_USE, _("Use >>")),          bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM)
561            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USE, bmp),
562                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
563          bsizer.Add(wxButton(self, ID_UNIQUE_DONTUSE, _("<< Don't Use")),          bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM)
564            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_DONTUSE, bmp),
565                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
566          bsizer.Add(wxButton(self, ID_UNIQUE_USENONE, _("Use None")),          bmp = resource.GetBitmapResource(USENONE_BMP, wxBITMAP_TYPE_XPM)
567            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USENONE, bmp),
568                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
569    
570          EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll)          EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll)
# Line 518  class GenUniquePanel(wxPanel): Line 581  class GenUniquePanel(wxPanel):
581          self.list_use_data = []          self.list_use_data = []
582          psizer.Add(self.list_use, 1, wxGROW, 0)          psizer.Add(self.list_use, 1, wxGROW, 0)
583    
584          psizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort")))          bsizer = wxBoxSizer(wxHORIZONTAL)
585            bsizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort")))
586          EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortUseList)          EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortList)
587    
588          sizer.Add(psizer, 1, wxGROW, 0)          bsizer.Add(wxButton(self, ID_UNIQUE_REVUSE, _("Reverse")))
589            EVT_BUTTON(self, ID_UNIQUE_REVUSE, self._OnReverseList)
590    
591          bsizer = wxBoxSizer(wxVERTICAL)          psizer.Add(bsizer, 0, wxGROW, 0)
         bsizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE,  
                             _("Retrieve From Table")),  
                    0, wxGROW | wxALL, 4)  
592    
593          EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve)          sizer.Add(psizer, 1, wxGROW, 0)
594    
         sizer.Add(bsizer, 0, wxALL, 4)  
595    
596          topSizer.Add(sizer, 1, wxGROW, 0)          topSizer.Add(sizer, 1, wxGROW, 0)
597    
# Line 552  class GenUniquePanel(wxPanel): Line 612  class GenUniquePanel(wxPanel):
612              list.append(self.dataList[self.list_use.GetItemData(i)])              list.append(self.dataList[self.list_use.GetItemData(i)])
613          return list          return list
614    
615      def _OnSortAvailList(self, event):      def _OnSortList(self, event):
616          self.list_avail.SortItems(lambda i1, i2:          id = event.GetId()
617                                      cmp(self.dataList[i1],  
618                                          self.dataList[i2]))          if id == ID_UNIQUE_SORTUSE:
619                list = self.list_use
620      def _OnSortUseList(self, event):          else:
621          self.list_use.SortItems(lambda i1, i2:              list = self.list_avail
622                                      cmp(self.dataList[i1],  
623                                          self.dataList[i2]))          list.SortItems(lambda i1, i2: cmp(self.dataList[i1],
624                                              self.dataList[i2]))
625    
626        def _OnReverseList(self, event):
627            id = event.GetId()
628    
629            if id == ID_UNIQUE_REVUSE:
630                list = self.list_use
631            else:
632                list = self.list_avail
633    
634            #
635            # always returning 1 reverses the list
636            #
637            list.SortItems(lambda i1, i2: 1)
638    
639      def _OnRetrieve(self, event):      def _OnRetrieve(self, event):
640          self.list_use.DeleteAllItems()          self.list_use.DeleteAllItems()
# Line 583  class GenUniquePanel(wxPanel): Line 657  class GenUniquePanel(wxPanel):
657              self.__MoveListItem(0, self.list_avail, self.list_use)              self.__MoveListItem(0, self.list_avail, self.list_use)
658    
659      def _OnUse(self, event):      def _OnUse(self, event):
         print "_OnUse"  
660          self.__MoveSelectedItems(self.list_avail, self.list_use)          self.__MoveSelectedItems(self.list_avail, self.list_use)
661    
662      def _OnDontUse(self, event):      def _OnDontUse(self, event):
         print "_OnDontUse"  
663          self.__MoveSelectedItems(self.list_use, self.list_avail)          self.__MoveSelectedItems(self.list_use, self.list_avail)
664    
665      def _OnUseNone(self, event):      def _OnUseNone(self, event):
         print "_OnUseNone"  
666    
667          for i in range(self.list_use.GetItemCount()):          for i in range(self.list_use.GetItemCount()):
668              self.__MoveListItem(0, self.list_use, self.list_avail)              self.__MoveListItem(0, self.list_use, self.list_avail)
# Line 657  class CustomRampPanel(wxPanel): Line 728  class CustomRampPanel(wxPanel):
728                        | wxALIGN_CENTER_VERTICAL, \                        | wxALIGN_CENTER_VERTICAL, \
729                     4)                     4)
730    
731            bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM)
732          bsizer = wxBoxSizer(wxVERTICAL)          bsizer = wxBoxSizer(wxVERTICAL)
733          bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYSTART, _("Copy >>")),          bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYSTART, bmp),
734                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
735          bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYEND, _("<< Copy")),          bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM)
736            bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYEND, bmp),
737                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
738    
739          topSizer.Add(bsizer,          topSizer.Add(bsizer,
# Line 696  class CustomRampPanel(wxPanel): Line 769  class CustomRampPanel(wxPanel):
769          self.SetAutoLayout(True)          self.SetAutoLayout(True)
770          topSizer.SetSizeHints(self)          topSizer.SetSizeHints(self)
771    
772      def GetStartProperties(self):      def GetRamp(self):
773          return self.startPropCtrl.GetProperties()          return CustomRamp(self.startPropCtrl.GetProperties(),
774                              self.endPropCtrl.GetProperties())
     def GetEndProperties(self):  
         return self.endPropCtrl.GetProperties()  
775    
776      def _OnCopyStart(self, event):      def _OnCopyStart(self, event):
777          self.endPropCtrl.SetProperties(self.startPropCtrl.GetProperties())          self.endPropCtrl.SetProperties(self.startPropCtrl.GetProperties())
# Line 716  class CustomRampPanel(wxPanel): Line 787  class CustomRampPanel(wxPanel):
787    
788  class ClassGenerator:  class ClassGenerator:
789    
790      def GenSingletonsFromList(self, list, numGroups, prop1, prop2):      def GenSingletonsFromList(self, list, numGroups, ramp):
791          """Generate a new classification consisting solely of singletons.          """Generate a new classification consisting solely of singletons.
792    
793          The resulting classification will consist of at most 'numGroups'          The resulting classification will consist of at most 'numGroups'
# Line 738  class ClassGenerator: Line 809  class ClassGenerator:
809          clazz = Classification()          clazz = Classification()
810          if numGroups == 0: return clazz          if numGroups == 0: return clazz
811    
812          for value, prop in zip(list, CustomRamp(numGroups, prop1, prop2)):          ramp.SetNumGroups(numGroups)
813    
814            for value, prop in zip(list, ramp):
815              clazz.AppendGroup(ClassGroupSingleton(value, prop))              clazz.AppendGroup(ClassGroupSingleton(value, prop))
816    
817          return clazz          return clazz
818    
819      def GenSingletons(self, min, max, numGroups, prop1, prop2):      def GenSingletons(self, min, max, numGroups, ramp):
820    
821          clazz = Classification()          clazz = Classification()
822    
823          #step = int((max - min) / float(numGroups))          #step = int((max - min) / float(numGroups))
         step = int(Str2Num(str((max - min + 1) / float(numGroups))))  
824    
825          if numGroups > 0:          if numGroups > 0:
826    
827                step = int((max - min + 1) / float(numGroups))
828              cur_value = min              cur_value = min
829    
830              for prop in CustomRamp(numGroups, prop1, prop2):              ramp.SetNumGroups(numGroups)
831                  clazz.AppendGroup(  
832                      ClassGroupSingleton(              for prop in ramp:
833                          Str2Num(str(cur_value)),                  clazz.AppendGroup(ClassGroupSingleton(cur_value), prop)
                         prop))  
834                  cur_value += step                  cur_value += step
835    
836          return clazz          return clazz
837    
838      def GenUnifromDistribution(self, min, max, numGroups,      def GenUnifromDistribution(self, min, max, numGroups,
839                                 prop1, prop2, intStep = False):                                 ramp, intStep = False):
840          """Generate a classification with numGroups range groups          """Generate a classification with numGroups range groups
841          each with the same interval.          each with the same interval.
842    
# Line 776  class ClassGenerator: Line 849  class ClassGenerator:
849          clazz = Classification()          clazz = Classification()
850          if numGroups == 0: return clazz          if numGroups == 0: return clazz
851    
852          step = Str2Num(str((max - min) / float(numGroups)))          ramp.SetNumGroups(numGroups)
853    
854            step = (max - min) / float(numGroups)
855    
856          if intStep:          if intStep:
857              step = int(step)              step = int(step)
# Line 785  class ClassGenerator: Line 860  class ClassGenerator:
860          cur_max = cur_min + step          cur_max = cur_min + step
861    
862          i = 0          i = 0
863          for prop in CustomRamp(numGroups, prop1, prop2):          for prop in ramp:
864    
865              if i == (numGroups - 1):              if i == (numGroups - 1):
866                  cur_max = max                  cur_max = max
867    
868              # this check guards against rounding issues              # this check guards against rounding issues
869              if cur_min != cur_max:              if cur_min != cur_max:
870                  clazz.AppendGroup(                  clazz.AppendGroup(ClassGroupRange(cur_min, cur_max, prop))
                     ClassGroupRange(  
                         Str2Num(str(cur_min)),  
                         Str2Num(str(cur_max)),  
                         prop))  
871    
872              cur_min = cur_max              cur_min = cur_max
873              cur_max += step              cur_max += step
# Line 808  CLR  = 0 Line 879  CLR  = 0
879  STEP = 1  STEP = 1
880  class CustomRamp:  class CustomRamp:
881    
882      def __init__(self, num, prop1, prop2):      def __init__(self, prop1, prop2):
883            self.prop1 = prop1
884            self.prop2 = prop2
885    
886            self.count = 0
887    
888        def __iter__(self):
889            return self
890    
891        def GetRamp(self):
892            return self
893    
894        def SetNumGroups(self, num):
895    
896            if num <= 0:
897                return False
898    
899          self.count = int(num)          self.count = int(num)
900          num = float(num)          num = float(num)
901    
902            prop1 = self.prop1
903            prop2 = self.prop2
904    
905          clr = prop1.GetLineColor()          clr = prop1.GetLineColor()
906          lineColor2 = prop2.GetLineColor()          lineColor2 = prop2.GetLineColor()
907                    
# Line 831  class CustomRamp: Line 920  class CustomRamp:
920          self.lineWidth = prop1.GetLineWidth()          self.lineWidth = prop1.GetLineWidth()
921          self.lineWidthStep = (prop2.GetLineWidth() - self.lineWidth) / num          self.lineWidthStep = (prop2.GetLineWidth() - self.lineWidth) / num
922    
923      def __iter__(self):          return True
         return self  
924    
925      def next(self):      def next(self):
926          if self.count == 0:          if self.count == 0:
# Line 897  class CustomRamp: Line 985  class CustomRamp:
985    
986    
987          return (color, step)          return (color, step)
988    
989    class MonochromaticRamp(CustomRamp):
990        def __init__(self, start, end):
991            sp = ClassGroupProperties()
992            sp.SetLineColor(start)
993            sp.SetFill(start)
994    
995            ep = ClassGroupProperties()
996            ep.SetLineColor(end)
997            ep.SetFill(end)
998    
999            CustomRamp.__init__(self, sp, ep)
1000    
1001    class GreyRamp(MonochromaticRamp):
1002        def __init__(self):
1003            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, 0))
1004    
1005    class RedRamp(MonochromaticRamp):
1006        def __init__(self):
1007            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(.8, 0, 0))
1008    
1009    class GreenRamp(MonochromaticRamp):
1010        def __init__(self):
1011            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, .8, 0))
1012    
1013    class BlueRamp(MonochromaticRamp):
1014        def __init__(self):
1015            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, .8))
1016    
1017    class HotToColdRamp:
1018    
1019        def __iter__(self):
1020            return self
1021            
1022        def GetRamp(self):
1023            return self
1024    
1025        def SetNumGroups(self, num):
1026            if num < 0:
1027                return False
1028    
1029            self.num = float(num)
1030            self.index = 0
1031    
1032            return True
1033    
1034        def next(self):
1035            if self.index == self.num:
1036                raise StopIteration
1037    
1038            clr = [1.0, 1.0, 1.0]
1039    
1040            if self.index < (.25 * self.num):
1041                clr[0] = 0
1042                clr[1] = 4 * self.index / self.num
1043            elif self.index < (.5 * self.num):
1044                clr[0] = 0
1045                clr[2] = 1 + 4 * (.25 * self.num - self.index) / self.num
1046            elif self.index < (.75 * self.num):
1047                clr[0] = 4 * (self.index - .5 * self.num) / self.num
1048                clr[2] = 0
1049            else:
1050                clr[1] = 1 + 4 * (.75 * self.num - self.index) / self.num
1051                clr[2] = 0
1052    
1053            self.index += 1
1054    
1055            prop = ClassGroupProperties()
1056            prop.SetLineColor(Color(clr[0], clr[1], clr[2]))
1057            prop.SetFill(Color(clr[0], clr[1], clr[2]))
1058    
1059            return prop
1060    
1061    #class Colors16Ramp:
1062    #
1063        #def __iter__(self):
1064            #return self
1065    #
1066        #def GetRamp(self):
1067            #return self
1068    #
1069        #def SetNumGroups(self, num):
1070            #if num < 0:
1071                #return False
1072    #
1073            #self.index = 0
1074    #
1075            #return True
1076    
1077        

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26