/[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 907 by bh, Fri May 16 15:01:04 2003 UTC revision 1341 by jonathan, Tue Jul 1 16:10:42 2003 UTC
# Line 17  from Thuban.Model.table import FIELDTYPE Line 17  from Thuban.Model.table import FIELDTYPE
17       FIELDTYPE_STRING       FIELDTYPE_STRING
18    
19  from Thuban.Model.range import Range  from Thuban.Model.range import Range
20    from Thuban.UI.common import ThubanBeginBusyCursor, ThubanEndBusyCursor
21    
22  import classifier, resource  import classifier, resource
23    
24  from Thuban.Model.classgen import ClassGenerator, \  from Thuban.Model.classgen import \
25        generate_uniform_distribution, generate_singletons, generate_quantiles, \
26      CustomRamp, GreyRamp, RedRamp, GreenRamp, BlueRamp, GreenToRedRamp, \      CustomRamp, GreyRamp, RedRamp, GreenRamp, BlueRamp, GreenToRedRamp, \
27      HotToColdRamp      HotToColdRamp
28    
# Line 59  class ClassGenDialog(wxDialog): Line 61  class ClassGenDialog(wxDialog):
61          self.layer = layer          self.layer = layer
62          self.clazz = None          self.clazz = None
63    
64          col = layer.table.Column(fieldName)          col = layer.ShapeStore().Table().Column(fieldName)
65          self.type = col.type          self.type = col.type
66    
67          self.fieldName = fieldName          self.fieldName = fieldName
# Line 74  class ClassGenDialog(wxDialog): Line 76  class ClassGenDialog(wxDialog):
76          # panels they will call AllowGenerate() which uses genButton.          # panels they will call AllowGenerate() which uses genButton.
77          #          #
78          self.genButton = wxButton(self, wxID_OK, _("Generate"))          self.genButton = wxButton(self, wxID_OK, _("Generate"))
79            self.cancelButton = wxButton(self, wxID_CANCEL, _("Close"))
80          self.genButton.SetDefault()          self.genButton.SetDefault()
81    
82          self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO)          self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO)
83    
84          self.genpanels.append((GENCOMBOSTR_UNIQUE, GenUniquePanel))          self.genpanels.append((GENCOMBOSTR_UNIQUE, GenUniquePanel))
# Line 87  class ClassGenDialog(wxDialog): Line 91  class ClassGenDialog(wxDialog):
91    
92          self.genChoice.SetSelection(0)          self.genChoice.SetSelection(0)
93    
94          self.propPanel = None          for i in range(self.genChoice.GetCount()):
95          custom_ramp_panel = CustomRampPanel(self, layer.ShapeType())              clazz, obj = self.genChoice.GetClientData(i)
96    
97          self.propCombo = wxChoice(self, ID_CLASSGEN_PROPCOMBO)              if obj is None:
98          self.propCombo.Append(PROPCOMBOSTR_GREY,  GreyRamp())                  obj = clazz(self, self.layer, self.fieldName, self.fieldType)
99          self.propCombo.Append(PROPCOMBOSTR_RED,   RedRamp())                  obj.Hide()
100          self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp())                  self.genChoice.SetClientData(i, [clazz, obj])
         self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp())  
         self.propCombo.Append(PROPCOMBOSTR_GREEN2RED, GreenToRedRamp())  
         self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())  
         self.propCombo.Append(PROPCOMBOSTR_CUSTOM, custom_ramp_panel)  
101    
         self.propCombo.SetSelection(0)  
102    
103          #############          #############
104    
# Line 125  class ClassGenDialog(wxDialog): Line 124  class ClassGenDialog(wxDialog):
124          psizer = wxBoxSizer(wxHORIZONTAL)          psizer = wxBoxSizer(wxHORIZONTAL)
125          psizer.Add(wxStaticText(self, -1, _("Color Scheme:")),          psizer.Add(wxStaticText(self, -1, _("Color Scheme:")),
126              0, wxALIGN_CENTER_VERTICAL, 0)              0, wxALIGN_CENTER_VERTICAL, 0)
127    
128            # Properties (Ramp) ComboBox
129            self.propCombo = wxChoice(self, ID_CLASSGEN_PROPCOMBO)
130    
131            self.propPanel = None
132            custom_ramp_panel = CustomRampPanel(self, layer.ShapeType())
133    
134            self.propCombo.Append(PROPCOMBOSTR_GREY,  GreyRamp)
135            self.propCombo.Append(PROPCOMBOSTR_RED,   RedRamp)
136            self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp)
137            self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp)
138            self.propCombo.Append(PROPCOMBOSTR_GREEN2RED, GreenToRedRamp)
139            self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())
140            self.propCombo.Append(PROPCOMBOSTR_CUSTOM, custom_ramp_panel)
141    
142            self.propCombo.SetSelection(0)
143    
144          psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4)          psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4)
145          sizer.Add(psizer, 0, wxALL | wxGROW, 4)          sizer.Add(psizer, 0, wxALL | wxGROW, 4)
146    
147          sizer.Add(custom_ramp_panel, 1, wxGROW | wxALL, 4)          sizer.Add(custom_ramp_panel, 1, wxGROW | wxALL, 4)
148          sizer.Show(custom_ramp_panel, False)          sizer.Show(custom_ramp_panel, False)
149    
150            # Finally place the main buttons
151          buttonSizer = wxBoxSizer(wxHORIZONTAL)          buttonSizer = wxBoxSizer(wxHORIZONTAL)
152          buttonSizer.Add(self.genButton, 0, wxALL, 4)          buttonSizer.Add(self.genButton, 0, wxRIGHT|wxEXPAND, 10)
153          buttonSizer.Add(60, 20, 0, wxALL, 4)          buttonSizer.Add(self.cancelButton, 0, wxRIGHT|wxEXPAND, 10)
154          buttonSizer.Add(wxButton(self, wxID_CANCEL, _("Close")),          sizer.Add(buttonSizer, 0, wxALIGN_RIGHT|wxBOTTOM|wxTOP, 10)
                         0, wxALL, 4)  
         sizer.Add(buttonSizer, 0,  
                   wxALL | wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL, 4)  
155    
156          self.SetSizer(sizer)          self.SetSizer(sizer)
157          self.SetAutoLayout(True)          self.SetAutoLayout(True)
# Line 198  class ClassGenDialog(wxDialog): Line 212  class ClassGenDialog(wxDialog):
212                      and max is not None \                      and max is not None \
213                      and numGroups is not None:                      and numGroups is not None:
214    
215                      self.clazz = ClassGenerator().GenUniformDistribution(                      self.clazz = generate_uniform_distribution(
216                                  min, max, numGroups, ramp,                                  min, max, numGroups, ramp,
217                                  self.type == FIELDTYPE_INT)                                  self.type == FIELDTYPE_INT)
218    
# Line 208  class ClassGenDialog(wxDialog): Line 222  class ClassGenDialog(wxDialog):
222    
223                  list = genPanel.GetValueList()                  list = genPanel.GetValueList()
224    
225                  if len(list) > 0 \                  if len(list) > 0:
226                      and numGroups is not None:                      self.clazz = generate_singletons(list, ramp)
   
                     self.clazz = ClassGenerator().GenSingletonsFromList(  
                                     list, numGroups, ramp)  
   
227                      self.parent._SetClassification(self.clazz)                      self.parent._SetClassification(self.clazz)
228    
229              elif genSel == GENCOMBOSTR_QUANTILES:              elif genSel == GENCOMBOSTR_QUANTILES:
# Line 225  class ClassGenDialog(wxDialog): Line 235  class ClassGenDialog(wxDialog):
235                  delta = 1 / float(numGroups)                  delta = 1 / float(numGroups)
236                  percents = [delta * i for i in range(1, numGroups + 1)]                  percents = [delta * i for i in range(1, numGroups + 1)]
237                  adjusted, self.clazz = \                  adjusted, self.clazz = \
238                      ClassGenerator().GenQuantiles(_list, percents, ramp, _range)                      generate_quantiles(_list, percents, ramp, _range)
239    
240                  if adjusted:                  if adjusted:
241                      dlg = wxMessageDialog(self,                      dlg = wxMessageDialog(self,
# Line 286  class ClassGenDialog(wxDialog): Line 296  class ClassGenDialog(wxDialog):
296    
297          clazz, obj = choice.GetClientData(sel)          clazz, obj = choice.GetClientData(sel)
298    
         if obj is None:  
             obj = clazz(self, self.layer, self.fieldName, self.fieldType)  
             choice.SetClientData(sel, [clazz, obj])  
   
299          if self.curGenPanel is not None:          if self.curGenPanel is not None:
300              self.curGenPanel.Hide()              self.curGenPanel.Hide()
301              self.sizer_genPanel.Remove(self.curGenPanel)              self.sizer_genPanel.Remove(self.curGenPanel)
# Line 495  class GenUniformPanel(wxPanel): Line 501  class GenUniformPanel(wxPanel):
501              self.parent.AllowGenerate(False)              self.parent.AllowGenerate(False)
502    
503      def _OnRetrieve(self, event):      def _OnRetrieve(self, event):
504            table = self.layer.ShapeStore().Table()
505          if self.layer.table is not None:          if table is not None:
506              wxBeginBusyCursor()              ThubanBeginBusyCursor()
507              min, max = self.layer.table.ValueRange(self.fieldName)              try:
508              self.minCtrl.SetValue(str(min))                  min, max = table.ValueRange(self.fieldName)
509              self.maxCtrl.SetValue(str(max))                  self.minCtrl.SetValue(str(min))
510              wxEndBusyCursor()                  self.maxCtrl.SetValue(str(max))
511                finally:
512                    ThubanEndBusyCursor()
513    
514      def __GetValidatedTypeEntry(self, win, value, type, badValue = None):      def __GetValidatedTypeEntry(self, win, value, type, badValue = None):
515    
# Line 543  class GenUniformPanel(wxPanel): Line 551  class GenUniformPanel(wxPanel):
551          return valid          return valid
552    
553      def __CalcStepping(self, min, max, ngroups):      def __CalcStepping(self, min, max, ngroups):
         step = (max - min) / float(ngroups)  
554          if self.fieldType == FIELDTYPE_INT:          if self.fieldType == FIELDTYPE_INT:
555              step = int(step)              step = int((max - min + 1) / float(ngroups))
556            else:
557                step = (max - min) / float(ngroups)
558    
559          return step          return step
560    
# Line 662  class GenUniquePanel(wxPanel): Line 671  class GenUniquePanel(wxPanel):
671          self.SetAutoLayout(True)          self.SetAutoLayout(True)
672          topSizer.SetSizeHints(self)          topSizer.SetSizeHints(self)
673    
674            width, height = self.list_avail.GetSizeTuple()
675            self.list_avail.SetColumnWidth(0,width)
676            width, height = self.list_use.GetSizeTuple()
677            self.list_use.SetColumnWidth(0,width)
678    
679          self.parent.AllowGenerate(False)          self.parent.AllowGenerate(False)
680    
681      def GetNumGroups(self):      def GetNumGroups(self):
# Line 703  class GenUniquePanel(wxPanel): Line 717  class GenUniquePanel(wxPanel):
717          self.list_avail.DeleteAllItems()          self.list_avail.DeleteAllItems()
718          self.list_avail_data = []          self.list_avail_data = []
719    
720          list = self.layer.table.UniqueValues(self.fieldName)          ThubanBeginBusyCursor()
721          index = 0          try:
722          for v in list:              list = self.layer.ShapeStore().Table().UniqueValues(self.fieldName)
723              self.dataList.append(v)              index = 0
724              i = self.list_avail.InsertStringItem(index, str(v))              for v in list:
725              self.list_avail.SetItemData(index, i)                  self.dataList.append(v)
726                    i = self.list_avail.InsertStringItem(index, str(v))
727              self.list_avail_data.append(v)                  self.list_avail.SetItemData(index, i)
728              index += 1      
729                    self.list_avail_data.append(v)
730                    index += 1
731            finally:
732                ThubanEndBusyCursor()
733    
734      def _OnUseAll(self, event):      def _OnUseAll(self, event):
735          for i in range(self.list_avail.GetItemCount()):          for i in range(self.list_avail.GetItemCount()):
# Line 815  class GenQuantilesPanel(wxPanel): Line 833  class GenQuantilesPanel(wxPanel):
833          return self.__range          return self.__range
834    
835      def GetList(self):      def GetList(self):
   
836          _list = []          _list = []
837            table = self.layer.ShapeStore().Table()
838          if self.layer.table is not None:          if table is not None:
839              wxBeginBusyCursor()              ThubanBeginBusyCursor()
840                try:
841              #                  #
842              # FIXME: Replace with a call to table when the method                  # FIXME: Replace with a call to table when the method
843              # has been written to get all the values                  # has been written to get all the values
844              #                  #
845              table = self.layer.table                  for i in range(table.NumRows()):
846              for i in range(table.NumRows()):                      _list.append(table.ReadValue(i, self.fieldName))
847                  _list.append(table.ReadValue(i, self.fieldName))              finally:
848                    ThubanEndBusyCursor()
             wxEndBusyCursor()  
849    
850          return _list          return _list
851    
# Line 846  class GenQuantilesPanel(wxPanel): Line 862  class GenQuantilesPanel(wxPanel):
862              self.text_range.SetForegroundColour(wxRED)              self.text_range.SetForegroundColour(wxRED)
863    
864      def OnRetrieve(self, event):      def OnRetrieve(self, event):
865            table = self.layer.ShapeStore().Table()
866          if self.layer.table is not None:          if table is not None:
867              wxBeginBusyCursor()              ThubanBeginBusyCursor()
868              min, max = self.layer.table.ValueRange(self.fieldName)              try:
869              self.text_range.SetValue("[" + str(min) + ";" + str(max) + "]")                  min, max = table.ValueRange(self.fieldName)
870              wxEndBusyCursor()                  self.text_range.SetValue("[" + str(min) + ";" + str(max) + "]")
871                finally:
872                    ThubanEndBusyCursor()
873    
874  ID_CUSTOMRAMP_COPYSTART = 4001  ID_CUSTOMRAMP_COPYSTART = 4001
875  ID_CUSTOMRAMP_COPYEND = 4002  ID_CUSTOMRAMP_COPYEND = 4002

Legend:
Removed from v.907  
changed lines
  Added in v.1341

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26