/[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 677 by jonathan, Tue Apr 15 19:21:01 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    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                                                                                                                                                                    
# Line 64  class ClassGenDialog(wxDialog): Line 81  class ClassGenDialog(wxDialog):
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 = wxComboBox(self,
92                                  ID_CLASSGEN_COMBO,                                     ID_CLASSGEN_GENCOMBO,
93                                  "", style = wxCB_READONLY)                                     "", style = wxCB_READONLY)
94          psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4)          psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4)
95          EVT_COMBOBOX(self, ID_CLASSGEN_COMBO, self._OnGenTypeSelect)          EVT_COMBOBOX(self, ID_CLASSGEN_GENCOMBO, self._OnGenTypeSelect)
96    
97          sizer.Add(psizer, 0, wxALL | wxGROW, 4)          sizer.Add(psizer, 0, wxALL | wxGROW, 4)
98    
# Line 86  class ClassGenDialog(wxDialog): Line 101  class ClassGenDialog(wxDialog):
101          self.genPanel = None          self.genPanel = None
102    
103          panel = GenUniquePanel(self, layer, fieldName, self.type)          panel = GenUniquePanel(self, layer, fieldName, self.type)
104          self.genCombo.Append(COMBOSTR_UNIQUE)          self.genCombo.Append(GENCOMBOSTR_UNIQUE, panel)
         self.genCombo.SetClientData(self.genCombo.GetCount() - 1, panel)  
105          sizer.Add(panel, 1, wxGROW | wxALL, 4)          sizer.Add(panel, 1, wxGROW | wxALL, 4)
106    
107          self.genPanel = panel          self.genPanel = panel
108    
109          if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):          if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):
110              panel = GenUniformPanel(self, layer, fieldName, self.type)              panel = GenUniformPanel(self, layer, fieldName, self.type)
111              self.genCombo.Append(COMBOSTR_UNIFORM)              self.genCombo.Append(GENCOMBOSTR_UNIFORM, panel)
112              self.genCombo.SetClientData(self.genCombo.GetCount() - 1, panel)              sizer.Add(panel, 1, wxGROW | wxALL, 4)
             sizer.Add(panel, 0, wxGROW | wxALL, 4)  
113              sizer.Show(panel, False)              sizer.Show(panel, False)
114    
115            self.genCombo.SetSelection(0)
116    
117          #############          #############
118    
119          self.propPanel = None          psizer = wxBoxSizer(wxHORIZONTAL)
120            psizer.Add(wxStaticText(self, -1, _("Color Scheme:")),
121                0, wxALIGN_CENTER_VERTICAL, 0)
122    
123          panel = CustomRampPanel(self, layer.ShapeType())          self.propCombo = wxComboBox(self,
124                                       ID_CLASSGEN_PROPCOMBO,
125                                       "", style = wxCB_READONLY)
126            psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4)
127            EVT_COMBOBOX(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect)
128            sizer.Add(psizer, 0, wxALL | wxGROW, 4)
129    
130          self.propPanel = panel          #############
131    
132            self.propPanel = None
133            panel = CustomRampPanel(self, layer.ShapeType())
134          sizer.Add(panel, 1, wxALL | wxGROW, 4)          sizer.Add(panel, 1, wxALL | wxGROW, 4)
135            sizer.Show(panel, False)
136    
137            self.propCombo.Append(PROPCOMBOSTR_GREY,  GreyRamp())
138            self.propCombo.Append(PROPCOMBOSTR_RED,   RedRamp())
139            self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp())
140            self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp())
141            self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())
142            self.propCombo.Append(PROPCOMBOSTR_CUSTOM, panel)
143    
144            self.propCombo.SetSelection(0)
145    
146    
147          #############          #############
148    
# Line 132  class ClassGenDialog(wxDialog): Line 167  class ClassGenDialog(wxDialog):
167    
168      def _OnGenerate(self, event):      def _OnGenerate(self, event):
169    
170          selIndex = self.genCombo.GetSelection()          index = self.genCombo.GetSelection()
171    
172          sel = self.genCombo.GetString(selIndex)          genSel = self.genCombo.GetString(index)
173          genPanel = self.genCombo.GetClientData(selIndex)          genPanel = self.genCombo.GetClientData(index)
         propPanel = self.propPanel  
174    
175          if sel == COMBOSTR_UNIFORM:          propPanel = self.propPanel
176    
177              min = genPanel.GetMin()          if genSel in (GENCOMBOSTR_UNIFORM, GENCOMBOSTR_UNIQUE):
             max = genPanel.GetMax()  
178              numGroups = genPanel.GetNumGroups()              numGroups = genPanel.GetNumGroups()
             sp = propPanel.GetStartProperties()  
             ep = propPanel.GetEndProperties()  
179    
180              if min is not None \              index = self.propCombo.GetSelection()
                 and max is not None \  
                 and numGroups is not None:  
181    
182                  self.clazz = ClassGenerator().GenUnifromDistribution(              propSel = self.propCombo.GetString(index)
183                               min, max, numGroups, sp, ep,              propPanel = self.propCombo.GetClientData(index)
                              self.type == FIELDTYPE_INT)  
184    
185                  self.parent._SetClassification(self.clazz)              ramp = propPanel.GetRamp()
186    
187          elif sel == COMBOSTR_UNIQUE:              if genSel == GENCOMBOSTR_UNIFORM:
188    
189              list = genPanel.GetValueList()                  min = genPanel.GetMin()
190              numGroups = genPanel.GetNumGroups()                  max = genPanel.GetMax()
             sp = propPanel.GetStartProperties()  
             ep = propPanel.GetEndProperties()  
191    
192              if len(list) > 0 \                  if min is not None \
193                  and numGroups is not None:                      and max is not None \
194                        and numGroups is not None:
195    
196                  self.clazz = ClassGenerator().GenSingletonsFromList(                      self.clazz = ClassGenerator().GenUnifromDistribution(
197                                  list, numGroups, sp, ep)                                  min, max, numGroups, ramp,
198                                    self.type == FIELDTYPE_INT)
199    
200                  self.parent._SetClassification(self.clazz)                      self.parent._SetClassification(self.clazz)
201    
202          else:              elif genSel == GENCOMBOSTR_UNIQUE:
203              pass  
204                    list = genPanel.GetValueList()
205    
206                    if len(list) > 0 \
207                        and numGroups is not None:
208    
209                        self.clazz = ClassGenerator().GenSingletonsFromList(
210                                        list, numGroups, ramp)
211    
212                        self.parent._SetClassification(self.clazz)
213    
214      def _OnCloseBtn(self, event):      def _OnCloseBtn(self, event):
215          self.Close()          self.Close()
# Line 193  class ClassGenDialog(wxDialog): Line 230  class ClassGenDialog(wxDialog):
230          self.sizer.SetSizeHints(self)          self.sizer.SetSizeHints(self)
231          self.sizer.Layout()          self.sizer.Layout()
232    
233        def _OnPropTypeSelect(self, event):
234            combo = event.GetEventObject()
235    
236            selIndex = combo.GetSelection()
237            sel = combo.GetString(selIndex)
238    
239            if isinstance(self.propPanel, wxPanel):
240                self.sizer.Show(self.propPanel, False)
241    
242            self.propPanel = combo.GetClientData(selIndex)
243    
244            if isinstance(self.propPanel, wxPanel):
245                self.sizer.Show(self.propPanel, True)
246    
247            self.sizer.SetSizeHints(self)
248            self.sizer.Layout()
249    
250    
251  ID_UNIFORM_MIN = 4001  ID_UNIFORM_MIN = 4001
252  ID_UNIFORM_MAX = 4002  ID_UNIFORM_MAX = 4002
# Line 238  class GenUniformPanel(wxPanel): Line 292  class GenUniformPanel(wxPanel):
292          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
293    
294          sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4)          sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4)
295          self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS, style=wxTE_RIGHT)          self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS,
296                                            style=wxTE_RIGHT)
297          EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)          EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)
298          EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)          EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)
299          sizer.Add(self.numGroupsCtrl, 1, wxALL, 4)          sizer.Add(self.numGroupsCtrl, 1, wxALL, 4)
# Line 259  class GenUniformPanel(wxPanel): Line 314  class GenUniformPanel(wxPanel):
314          self.numGroupsChanging = False          self.numGroupsChanging = False
315          self.steppingChanging = False          self.steppingChanging = False
316    
317          self.numGroupsCtrl.SetRange(1, 100)          self.numGroupsCtrl.SetRange(1, sys.maxint)
318    
319          self.numGroupsCtrl.SetValue(1)          self.numGroupsCtrl.SetValue(1)
320          self.stepCtrl.SetValue("1")          self.stepCtrl.SetValue("1")
# Line 309  class GenUniformPanel(wxPanel): Line 364  class GenUniformPanel(wxPanel):
364          self.numGroupsCtrl.Enable(on)          self.numGroupsCtrl.Enable(on)
365          self.stepCtrl.Enable(on)          self.stepCtrl.Enable(on)
366    
         if on:  
             self.numGroupsCtrl.SetRange(1, abs(max - min) / 0.001)  
   
367          ngroups = self.GetNumGroups()          ngroups = self.GetNumGroups()
368    
369          if ngroups is not None  \          if ngroups is not None  \
# Line 342  class GenUniformPanel(wxPanel): Line 394  class GenUniformPanel(wxPanel):
394          min = self.GetMin()          min = self.GetMin()
395          max = self.GetMax()          max = self.GetMax()
396    
         if ngroups >= self.numGroupsCtrl.GetMax():  
             self.numGroupsCtrl.SetRange(1, ngroups + 1)  
   
397          if ngroups is not None  \          if ngroups is not None  \
398              and min is not None \              and min is not None \
399              and max is not None \              and max is not None \
# Line 461  ID_UNIQUE_DONTUSE = 4004 Line 510  ID_UNIQUE_DONTUSE = 4004
510  ID_UNIQUE_USENONE = 4005  ID_UNIQUE_USENONE = 4005
511  ID_UNIQUE_SORTAVAIL = 4006  ID_UNIQUE_SORTAVAIL = 4006
512  ID_UNIQUE_SORTUSE = 4007  ID_UNIQUE_SORTUSE = 4007
513    ID_UNIQUE_REVAVAIL = 4008
514    ID_UNIQUE_REVUSE = 4009
515    
516  class GenUniquePanel(wxPanel):  class GenUniquePanel(wxPanel):
517    
# Line 476  class GenUniquePanel(wxPanel): Line 527  class GenUniquePanel(wxPanel):
527                                      wxVERTICAL)                                      wxVERTICAL)
528    
529    
530            #bsizer = wxBoxSizer(wxVERTICAL)
531            topSizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE,
532                                _("Retrieve From Table")),
533                       0, wxALL | wxALIGN_RIGHT, 4)
534    
535            EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve)
536    
537            #topSizer.Add(bsizer, 0, wxALL, 4)
538    
539          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
540    
541          self.dataList = []          self.dataList = []
# Line 487  class GenUniquePanel(wxPanel): Line 547  class GenUniquePanel(wxPanel):
547          self.list_avail_data = []          self.list_avail_data = []
548          psizer.Add(self.list_avail, 1, wxGROW, 0)          psizer.Add(self.list_avail, 1, wxGROW, 0)
549    
550          psizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort")))          bsizer = wxBoxSizer(wxHORIZONTAL)
551            bsizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort")))
552            EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortList)
553    
554          EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortAvailList)          bsizer.Add(wxButton(self, ID_UNIQUE_REVAVAIL, _("Reverse")))
555            EVT_BUTTON(self, ID_UNIQUE_REVAVAIL, self._OnReverseList)
556    
557            psizer.Add(bsizer, 0, wxGROW, 0)
558          sizer.Add(psizer, 1, wxGROW, 0)          sizer.Add(psizer, 1, wxGROW, 0)
559    
560                    
561          bsizer = wxBoxSizer(wxVERTICAL)          bsizer = wxBoxSizer(wxVERTICAL)
562          bsizer.Add(wxButton(self, ID_UNIQUE_USEALL, _("Use All")),  
563            bmp = resource.GetBitmapResource(USEALL_BMP, wxBITMAP_TYPE_XPM)
564            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USEALL, bmp),
565                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
566          bsizer.Add(wxButton(self, ID_UNIQUE_USE, _("Use >>")),          bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM)
567            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USE, bmp),
568                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
569          bsizer.Add(wxButton(self, ID_UNIQUE_DONTUSE, _("<< Don't Use")),          bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM)
570            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_DONTUSE, bmp),
571                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
572          bsizer.Add(wxButton(self, ID_UNIQUE_USENONE, _("Use None")),          bmp = resource.GetBitmapResource(USENONE_BMP, wxBITMAP_TYPE_XPM)
573            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USENONE, bmp),
574                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
575    
576          EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll)          EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll)
# Line 518  class GenUniquePanel(wxPanel): Line 587  class GenUniquePanel(wxPanel):
587          self.list_use_data = []          self.list_use_data = []
588          psizer.Add(self.list_use, 1, wxGROW, 0)          psizer.Add(self.list_use, 1, wxGROW, 0)
589    
590          psizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort")))          bsizer = wxBoxSizer(wxHORIZONTAL)
591            bsizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort")))
592            EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortList)
593    
594          EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortUseList)          bsizer.Add(wxButton(self, ID_UNIQUE_REVUSE, _("Reverse")))
595            EVT_BUTTON(self, ID_UNIQUE_REVUSE, self._OnReverseList)
596    
597          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)  
598    
599          EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve)          sizer.Add(psizer, 1, wxGROW, 0)
600    
         sizer.Add(bsizer, 0, wxALL, 4)  
601    
602          topSizer.Add(sizer, 1, wxGROW, 0)          topSizer.Add(sizer, 1, wxGROW, 0)
603    
# Line 552  class GenUniquePanel(wxPanel): Line 618  class GenUniquePanel(wxPanel):
618              list.append(self.dataList[self.list_use.GetItemData(i)])              list.append(self.dataList[self.list_use.GetItemData(i)])
619          return list          return list
620    
621      def _OnSortAvailList(self, event):      def _OnSortList(self, event):
622          self.list_avail.SortItems(lambda i1, i2:          id = event.GetId()
623                                      cmp(self.dataList[i1],  
624                                          self.dataList[i2]))          if id == ID_UNIQUE_SORTUSE:
625                list = self.list_use
626      def _OnSortUseList(self, event):          else:
627          self.list_use.SortItems(lambda i1, i2:              list = self.list_avail
628                                      cmp(self.dataList[i1],  
629                                          self.dataList[i2]))          list.SortItems(lambda i1, i2: cmp(self.dataList[i1],
630                                              self.dataList[i2]))
631    
632        def _OnReverseList(self, event):
633            id = event.GetId()
634    
635            if id == ID_UNIQUE_REVUSE:
636                list = self.list_use
637            else:
638                list = self.list_avail
639    
640            #
641            # always returning 1 reverses the list
642            #
643            list.SortItems(lambda i1, i2: 1)
644    
645      def _OnRetrieve(self, event):      def _OnRetrieve(self, event):
646          self.list_use.DeleteAllItems()          self.list_use.DeleteAllItems()
# Line 583  class GenUniquePanel(wxPanel): Line 663  class GenUniquePanel(wxPanel):
663              self.__MoveListItem(0, self.list_avail, self.list_use)              self.__MoveListItem(0, self.list_avail, self.list_use)
664    
665      def _OnUse(self, event):      def _OnUse(self, event):
         print "_OnUse"  
666          self.__MoveSelectedItems(self.list_avail, self.list_use)          self.__MoveSelectedItems(self.list_avail, self.list_use)
667    
668      def _OnDontUse(self, event):      def _OnDontUse(self, event):
         print "_OnDontUse"  
669          self.__MoveSelectedItems(self.list_use, self.list_avail)          self.__MoveSelectedItems(self.list_use, self.list_avail)
670    
671      def _OnUseNone(self, event):      def _OnUseNone(self, event):
         print "_OnUseNone"  
672    
673          for i in range(self.list_use.GetItemCount()):          for i in range(self.list_use.GetItemCount()):
674              self.__MoveListItem(0, self.list_use, self.list_avail)              self.__MoveListItem(0, self.list_use, self.list_avail)
# Line 657  class CustomRampPanel(wxPanel): Line 734  class CustomRampPanel(wxPanel):
734                        | wxALIGN_CENTER_VERTICAL, \                        | wxALIGN_CENTER_VERTICAL, \
735                     4)                     4)
736    
737            bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM)
738          bsizer = wxBoxSizer(wxVERTICAL)          bsizer = wxBoxSizer(wxVERTICAL)
739          bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYSTART, _("Copy >>")),          bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYSTART, bmp),
740                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
741          bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYEND, _("<< Copy")),          bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM)
742            bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYEND, bmp),
743                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
744    
745          topSizer.Add(bsizer,          topSizer.Add(bsizer,
# Line 696  class CustomRampPanel(wxPanel): Line 775  class CustomRampPanel(wxPanel):
775          self.SetAutoLayout(True)          self.SetAutoLayout(True)
776          topSizer.SetSizeHints(self)          topSizer.SetSizeHints(self)
777    
778      def GetStartProperties(self):      def GetRamp(self):
779          return self.startPropCtrl.GetProperties()          return CustomRamp(self.startPropCtrl.GetProperties(),
780                              self.endPropCtrl.GetProperties())
     def GetEndProperties(self):  
         return self.endPropCtrl.GetProperties()  
781    
782      def _OnCopyStart(self, event):      def _OnCopyStart(self, event):
783          self.endPropCtrl.SetProperties(self.startPropCtrl.GetProperties())          self.endPropCtrl.SetProperties(self.startPropCtrl.GetProperties())
# Line 716  class CustomRampPanel(wxPanel): Line 793  class CustomRampPanel(wxPanel):
793    
794  class ClassGenerator:  class ClassGenerator:
795    
796      def GenSingletonsFromList(self, list, numGroups, prop1, prop2):      def GenSingletonsFromList(self, list, numGroups, ramp):
797          """Generate a new classification consisting solely of singletons.          """Generate a new classification consisting solely of singletons.
798    
799          The resulting classification will consist of at most 'numGroups'          The resulting classification will consist of at most 'numGroups'
# Line 738  class ClassGenerator: Line 815  class ClassGenerator:
815          clazz = Classification()          clazz = Classification()
816          if numGroups == 0: return clazz          if numGroups == 0: return clazz
817    
818          for value, prop in zip(list, CustomRamp(numGroups, prop1, prop2)):          ramp.SetNumGroups(numGroups)
819    
820            for value, prop in zip(list, ramp):
821              clazz.AppendGroup(ClassGroupSingleton(value, prop))              clazz.AppendGroup(ClassGroupSingleton(value, prop))
822    
823          return clazz          return clazz
824    
825      def GenSingletons(self, min, max, numGroups, prop1, prop2):      def GenSingletons(self, min, max, numGroups, ramp):
826    
827          clazz = Classification()          clazz = Classification()
828    
# Line 753  class ClassGenerator: Line 832  class ClassGenerator:
832          if numGroups > 0:          if numGroups > 0:
833              cur_value = min              cur_value = min
834    
835              for prop in CustomRamp(numGroups, prop1, prop2):              ramp.SetNumGroups(numGroups)
836    
837                for prop in ramp:
838                  clazz.AppendGroup(                  clazz.AppendGroup(
839                      ClassGroupSingleton(                      ClassGroupSingleton(
840                          Str2Num(str(cur_value)),                          Str2Num(str(cur_value)),
# Line 763  class ClassGenerator: Line 844  class ClassGenerator:
844          return clazz          return clazz
845    
846      def GenUnifromDistribution(self, min, max, numGroups,      def GenUnifromDistribution(self, min, max, numGroups,
847                                 prop1, prop2, intStep = False):                                 ramp, intStep = False):
848          """Generate a classification with numGroups range groups          """Generate a classification with numGroups range groups
849          each with the same interval.          each with the same interval.
850    
# Line 776  class ClassGenerator: Line 857  class ClassGenerator:
857          clazz = Classification()          clazz = Classification()
858          if numGroups == 0: return clazz          if numGroups == 0: return clazz
859    
860            ramp.SetNumGroups(numGroups)
861    
862          step = Str2Num(str((max - min) / float(numGroups)))          step = Str2Num(str((max - min) / float(numGroups)))
863    
864          if intStep:          if intStep:
# Line 785  class ClassGenerator: Line 868  class ClassGenerator:
868          cur_max = cur_min + step          cur_max = cur_min + step
869    
870          i = 0          i = 0
871          for prop in CustomRamp(numGroups, prop1, prop2):          for prop in ramp:
872    
873              if i == (numGroups - 1):              if i == (numGroups - 1):
874                  cur_max = max                  cur_max = max
# Line 808  CLR  = 0 Line 891  CLR  = 0
891  STEP = 1  STEP = 1
892  class CustomRamp:  class CustomRamp:
893    
894      def __init__(self, num, prop1, prop2):      def __init__(self, prop1, prop2):
895            self.prop1 = prop1
896            self.prop2 = prop2
897    
898            self.count = 0
899    
900        def __iter__(self):
901            return self
902    
903        def GetRamp(self):
904            return self
905    
906        def SetNumGroups(self, num):
907    
908            if num <= 0:
909                return False
910    
911          self.count = int(num)          self.count = int(num)
912          num = float(num)          num = float(num)
913    
914            prop1 = self.prop1
915            prop2 = self.prop2
916    
917          clr = prop1.GetLineColor()          clr = prop1.GetLineColor()
918          lineColor2 = prop2.GetLineColor()          lineColor2 = prop2.GetLineColor()
919                    
# Line 831  class CustomRamp: Line 932  class CustomRamp:
932          self.lineWidth = prop1.GetLineWidth()          self.lineWidth = prop1.GetLineWidth()
933          self.lineWidthStep = (prop2.GetLineWidth() - self.lineWidth) / num          self.lineWidthStep = (prop2.GetLineWidth() - self.lineWidth) / num
934    
935      def __iter__(self):          return True
         return self  
936    
937      def next(self):      def next(self):
938          if self.count == 0:          if self.count == 0:
# Line 897  class CustomRamp: Line 997  class CustomRamp:
997    
998    
999          return (color, step)          return (color, step)
1000    
1001    class MonochromaticRamp(CustomRamp):
1002        def __init__(self, start, end):
1003            sp = ClassGroupProperties()
1004            sp.SetLineColor(start)
1005            sp.SetFill(start)
1006    
1007            ep = ClassGroupProperties()
1008            ep.SetLineColor(end)
1009            ep.SetFill(end)
1010    
1011            CustomRamp.__init__(self, sp, ep)
1012    
1013    class GreyRamp(MonochromaticRamp):
1014        def __init__(self):
1015            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, 0))
1016    
1017    class RedRamp(MonochromaticRamp):
1018        def __init__(self):
1019            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(.8, 0, 0))
1020    
1021    class GreenRamp(MonochromaticRamp):
1022        def __init__(self):
1023            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, .8, 0))
1024    
1025    class BlueRamp(MonochromaticRamp):
1026        def __init__(self):
1027            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, .8))
1028    
1029    class HotToColdRamp:
1030    
1031        def __iter__(self):
1032            return self
1033            
1034        def GetRamp(self):
1035            return self
1036    
1037        def SetNumGroups(self, num):
1038            if num < 0:
1039                return False
1040    
1041            self.num = float(num)
1042            self.index = 0
1043    
1044            return True
1045    
1046        def next(self):
1047            if self.index == self.num:
1048                raise StopIteration
1049    
1050            clr = [1.0, 1.0, 1.0]
1051    
1052            if self.index < (.25 * self.num):
1053                clr[0] = 0
1054                clr[1] = 4 * self.index / self.num
1055            elif self.index < (.5 * self.num):
1056                clr[0] = 0
1057                clr[2] = 1 + 4 * (.25 * self.num - self.index) / self.num
1058            elif self.index < (.75 * self.num):
1059                clr[0] = 4 * (self.index - .5 * self.num) / self.num
1060                clr[2] = 0
1061            else:
1062                clr[1] = 1 + 4 * (.75 * self.num - self.index) / self.num
1063                clr[2] = 0
1064    
1065            self.index += 1
1066    
1067            prop = ClassGroupProperties()
1068            prop.SetLineColor(Color(clr[0], clr[1], clr[2]))
1069            prop.SetFill(Color(clr[0], clr[1], clr[2]))
1070    
1071            return prop
1072    
1073    #class Colors16Ramp:
1074    #
1075        #def __iter__(self):
1076            #return self
1077    #
1078        #def GetRamp(self):
1079            #return self
1080    #
1081        #def SetNumGroups(self, num):
1082            #if num < 0:
1083                #return False
1084    #
1085            #self.index = 0
1086    #
1087            #return True
1088    
1089        

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26