/[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 1100 by jonathan, Fri May 30 06:28:21 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 \  from Thuban.Model.classgen import \
25      GenUniformDistribution, GenSingletonsFromList, GenQuantiles, \      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 60  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 75  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"))
         self.genButton.SetDefault()  
79          self.cancelButton = wxButton(self, wxID_CANCEL, _("Close"))          self.cancelButton = wxButton(self, wxID_CANCEL, _("Close"))
80            self.genButton.SetDefault()
81    
82          self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO)          self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO)
83    
# Line 130  class ClassGenDialog(wxDialog): Line 131  class ClassGenDialog(wxDialog):
131          self.propPanel = None          self.propPanel = None
132          custom_ramp_panel = CustomRampPanel(self, layer.ShapeType())          custom_ramp_panel = CustomRampPanel(self, layer.ShapeType())
133    
134          self.propCombo.Append(PROPCOMBOSTR_GREY,  GreyRamp())          self.propCombo.Append(PROPCOMBOSTR_GREY,  GreyRamp)
135          self.propCombo.Append(PROPCOMBOSTR_RED,   RedRamp())          self.propCombo.Append(PROPCOMBOSTR_RED,   RedRamp)
136          self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp())          self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp)
137          self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp())          self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp)
138          self.propCombo.Append(PROPCOMBOSTR_GREEN2RED, GreenToRedRamp())          self.propCombo.Append(PROPCOMBOSTR_GREEN2RED, GreenToRedRamp)
139          self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())          self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())
140          self.propCombo.Append(PROPCOMBOSTR_CUSTOM, custom_ramp_panel)          self.propCombo.Append(PROPCOMBOSTR_CUSTOM, custom_ramp_panel)
141    
# Line 211  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 = 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 221  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 = 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 238  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                      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 504  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              try:              try:
508                  min, max = self.layer.table.ValueRange(self.fieldName)                  min, max = table.ValueRange(self.fieldName)
509                  self.minCtrl.SetValue(str(min))                  self.minCtrl.SetValue(str(min))
510                  self.maxCtrl.SetValue(str(max))                  self.maxCtrl.SetValue(str(max))
511              finally:              finally:
512                  wxEndBusyCursor()                  ThubanEndBusyCursor()
513    
514      def __GetValidatedTypeEntry(self, win, value, type, badValue = None):      def __GetValidatedTypeEntry(self, win, value, type, badValue = None):
515    
# Line 554  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 719  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 831  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                ThubanBeginBusyCursor()
840              try:              try:
                 wxBeginBusyCursor()  
   
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                  #                  #
                 table = self.layer.table  
845                  for i in range(table.NumRows()):                  for i in range(table.NumRows()):
846                      _list.append(table.ReadValue(i, self.fieldName))                      _list.append(table.ReadValue(i, self.fieldName))
847              finally:              finally:
848                  wxEndBusyCursor()                  ThubanEndBusyCursor()
849    
850          return _list          return _list
851    
# Line 863  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              try:              try:
869                  min, max = self.layer.table.ValueRange(self.fieldName)                  min, max = table.ValueRange(self.fieldName)
870                  self.text_range.SetValue("[" + str(min) + ";" + str(max) + "]")                  self.text_range.SetValue("[" + str(min) + ";" + str(max) + "]")
871              finally:              finally:
872                  wxEndBusyCursor()                  ThubanEndBusyCursor()
873    
874  ID_CUSTOMRAMP_COPYSTART = 4001  ID_CUSTOMRAMP_COPYSTART = 4001
875  ID_CUSTOMRAMP_COPYEND = 4002  ID_CUSTOMRAMP_COPYEND = 4002

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26