/[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 1163 by jonathan, Thu Jun 12 12:41:31 2003 UTC revision 1432 by jonathan, Wed Jul 16 13:24:03 2003 UTC
# Line 16  from Thuban.Model.classification import Line 16  from Thuban.Model.classification import
16  from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \  from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \
17       FIELDTYPE_STRING       FIELDTYPE_STRING
18    
19    from Thuban.Model.layer import SHAPETYPE_ARC
20  from Thuban.Model.range import Range  from Thuban.Model.range import Range
21    from Thuban.UI.common import ThubanBeginBusyCursor, ThubanEndBusyCursor
22    
23  import classifier, resource  import classifier, resource
24    
25  from Thuban.Model.classgen import \  from Thuban.Model.classgen import \
26      generate_uniform_distribution, generate_singletons, generate_quantiles, \      generate_uniform_distribution, generate_singletons, generate_quantiles, \
27      CustomRamp, GreyRamp, RedRamp, GreenRamp, BlueRamp, GreenToRedRamp, \      CustomRamp, GreyRamp, RedRamp, GreenRamp, BlueRamp, GreenToRedRamp, \
28      HotToColdRamp      HotToColdRamp, FixedRamp
29    
30    
31  USEALL_BMP  = "group_use_all"  USEALL_BMP  = "group_use_all"
32  USE_BMP     = "group_use"  USE_BMP     = "group_use"
# Line 45  PROPCOMBOSTR_HOT2COLD   = _("Hot-to-Cold Line 48  PROPCOMBOSTR_HOT2COLD   = _("Hot-to-Cold
48  ID_CLASSGEN_GENCOMBO = 4007  ID_CLASSGEN_GENCOMBO = 4007
49  ID_CLASSGEN_PROPCOMBO = 4008  ID_CLASSGEN_PROPCOMBO = 4008
50    
51    ID_BORDER_COLOR = 4009
52    ID_BORDER_COLOR_CHANGE = 4010
53    
54  class ClassGenDialog(wxDialog):  class ClassGenDialog(wxDialog):
55    
56      def __init__(self, parent, layer, fieldName):      def __init__(self, parent, layer, fieldName):
# Line 60  class ClassGenDialog(wxDialog): Line 66  class ClassGenDialog(wxDialog):
66          self.layer = layer          self.layer = layer
67          self.clazz = None          self.clazz = None
68    
69          col = layer.table.Column(fieldName)          col = layer.ShapeStore().Table().Column(fieldName)
70          self.type = col.type          self.type = col.type
71    
72          self.fieldName = fieldName          self.fieldName = fieldName
# Line 75  class ClassGenDialog(wxDialog): Line 81  class ClassGenDialog(wxDialog):
81          # panels they will call AllowGenerate() which uses genButton.          # panels they will call AllowGenerate() which uses genButton.
82          #          #
83          self.genButton = wxButton(self, wxID_OK, _("Generate"))          self.genButton = wxButton(self, wxID_OK, _("Generate"))
         self.genButton.SetDefault()  
84          self.cancelButton = wxButton(self, wxID_CANCEL, _("Close"))          self.cancelButton = wxButton(self, wxID_CANCEL, _("Close"))
85            self.genButton.SetDefault()
86    
87          self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO)          self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO)
88    
# Line 130  class ClassGenDialog(wxDialog): Line 136  class ClassGenDialog(wxDialog):
136          self.propPanel = None          self.propPanel = None
137          custom_ramp_panel = CustomRampPanel(self, layer.ShapeType())          custom_ramp_panel = CustomRampPanel(self, layer.ShapeType())
138    
139          self.propCombo.Append(PROPCOMBOSTR_GREY,  GreyRamp())          self.propCombo.Append(PROPCOMBOSTR_GREY,  GreyRamp)
140          self.propCombo.Append(PROPCOMBOSTR_RED,   RedRamp())          self.propCombo.Append(PROPCOMBOSTR_RED,   RedRamp)
141          self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp())          self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp)
142          self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp())          self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp)
143          self.propCombo.Append(PROPCOMBOSTR_GREEN2RED, GreenToRedRamp())          self.propCombo.Append(PROPCOMBOSTR_GREEN2RED, GreenToRedRamp)
144          self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())          self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())
145          self.propCombo.Append(PROPCOMBOSTR_CUSTOM, custom_ramp_panel)          self.propCombo.Append(PROPCOMBOSTR_CUSTOM, custom_ramp_panel)
146    
# Line 143  class ClassGenDialog(wxDialog): Line 149  class ClassGenDialog(wxDialog):
149          psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4)          psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4)
150          sizer.Add(psizer, 0, wxALL | wxGROW, 4)          sizer.Add(psizer, 0, wxALL | wxGROW, 4)
151    
152            if layer.ShapeType() != SHAPETYPE_ARC:
153                psizer = wxBoxSizer(wxHORIZONTAL)
154                self.fix_border_check = wxCheckBox(self, -1, _("Fix Border Color"))
155                psizer.Add(self.fix_border_check, 0, wxALL | wxGROW, 4)
156                self.border_color = classifier.ClassGroupPropertiesCtrl(
157                    self, ID_BORDER_COLOR,
158                    ClassGroupProperties(), SHAPETYPE_ARC,
159                    style=wxSIMPLE_BORDER, size=(40, 20))
160                psizer.Add(self.border_color, 0, wxALL | wxGROW, 4)
161                psizer.Add(wxButton(self, ID_BORDER_COLOR_CHANGE, _("Change")),
162                        0, wxALL, 4)
163                sizer.Add(psizer, 0, wxALL | wxGROW, 4)
164                EVT_BUTTON(self, ID_BORDER_COLOR_CHANGE, self.OnBorderColorChange)
165            else:
166                self.border_color = None
167    
168          sizer.Add(custom_ramp_panel, 1, wxGROW | wxALL, 4)          sizer.Add(custom_ramp_panel, 1, wxGROW | wxALL, 4)
169          sizer.Show(custom_ramp_panel, False)          sizer.Show(custom_ramp_panel, False)
170    
# Line 201  class ClassGenDialog(wxDialog): Line 223  class ClassGenDialog(wxDialog):
223              propPanel = self.propCombo.GetClientData(index)              propPanel = self.propCombo.GetClientData(index)
224    
225              ramp = propPanel.GetRamp()              ramp = propPanel.GetRamp()
226                if self.border_color and self.fix_border_check.IsChecked():
227                    props = self.border_color.GetProperties()
228                    ramp = FixedRamp(ramp,
229                        (props.GetLineColor(), props.GetLineWidth(), None))
230    
231              if genSel == GENCOMBOSTR_UNIFORM:              if genSel == GENCOMBOSTR_UNIFORM:
232    
# Line 221  class ClassGenDialog(wxDialog): Line 247  class ClassGenDialog(wxDialog):
247    
248                  list = genPanel.GetValueList()                  list = genPanel.GetValueList()
249    
250                  if len(list) > 0 \                  if len(list) > 0:
251                      and numGroups is not None:                      self.clazz = generate_singletons(list, ramp)
   
                     self.clazz = generate_singletons(  
                                     list, numGroups, ramp)  
   
252                      self.parent._SetClassification(self.clazz)                      self.parent._SetClassification(self.clazz)
253    
254              elif genSel == GENCOMBOSTR_QUANTILES:              elif genSel == GENCOMBOSTR_QUANTILES:
# Line 256  class ClassGenDialog(wxDialog): Line 278  class ClassGenDialog(wxDialog):
278      def OnCancel(self, event):      def OnCancel(self, event):
279          self.Close()          self.Close()
280    
281        def OnBorderColorChange(self, event):
282            self.border_color.DoEdit()
283    
284      def _OnGenTypeSelect(self, event):      def _OnGenTypeSelect(self, event):
285          self.__DoOnGenTypeSelect()          self.__DoOnGenTypeSelect()
286          return          return
# Line 504  class GenUniformPanel(wxPanel): Line 529  class GenUniformPanel(wxPanel):
529              self.parent.AllowGenerate(False)              self.parent.AllowGenerate(False)
530    
531      def _OnRetrieve(self, event):      def _OnRetrieve(self, event):
532            table = self.layer.ShapeStore().Table()
533          if self.layer.table is not None:          if table is not None:
534              wxBeginBusyCursor()              ThubanBeginBusyCursor()
535              try:              try:
536                  min, max = self.layer.table.ValueRange(self.fieldName)                  min, max = table.ValueRange(self.fieldName)
537                  self.minCtrl.SetValue(str(min))                  self.minCtrl.SetValue(str(min))
538                  self.maxCtrl.SetValue(str(max))                  self.maxCtrl.SetValue(str(max))
539              finally:              finally:
540                  wxEndBusyCursor()                  ThubanEndBusyCursor()
541    
542      def __GetValidatedTypeEntry(self, win, value, type, badValue = None):      def __GetValidatedTypeEntry(self, win, value, type, badValue = None):
543    
# Line 720  class GenUniquePanel(wxPanel): Line 745  class GenUniquePanel(wxPanel):
745          self.list_avail.DeleteAllItems()          self.list_avail.DeleteAllItems()
746          self.list_avail_data = []          self.list_avail_data = []
747    
748          list = self.layer.table.UniqueValues(self.fieldName)          ThubanBeginBusyCursor()
749          index = 0          try:
750          for v in list:              list = self.layer.ShapeStore().Table().UniqueValues(self.fieldName)
751              self.dataList.append(v)              index = 0
752              i = self.list_avail.InsertStringItem(index, str(v))              for v in list:
753              self.list_avail.SetItemData(index, i)                  self.dataList.append(v)
754                    i = self.list_avail.InsertStringItem(index, str(v))
755              self.list_avail_data.append(v)                  self.list_avail.SetItemData(index, i)
756              index += 1      
757                    self.list_avail_data.append(v)
758                    index += 1
759            finally:
760                ThubanEndBusyCursor()
761    
762      def _OnUseAll(self, event):      def _OnUseAll(self, event):
763          for i in range(self.list_avail.GetItemCount()):          for i in range(self.list_avail.GetItemCount()):
# Line 832  class GenQuantilesPanel(wxPanel): Line 861  class GenQuantilesPanel(wxPanel):
861          return self.__range          return self.__range
862    
863      def GetList(self):      def GetList(self):
   
864          _list = []          _list = []
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                  #                  #
870                  # FIXME: Replace with a call to table when the method                  # FIXME: Replace with a call to table when the method
871                  # has been written to get all the values                  # has been written to get all the values
872                  #                  #
                 table = self.layer.table  
873                  for i in range(table.NumRows()):                  for i in range(table.NumRows()):
874                      _list.append(table.ReadValue(i, self.fieldName))                      _list.append(table.ReadValue(i, self.fieldName))
875              finally:              finally:
876                  wxEndBusyCursor()                  ThubanEndBusyCursor()
877    
878          return _list          return _list
879    
# Line 863  class GenQuantilesPanel(wxPanel): Line 890  class GenQuantilesPanel(wxPanel):
890              self.text_range.SetForegroundColour(wxRED)              self.text_range.SetForegroundColour(wxRED)
891    
892      def OnRetrieve(self, event):      def OnRetrieve(self, event):
893            table = self.layer.ShapeStore().Table()
894          if self.layer.table is not None:          if table is not None:
895              wxBeginBusyCursor()              ThubanBeginBusyCursor()
896              try:              try:
897                  min, max = self.layer.table.ValueRange(self.fieldName)                  min, max = table.ValueRange(self.fieldName)
898                  self.text_range.SetValue("[" + str(min) + ";" + str(max) + "]")                  self.text_range.SetValue("[" + str(min) + ";" + str(max) + "]")
899              finally:              finally:
900                  wxEndBusyCursor()                  ThubanEndBusyCursor()
901    
902  ID_CUSTOMRAMP_COPYSTART = 4001  ID_CUSTOMRAMP_COPYSTART = 4001
903  ID_CUSTOMRAMP_COPYEND = 4002  ID_CUSTOMRAMP_COPYEND = 4002

Legend:
Removed from v.1163  
changed lines
  Added in v.1432

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26