/[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 677 by jonathan, Tue Apr 15 19:21:01 2003 UTC revision 834 by bh, Tue May 6 15:52:36 2003 UTC
# Line 23  import classifier Line 23  import classifier
23    
24  import resource  import resource
25    
 from Thuban.common import Str2Num  
   
 ID_CLASSGEN_GEN = 4001  
 ID_CLASSGEN_CLOSE = 4002  
26  ID_CLASSGEN_GENCOMBO = 4007  ID_CLASSGEN_GENCOMBO = 4007
27  ID_CLASSGEN_PROPCOMBO = 4008  ID_CLASSGEN_PROPCOMBO = 4008
28    
# Line 46  PROPCOMBOSTR_BLUE       = _("Blue Ramp") Line 42  PROPCOMBOSTR_BLUE       = _("Blue Ramp")
42  PROPCOMBOSTR_HOT2COLD   = _("Hot-to-Cold Ramp")  PROPCOMBOSTR_HOT2COLD   = _("Hot-to-Cold Ramp")
43    
44  class ClassGenDialog(wxDialog):  class ClassGenDialog(wxDialog):
45                                                                                    
46      def __init__(self, parent, layer, fieldName):      def __init__(self, parent, layer, fieldName):
47          """Inialize the class generating dialog.          """Inialize the class generating dialog.
48    
# Line 55  class ClassGenDialog(wxDialog): Line 51  class ClassGenDialog(wxDialog):
51    
52          wxDialog.__init__(self, parent, -1, _("Generate Classification"),          wxDialog.__init__(self, parent, -1, _("Generate Classification"),
53                            style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)                            style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
54                                                                                    
55          self.parent = parent          self.parent = parent
56          self.clazz = None          self.clazz = None
57    
58          self.type, name, width, prec = layer.table.field_info_by_name(fieldName)          col = layer.table.Column(fieldName)
59            self.type = col.type
60    
61          #############          #############
62          # we need to create genButton first because when we create the          # we need to create genButton first because when we create the
63          # panels they will call AllowGenerate() which uses genButton.          # panels they will call AllowGenerate() which uses genButton.
64          #          #
65          buttonSizer = wxBoxSizer(wxHORIZONTAL)          self.genButton = wxButton(self, wxID_OK, _("Generate"))
66          self.genButton = wxButton(self, ID_CLASSGEN_GEN, _("Generate"))          self.genButton.SetDefault()
67    
68          buttonSizer.Add(self.genButton, 0, wxALL, 4)          self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO)
69          buttonSizer.Add(60, 20, 0, wxALL, 4)  
70          buttonSizer.Add(wxButton(self, ID_CLASSGEN_CLOSE, _("Close")),          uniq_panel = GenUniquePanel(self, layer, fieldName, self.type)
71                          0, wxALL, 4)  
72            self.genPanel = uniq_panel
73            self.genChoice.Append(GENCOMBOSTR_UNIQUE, uniq_panel)
74    
75            if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):
76                uni_panel = GenUniformPanel(self, layer, fieldName, self.type)
77                self.genChoice.Append(GENCOMBOSTR_UNIFORM, uni_panel)
78    
79            self.genChoice.SetSelection(0)
80    
81            self.propPanel = None
82            custom_ramp_panel = CustomRampPanel(self, layer.ShapeType())
83    
84            self.propCombo = wxChoice(self, ID_CLASSGEN_PROPCOMBO)
85            self.propCombo.Append(PROPCOMBOSTR_GREY,  GreyRamp())
86            self.propCombo.Append(PROPCOMBOSTR_RED,   RedRamp())
87            self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp())
88            self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp())
89            self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())
90            self.propCombo.Append(PROPCOMBOSTR_CUSTOM, custom_ramp_panel)
91    
92            self.propCombo.SetSelection(0)
93    
94          #############          #############
95    
# Line 87  class ClassGenDialog(wxDialog): Line 105  class ClassGenDialog(wxDialog):
105          psizer = wxBoxSizer(wxHORIZONTAL)          psizer = wxBoxSizer(wxHORIZONTAL)
106          psizer.Add(wxStaticText(self, -1, _("Generate:")),          psizer.Add(wxStaticText(self, -1, _("Generate:")),
107              0, wxALIGN_CENTER_VERTICAL, 0)              0, wxALIGN_CENTER_VERTICAL, 0)
108            psizer.Add(self.genChoice, 1, wxALL | wxGROW, 4)
         self.genCombo = wxComboBox(self,  
                                    ID_CLASSGEN_GENCOMBO,  
                                    "", style = wxCB_READONLY)  
         psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4)  
         EVT_COMBOBOX(self, ID_CLASSGEN_GENCOMBO, self._OnGenTypeSelect)  
109    
110          sizer.Add(psizer, 0, wxALL | wxGROW, 4)          sizer.Add(psizer, 0, wxALL | wxGROW, 4)
111            sizer.Add(self.genPanel, 1, wxGROW | wxALL, 4)
112    
113          #############          sizer.Show(uniq_panel, True)
   
         self.genPanel = None  
   
         panel = GenUniquePanel(self, layer, fieldName, self.type)  
         self.genCombo.Append(GENCOMBOSTR_UNIQUE, panel)  
         sizer.Add(panel, 1, wxGROW | wxALL, 4)  
   
         self.genPanel = panel  
   
114          if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):          if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):
115              panel = GenUniformPanel(self, layer, fieldName, self.type)              sizer.Add(uni_panel, 1, wxGROW | wxALL, 4)
116              self.genCombo.Append(GENCOMBOSTR_UNIFORM, panel)              sizer.Show(uni_panel, False)
             sizer.Add(panel, 1, wxGROW | wxALL, 4)  
             sizer.Show(panel, False)  
   
         self.genCombo.SetSelection(0)  
   
         #############  
117    
118          psizer = wxBoxSizer(wxHORIZONTAL)          psizer = wxBoxSizer(wxHORIZONTAL)
119          psizer.Add(wxStaticText(self, -1, _("Color Scheme:")),          psizer.Add(wxStaticText(self, -1, _("Color Scheme:")),
120              0, wxALIGN_CENTER_VERTICAL, 0)              0, wxALIGN_CENTER_VERTICAL, 0)
   
         self.propCombo = wxComboBox(self,  
                                    ID_CLASSGEN_PROPCOMBO,  
                                    "", style = wxCB_READONLY)  
121          psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4)          psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4)
         EVT_COMBOBOX(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect)  
122          sizer.Add(psizer, 0, wxALL | wxGROW, 4)          sizer.Add(psizer, 0, wxALL | wxGROW, 4)
123    
124          #############          sizer.Add(custom_ramp_panel, 1, wxGROW | wxALL, 4)
125            sizer.Show(custom_ramp_panel, False)
         self.propPanel = None  
         panel = CustomRampPanel(self, layer.ShapeType())  
         sizer.Add(panel, 1, wxALL | wxGROW, 4)  
         sizer.Show(panel, False)  
   
         self.propCombo.Append(PROPCOMBOSTR_GREY,  GreyRamp())  
         self.propCombo.Append(PROPCOMBOSTR_RED,   RedRamp())  
         self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp())  
         self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp())  
         self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())  
         self.propCombo.Append(PROPCOMBOSTR_CUSTOM, panel)  
   
         self.propCombo.SetSelection(0)  
   
   
         #############  
126    
127            buttonSizer = wxBoxSizer(wxHORIZONTAL)
128            buttonSizer.Add(self.genButton, 0, wxALL, 4)
129            buttonSizer.Add(60, 20, 0, wxALL, 4)
130            buttonSizer.Add(wxButton(self, wxID_CANCEL, _("Close")),
131                            0, wxALL, 4)
132          sizer.Add(buttonSizer, 0,          sizer.Add(buttonSizer, 0,
133                    wxALL | wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL, 4)                    wxALL | wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL, 4)
134    
   
135          self.SetSizer(sizer)          self.SetSizer(sizer)
136          self.SetAutoLayout(True)          self.SetAutoLayout(True)
137          sizer.SetSizeHints(self)          sizer.SetSizeHints(self)
138    
139          self.sizer = sizer          self.sizer = sizer
140    
141          EVT_BUTTON(self, ID_CLASSGEN_GEN, self._OnGenerate)          EVT_CHOICE(self, ID_CLASSGEN_GENCOMBO, self._OnGenTypeSelect)
142          EVT_BUTTON(self, ID_CLASSGEN_CLOSE, self._OnCloseBtn)          EVT_CHOICE(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect)
143            EVT_BUTTON(self, wxID_OK, self.OnOK)
144            EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
145    
146    
147            self.genChoice.SetFocus()
148    
149      def GetClassification(self):      def GetClassification(self):
150          return self.clazz          return self.clazz
# Line 165  class ClassGenDialog(wxDialog): Line 152  class ClassGenDialog(wxDialog):
152      def AllowGenerate(self, on):      def AllowGenerate(self, on):
153          pass #self.genButton.Enable(on)          pass #self.genButton.Enable(on)
154    
155      def _OnGenerate(self, event):      def OnOK(self, event):
156            """This is really the generate button, but we want to override
157            the wxDialog class.
158            """
159    
160          index = self.genCombo.GetSelection()          index = self.genChoice.GetSelection()
161    
162          genSel = self.genCombo.GetString(index)          genSel = self.genChoice.GetString(index)
163          genPanel = self.genCombo.GetClientData(index)          genPanel = self.genChoice.GetClientData(index)
164    
165          propPanel = self.propPanel          propPanel = self.propPanel
166    
# Line 211  class ClassGenDialog(wxDialog): Line 201  class ClassGenDialog(wxDialog):
201    
202                      self.parent._SetClassification(self.clazz)                      self.parent._SetClassification(self.clazz)
203    
204      def _OnCloseBtn(self, event):      def OnCancel(self, event):
205          self.Close()          self.Close()
206    
207      def _OnGenTypeSelect(self, event):      def _OnGenTypeSelect(self, event):
# Line 442  class GenUniformPanel(wxPanel): Line 432  class GenUniformPanel(wxPanel):
432      def _OnRetrieve(self, event):      def _OnRetrieve(self, event):
433    
434          if self.layer.table is not None:          if self.layer.table is not None:
435              range = self.layer.table.field_range(self.fieldName)              wxBeginBusyCursor()
436              self.minCtrl.SetValue(str(range[0][0]))              min, max = self.layer.table.ValueRange(self.fieldName)
437              self.maxCtrl.SetValue(str(range[1][0]))              self.minCtrl.SetValue(str(min))
438                self.maxCtrl.SetValue(str(max))
439                wxEndBusyCursor()
440    
441      def __GetValidatedTypeEntry(self, win, value, type, badValue = None):      def __GetValidatedTypeEntry(self, win, value, type, badValue = None):
442    
# Line 486  class GenUniformPanel(wxPanel): Line 478  class GenUniformPanel(wxPanel):
478          return valid          return valid
479    
480      def __CalcStepping(self, min, max, ngroups):      def __CalcStepping(self, min, max, ngroups):
481          step = Str2Num(str((max - min) / float(ngroups)))          step = (max - min) / float(ngroups)
482          if self.fieldType == FIELDTYPE_INT:          if self.fieldType == FIELDTYPE_INT:
483              step = int(step)              step = int(step)
484    
# Line 648  class GenUniquePanel(wxPanel): Line 640  class GenUniquePanel(wxPanel):
640          self.list_avail.DeleteAllItems()          self.list_avail.DeleteAllItems()
641          self.list_avail_data = []          self.list_avail_data = []
642    
643          list = self.layer.table.GetUniqueValues(self.fieldName)          list = self.layer.table.UniqueValues(self.fieldName)
644          index = 0          index = 0
645          for v in list:          for v in list:
646              self.dataList.append(v)              self.dataList.append(v)
# Line 827  class ClassGenerator: Line 819  class ClassGenerator:
819          clazz = Classification()          clazz = Classification()
820    
821          #step = int((max - min) / float(numGroups))          #step = int((max - min) / float(numGroups))
         step = int(Str2Num(str((max - min + 1) / float(numGroups))))  
822    
823          if numGroups > 0:          if numGroups > 0:
824    
825                step = int((max - min + 1) / float(numGroups))
826              cur_value = min              cur_value = min
827    
828              ramp.SetNumGroups(numGroups)              ramp.SetNumGroups(numGroups)
829    
830              for prop in ramp:              for prop in ramp:
831                  clazz.AppendGroup(                  clazz.AppendGroup(ClassGroupSingleton(cur_value), prop)
                     ClassGroupSingleton(  
                         Str2Num(str(cur_value)),  
                         prop))  
832                  cur_value += step                  cur_value += step
833    
834          return clazz          return clazz
# Line 859  class ClassGenerator: Line 849  class ClassGenerator:
849    
850          ramp.SetNumGroups(numGroups)          ramp.SetNumGroups(numGroups)
851    
852          step = Str2Num(str((max - min) / float(numGroups)))          step = (max - min) / float(numGroups)
853    
854          if intStep:          if intStep:
855              step = int(step)              step = int(step)
# Line 875  class ClassGenerator: Line 865  class ClassGenerator:
865    
866              # this check guards against rounding issues              # this check guards against rounding issues
867              if cur_min != cur_max:              if cur_min != cur_max:
868                  clazz.AppendGroup(                  clazz.AppendGroup(ClassGroupRange(cur_min, cur_max, prop))
                     ClassGroupRange(  
                         Str2Num(str(cur_min)),  
                         Str2Num(str(cur_max)),  
                         prop))  
869    
870              cur_min = cur_max              cur_min = cur_max
871              cur_max += step              cur_max += step

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26