/[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 654 by jonathan, Fri Apr 11 15:49:58 2003 UTC revision 812 by jonathan, Mon May 5 15:04:06 2003 UTC
# Line 5  Line 5 
5  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
6  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
7    
8    import sys
9    
10  from Thuban import _  from Thuban import _
11    
12  from wxPython.wx import *  from wxPython.wx import *
# Line 21  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 63  class ClassGenDialog(wxDialog): Line 61  class ClassGenDialog(wxDialog):
61          # we need to create genButton first because when we create the          # we need to create genButton first because when we create the
62          # panels they will call AllowGenerate() which uses genButton.          # panels they will call AllowGenerate() which uses genButton.
63          #          #
64          buttonSizer = wxBoxSizer(wxHORIZONTAL)          self.genButton = wxButton(self, wxID_OK, _("Generate"))
65          self.genButton = wxButton(self, ID_CLASSGEN_GEN, _("Generate"))          self.genButton.SetDefault()
66    
67          buttonSizer.Add(self.genButton, 0, wxALL, 4)          self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO)
68          buttonSizer.Add(60, 20, 0, wxALL, 4)  
69          buttonSizer.Add(wxButton(self, ID_CLASSGEN_CLOSE, _("Close")),          uniq_panel = GenUniquePanel(self, layer, fieldName, self.type)
70                          0, wxALL, 4)  
71            self.genPanel = uniq_panel
72            self.genChoice.Append(GENCOMBOSTR_UNIQUE, uniq_panel)
73    
74            if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):
75                uni_panel = GenUniformPanel(self, layer, fieldName, self.type)
76                self.genChoice.Append(GENCOMBOSTR_UNIFORM, uni_panel)
77    
78            self.genChoice.SetSelection(0)
79    
80            self.propPanel = None
81            custom_ramp_panel = CustomRampPanel(self, layer.ShapeType())
82    
83            self.propCombo = wxChoice(self, ID_CLASSGEN_PROPCOMBO)
84            self.propCombo.Append(PROPCOMBOSTR_GREY,  GreyRamp())
85            self.propCombo.Append(PROPCOMBOSTR_RED,   RedRamp())
86            self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp())
87            self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp())
88            self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())
89            self.propCombo.Append(PROPCOMBOSTR_CUSTOM, custom_ramp_panel)
90    
91            self.propCombo.SetSelection(0)
92    
93          #############          #############
94    
# Line 85  class ClassGenDialog(wxDialog): Line 104  class ClassGenDialog(wxDialog):
104          psizer = wxBoxSizer(wxHORIZONTAL)          psizer = wxBoxSizer(wxHORIZONTAL)
105          psizer.Add(wxStaticText(self, -1, _("Generate:")),          psizer.Add(wxStaticText(self, -1, _("Generate:")),
106              0, wxALIGN_CENTER_VERTICAL, 0)              0, wxALIGN_CENTER_VERTICAL, 0)
107            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)  
108    
109          sizer.Add(psizer, 0, wxALL | wxGROW, 4)          sizer.Add(psizer, 0, wxALL | wxGROW, 4)
110            sizer.Add(self.genPanel, 1, wxGROW | wxALL, 4)
111    
112          #############          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  
   
113          if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):          if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):
114              panel = GenUniformPanel(self, layer, fieldName, self.type)              sizer.Add(uni_panel, 1, wxGROW | wxALL, 4)
115              self.genCombo.Append(GENCOMBOSTR_UNIFORM, panel)              sizer.Show(uni_panel, False)
             sizer.Add(panel, 0, wxGROW | wxALL, 4)  
             sizer.Show(panel, False)  
   
         #############  
116    
117          psizer = wxBoxSizer(wxHORIZONTAL)          psizer = wxBoxSizer(wxHORIZONTAL)
118          psizer.Add(wxStaticText(self, -1, _("Color Schemes:")),          psizer.Add(wxStaticText(self, -1, _("Color Scheme:")),
119              0, wxALIGN_CENTER_VERTICAL, 0)              0, wxALIGN_CENTER_VERTICAL, 0)
   
         self.propCombo = wxComboBox(self,  
                                    ID_CLASSGEN_PROPCOMBO,  
                                    "", style = wxCB_READONLY)  
120          psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4)          psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4)
         EVT_COMBOBOX(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect)  
121          sizer.Add(psizer, 0, wxALL | wxGROW, 4)          sizer.Add(psizer, 0, wxALL | wxGROW, 4)
122    
123          #############          sizer.Add(custom_ramp_panel, 1, wxGROW | wxALL, 4)
124            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)  
   
   
   
         #############  
125    
126            buttonSizer = wxBoxSizer(wxHORIZONTAL)
127            buttonSizer.Add(self.genButton, 0, wxALL, 4)
128            buttonSizer.Add(60, 20, 0, wxALL, 4)
129            buttonSizer.Add(wxButton(self, wxID_CANCEL, _("Close")),
130                            0, wxALL, 4)
131          sizer.Add(buttonSizer, 0,          sizer.Add(buttonSizer, 0,
132                    wxALL | wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL, 4)                    wxALL | wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL, 4)
133    
   
134          self.SetSizer(sizer)          self.SetSizer(sizer)
135          self.SetAutoLayout(True)          self.SetAutoLayout(True)
136          sizer.SetSizeHints(self)          sizer.SetSizeHints(self)
137    
138          self.sizer = sizer          self.sizer = sizer
139    
140          EVT_BUTTON(self, ID_CLASSGEN_GEN, self._OnGenerate)          EVT_CHOICE(self, ID_CLASSGEN_GENCOMBO, self._OnGenTypeSelect)
141          EVT_BUTTON(self, ID_CLASSGEN_CLOSE, self._OnCloseBtn)          EVT_CHOICE(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect)
142            EVT_BUTTON(self, wxID_OK, self.OnOK)
143            EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
144    
145    
146            self.genChoice.SetFocus()
147    
148      def GetClassification(self):      def GetClassification(self):
149          return self.clazz          return self.clazz
# Line 160  class ClassGenDialog(wxDialog): Line 151  class ClassGenDialog(wxDialog):
151      def AllowGenerate(self, on):      def AllowGenerate(self, on):
152          pass #self.genButton.Enable(on)          pass #self.genButton.Enable(on)
153    
154      def _OnGenerate(self, event):      def OnOK(self, event):
155            """This is really the generate button, but we want to override
156            the wxDialog class.
157            """
158    
159          index = self.genCombo.GetSelection()          index = self.genChoice.GetSelection()
160    
161          genSel = self.genCombo.GetString(index)          genSel = self.genChoice.GetString(index)
162          genPanel = self.genCombo.GetClientData(index)          genPanel = self.genChoice.GetClientData(index)
163    
164          propPanel = self.propPanel          propPanel = self.propPanel
165    
# Line 206  class ClassGenDialog(wxDialog): Line 200  class ClassGenDialog(wxDialog):
200    
201                      self.parent._SetClassification(self.clazz)                      self.parent._SetClassification(self.clazz)
202    
203      def _OnCloseBtn(self, event):      def OnCancel(self, event):
204          self.Close()          self.Close()
205    
206      def _OnGenTypeSelect(self, event):      def _OnGenTypeSelect(self, event):
# Line 287  class GenUniformPanel(wxPanel): Line 281  class GenUniformPanel(wxPanel):
281          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
282    
283          sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4)          sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4)
284          self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS, style=wxTE_RIGHT)          self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS,
285                                            style=wxTE_RIGHT)
286          EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)          EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)
287          EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)          EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)
288          sizer.Add(self.numGroupsCtrl, 1, wxALL, 4)          sizer.Add(self.numGroupsCtrl, 1, wxALL, 4)
# Line 308  class GenUniformPanel(wxPanel): Line 303  class GenUniformPanel(wxPanel):
303          self.numGroupsChanging = False          self.numGroupsChanging = False
304          self.steppingChanging = False          self.steppingChanging = False
305    
306          self.numGroupsCtrl.SetRange(1, 100)          self.numGroupsCtrl.SetRange(1, sys.maxint)
307    
308          self.numGroupsCtrl.SetValue(1)          self.numGroupsCtrl.SetValue(1)
309          self.stepCtrl.SetValue("1")          self.stepCtrl.SetValue("1")
# Line 358  class GenUniformPanel(wxPanel): Line 353  class GenUniformPanel(wxPanel):
353          self.numGroupsCtrl.Enable(on)          self.numGroupsCtrl.Enable(on)
354          self.stepCtrl.Enable(on)          self.stepCtrl.Enable(on)
355    
         if on:  
             self.numGroupsCtrl.SetRange(1, abs(max - min) / 0.001)  
   
356          ngroups = self.GetNumGroups()          ngroups = self.GetNumGroups()
357    
358          if ngroups is not None  \          if ngroups is not None  \
# Line 391  class GenUniformPanel(wxPanel): Line 383  class GenUniformPanel(wxPanel):
383          min = self.GetMin()          min = self.GetMin()
384          max = self.GetMax()          max = self.GetMax()
385    
         if ngroups >= self.numGroupsCtrl.GetMax():  
             self.numGroupsCtrl.SetRange(1, ngroups + 1)  
   
386          if ngroups is not None  \          if ngroups is not None  \
387              and min is not None \              and min is not None \
388              and max is not None \              and max is not None \
# Line 442  class GenUniformPanel(wxPanel): Line 431  class GenUniformPanel(wxPanel):
431      def _OnRetrieve(self, event):      def _OnRetrieve(self, event):
432    
433          if self.layer.table is not None:          if self.layer.table is not None:
434                wxBeginBusyCursor()
435              range = self.layer.table.field_range(self.fieldName)              range = self.layer.table.field_range(self.fieldName)
436              self.minCtrl.SetValue(str(range[0][0]))              self.minCtrl.SetValue(str(range[0][0]))
437              self.maxCtrl.SetValue(str(range[1][0]))              self.maxCtrl.SetValue(str(range[1][0]))
438                wxEndBusyCursor()
439    
440      def __GetValidatedTypeEntry(self, win, value, type, badValue = None):      def __GetValidatedTypeEntry(self, win, value, type, badValue = None):
441    
# Line 486  class GenUniformPanel(wxPanel): Line 477  class GenUniformPanel(wxPanel):
477          return valid          return valid
478    
479      def __CalcStepping(self, min, max, ngroups):      def __CalcStepping(self, min, max, ngroups):
480          step = Str2Num(str((max - min) / float(ngroups)))          step = (max - min) / float(ngroups)
481          if self.fieldType == FIELDTYPE_INT:          if self.fieldType == FIELDTYPE_INT:
482              step = int(step)              step = int(step)
483    
# Line 827  class ClassGenerator: Line 818  class ClassGenerator:
818          clazz = Classification()          clazz = Classification()
819    
820          #step = int((max - min) / float(numGroups))          #step = int((max - min) / float(numGroups))
         step = int(Str2Num(str((max - min + 1) / float(numGroups))))  
821    
822          if numGroups > 0:          if numGroups > 0:
823    
824                step = int((max - min + 1) / float(numGroups))
825              cur_value = min              cur_value = min
826    
827              ramp.SetNumGroups(numGroups)              ramp.SetNumGroups(numGroups)
828    
829              for prop in ramp:              for prop in ramp:
830                  clazz.AppendGroup(                  clazz.AppendGroup(ClassGroupSingleton(cur_value), prop)
                     ClassGroupSingleton(  
                         Str2Num(str(cur_value)),  
                         prop))  
831                  cur_value += step                  cur_value += step
832    
833          return clazz          return clazz
# Line 859  class ClassGenerator: Line 848  class ClassGenerator:
848    
849          ramp.SetNumGroups(numGroups)          ramp.SetNumGroups(numGroups)
850    
851          step = Str2Num(str((max - min) / float(numGroups)))          step = (max - min) / float(numGroups)
852    
853          if intStep:          if intStep:
854              step = int(step)              step = int(step)
# Line 875  class ClassGenerator: Line 864  class ClassGenerator:
864    
865              # this check guards against rounding issues              # this check guards against rounding issues
866              if cur_min != cur_max:              if cur_min != cur_max:
867                  clazz.AppendGroup(                  clazz.AppendGroup(ClassGroupRange(cur_min, cur_max, prop))
                     ClassGroupRange(  
                         Str2Num(str(cur_min)),  
                         Str2Num(str(cur_max)),  
                         prop))  
868    
869              cur_min = cur_max              cur_min = cur_max
870              cur_max += step              cur_max += step

Legend:
Removed from v.654  
changed lines
  Added in v.812

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26