/[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 877 by jonathan, Fri May 9 16:32:17 2003 UTC revision 1274 by jonathan, Fri Jun 20 17:46:04 2003 UTC
# Line 11  from Thuban import _ Line 11  from Thuban import _
11    
12  from wxPython.wx import *  from wxPython.wx import *
13    
14  from Thuban.Model.classification import Classification, ClassGroupRange, \  from Thuban.Model.classification import ClassGroupProperties
     ClassGroupSingleton, ClassGroupProperties  
15    
16  from Thuban.Model.table import Table, FIELDTYPE_INT, FIELDTYPE_DOUBLE, \  from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \
17       FIELDTYPE_STRING       FIELDTYPE_STRING
18    
 from Thuban.Model.color import Color  
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 61  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 77  class ClassGenDialog(wxDialog): Line 77  class ClassGenDialog(wxDialog):
77          #          #
78          self.genButton = wxButton(self, wxID_OK, _("Generate"))          self.genButton = wxButton(self, wxID_OK, _("Generate"))
79          self.genButton.SetDefault()          self.genButton.SetDefault()
80            self.cancelButton = wxButton(self, wxID_CANCEL, _("Close"))
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 89  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 127  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 200  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().GenUnifromDistribution(                      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 213  class ClassGenDialog(wxDialog): Line 225  class ClassGenDialog(wxDialog):
225                  if len(list) > 0 \                  if len(list) > 0 \
226                      and numGroups is not None:                      and numGroups is not None:
227    
228                      self.clazz = ClassGenerator().GenSingletonsFromList(                      self.clazz = generate_singletons(
229                                      list, numGroups, ramp)                                      list, numGroups, ramp)
230    
231                      self.parent._SetClassification(self.clazz)                      self.parent._SetClassification(self.clazz)
# Line 227  class ClassGenDialog(wxDialog): Line 239  class ClassGenDialog(wxDialog):
239                  delta = 1 / float(numGroups)                  delta = 1 / float(numGroups)
240                  percents = [delta * i for i in range(1, numGroups + 1)]                  percents = [delta * i for i in range(1, numGroups + 1)]
241                  adjusted, self.clazz = \                  adjusted, self.clazz = \
242                      ClassGenerator().GenQuantiles(_list, percents, ramp, _range)                      generate_quantiles(_list, percents, ramp, _range)
243    
244                  if adjusted:                  if adjusted:
245                      dlg = wxMessageDialog(self,                      dlg = wxMessageDialog(self,
# Line 288  class ClassGenDialog(wxDialog): Line 300  class ClassGenDialog(wxDialog):
300    
301          clazz, obj = choice.GetClientData(sel)          clazz, obj = choice.GetClientData(sel)
302    
         if obj is None:  
             obj = clazz(self, self.layer, self.fieldName, self.fieldType)  
             choice.SetClientData(sel, [clazz, obj])  
   
303          if self.curGenPanel is not None:          if self.curGenPanel is not None:
304              self.curGenPanel.Hide()              self.curGenPanel.Hide()
305              self.sizer_genPanel.Remove(self.curGenPanel)              self.sizer_genPanel.Remove(self.curGenPanel)
# Line 497  class GenUniformPanel(wxPanel): Line 505  class GenUniformPanel(wxPanel):
505              self.parent.AllowGenerate(False)              self.parent.AllowGenerate(False)
506    
507      def _OnRetrieve(self, event):      def _OnRetrieve(self, event):
508            table = self.layer.ShapeStore().Table()
509          if self.layer.table is not None:          if table is not None:
510              wxBeginBusyCursor()              ThubanBeginBusyCursor()
511              min, max = self.layer.table.ValueRange(self.fieldName)              try:
512              self.minCtrl.SetValue(str(min))                  min, max = table.ValueRange(self.fieldName)
513              self.maxCtrl.SetValue(str(max))                  self.minCtrl.SetValue(str(min))
514              wxEndBusyCursor()                  self.maxCtrl.SetValue(str(max))
515                finally:
516                    ThubanEndBusyCursor()
517    
518      def __GetValidatedTypeEntry(self, win, value, type, badValue = None):      def __GetValidatedTypeEntry(self, win, value, type, badValue = None):
519    
# Line 545  class GenUniformPanel(wxPanel): Line 555  class GenUniformPanel(wxPanel):
555          return valid          return valid
556    
557      def __CalcStepping(self, min, max, ngroups):      def __CalcStepping(self, min, max, ngroups):
         step = (max - min) / float(ngroups)  
558          if self.fieldType == FIELDTYPE_INT:          if self.fieldType == FIELDTYPE_INT:
559              step = int(step)              step = int((max - min + 1) / float(ngroups))
560            else:
561                step = (max - min) / float(ngroups)
562    
563          return step          return step
564    
# Line 664  class GenUniquePanel(wxPanel): Line 675  class GenUniquePanel(wxPanel):
675          self.SetAutoLayout(True)          self.SetAutoLayout(True)
676          topSizer.SetSizeHints(self)          topSizer.SetSizeHints(self)
677    
678            width, height = self.list_avail.GetSizeTuple()
679            self.list_avail.SetColumnWidth(0,width)
680            width, height = self.list_use.GetSizeTuple()
681            self.list_use.SetColumnWidth(0,width)
682    
683          self.parent.AllowGenerate(False)          self.parent.AllowGenerate(False)
684    
685      def GetNumGroups(self):      def GetNumGroups(self):
# Line 705  class GenUniquePanel(wxPanel): Line 721  class GenUniquePanel(wxPanel):
721          self.list_avail.DeleteAllItems()          self.list_avail.DeleteAllItems()
722          self.list_avail_data = []          self.list_avail_data = []
723    
724          list = self.layer.table.UniqueValues(self.fieldName)          ThubanBeginBusyCursor()
725          index = 0          try:
726          for v in list:              list = self.layer.ShapeStore().Table().UniqueValues(self.fieldName)
727              self.dataList.append(v)              index = 0
728              i = self.list_avail.InsertStringItem(index, str(v))              for v in list:
729              self.list_avail.SetItemData(index, i)                  self.dataList.append(v)
730                    i = self.list_avail.InsertStringItem(index, str(v))
731              self.list_avail_data.append(v)                  self.list_avail.SetItemData(index, i)
732              index += 1      
733                    self.list_avail_data.append(v)
734                    index += 1
735            finally:
736                ThubanEndBusyCursor()
737    
738      def _OnUseAll(self, event):      def _OnUseAll(self, event):
739          for i in range(self.list_avail.GetItemCount()):          for i in range(self.list_avail.GetItemCount()):
# Line 817  class GenQuantilesPanel(wxPanel): Line 837  class GenQuantilesPanel(wxPanel):
837          return self.__range          return self.__range
838    
839      def GetList(self):      def GetList(self):
840            _list = []
841            table = self.layer.ShapeStore().Table()
842            if table is not None:
843                ThubanBeginBusyCursor()
844                try:
845                    #
846                    # FIXME: Replace with a call to table when the method
847                    # has been written to get all the values
848                    #
849                    for i in range(table.NumRows()):
850                        _list.append(table.ReadValue(i, self.fieldName))
851                finally:
852                    ThubanEndBusyCursor()
853    
854          if self.layer.table is not None:          return _list
             wxBeginBusyCursor()  
             _list = self.layer.table.UniqueValues(self.fieldName)  
             wxEndBusyCursor()  
             return _list  
   
         return []  
855    
856      def OnRangeText(self, event):      def OnRangeText(self, event):
857    
# Line 839  class GenQuantilesPanel(wxPanel): Line 866  class GenQuantilesPanel(wxPanel):
866              self.text_range.SetForegroundColour(wxRED)              self.text_range.SetForegroundColour(wxRED)
867    
868      def OnRetrieve(self, event):      def OnRetrieve(self, event):
869            table = self.layer.ShapeStore().Table()
870          if self.layer.table is not None:          if table is not None:
871              wxBeginBusyCursor()              ThubanBeginBusyCursor()
872              min, max = self.layer.table.ValueRange(self.fieldName)              try:
873              self.text_range.SetValue("[" + str(min) + ";" + str(max) + "]")                  min, max = table.ValueRange(self.fieldName)
874              wxEndBusyCursor()                  self.text_range.SetValue("[" + str(min) + ";" + str(max) + "]")
875                finally:
876                    ThubanEndBusyCursor()
877    
878  ID_CUSTOMRAMP_COPYSTART = 4001  ID_CUSTOMRAMP_COPYSTART = 4001
879  ID_CUSTOMRAMP_COPYEND = 4002  ID_CUSTOMRAMP_COPYEND = 4002

Legend:
Removed from v.877  
changed lines
  Added in v.1274

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26