/[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 635 by jonathan, Wed Apr 9 15:42:25 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 19  from Thuban.Model.color import Color Line 21  from Thuban.Model.color import Color
21    
22  import classifier  import classifier
23    
24  from Thuban.common import Str2Num  import resource
25    
 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    
29    USEALL_BMP  = "group_use_all"
30    USE_BMP     = "group_use"
31    USENOT_BMP  = "group_use_not"
32    USENONE_BMP = "group_use_none"
33    
34  GENCOMBOSTR_UNIFORM = _("Uniform Distribution")  GENCOMBOSTR_UNIFORM = _("Uniform Distribution")
35  GENCOMBOSTR_UNIQUE = _("Unique Values")  GENCOMBOSTR_UNIQUE = _("Unique Values")
36    
37  PROPCOMBOSTR_CUSTOM = _("Custom Ramp")  PROPCOMBOSTR_CUSTOM     = _("Custom Ramp")
38  PROPCOMBOSTR_RED    = _("Red Ramp")  PROPCOMBOSTR_GREY       = _("Grey Ramp")
39  PROPCOMBOSTR_GREEN  = _("Green Ramp")  PROPCOMBOSTR_RED        = _("Red Ramp")
40  PROPCOMBOSTR_BLUE   = _("Blue Ramp")  PROPCOMBOSTR_GREEN      = _("Green Ramp")
41    PROPCOMBOSTR_BLUE       = _("Blue Ramp")
42    PROPCOMBOSTR_HOT2COLD   = _("Hot-to-Cold Ramp")
43    
44  class ClassGenDialog(wxDialog):  class ClassGenDialog(wxDialog):
45                                                                                                                                                                    
# Line 54  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 70  class ClassGenDialog(wxDialog): Line 98  class ClassGenDialog(wxDialog):
98                    0, wxALL, 4)                    0, wxALL, 4)
99          sizer.Add(wxStaticText(          sizer.Add(wxStaticText(
100              self, -1,              self, -1,
101              _("Field Type: %s") % classifier.Classifier.type2string[self.type]),              _("Data Type: %s") % classifier.Classifier.type2string[self.type]),
102              0, wxALL, 4)              0, wxALL, 4)
103    
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_RED,   RedRamp())  
         self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp())  
         self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp())  
         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 149  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 195  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 276  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 297  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 347  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 380  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 431  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 475  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 499  ID_UNIQUE_DONTUSE = 4004 Line 501  ID_UNIQUE_DONTUSE = 4004
501  ID_UNIQUE_USENONE = 4005  ID_UNIQUE_USENONE = 4005
502  ID_UNIQUE_SORTAVAIL = 4006  ID_UNIQUE_SORTAVAIL = 4006
503  ID_UNIQUE_SORTUSE = 4007  ID_UNIQUE_SORTUSE = 4007
504    ID_UNIQUE_REVAVAIL = 4008
505    ID_UNIQUE_REVUSE = 4009
506    
507  class GenUniquePanel(wxPanel):  class GenUniquePanel(wxPanel):
508    
# Line 514  class GenUniquePanel(wxPanel): Line 518  class GenUniquePanel(wxPanel):
518                                      wxVERTICAL)                                      wxVERTICAL)
519    
520    
521            #bsizer = wxBoxSizer(wxVERTICAL)
522            topSizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE,
523                                _("Retrieve From Table")),
524                       0, wxALL | wxALIGN_RIGHT, 4)
525    
526            EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve)
527    
528            #topSizer.Add(bsizer, 0, wxALL, 4)
529    
530          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
531    
532          self.dataList = []          self.dataList = []
# Line 525  class GenUniquePanel(wxPanel): Line 538  class GenUniquePanel(wxPanel):
538          self.list_avail_data = []          self.list_avail_data = []
539          psizer.Add(self.list_avail, 1, wxGROW, 0)          psizer.Add(self.list_avail, 1, wxGROW, 0)
540    
541          psizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort")))          bsizer = wxBoxSizer(wxHORIZONTAL)
542            bsizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort")))
543            EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortList)
544    
545          EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortAvailList)          bsizer.Add(wxButton(self, ID_UNIQUE_REVAVAIL, _("Reverse")))
546            EVT_BUTTON(self, ID_UNIQUE_REVAVAIL, self._OnReverseList)
547    
548            psizer.Add(bsizer, 0, wxGROW, 0)
549          sizer.Add(psizer, 1, wxGROW, 0)          sizer.Add(psizer, 1, wxGROW, 0)
550    
551                    
552          bsizer = wxBoxSizer(wxVERTICAL)          bsizer = wxBoxSizer(wxVERTICAL)
553          bsizer.Add(wxButton(self, ID_UNIQUE_USEALL, _("Use All")),  
554            bmp = resource.GetBitmapResource(USEALL_BMP, wxBITMAP_TYPE_XPM)
555            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USEALL, bmp),
556                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
557          bsizer.Add(wxButton(self, ID_UNIQUE_USE, _("Use >>")),          bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM)
558            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USE, bmp),
559                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
560          bsizer.Add(wxButton(self, ID_UNIQUE_DONTUSE, _("<< Don't Use")),          bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM)
561            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_DONTUSE, bmp),
562                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
563          bsizer.Add(wxButton(self, ID_UNIQUE_USENONE, _("Use None")),          bmp = resource.GetBitmapResource(USENONE_BMP, wxBITMAP_TYPE_XPM)
564            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USENONE, bmp),
565                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
566    
567          EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll)          EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll)
# Line 556  class GenUniquePanel(wxPanel): Line 578  class GenUniquePanel(wxPanel):
578          self.list_use_data = []          self.list_use_data = []
579          psizer.Add(self.list_use, 1, wxGROW, 0)          psizer.Add(self.list_use, 1, wxGROW, 0)
580    
581          psizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort")))          bsizer = wxBoxSizer(wxHORIZONTAL)
582            bsizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort")))
583            EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortList)
584    
585          EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortUseList)          bsizer.Add(wxButton(self, ID_UNIQUE_REVUSE, _("Reverse")))
586            EVT_BUTTON(self, ID_UNIQUE_REVUSE, self._OnReverseList)
587    
588          sizer.Add(psizer, 1, wxGROW, 0)          psizer.Add(bsizer, 0, wxGROW, 0)
589    
590          bsizer = wxBoxSizer(wxVERTICAL)          sizer.Add(psizer, 1, wxGROW, 0)
         bsizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE,  
                             _("Retrieve From Table")),  
                    0, wxGROW | wxALL, 4)  
   
         EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve)  
591    
         sizer.Add(bsizer, 0, wxALL, 4)  
592    
593          topSizer.Add(sizer, 1, wxGROW, 0)          topSizer.Add(sizer, 1, wxGROW, 0)
594    
# Line 590  class GenUniquePanel(wxPanel): Line 609  class GenUniquePanel(wxPanel):
609              list.append(self.dataList[self.list_use.GetItemData(i)])              list.append(self.dataList[self.list_use.GetItemData(i)])
610          return list          return list
611    
612      def _OnSortAvailList(self, event):      def _OnSortList(self, event):
613          self.list_avail.SortItems(lambda i1, i2:          id = event.GetId()
614                                      cmp(self.dataList[i1],  
615                                          self.dataList[i2]))          if id == ID_UNIQUE_SORTUSE:
616                list = self.list_use
617      def _OnSortUseList(self, event):          else:
618          self.list_use.SortItems(lambda i1, i2:              list = self.list_avail
619                                      cmp(self.dataList[i1],  
620                                          self.dataList[i2]))          list.SortItems(lambda i1, i2: cmp(self.dataList[i1],
621                                              self.dataList[i2]))
622    
623        def _OnReverseList(self, event):
624            id = event.GetId()
625    
626            if id == ID_UNIQUE_REVUSE:
627                list = self.list_use
628            else:
629                list = self.list_avail
630    
631            #
632            # always returning 1 reverses the list
633            #
634            list.SortItems(lambda i1, i2: 1)
635    
636      def _OnRetrieve(self, event):      def _OnRetrieve(self, event):
637          self.list_use.DeleteAllItems()          self.list_use.DeleteAllItems()
# Line 621  class GenUniquePanel(wxPanel): Line 654  class GenUniquePanel(wxPanel):
654              self.__MoveListItem(0, self.list_avail, self.list_use)              self.__MoveListItem(0, self.list_avail, self.list_use)
655    
656      def _OnUse(self, event):      def _OnUse(self, event):
         print "_OnUse"  
657          self.__MoveSelectedItems(self.list_avail, self.list_use)          self.__MoveSelectedItems(self.list_avail, self.list_use)
658    
659      def _OnDontUse(self, event):      def _OnDontUse(self, event):
         print "_OnDontUse"  
660          self.__MoveSelectedItems(self.list_use, self.list_avail)          self.__MoveSelectedItems(self.list_use, self.list_avail)
661    
662      def _OnUseNone(self, event):      def _OnUseNone(self, event):
         print "_OnUseNone"  
663    
664          for i in range(self.list_use.GetItemCount()):          for i in range(self.list_use.GetItemCount()):
665              self.__MoveListItem(0, self.list_use, self.list_avail)              self.__MoveListItem(0, self.list_use, self.list_avail)
# Line 695  class CustomRampPanel(wxPanel): Line 725  class CustomRampPanel(wxPanel):
725                        | wxALIGN_CENTER_VERTICAL, \                        | wxALIGN_CENTER_VERTICAL, \
726                     4)                     4)
727    
728            bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM)
729          bsizer = wxBoxSizer(wxVERTICAL)          bsizer = wxBoxSizer(wxVERTICAL)
730          bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYSTART, _("Copy >>")),          bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYSTART, bmp),
731                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
732          bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYEND, _("<< Copy")),          bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM)
733            bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYEND, bmp),
734                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
735    
736          topSizer.Add(bsizer,          topSizer.Add(bsizer,
# Line 786  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 818  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 834  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
# Line 969  class MonochromaticRamp(CustomRamp): Line 995  class MonochromaticRamp(CustomRamp):
995    
996          CustomRamp.__init__(self, sp, ep)          CustomRamp.__init__(self, sp, ep)
997    
998    class GreyRamp(MonochromaticRamp):
999        def __init__(self):
1000            MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, 0))
1001    
1002  class RedRamp(MonochromaticRamp):  class RedRamp(MonochromaticRamp):
1003      def __init__(self):      def __init__(self):
1004          MonochromaticRamp.__init__(self, Color(.2, 0, 0), Color(1, 0, 0))          MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(.8, 0, 0))
1005    
1006  class GreenRamp(MonochromaticRamp):  class GreenRamp(MonochromaticRamp):
1007      def __init__(self):      def __init__(self):
1008          MonochromaticRamp.__init__(self, Color(0, .2, 0), Color(0, 1, 0))          MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, .8, 0))
1009    
1010  class BlueRamp(MonochromaticRamp):  class BlueRamp(MonochromaticRamp):
1011      def __init__(self):      def __init__(self):
1012          MonochromaticRamp.__init__(self, Color(0, 0, .2), Color(0, 0, 1))          MonochromaticRamp.__init__(self, Color(1, 1, 1), Color(0, 0, .8))
1013    
1014    class HotToColdRamp:
1015    
1016        def __iter__(self):
1017            return self
1018            
1019        def GetRamp(self):
1020            return self
1021    
1022        def SetNumGroups(self, num):
1023            if num < 0:
1024                return False
1025    
1026            self.num = float(num)
1027            self.index = 0
1028    
1029            return True
1030    
1031        def next(self):
1032            if self.index == self.num:
1033                raise StopIteration
1034    
1035            clr = [1.0, 1.0, 1.0]
1036    
1037            if self.index < (.25 * self.num):
1038                clr[0] = 0
1039                clr[1] = 4 * self.index / self.num
1040            elif self.index < (.5 * self.num):
1041                clr[0] = 0
1042                clr[2] = 1 + 4 * (.25 * self.num - self.index) / self.num
1043            elif self.index < (.75 * self.num):
1044                clr[0] = 4 * (self.index - .5 * self.num) / self.num
1045                clr[2] = 0
1046            else:
1047                clr[1] = 1 + 4 * (.75 * self.num - self.index) / self.num
1048                clr[2] = 0
1049    
1050            self.index += 1
1051    
1052            prop = ClassGroupProperties()
1053            prop.SetLineColor(Color(clr[0], clr[1], clr[2]))
1054            prop.SetFill(Color(clr[0], clr[1], clr[2]))
1055    
1056            return prop
1057    
1058    #class Colors16Ramp:
1059    #
1060        #def __iter__(self):
1061            #return self
1062    #
1063        #def GetRamp(self):
1064            #return self
1065    #
1066        #def SetNumGroups(self, num):
1067            #if num < 0:
1068                #return False
1069    #
1070            #self.index = 0
1071    #
1072            #return True
1073    
1074        

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26