Changeset 4490


Ignore:
Timestamp:
Jun 17, 2020 12:58:02 PM (3 years ago)
Author:
vondreele
Message:

replace all single value TextCtrl? with ValidatedTextCtrl?; remove thus unused routines

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIddataGUI.py

    r4416 r4490  
    137137        UseList[G2frame.hist][name][2][2] = Obj.GetValue()
    138138       
    139     def OnLGmixVal(event):
    140         event.Skip()
    141         Obj = event.GetEventObject()
    142         hist,name = Indx[Obj.GetId()]
    143         try:
    144             value = float(Obj.GetValue())
    145             UseList[G2frame.hist][name][1][2] = value
    146 #            if 0 <= value <= 1:
    147 #                UseList[G2frame.hist][name][1][2] = value
    148 #            else:
    149 #                raise ValueError
    150         except ValueError:
    151             pass
    152         Obj.SetValue("%.4f"%(UseList[G2frame.hist][name][1][2]))          #reset in case of error
    153 
    154139    def OnSizeType(event):
    155140        Obj = event.GetEventObject()
     
    166151            UseList[G2frame.hist]['Size'][2][pid] = Obj.GetValue()
    167152       
    168     def OnSizeVal(event):
    169         event.Skip()
    170         Obj = event.GetEventObject()
    171         hist,pid = Indx[Obj.GetId()]
    172         if UseList[G2frame.hist]['Size'][0] == 'ellipsoidal':
    173             try:
    174                 size = float(Obj.GetValue())
    175                 if pid < 3 and size < 0.001:            #10A lower limit!
    176                     raise ValueError
    177                 UseList[G2frame.hist]['Size'][4][pid] = size                   
    178             except ValueError:
    179                 pass
    180             Obj.SetValue("%.5f"%(UseList[G2frame.hist]['Size'][4][pid]))          #reset in case of error
    181             wx.CallAfter(UpdateDData,G2frame,DData,data,G2frame.hist)
    182         else:
    183             try:
    184                 size = float(Obj.GetValue())
    185                 if size < 0.001:            #10A lower limit!
    186                     raise ValueError
    187                 UseList[G2frame.hist]['Size'][1][pid] = size
    188             except ValueError:
    189                 pass
    190             Obj.SetValue("%.5f"%(UseList[G2frame.hist]['Size'][1][pid]))          #reset in case of error
    191         wx.CallAfter(G2plt.PlotSizeStrainPO,G2frame,data,hist)
    192        
    193153    def OnStrainType(event):
    194154        Obj = event.GetEventObject()
     
    204164        else:
    205165            UseList[G2frame.hist]['Mustrain'][2][pid] = Obj.GetValue()
    206        
    207     def OnStrainVal(event):
    208         event.Skip()
    209         Snames = G2spc.MustrainNames(SGData)
    210         Obj = event.GetEventObject()
    211         hist,pid = Indx[Obj.GetId()]
    212         try:
    213             strain = float(Obj.GetValue())
    214             if UseList[G2frame.hist]['Mustrain'][0] == 'generalized':
    215                 if '4' in Snames[pid] and strain < 0:
    216                     raise ValueError
    217                 UseList[G2frame.hist]['Mustrain'][4][pid] = strain
    218             else:
    219                 if strain <= 0:
    220                     raise ValueError
    221                 UseList[G2frame.hist]['Mustrain'][1][pid] = strain
    222         except ValueError:
    223             pass
    224         if UseList[G2frame.hist]['Mustrain'][0] == 'generalized':
    225             Obj.SetValue("%.1f"%(UseList[G2frame.hist]['Mustrain'][4][pid]))          #reset in case of error
    226             wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
    227         else:
    228             Obj.SetValue("%.1f"%(UseList[G2frame.hist]['Mustrain'][1][pid]))          #reset in case of error
    229         wx.CallAfter(G2plt.PlotSizeStrainPO,G2frame,data,hist)
    230166       
    231167    def OnStrainAxis(event):
     
    246182    def OnResetStrain(event):
    247183        Obj = event.GetEventObject()
    248         Obj.SetValue(False)
    249184        item,name = Indx[Obj.GetId()]
    250185        if name == 'isotropic':
     
    310245        return axis
    311246       
     247    def OnNewValue(invalid,value,tc):
     248        G2plt.PlotSizeStrainPO(G2frame,data,G2frame.hist)
     249           
     250    def OnNewValueReDraw(invalid,value,tc):
     251        G2plt.PlotSizeStrainPO(G2frame,data,G2frame.hist)
     252        wx.CallLater(100,RepaintHistogramInfo,DData.GetScrollPos(wx.VERTICAL))
     253           
    312254    def TopSizer(name,choices,parm,OnType):
    313255        topSizer = wx.BoxSizer(wx.HORIZONTAL)
     
    319261        return topSizer
    320262       
    321     def LGmixSizer(name,OnVal,OnRef):
     263    def LGmixSizer(name,Limits,OnRef):
    322264        lgmixSizer = wx.BoxSizer(wx.HORIZONTAL)
    323265        lgmixRef = wx.CheckBox(DData,wx.ID_ANY,label='LGmix')
     
    327269        lgmixRef.Bind(wx.EVT_CHECKBOX, OnRef)
    328270        lgmixSizer.Add(lgmixRef,0,WACV|wx.LEFT,5)
    329 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    330         lgmixVal = wx.TextCtrl(DData,wx.ID_ANY,
    331             '%.4f'%(UseList[G2frame.hist][name][1][2]),style=wx.TE_PROCESS_ENTER)
    332         Indx[lgmixVal.GetId()] = [G2frame.hist,name]
    333         lgmixVal.Bind(wx.EVT_TEXT_ENTER,OnVal)
    334         lgmixVal.Bind(wx.EVT_KILL_FOCUS,OnVal)
     271        lgmixVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist][name][1],2,
     272            nDig=(10,3),min=Limits[0],max=Limits[1])
    335273        lgmixSizer.Add(lgmixVal,0,WACV|wx.LEFT,5)
    336274        return lgmixSizer
     
    338276    def ResetSizer(name,OnReset):
    339277        resetSizer = wx.BoxSizer(wx.HORIZONTAL)
    340         reset = wx.CheckBox(DData,wx.ID_ANY,label='Reset?')
     278        reset = wx.Button(DData,wx.ID_ANY,label='Reset?')
    341279        reset.thisown = False
    342         reset.SetValue(False)
    343280        Indx[reset.GetId()] = [G2frame.hist,name]
    344         reset.Bind(wx.EVT_CHECKBOX,OnReset)
    345         resetSizer.Add(reset,0,WACV|wx.TOP|wx.LEFT,5)
     281        reset.Bind(wx.EVT_BUTTON,OnReset)
     282        resetSizer.Add(reset,0,WACV)
    346283        return resetSizer
    347284       
    348     def IsoSizer(name,parm,fmt,OnVal,OnRef):
     285    def IsoSizer(name,parm,fmt,Limits,OnRef):
    349286        isoSizer = wx.BoxSizer(wx.HORIZONTAL)
    350287        sizeRef = wx.CheckBox(DData,wx.ID_ANY,label=name)
     
    354291        sizeRef.Bind(wx.EVT_CHECKBOX, OnRef)
    355292        isoSizer.Add(sizeRef,0,WACV|wx.LEFT,5)
    356 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    357         sizeVal = wx.TextCtrl(DData,wx.ID_ANY,
    358             fmt%(UseList[G2frame.hist][parm][1][0]),style=wx.TE_PROCESS_ENTER)
    359         Indx[sizeVal.GetId()] = [G2frame.hist,0]
    360         sizeVal.Bind(wx.EVT_TEXT_ENTER,OnVal)
    361         sizeVal.Bind(wx.EVT_KILL_FOCUS,OnVal)
     293        sizeVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist][parm][1],0,
     294            nDig=fmt,min=Limits[0],max=Limits[1],OnLeave=OnNewValue)
    362295        isoSizer.Add(sizeVal,0,WACV)
    363296        return isoSizer
     
    373306        return uniSizer
    374307       
    375     def UniDataSizer(parmName,parm,fmt,OnVal,OnRef):
     308    def UniDataSizer(parmName,parm,fmt,Limits,OnRef):
    376309        dataSizer = wx.BoxSizer(wx.HORIZONTAL)
    377310        parms = zip([' Equatorial '+parmName,' Axial '+parmName],
    378             UseList[G2frame.hist][parm][1],UseList[G2frame.hist][parm][2],range(2))
    379         for Pa,val,ref,Id in parms:
     311            UseList[G2frame.hist][parm][2],range(2))
     312        for Pa,ref,Id in parms:
    380313            sizeRef = wx.CheckBox(DData,wx.ID_ANY,label=Pa)
    381314            sizeRef.thisown = False
     
    384317            sizeRef.Bind(wx.EVT_CHECKBOX, OnRef)
    385318            dataSizer.Add(sizeRef,0,WACV|wx.LEFT,5)
    386 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    387             sizeVal = wx.TextCtrl(DData,wx.ID_ANY,fmt%(val),style=wx.TE_PROCESS_ENTER)
    388             Indx[sizeVal.GetId()] = [G2frame.hist,Id]
    389             sizeVal.Bind(wx.EVT_TEXT_ENTER,OnVal)
    390             sizeVal.Bind(wx.EVT_KILL_FOCUS,OnVal)
    391             dataSizer.Add(sizeVal,0,WACV|wx.BOTTOM,5)
     319            sizeVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist][parm][1],
     320                Id,fmt,min=Limits[0],max=Limits[1],OnLeave=OnNewValue)
     321            dataSizer.Add(sizeVal,0,WACV)
    392322        return dataSizer
    393323
     
    396326            UseList[G2frame.hist]['Size'][5],range(6))
    397327        dataSizer = wx.BoxSizer(wx.VERTICAL)
    398         # dataSizer = wx.FlexGridSizer(0,6,5,5)
    399328        matrixSizer = wx.FlexGridSizer(0,6,5,5)
    400329        Sij = []
    401         for Pa,val,ref,id in parms:
     330        for Pa,val,ref,Id in parms:
    402331            sizeRef = wx.CheckBox(DData,wx.ID_ANY,label=Pa)
    403332            sizeRef.thisown = False
    404333            sizeRef.SetValue(ref)
    405             Indx[sizeRef.GetId()] = [G2frame.hist,id]
     334            Indx[sizeRef.GetId()] = [G2frame.hist,Id]
    406335            sizeRef.Bind(wx.EVT_CHECKBOX, OnSizeRef)
    407             # dataSizer.Add(sizeRef,0,WACV)
    408336            matrixSizer.Add(sizeRef,0,WACV)
    409     #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    410             sizeVal = wx.TextCtrl(DData,wx.ID_ANY,'%.3f'%(val),style=wx.TE_PROCESS_ENTER)
     337            if Id < 3:
     338                sizeVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Size'][4],
     339                    Id,nDig=(10,3),min=0.,max=4.,OnLeave=OnNewValueReDraw)
     340            else:
     341                sizeVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Size'][4],
     342                    Id,nDig=(10,3),OnLeave=OnNewValueReDraw)
    411343            # Create Sij matrix
    412344            Sij += [val]
    413             Indx[sizeVal.GetId()] = [G2frame.hist,id]
    414             sizeVal.Bind(wx.EVT_TEXT_ENTER,OnSizeVal)
    415             sizeVal.Bind(wx.EVT_KILL_FOCUS,OnSizeVal)
    416             # dataSizer.Add(sizeVal,0,WACV)
    417345            matrixSizer.Add(sizeVal,0,WACV)
    418346        dataSizer.Add(matrixSizer, 0, WACV)
     
    442370            onumb += 1
    443371        muMean = G2spc.MuShklMean(SGData,Amat,UseList[G2frame.hist]['Mustrain'][4])
    444         parms = zip(Snames,UseList[G2frame.hist]['Mustrain'][4],UseList[G2frame.hist]['Mustrain'][5],range(numb))
     372        parms = zip(Snames,UseList[G2frame.hist]['Mustrain'][5],range(numb))
    445373        dataSizer = wx.FlexGridSizer(0,6,5,5)
    446         for Pa,val,ref,Id in parms:
     374        for Pa,ref,Id in parms:
    447375            strainRef = wx.CheckBox(DData,wx.ID_ANY,label=Pa)
    448376            strainRef.thisown = False
     
    451379            strainRef.Bind(wx.EVT_CHECKBOX, OnStrainRef)
    452380            dataSizer.Add(strainRef,0,WACV)
    453 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    454             strainVal = wx.TextCtrl(DData,wx.ID_ANY,'%.1f'%(val),style=wx.TE_PROCESS_ENTER)
    455             Indx[strainVal.GetId()] = [G2frame.hist,Id]
    456             strainVal.Bind(wx.EVT_TEXT_ENTER,OnStrainVal)
    457             strainVal.Bind(wx.EVT_KILL_FOCUS,OnStrainVal)
     381            strainVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['Mustrain'][4],
     382                Id,nDig=(10,2),OnLeave=OnNewValueReDraw)
    458383            dataSizer.Add(strainVal,0,WACV)
    459384        dataSizer.Add(wx.StaticText(DData,label=' Mean mustrain %.1f'%muMean),0,WACV)
     
    467392            UseList[G2frame.hist]['HStrain'][1][pid] = Obj.GetValue()
    468393           
    469         def OnHstrainVal(event):
    470             event.Skip()
    471             Obj = event.GetEventObject()
    472             hist,pid = Indx[Obj.GetId()]
    473             try:
    474                 strain = float(Obj.GetValue())
    475                 UseList[G2frame.hist]['HStrain'][0][pid] = strain
    476             except ValueError:
    477                 pass
    478             Obj.SetValue("%.3g"%(UseList[G2frame.hist]['HStrain'][0][pid]))          #reset in case of error
    479        
    480394        hstrainSizer = wx.FlexGridSizer(0,6,5,5)
    481395        Hsnames = G2spc.HStrainNames(SGData)
    482         parms = zip(Hsnames,UseList[G2frame.hist]['HStrain'][0],UseList[G2frame.hist]['HStrain'][1],range(len(Hsnames)))
    483         for Pa,val,ref,Id in parms:
     396        parms = zip(Hsnames,UseList[G2frame.hist]['HStrain'][1],range(len(Hsnames)))
     397        for Pa,ref,Id in parms:
    484398            hstrainRef = wx.CheckBox(DData,wx.ID_ANY,label=Pa)
    485399            hstrainRef.thisown = False
     
    488402            hstrainRef.Bind(wx.EVT_CHECKBOX, OnHstrainRef)
    489403            hstrainSizer.Add(hstrainRef,0,WACV|wx.LEFT,5)
    490 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    491             hstrainVal = wx.TextCtrl(DData,wx.ID_ANY,'%.3g'%(val),style=wx.TE_PROCESS_ENTER)
    492             Indx[hstrainVal.GetId()] = [G2frame.hist,Id]
    493             hstrainVal.Bind(wx.EVT_TEXT_ENTER,OnHstrainVal)
    494             hstrainVal.Bind(wx.EVT_KILL_FOCUS,OnHstrainVal)
     404            hstrainVal = G2G.ValidatedTxtCtrl(DData,UseList[G2frame.hist]['HStrain'][0],Id,nDig=(10,3,'g'))
    495405            hstrainSizer.Add(hstrainVal,0,WACV)
    496406        return hstrainSizer
     
    535445    def SHDataSizer(POData):
    536446       
    537         def OnODFValue(invalid,value,tc):
    538             G2plt.PlotSizeStrainPO(G2frame,data,G2frame.hist)
    539    
    540447        ODFSizer = wx.FlexGridSizer(0,8,2,2)
    541448        ODFkeys = list(POData[5].keys())
     
    543450        for odf in ODFkeys:
    544451            ODFSizer.Add(wx.StaticText(DData,wx.ID_ANY,odf),0,WACV)
    545             ODFval = G2G.ValidatedTxtCtrl(DData,POData[5],odf,nDig=(8,3),typeHint=float,OnLeave=OnODFValue)
     452            ODFval = G2G.ValidatedTxtCtrl(DData,POData[5],odf,nDig=(8,3),typeHint=float,OnLeave=OnNewValue)
    546453            ODFSizer.Add(ODFval,0,WACV|wx.LEFT,5)
    547454        return ODFSizer
     
    882789        def OnResetSize(event):
    883790            Obj = event.GetEventObject()
    884             Obj.SetValue(False)
    885791            item,name = Indx[Obj.GetId()]
    886792            if name == 'isotropic':
     
    972878                isoSizer.Add(TopSizer(' Domain size model: ',['isotropic','uniaxial','ellipsoidal'],
    973879                    'Size',OnSizeType),0,WACV)
    974                 isoSizer.Add(LGmixSizer('Size',OnLGmixVal,OnLGmixRef))
     880                isoSizer.Add(LGmixSizer('Size',[0.,1.],OnLGmixRef))
    975881                isoSizer.Add(ResetSizer('isotropic',OnResetSize),0,WACV)
    976882                bottomSizer.Add(isoSizer)
    977                 bottomSizer.Add(IsoSizer(u'size(\xb5m): ','Size','%.3f',
    978                     OnSizeVal,OnSizeRef),0,WACV|wx.BOTTOM,5)
     883                bottomSizer.Add(IsoSizer(u'size(\xb5m): ','Size',(10,4),
     884                    [0.,4.],OnSizeRef),0,WACV|wx.BOTTOM,5)
    979885            elif UseList[G2frame.hist]['Size'][0] == 'uniaxial':
    980886                uniSizer = wx.BoxSizer(wx.HORIZONTAL)
    981887                uniSizer.Add(TopSizer(' Domain size model: ',['isotropic','uniaxial','ellipsoidal'],
    982888                    'Size',OnSizeType),0,WACV)
    983                 uniSizer.Add(LGmixSizer('Size',OnLGmixVal,OnLGmixRef))
     889                uniSizer.Add(LGmixSizer('Size',[0.,1.],OnLGmixRef))
    984890                uniSizer.Add(ResetSizer('uniaxial',OnResetSize),0,WACV)
    985891                bottomSizer.Add(UniSizer('Size',OnSizeAxis),0,WACV)
    986892                bottomSizer.Add(uniSizer)
    987                 bottomSizer.Add(UniDataSizer(u'size(\xb5m): ','Size','%.3f',OnSizeVal,OnSizeRef)
     893                bottomSizer.Add(UniDataSizer(u'size(\xb5m): ','Size',(10,3),[0.,4.],OnSizeRef)
    988894                    ,0,WACV|wx.BOTTOM,5)
    989895            elif UseList[G2frame.hist]['Size'][0] == 'ellipsoidal':
     
    991897                ellSizer.Add(TopSizer(' Domain size model: ',['isotropic','uniaxial','ellipsoidal'],
    992898                    'Size',OnSizeType),0,WACV)
    993                 ellSizer.Add(LGmixSizer('Size',OnLGmixVal,OnLGmixRef))
     899                ellSizer.Add(LGmixSizer('Size',[0.,1.],OnLGmixRef))
    994900                ellSizer.Add(ResetSizer('ellipsoidal',OnResetSize),0,WACV)
    995901                bottomSizer.Add(ellSizer)
     
    1000906                isoSizer.Add(TopSizer(' Mustrain model: ',['isotropic','uniaxial','generalized',],
    1001907                    'Mustrain',OnStrainType),0,WACV)
    1002                 isoSizer.Add(LGmixSizer('Mustrain',OnLGmixVal,OnLGmixRef))
     908                isoSizer.Add(LGmixSizer('Mustrain',[0.,1.],OnLGmixRef))
    1003909                isoSizer.Add(ResetSizer('isotropic',OnResetStrain),0,WACV)
    1004910                bottomSizer.Add(isoSizer)
    1005                 bottomSizer.Add(IsoSizer(' microstrain: ','Mustrain','%.1f',
    1006                     OnStrainVal,OnStrainRef),0,WACV|wx.BOTTOM,5)
     911                bottomSizer.Add(IsoSizer(' microstrain: ','Mustrain',(10,1),
     912                    [0.,1.e5],OnStrainRef),0,WACV|wx.BOTTOM,5)
    1007913            elif UseList[G2frame.hist]['Mustrain'][0] == 'uniaxial':
    1008914                uniSizer = wx.BoxSizer(wx.HORIZONTAL)
    1009915                uniSizer.Add(TopSizer(' Mustrain model: ',['isotropic','uniaxial','generalized',],
    1010916                    'Mustrain',OnStrainType),0,WACV)
    1011                 uniSizer.Add(LGmixSizer('Mustrain',OnLGmixVal,OnLGmixRef))
     917                uniSizer.Add(LGmixSizer('Mustrain',[0.,1.],OnLGmixRef))
    1012918                uniSizer.Add(ResetSizer('uniaxial',OnResetStrain),0,WACV)
    1013919                bottomSizer.Add(uniSizer)
    1014920                bottomSizer.Add(UniSizer('Mustrain',OnStrainAxis),0,WACV)
    1015                 bottomSizer.Add(UniDataSizer('mustrain: ','Mustrain','%.1f',OnStrainVal,OnStrainRef)
     921                bottomSizer.Add(UniDataSizer('mustrain: ','Mustrain',(10,1),[0.,1.e5],OnStrainRef)
    1016922                                ,0,WACV|wx.BOTTOM,5)
    1017923            elif UseList[G2frame.hist]['Mustrain'][0] == 'generalized':
     
    1019925                genSizer.Add(TopSizer(' Mustrain model: ',['isotropic','uniaxial','generalized',],
    1020926                    'Mustrain',OnStrainType),0,WACV)
    1021                 genSizer.Add(LGmixSizer('Mustrain',OnLGmixVal,OnLGmixRef))
     927                genSizer.Add(LGmixSizer('Mustrain',[0.,1.],OnLGmixRef))
    1022928                genSizer.Add(ResetSizer('generalized',OnResetStrain),0,WACV)
    1023929                bottomSizer.Add(genSizer)
Note: See TracChangeset for help on using the changeset viewer.