/[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 649 by jonathan, Fri Apr 11 14:27:12 2003 UTC revision 781 by jonathan, Tue Apr 29 16:53:38 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  
   
26  ID_CLASSGEN_GEN = 4001  ID_CLASSGEN_GEN = 4001
27  ID_CLASSGEN_CLOSE = 4002  ID_CLASSGEN_CLOSE = 4002
28  ID_CLASSGEN_GENCOMBO = 4007  ID_CLASSGEN_GENCOMBO = 4007
# Line 86  class ClassGenDialog(wxDialog): Line 86  class ClassGenDialog(wxDialog):
86          psizer.Add(wxStaticText(self, -1, _("Generate:")),          psizer.Add(wxStaticText(self, -1, _("Generate:")),
87              0, wxALIGN_CENTER_VERTICAL, 0)              0, wxALIGN_CENTER_VERTICAL, 0)
88    
89          self.genCombo = wxComboBox(self,          self.genChoice = wxChoice(self, ID_CLASSGEN_GENCOMBO)
90                                     ID_CLASSGEN_GENCOMBO,          psizer.Add(self.genChoice, 1, wxALL | wxGROW, 4)
91                                     "", style = wxCB_READONLY)          EVT_CHOICE(self, ID_CLASSGEN_GENCOMBO, self._OnGenTypeSelect)
         psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4)  
         EVT_COMBOBOX(self, ID_CLASSGEN_GENCOMBO, self._OnGenTypeSelect)  
92    
93          sizer.Add(psizer, 0, wxALL | wxGROW, 4)          sizer.Add(psizer, 0, wxALL | wxGROW, 4)
94    
# Line 99  class ClassGenDialog(wxDialog): Line 97  class ClassGenDialog(wxDialog):
97          self.genPanel = None          self.genPanel = None
98    
99          panel = GenUniquePanel(self, layer, fieldName, self.type)          panel = GenUniquePanel(self, layer, fieldName, self.type)
100          self.genCombo.Append(GENCOMBOSTR_UNIQUE, panel)          self.genChoice.Append(GENCOMBOSTR_UNIQUE, panel)
101          sizer.Add(panel, 1, wxGROW | wxALL, 4)          sizer.Add(panel, 1, wxGROW | wxALL, 4)
102    
103          self.genPanel = panel          self.genPanel = panel
104    
105          if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):          if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE):
106              panel = GenUniformPanel(self, layer, fieldName, self.type)              panel = GenUniformPanel(self, layer, fieldName, self.type)
107              self.genCombo.Append(GENCOMBOSTR_UNIFORM, panel)              self.genChoice.Append(GENCOMBOSTR_UNIFORM, panel)
108              sizer.Add(panel, 0, wxGROW | wxALL, 4)              sizer.Add(panel, 1, wxGROW | wxALL, 4)
109              sizer.Show(panel, False)              sizer.Show(panel, False)
110    
111            self.genChoice.SetSelection(0)
112    
113          #############          #############
114    
115          psizer = wxBoxSizer(wxHORIZONTAL)          psizer = wxBoxSizer(wxHORIZONTAL)
116          psizer.Add(wxStaticText(self, -1, _("Color Schemes:")),          psizer.Add(wxStaticText(self, -1, _("Color Scheme:")),
117              0, wxALIGN_CENTER_VERTICAL, 0)              0, wxALIGN_CENTER_VERTICAL, 0)
118    
119          self.propCombo = wxComboBox(self,          self.propCombo = wxChoice(self, ID_CLASSGEN_PROPCOMBO)
                                    ID_CLASSGEN_PROPCOMBO,  
                                    "", style = wxCB_READONLY)  
120          psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4)          psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4)
121          EVT_COMBOBOX(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect)          EVT_CHOICE(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect)
122          sizer.Add(psizer, 0, wxALL | wxGROW, 4)          sizer.Add(psizer, 0, wxALL | wxGROW, 4)
123    
124          #############          #############
# Line 137  class ClassGenDialog(wxDialog): Line 135  class ClassGenDialog(wxDialog):
135          self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())          self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())
136          self.propCombo.Append(PROPCOMBOSTR_CUSTOM, panel)          self.propCombo.Append(PROPCOMBOSTR_CUSTOM, panel)
137    
138            self.propCombo.SetSelection(0)
139    
140    
141          #############          #############
# Line 162  class ClassGenDialog(wxDialog): Line 161  class ClassGenDialog(wxDialog):
161    
162      def _OnGenerate(self, event):      def _OnGenerate(self, event):
163    
164          index = self.genCombo.GetSelection()          index = self.genChoice.GetSelection()
165    
166          genSel = self.genCombo.GetString(index)          genSel = self.genChoice.GetString(index)
167          genPanel = self.genCombo.GetClientData(index)          genPanel = self.genChoice.GetClientData(index)
168    
169          propPanel = self.propPanel          propPanel = self.propPanel
170    
# Line 287  class GenUniformPanel(wxPanel): Line 286  class GenUniformPanel(wxPanel):
286          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
287    
288          sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4)          sizer.Add(wxStaticText(self, -1, _("Number of Groups:")), 0, wxALL, 4)
289          self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS, style=wxTE_RIGHT)          self.numGroupsCtrl = wxSpinCtrl(self, ID_UNIFORM_NGROUPS,
290                                            style=wxTE_RIGHT)
291          EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)          EVT_TEXT(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)
292          EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)          EVT_SPINCTRL(self, ID_UNIFORM_NGROUPS, self._OnNumGroupsChanged)
293          sizer.Add(self.numGroupsCtrl, 1, wxALL, 4)          sizer.Add(self.numGroupsCtrl, 1, wxALL, 4)
# Line 308  class GenUniformPanel(wxPanel): Line 308  class GenUniformPanel(wxPanel):
308          self.numGroupsChanging = False          self.numGroupsChanging = False
309          self.steppingChanging = False          self.steppingChanging = False
310    
311          self.numGroupsCtrl.SetRange(1, 100)          self.numGroupsCtrl.SetRange(1, sys.maxint)
312    
313          self.numGroupsCtrl.SetValue(1)          self.numGroupsCtrl.SetValue(1)
314          self.stepCtrl.SetValue("1")          self.stepCtrl.SetValue("1")
# Line 358  class GenUniformPanel(wxPanel): Line 358  class GenUniformPanel(wxPanel):
358          self.numGroupsCtrl.Enable(on)          self.numGroupsCtrl.Enable(on)
359          self.stepCtrl.Enable(on)          self.stepCtrl.Enable(on)
360    
         if on:  
             self.numGroupsCtrl.SetRange(1, abs(max - min) / 0.001)  
   
361          ngroups = self.GetNumGroups()          ngroups = self.GetNumGroups()
362    
363          if ngroups is not None  \          if ngroups is not None  \
# Line 391  class GenUniformPanel(wxPanel): Line 388  class GenUniformPanel(wxPanel):
388          min = self.GetMin()          min = self.GetMin()
389          max = self.GetMax()          max = self.GetMax()
390    
         if ngroups >= self.numGroupsCtrl.GetMax():  
             self.numGroupsCtrl.SetRange(1, ngroups + 1)  
   
391          if ngroups is not None  \          if ngroups is not None  \
392              and min is not None \              and min is not None \
393              and max is not None \              and max is not None \
# Line 486  class GenUniformPanel(wxPanel): Line 480  class GenUniformPanel(wxPanel):
480          return valid          return valid
481    
482      def __CalcStepping(self, min, max, ngroups):      def __CalcStepping(self, min, max, ngroups):
483          step = Str2Num(str((max - min) / float(ngroups)))          step = (max - min) / float(ngroups)
484          if self.fieldType == FIELDTYPE_INT:          if self.fieldType == FIELDTYPE_INT:
485              step = int(step)              step = int(step)
486    
# Line 827  class ClassGenerator: Line 821  class ClassGenerator:
821          clazz = Classification()          clazz = Classification()
822    
823          #step = int((max - min) / float(numGroups))          #step = int((max - min) / float(numGroups))
         step = int(Str2Num(str((max - min + 1) / float(numGroups))))  
824    
825          if numGroups > 0:          if numGroups > 0:
826    
827                step = int((max - min + 1) / float(numGroups))
828              cur_value = min              cur_value = min
829    
830              ramp.SetNumGroups(numGroups)              ramp.SetNumGroups(numGroups)
831    
832              for prop in ramp:              for prop in ramp:
833                  clazz.AppendGroup(                  clazz.AppendGroup(ClassGroupSingleton(cur_value), prop)
                     ClassGroupSingleton(  
                         Str2Num(str(cur_value)),  
                         prop))  
834                  cur_value += step                  cur_value += step
835    
836          return clazz          return clazz
# Line 859  class ClassGenerator: Line 851  class ClassGenerator:
851    
852          ramp.SetNumGroups(numGroups)          ramp.SetNumGroups(numGroups)
853    
854          step = Str2Num(str((max - min) / float(numGroups)))          step = (max - min) / float(numGroups)
855    
856          if intStep:          if intStep:
857              step = int(step)              step = int(step)
# Line 875  class ClassGenerator: Line 867  class ClassGenerator:
867    
868              # this check guards against rounding issues              # this check guards against rounding issues
869              if cur_min != cur_max:              if cur_min != cur_max:
870                  clazz.AppendGroup(                  clazz.AppendGroup(ClassGroupRange(cur_min, cur_max, prop))
                     ClassGroupRange(  
                         Str2Num(str(cur_min)),  
                         Str2Num(str(cur_max)),  
                         prop))  
871    
872              cur_min = cur_max              cur_min = cur_max
873              cur_max += step              cur_max += step
# Line 1012  class MonochromaticRamp(CustomRamp): Line 1000  class MonochromaticRamp(CustomRamp):
1000    
1001  class GreyRamp(MonochromaticRamp):  class GreyRamp(MonochromaticRamp):
1002      def __init__(self):      def __init__(self):
1003          MonochromaticRamp.__init__(self, Color(0, 0, 0), Color(1, 1, 1))          MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, 0))
1004    
1005  class RedRamp(MonochromaticRamp):  class RedRamp(MonochromaticRamp):
1006      def __init__(self):      def __init__(self):
1007          MonochromaticRamp.__init__(self, Color(.2, 0, 0), Color(1, 0, 0))          MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(.8, 0, 0))
1008    
1009  class GreenRamp(MonochromaticRamp):  class GreenRamp(MonochromaticRamp):
1010      def __init__(self):      def __init__(self):
1011          MonochromaticRamp.__init__(self, Color(0, .2, 0), Color(0, 1, 0))          MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, .8, 0))
1012    
1013  class BlueRamp(MonochromaticRamp):  class BlueRamp(MonochromaticRamp):
1014      def __init__(self):      def __init__(self):
1015          MonochromaticRamp.__init__(self, Color(0, 0, .2), Color(0, 0, 1))          MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, .8))
1016    
1017  class HotToColdRamp:  class HotToColdRamp:
1018    

Legend:
Removed from v.649  
changed lines
  Added in v.781

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26