/[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 648 by jonathan, Wed Apr 9 15:42:25 2003 UTC revision 649 by jonathan, Fri Apr 11 14:27:12 2003 UTC
# Line 19  from Thuban.Model.color import Color Line 19  from Thuban.Model.color import Color
19    
20  import classifier  import classifier
21    
22    import resource
23    
24  from Thuban.common import Str2Num  from Thuban.common import Str2Num
25    
26  ID_CLASSGEN_GEN = 4001  ID_CLASSGEN_GEN = 4001
# Line 26  ID_CLASSGEN_CLOSE = 4002 Line 28  ID_CLASSGEN_CLOSE = 4002
28  ID_CLASSGEN_GENCOMBO = 4007  ID_CLASSGEN_GENCOMBO = 4007
29  ID_CLASSGEN_PROPCOMBO = 4008  ID_CLASSGEN_PROPCOMBO = 4008
30    
31    USEALL_BMP  = "group_use_all"
32    USE_BMP     = "group_use"
33    USENOT_BMP  = "group_use_not"
34    USENONE_BMP = "group_use_none"
35    
36  GENCOMBOSTR_UNIFORM = _("Uniform Distribution")  GENCOMBOSTR_UNIFORM = _("Uniform Distribution")
37  GENCOMBOSTR_UNIQUE = _("Unique Values")  GENCOMBOSTR_UNIQUE = _("Unique Values")
38    
39  PROPCOMBOSTR_CUSTOM = _("Custom Ramp")  PROPCOMBOSTR_CUSTOM     = _("Custom Ramp")
40  PROPCOMBOSTR_RED    = _("Red Ramp")  PROPCOMBOSTR_GREY       = _("Grey Ramp")
41  PROPCOMBOSTR_GREEN  = _("Green Ramp")  PROPCOMBOSTR_RED        = _("Red Ramp")
42  PROPCOMBOSTR_BLUE   = _("Blue Ramp")  PROPCOMBOSTR_GREEN      = _("Green Ramp")
43    PROPCOMBOSTR_BLUE       = _("Blue Ramp")
44    PROPCOMBOSTR_HOT2COLD   = _("Hot-to-Cold Ramp")
45    
46  class ClassGenDialog(wxDialog):  class ClassGenDialog(wxDialog):
47                                                                                                                                                                    
# Line 70  class ClassGenDialog(wxDialog): Line 79  class ClassGenDialog(wxDialog):
79                    0, wxALL, 4)                    0, wxALL, 4)
80          sizer.Add(wxStaticText(          sizer.Add(wxStaticText(
81              self, -1,              self, -1,
82              _("Field Type: %s") % classifier.Classifier.type2string[self.type]),              _("Data Type: %s") % classifier.Classifier.type2string[self.type]),
83              0, wxALL, 4)              0, wxALL, 4)
84    
85          psizer = wxBoxSizer(wxHORIZONTAL)          psizer = wxBoxSizer(wxHORIZONTAL)
# Line 121  class ClassGenDialog(wxDialog): Line 130  class ClassGenDialog(wxDialog):
130          sizer.Add(panel, 1, wxALL | wxGROW, 4)          sizer.Add(panel, 1, wxALL | wxGROW, 4)
131          sizer.Show(panel, False)          sizer.Show(panel, False)
132    
133            self.propCombo.Append(PROPCOMBOSTR_GREY,  GreyRamp())
134          self.propCombo.Append(PROPCOMBOSTR_RED,   RedRamp())          self.propCombo.Append(PROPCOMBOSTR_RED,   RedRamp())
135          self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp())          self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp())
136          self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp())          self.propCombo.Append(PROPCOMBOSTR_BLUE,  BlueRamp())
137            self.propCombo.Append(PROPCOMBOSTR_HOT2COLD,  HotToColdRamp())
138          self.propCombo.Append(PROPCOMBOSTR_CUSTOM, panel)          self.propCombo.Append(PROPCOMBOSTR_CUSTOM, panel)
139    
140    
# Line 499  ID_UNIQUE_DONTUSE = 4004 Line 510  ID_UNIQUE_DONTUSE = 4004
510  ID_UNIQUE_USENONE = 4005  ID_UNIQUE_USENONE = 4005
511  ID_UNIQUE_SORTAVAIL = 4006  ID_UNIQUE_SORTAVAIL = 4006
512  ID_UNIQUE_SORTUSE = 4007  ID_UNIQUE_SORTUSE = 4007
513    ID_UNIQUE_REVAVAIL = 4008
514    ID_UNIQUE_REVUSE = 4009
515    
516  class GenUniquePanel(wxPanel):  class GenUniquePanel(wxPanel):
517    
# Line 514  class GenUniquePanel(wxPanel): Line 527  class GenUniquePanel(wxPanel):
527                                      wxVERTICAL)                                      wxVERTICAL)
528    
529    
530            #bsizer = wxBoxSizer(wxVERTICAL)
531            topSizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE,
532                                _("Retrieve From Table")),
533                       0, wxALL | wxALIGN_RIGHT, 4)
534    
535            EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve)
536    
537            #topSizer.Add(bsizer, 0, wxALL, 4)
538    
539          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
540    
541          self.dataList = []          self.dataList = []
# Line 525  class GenUniquePanel(wxPanel): Line 547  class GenUniquePanel(wxPanel):
547          self.list_avail_data = []          self.list_avail_data = []
548          psizer.Add(self.list_avail, 1, wxGROW, 0)          psizer.Add(self.list_avail, 1, wxGROW, 0)
549    
550          psizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort")))          bsizer = wxBoxSizer(wxHORIZONTAL)
551            bsizer.Add(wxButton(self, ID_UNIQUE_SORTAVAIL, _("Sort")))
552            EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortList)
553    
554          EVT_BUTTON(self, ID_UNIQUE_SORTAVAIL, self._OnSortAvailList)          bsizer.Add(wxButton(self, ID_UNIQUE_REVAVAIL, _("Reverse")))
555            EVT_BUTTON(self, ID_UNIQUE_REVAVAIL, self._OnReverseList)
556    
557            psizer.Add(bsizer, 0, wxGROW, 0)
558          sizer.Add(psizer, 1, wxGROW, 0)          sizer.Add(psizer, 1, wxGROW, 0)
559    
560                    
561          bsizer = wxBoxSizer(wxVERTICAL)          bsizer = wxBoxSizer(wxVERTICAL)
562          bsizer.Add(wxButton(self, ID_UNIQUE_USEALL, _("Use All")),  
563            bmp = resource.GetBitmapResource(USEALL_BMP, wxBITMAP_TYPE_XPM)
564            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USEALL, bmp),
565                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
566          bsizer.Add(wxButton(self, ID_UNIQUE_USE, _("Use >>")),          bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM)
567            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USE, bmp),
568                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
569          bsizer.Add(wxButton(self, ID_UNIQUE_DONTUSE, _("<< Don't Use")),          bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM)
570            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_DONTUSE, bmp),
571                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
572          bsizer.Add(wxButton(self, ID_UNIQUE_USENONE, _("Use None")),          bmp = resource.GetBitmapResource(USENONE_BMP, wxBITMAP_TYPE_XPM)
573            bsizer.Add(wxBitmapButton(self, ID_UNIQUE_USENONE, bmp),
574                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
575    
576          EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll)          EVT_BUTTON(self, ID_UNIQUE_USEALL, self._OnUseAll)
# Line 556  class GenUniquePanel(wxPanel): Line 587  class GenUniquePanel(wxPanel):
587          self.list_use_data = []          self.list_use_data = []
588          psizer.Add(self.list_use, 1, wxGROW, 0)          psizer.Add(self.list_use, 1, wxGROW, 0)
589    
590          psizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort")))          bsizer = wxBoxSizer(wxHORIZONTAL)
591            bsizer.Add(wxButton(self, ID_UNIQUE_SORTUSE, _("Sort")))
592          EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortUseList)          EVT_BUTTON(self, ID_UNIQUE_SORTUSE, self._OnSortList)
593    
594          sizer.Add(psizer, 1, wxGROW, 0)          bsizer.Add(wxButton(self, ID_UNIQUE_REVUSE, _("Reverse")))
595            EVT_BUTTON(self, ID_UNIQUE_REVUSE, self._OnReverseList)
596    
597          bsizer = wxBoxSizer(wxVERTICAL)          psizer.Add(bsizer, 0, wxGROW, 0)
         bsizer.Add(wxButton(self, ID_UNIQUE_RETRIEVE,  
                             _("Retrieve From Table")),  
                    0, wxGROW | wxALL, 4)  
598    
599          EVT_BUTTON(self, ID_UNIQUE_RETRIEVE, self._OnRetrieve)          sizer.Add(psizer, 1, wxGROW, 0)
600    
         sizer.Add(bsizer, 0, wxALL, 4)  
601    
602          topSizer.Add(sizer, 1, wxGROW, 0)          topSizer.Add(sizer, 1, wxGROW, 0)
603    
# Line 590  class GenUniquePanel(wxPanel): Line 618  class GenUniquePanel(wxPanel):
618              list.append(self.dataList[self.list_use.GetItemData(i)])              list.append(self.dataList[self.list_use.GetItemData(i)])
619          return list          return list
620    
621      def _OnSortAvailList(self, event):      def _OnSortList(self, event):
622          self.list_avail.SortItems(lambda i1, i2:          id = event.GetId()
623                                      cmp(self.dataList[i1],  
624                                          self.dataList[i2]))          if id == ID_UNIQUE_SORTUSE:
625                list = self.list_use
626      def _OnSortUseList(self, event):          else:
627          self.list_use.SortItems(lambda i1, i2:              list = self.list_avail
628                                      cmp(self.dataList[i1],  
629                                          self.dataList[i2]))          list.SortItems(lambda i1, i2: cmp(self.dataList[i1],
630                                              self.dataList[i2]))
631    
632        def _OnReverseList(self, event):
633            id = event.GetId()
634    
635            if id == ID_UNIQUE_REVUSE:
636                list = self.list_use
637            else:
638                list = self.list_avail
639    
640            #
641            # always returning 1 reverses the list
642            #
643            list.SortItems(lambda i1, i2: 1)
644    
645      def _OnRetrieve(self, event):      def _OnRetrieve(self, event):
646          self.list_use.DeleteAllItems()          self.list_use.DeleteAllItems()
# Line 621  class GenUniquePanel(wxPanel): Line 663  class GenUniquePanel(wxPanel):
663              self.__MoveListItem(0, self.list_avail, self.list_use)              self.__MoveListItem(0, self.list_avail, self.list_use)
664    
665      def _OnUse(self, event):      def _OnUse(self, event):
         print "_OnUse"  
666          self.__MoveSelectedItems(self.list_avail, self.list_use)          self.__MoveSelectedItems(self.list_avail, self.list_use)
667    
668      def _OnDontUse(self, event):      def _OnDontUse(self, event):
         print "_OnDontUse"  
669          self.__MoveSelectedItems(self.list_use, self.list_avail)          self.__MoveSelectedItems(self.list_use, self.list_avail)
670    
671      def _OnUseNone(self, event):      def _OnUseNone(self, event):
         print "_OnUseNone"  
672    
673          for i in range(self.list_use.GetItemCount()):          for i in range(self.list_use.GetItemCount()):
674              self.__MoveListItem(0, self.list_use, self.list_avail)              self.__MoveListItem(0, self.list_use, self.list_avail)
# Line 695  class CustomRampPanel(wxPanel): Line 734  class CustomRampPanel(wxPanel):
734                        | wxALIGN_CENTER_VERTICAL, \                        | wxALIGN_CENTER_VERTICAL, \
735                     4)                     4)
736    
737            bmp = resource.GetBitmapResource(USE_BMP, wxBITMAP_TYPE_XPM)
738          bsizer = wxBoxSizer(wxVERTICAL)          bsizer = wxBoxSizer(wxVERTICAL)
739          bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYSTART, _("Copy >>")),          bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYSTART, bmp),
740                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
741          bsizer.Add(wxButton(self, ID_CUSTOMRAMP_COPYEND, _("<< Copy")),          bmp = resource.GetBitmapResource(USENOT_BMP, wxBITMAP_TYPE_XPM)
742            bsizer.Add(wxBitmapButton(self, ID_CUSTOMRAMP_COPYEND, bmp),
743                     0, wxGROW | wxALL, 4)                     0, wxGROW | wxALL, 4)
744    
745          topSizer.Add(bsizer,          topSizer.Add(bsizer,
# Line 969  class MonochromaticRamp(CustomRamp): Line 1010  class MonochromaticRamp(CustomRamp):
1010    
1011          CustomRamp.__init__(self, sp, ep)          CustomRamp.__init__(self, sp, ep)
1012    
1013    class GreyRamp(MonochromaticRamp):
1014        def __init__(self):
1015            MonochromaticRamp.__init__(self, Color(0, 0, 0), Color(1, 1, 1))
1016    
1017  class RedRamp(MonochromaticRamp):  class RedRamp(MonochromaticRamp):
1018      def __init__(self):      def __init__(self):
1019          MonochromaticRamp.__init__(self, Color(.2, 0, 0), Color(1, 0, 0))          MonochromaticRamp.__init__(self, Color(.2, 0, 0), Color(1, 0, 0))
# Line 981  class BlueRamp(MonochromaticRamp): Line 1026  class BlueRamp(MonochromaticRamp):
1026      def __init__(self):      def __init__(self):
1027          MonochromaticRamp.__init__(self, Color(0, 0, .2), Color(0, 0, 1))          MonochromaticRamp.__init__(self, Color(0, 0, .2), Color(0, 0, 1))
1028    
1029    class HotToColdRamp:
1030    
1031        def __iter__(self):
1032            return self
1033            
1034        def GetRamp(self):
1035            return self
1036    
1037        def SetNumGroups(self, num):
1038            if num < 0:
1039                return False
1040    
1041            self.num = float(num)
1042            self.index = 0
1043    
1044            return True
1045    
1046        def next(self):
1047            if self.index == self.num:
1048                raise StopIteration
1049    
1050            clr = [1.0, 1.0, 1.0]
1051    
1052            if self.index < (.25 * self.num):
1053                clr[0] = 0
1054                clr[1] = 4 * self.index / self.num
1055            elif self.index < (.5 * self.num):
1056                clr[0] = 0
1057                clr[2] = 1 + 4 * (.25 * self.num - self.index) / self.num
1058            elif self.index < (.75 * self.num):
1059                clr[0] = 4 * (self.index - .5 * self.num) / self.num
1060                clr[2] = 0
1061            else:
1062                clr[1] = 1 + 4 * (.75 * self.num - self.index) / self.num
1063                clr[2] = 0
1064    
1065            self.index += 1
1066    
1067            prop = ClassGroupProperties()
1068            prop.SetLineColor(Color(clr[0], clr[1], clr[2]))
1069            prop.SetFill(Color(clr[0], clr[1], clr[2]))
1070    
1071            return prop
1072    
1073    #class Colors16Ramp:
1074    #
1075        #def __iter__(self):
1076            #return self
1077    #
1078        #def GetRamp(self):
1079            #return self
1080    #
1081        #def SetNumGroups(self, num):
1082            #if num < 0:
1083                #return False
1084    #
1085            #self.index = 0
1086    #
1087            #return True
1088    
1089        

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26