Changeset 5047


Ignore:
Timestamp:
Oct 14, 2021 4:59:02 PM (20 months ago)
Author:
toby
Message:

CIF export fixes; work around for IsModified?() not showing changes

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIctrlGUI.py

    r5020 r5047  
    752752        but (unlike _onLoseFocus) don't update the textbox contents.
    753753        '''
    754         if not self.IsModified():   #ignore mouse crusing
    755             return
     754        if self.type is not str:
     755            if not self.IsModified(): return  #ignore mouse crusing
     756        elif self.result[self.key] == self.GetValue(): # .IsModified() seems unreliable for str
     757           return
    756758        if self.evaluated and not self.invalid: # deal with computed expressions
    757759            self.evaluated = False # expression has been recast as value, reset flag
     
    771773        '''
    772774        if event: event.Skip()
    773         if not self.IsModified():   #ignore mouse crusing
    774             return
     775        if self.type is not str:
     776            if not self.IsModified(): return  #ignore mouse crusing
     777        elif self.result[self.key] == self.GetValue(): # .IsModified() seems unreliable for str
     778           return
    775779        if self.evaluated: # deal with computed expressions
    776780            if self.invalid: # don't substitute for an invalid expression
  • trunk/GSASIIpath.py

    r5046 r5047  
    924924    msg   = 'Entering IPython console inside {0.f_code.co_filename} at line {0.f_lineno}\n'.format(frame)
    925925    if userMsg: msg += userMsg
     926    # globals().update(locals()) # This might help with vars inside list comprehensions, etc.
    926927    ipshell(msg,stack_depth=2) # Go up one level, to see the calling routine
    927928    sys.excepthook = savehook # reset IPython's change to the exception hook
  • trunk/config_example.py

    r4965 r5047  
    3838
    3939debug = False
    40 '''Set to True to turn on debugging mode.This enables use of IPython on
    41 exceptions and on calls to :func:`GSASIIpath.IPyBreak`. Calls to
    42 :func:`GSASIIpath.pdbBreak` will invoke pdb at that location.
    43 
    44 If debug is False, calls to :func:`GSASIIpath.IPyBreak` and
     40'''Set to True to turn on debugging mode. This enables use of IPython on
     41exceptions and on calls to :func:`GSASIIpath.IPyBreak` or breakpoint().
     42Calls to :func:`GSASIIpath.pdbBreak` will invoke pdb at that location.
     43%%
     44If debug is False, calls to :func:`GSASIIpath.IPyBreak`, breakpoint() and
    4545:func:`GSASIIpath.pdbBreak` are ignored.
     46%%
     47From inside Spyder, calls to breakpoint() invoke the Spyder debugger,
     48independent of the setting of debug.
     49%%
     50Restart GSAS-II for the setting of debug to take effect.
    4651'''
    4752
  • trunk/exports/G2export_CIF.py

    r5042 r5047  
    26982698            parameters (mostly related to templates).
    26992699            '''
    2700             self.cifdefs.DestroyChildren()
     2700            if len(self.cifdefs.GetChildren()) > 0:
     2701                saveSize = self.cifdefs.GetSize()
     2702                self.cifdefs.DestroyChildren()
     2703            else:
     2704                saveSize = None
    27012705            self.cifdefs.SetTitle('Edit CIF settings')
    27022706            vbox = wx.BoxSizer(wx.VERTICAL)
     
    28002804            vbox.Add(btnsizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    28012805            self.cifdefs.SetSizer(vbox)
    2802             vbox.Fit(self.cifdefs)
     2806            if not saveSize:
     2807                vbox.Fit(self.cifdefs)
    28032808            self.cifdefs.Layout()
    28042809
     
    29942999                s += '.'
    29953000        self.CIFname = s
    2996        
     3001        phasebyhistDict = {} # a cross-reference to phases by histogram -- sequential fits
    29973002        #=================================================================
    29983003        # write quick CIFs
     
    32393244        elif seqHistList:
    32403245            #---- sequential fit project (multiblock)  ====================
    3241             phasebyhistDict = {} # create a cross-reference to phases by histogram
    32423246            for phasenam in sorted(self.Phases.keys()):
    32433247                rId = phasedict['ranId']
     
    34573461                self.CellHistSelection[rId] = self._CellSelectHist(phasenam)
    34583462            nsteps = 1 + len(self.Phases) + len(self.powderDict) + len(self.xtalDict)
    3459             dlg = wx.ProgressDialog('CIF progress','starting',nsteps,parent=self.G2frame)
    3460             dlg.CenterOnParent()
    3461 
    3462             # publication info
    3463             step = 1
    3464             dlg.Update(step,"Exporting overall section")
    3465             WriteCIFitem(self.fp, '\ndata_'+self.CIFname+'_publ')
    3466             WriteAudit()
    3467             WriteCIFitem(self.fp, '_pd_block_id',
    3468                          str(self.CIFdate) + "|" + str(self.CIFname) + "|" +
    3469                          str(self.shortauthorname) + "|Overall")
    3470             writeCIFtemplate(self.OverallParms['Controls'],'publ') #insert the publication template
    3471             # ``template_publ.cif`` or a modified version
    3472             # overall info
    3473             WriteCIFitem(self.fp, 'data_'+str(self.CIFname)+'_overall')
    3474             WriteOverall()
    3475             #============================================================
    3476             WriteCIFitem(self.fp, '# POINTERS TO PHASE AND HISTOGRAM BLOCKS')
    3477             datablockidDict = {} # save block names here -- N.B. check for conflicts between phase & hist names (unlikely!)
    3478             # loop over phase blocks
    3479             if len(self.Phases) > 1:
    3480                 loopprefix = ''
    3481                 WriteCIFitem(self.fp, 'loop_   _pd_phase_block_id')
    3482             else:
    3483                 loopprefix = '_pd_phase_block_id'
    3484 
    3485             for phasenam in sorted(self.Phases.keys()):
    3486                 i = self.Phases[phasenam]['pId']
    3487                 datablockidDict[phasenam] = (str(self.CIFdate) + "|" + str(self.CIFname) + "|" +
    3488                              'phase_'+ str(i) + '|' + str(self.shortauthorname))
    3489                 WriteCIFitem(self.fp, loopprefix,datablockidDict[phasenam])
    3490             # loop over data blocks
    3491             if len(self.powderDict) + len(self.xtalDict) > 1:
    3492                 loopprefix = ''
    3493                 WriteCIFitem(self.fp, 'loop_   _pd_block_diffractogram_id')
    3494             else:
    3495                 loopprefix = '_pd_block_diffractogram_id'
    3496             for i in sorted(self.powderDict.keys()):
    3497                 hist = self.powderDict[i]
    3498                 histblk = self.Histograms[hist]
    3499                 instnam = histblk["Sample Parameters"]['InstrName']
    3500                 instnam = instnam.replace(' ','')
    3501                 j = histblk['hId']
    3502                 datablockidDict[hist] = (str(self.CIFdate) + "|" + str(self.CIFname) + "|" +
    3503                                          str(self.shortauthorname) + "|" +
    3504                                          instnam + "_hist_"+str(j))
    3505                 WriteCIFitem(self.fp, loopprefix,datablockidDict[hist])
    3506             for i in sorted(self.xtalDict.keys()):
    3507                 hist = self.xtalDict[i]
    3508                 histblk = self.Histograms[hist]
    3509                 instnam = histblk["Instrument Parameters"][0]['InstrName']
    3510                 instnam = instnam.replace(' ','')
    3511                 i = histblk['hId']
    3512                 datablockidDict[hist] = (str(self.CIFdate) + "|" + str(self.CIFname) + "|" +
    3513                                          str(self.shortauthorname) + "|" +
    3514                                          instnam + "_hist_"+str(i))
    3515                 WriteCIFitem(self.fp, loopprefix,datablockidDict[hist])
    3516             #============================================================
    3517             # loop over phases, exporting them
    3518             for j,phasenam in enumerate(sorted(self.Phases.keys())):
    3519                 step += 1
    3520                 dlg.Update(step,"Exporting phase "+phasenam+' (#'+str(j+1)+')')
    3521                 i = self.Phases[phasenam]['pId']
    3522                 WriteCIFitem(self.fp, '\ndata_'+self.CIFname+"_phase_"+str(i))
    3523                 WriteCIFitem(self.fp, '# Information for phase '+str(i))
    3524                 WriteCIFitem(self.fp, '_pd_block_id',datablockidDict[phasenam])
    3525                 # report the phase
    3526                 writeCIFtemplate(self.Phases[phasenam]['General'],'phase',phasenam) # write phase template
    3527                 WritePhaseInfo(phasenam,False,False)
    3528                 # preferred orientation
    3529                 if self.ifPWDR:
    3530                     SH = FormatSH(phasenam)
    3531                     MD = FormatHAPpo(phasenam)
    3532                     if SH and MD:
    3533                         WriteCIFitem(self.fp, '_pd_proc_ls_pref_orient_corr', SH + '\n' + MD)
    3534                     elif SH or MD:
    3535                         WriteCIFitem(self.fp, '_pd_proc_ls_pref_orient_corr', SH + MD)
    3536                     else:
    3537                         WriteCIFitem(self.fp, '_pd_proc_ls_pref_orient_corr', 'none')
    3538                 # report sample profile terms for all histograms with current phase
    3539                 PP = FormatPhaseProfile(phasenam)
    3540                 if PP:
    3541                     WriteCIFitem(self.fp, '_pd_proc_ls_profile_function',PP)
    3542                 self.ShowHstrainCells(phasenam,datablockidDict)
    3543 
    3544             #============================================================
    3545             # loop over histograms, exporting them
    3546             # first, get atoms across all phases
    3547             uniqueAtoms = []
    3548             for phasenam in self.Phases:
    3549                 cx,ct,cs,cia = self.Phases[phasenam]['General']['AtomPtrs']
    3550                 for line in self.Phases[phasenam]['Atoms']:
    3551                     atype = line[ct].strip()
    3552                     if atype.find('-') != -1: atype = atype.split('-')[0]
    3553                     if atype.find('+') != -1: atype = atype.split('+')[0]
    3554                     atype = atype[0].upper()+atype[1:2].lower() # force case conversion
    3555                     if atype == "D" or atype == "D": atype = "H"
    3556                     if atype not in uniqueAtoms:
    3557                         uniqueAtoms.append(atype)
    3558 
    3559             for i in sorted(self.powderDict.keys()):
    3560                 hist = self.powderDict[i]
    3561                 histblk = self.Histograms[hist]
    3562                 if hist.startswith("PWDR"):
     3463            try:
     3464                dlg = wx.ProgressDialog('CIF progress','starting',nsteps,parent=self.G2frame)
     3465                dlg.CenterOnParent()
     3466
     3467                # publication info
     3468                step = 1
     3469                dlg.Update(step,"Exporting overall section")
     3470                WriteCIFitem(self.fp, '\ndata_'+self.CIFname+'_publ')
     3471                WriteAudit()
     3472                WriteCIFitem(self.fp, '_pd_block_id',
     3473                             str(self.CIFdate) + "|" + str(self.CIFname) + "|" +
     3474                             str(self.shortauthorname) + "|Overall")
     3475                writeCIFtemplate(self.OverallParms['Controls'],'publ') #insert the publication template
     3476                # ``template_publ.cif`` or a modified version
     3477                # overall info
     3478                WriteCIFitem(self.fp, 'data_'+str(self.CIFname)+'_overall')
     3479                WriteOverall()
     3480                #============================================================
     3481                WriteCIFitem(self.fp, '# POINTERS TO PHASE AND HISTOGRAM BLOCKS')
     3482                datablockidDict = {} # save block names here -- N.B. check for conflicts between phase & hist names (unlikely!)
     3483                # loop over phase blocks
     3484                if len(self.Phases) > 1:
     3485                    loopprefix = ''
     3486                    WriteCIFitem(self.fp, 'loop_   _pd_phase_block_id')
     3487                else:
     3488                    loopprefix = '_pd_phase_block_id'
     3489
     3490                for phasenam in sorted(self.Phases.keys()):
     3491                    i = self.Phases[phasenam]['pId']
     3492                    datablockidDict[phasenam] = (str(self.CIFdate) + "|" + str(self.CIFname) + "|" +
     3493                                 'phase_'+ str(i) + '|' + str(self.shortauthorname))
     3494                    WriteCIFitem(self.fp, loopprefix,datablockidDict[phasenam])
     3495                # loop over data blocks
     3496                if len(self.powderDict) + len(self.xtalDict) > 1:
     3497                    loopprefix = ''
     3498                    WriteCIFitem(self.fp, 'loop_   _pd_block_diffractogram_id')
     3499                else:
     3500                    loopprefix = '_pd_block_diffractogram_id'
     3501                for i in sorted(self.powderDict.keys()):
     3502                    hist = self.powderDict[i]
     3503                    histblk = self.Histograms[hist]
     3504                    instnam = histblk["Sample Parameters"]['InstrName']
     3505                    instnam = instnam.replace(' ','')
     3506                    j = histblk['hId']
     3507                    datablockidDict[hist] = (str(self.CIFdate) + "|" + str(self.CIFname) + "|" +
     3508                                             str(self.shortauthorname) + "|" +
     3509                                             instnam + "_hist_"+str(j))
     3510                    WriteCIFitem(self.fp, loopprefix,datablockidDict[hist])
     3511                for i in sorted(self.xtalDict.keys()):
     3512                    hist = self.xtalDict[i]
     3513                    histblk = self.Histograms[hist]
     3514                    instnam = histblk["Instrument Parameters"][0]['InstrName']
     3515                    instnam = instnam.replace(' ','')
     3516                    i = histblk['hId']
     3517                    datablockidDict[hist] = (str(self.CIFdate) + "|" + str(self.CIFname) + "|" +
     3518                                             str(self.shortauthorname) + "|" +
     3519                                             instnam + "_hist_"+str(i))
     3520                    WriteCIFitem(self.fp, loopprefix,datablockidDict[hist])
     3521                #============================================================
     3522                # loop over phases, exporting them
     3523                for j,phasenam in enumerate(sorted(self.Phases.keys())):
    35633524                    step += 1
    3564                     dlg.Update(step,"Exporting "+hist.strip())
    3565                     WriteCIFitem(self.fp, '\ndata_'+self.CIFname+"_pwd_"+str(i))
    3566                     WriteCIFitem(self.fp, '# Information for histogram '+str(i)+': '+hist)
    3567                     #instnam = histblk["Sample Parameters"]['InstrName']
    3568                     # report instrumental profile terms
    3569                     WriteCIFitem(self.fp, '_pd_proc_ls_profile_function',
    3570                         FormatInstProfile(histblk["Instrument Parameters"],histblk['hId']))
    3571                     WriteCIFitem(self.fp, '_pd_block_id',datablockidDict[hist])
    3572                     histprm = self.Histograms[hist]["Sample Parameters"]
    3573                     writeCIFtemplate(histprm,'powder',histprm['InstrName']) # powder template
    3574                    
    3575                     # get xray wavelength and compute & write f' & f''
    3576                     lam = None
    3577                     if 'X' in histblk['Instrument Parameters'][0]['Type'][0]:
    3578                         for k in ('Lam','Lam1'):
    3579                             if k in histblk['Instrument Parameters'][0]:
    3580                                 lam = histblk['Instrument Parameters'][0][k][0]
    3581                                 break
    3582                     if lam:
    3583                         keV = 12.397639/lam
    3584                         WriteCIFitem(self.fp,'loop_')
    3585                         for item in ('_atom_type_symbol','_atom_type_scat_dispersion_real',
    3586                                          '_atom_type_scat_dispersion_imag','_atom_type_scat_dispersion_source'):
    3587                             WriteCIFitem(self.fp,'     '+item)
    3588                         for elem in HillSortElements(uniqueAtoms):
    3589                             s = '  '
    3590                             s += PutInCol(elem,4)
    3591                             Orbs = G2el.GetXsectionCoeff(elem)
    3592                             FP,FPP,Mu = G2el.FPcalc(Orbs, keV)
    3593                             s += '  {:8.3f}{:8.3f}   https://subversion.xray.aps.anl.gov/pyGSAS/trunk/atmdata.py'.format(FP,FPP)
    3594                             WriteCIFitem(self.fp,s.rstrip())
    3595                         WriteCIFitem(self.fp,'')
    3596                     WritePowderData(hist)
    3597             for i in sorted(self.xtalDict.keys()):
    3598                 hist = self.xtalDict[i]
    3599                 histblk = self.Histograms[hist]
    3600                 if hist.startswith("HKLF"):
    3601                     step += 1
    3602                     dlg.Update(step,"Exporting "+hist.strip())
    3603                     WriteCIFitem(self.fp, '\ndata_'+self.CIFname+"_sx_"+str(i))
    3604                     #instnam = histblk["Instrument Parameters"][0]['InstrName']
    3605                     WriteCIFitem(self.fp, '# Information for histogram '+str(i)+': '+hist)
    3606                     WriteCIFitem(self.fp, '_pd_block_id',datablockidDict[hist])
    3607                     histprm = self.Histograms[hist]["Instrument Parameters"][0]
    3608                     writeCIFtemplate(histprm,'single',histprm['InstrName']) # single crystal template
    3609                     WriteSingleXtalData(hist)
    3610 
    3611             dlg.Destroy()
     3525                    dlg.Update(step,"Exporting phase "+phasenam+' (#'+str(j+1)+')')
     3526                    i = self.Phases[phasenam]['pId']
     3527                    WriteCIFitem(self.fp, '\ndata_'+self.CIFname+"_phase_"+str(i))
     3528                    WriteCIFitem(self.fp, '# Information for phase '+str(i))
     3529                    WriteCIFitem(self.fp, '_pd_block_id',datablockidDict[phasenam])
     3530                    # report the phase
     3531                    writeCIFtemplate(self.Phases[phasenam]['General'],'phase',phasenam) # write phase template
     3532                    WritePhaseInfo(phasenam,False,False)
     3533                    # preferred orientation
     3534                    if self.ifPWDR:
     3535                        SH = FormatSH(phasenam)
     3536                        MD = FormatHAPpo(phasenam)
     3537                        if SH and MD:
     3538                            WriteCIFitem(self.fp, '_pd_proc_ls_pref_orient_corr', SH + '\n' + MD)
     3539                        elif SH or MD:
     3540                            WriteCIFitem(self.fp, '_pd_proc_ls_pref_orient_corr', SH + MD)
     3541                        else:
     3542                            WriteCIFitem(self.fp, '_pd_proc_ls_pref_orient_corr', 'none')
     3543                    # report sample profile terms for all histograms with current phase
     3544                    PP = FormatPhaseProfile(phasenam)
     3545                    if PP:
     3546                        WriteCIFitem(self.fp, '_pd_proc_ls_profile_function',PP)
     3547                    self.ShowHstrainCells(phasenam,datablockidDict)
     3548
     3549                #============================================================
     3550                # loop over histograms, exporting them
     3551                # first, get atoms across all phases
     3552                uniqueAtoms = []
     3553                for phasenam in self.Phases:
     3554                    cx,ct,cs,cia = self.Phases[phasenam]['General']['AtomPtrs']
     3555                    for line in self.Phases[phasenam]['Atoms']:
     3556                        atype = line[ct].strip()
     3557                        if atype.find('-') != -1: atype = atype.split('-')[0]
     3558                        if atype.find('+') != -1: atype = atype.split('+')[0]
     3559                        atype = atype[0].upper()+atype[1:2].lower() # force case conversion
     3560                        if atype == "D" or atype == "D": atype = "H"
     3561                        if atype not in uniqueAtoms:
     3562                            uniqueAtoms.append(atype)
     3563
     3564                for i in sorted(self.powderDict.keys()):
     3565                    hist = self.powderDict[i]
     3566                    histblk = self.Histograms[hist]
     3567                    if hist.startswith("PWDR"):
     3568                        step += 1
     3569                        dlg.Update(step,"Exporting "+hist.strip())
     3570                        WriteCIFitem(self.fp, '\ndata_'+self.CIFname+"_pwd_"+str(i))
     3571                        WriteCIFitem(self.fp, '# Information for histogram '+str(i)+': '+hist)
     3572                        #instnam = histblk["Sample Parameters"]['InstrName']
     3573                        # report instrumental profile terms
     3574                        WriteCIFitem(self.fp, '_pd_proc_ls_profile_function',
     3575                            FormatInstProfile(histblk["Instrument Parameters"],histblk['hId']))
     3576                        WriteCIFitem(self.fp, '_pd_block_id',datablockidDict[hist])
     3577                        histprm = self.Histograms[hist]["Sample Parameters"]
     3578                        writeCIFtemplate(histprm,'powder',histprm['InstrName']) # powder template
     3579
     3580                        # get xray wavelength and compute & write f' & f''
     3581                        lam = None
     3582                        if 'X' in histblk['Instrument Parameters'][0]['Type'][0]:
     3583                            for k in ('Lam','Lam1'):
     3584                                if k in histblk['Instrument Parameters'][0]:
     3585                                    lam = histblk['Instrument Parameters'][0][k][0]
     3586                                    break
     3587                        if lam:
     3588                            keV = 12.397639/lam
     3589                            WriteCIFitem(self.fp,'loop_')
     3590                            for item in ('_atom_type_symbol','_atom_type_scat_dispersion_real',
     3591                                             '_atom_type_scat_dispersion_imag','_atom_type_scat_dispersion_source'):
     3592                                WriteCIFitem(self.fp,'     '+item)
     3593                            for elem in HillSortElements(uniqueAtoms):
     3594                                s = '  '
     3595                                s += PutInCol(elem,4)
     3596                                Orbs = G2el.GetXsectionCoeff(elem)
     3597                                FP,FPP,Mu = G2el.FPcalc(Orbs, keV)
     3598                                s += '  {:8.3f}{:8.3f}   https://subversion.xray.aps.anl.gov/pyGSAS/trunk/atmdata.py'.format(FP,FPP)
     3599                                WriteCIFitem(self.fp,s.rstrip())
     3600                            WriteCIFitem(self.fp,'')
     3601                        WritePowderData(hist)
     3602                for i in sorted(self.xtalDict.keys()):
     3603                    hist = self.xtalDict[i]
     3604                    histblk = self.Histograms[hist]
     3605                    if hist.startswith("HKLF"):
     3606                        step += 1
     3607                        dlg.Update(step,"Exporting "+hist.strip())
     3608                        WriteCIFitem(self.fp, '\ndata_'+self.CIFname+"_sx_"+str(i))
     3609                        #instnam = histblk["Instrument Parameters"][0]['InstrName']
     3610                        WriteCIFitem(self.fp, '# Information for histogram '+str(i)+': '+hist)
     3611                        WriteCIFitem(self.fp, '_pd_block_id',datablockidDict[hist])
     3612                        histprm = self.Histograms[hist]["Instrument Parameters"][0]
     3613                        writeCIFtemplate(histprm,'single',histprm['InstrName']) # single crystal template
     3614                        WriteSingleXtalData(hist)
     3615            finally:
     3616                dlg.Destroy()
    36123617
    36133618        WriteCIFitem(self.fp, '#--' + 15*'eof--' + '#')
     
    42594264    '''
    42604265    def __init__(self,frame,panel,tmplate,G2dict, repaint, title, defaultname=''):
     4266        def _onResetTemplate(event):
     4267            self.CIF = None
     4268            self.dict["CIF_template"] = resetTemplate
     4269            wx.CallAfter(self.repaint)
    42614270        wx.BoxSizer.__init__(self,wx.VERTICAL)
    42624271        self.cifdefs = frame
     
    42654274        self.G2frame = frame.G2frame
    42664275        templateDefName = 'template_'+tmplate+'.cif'
    4267         self.CIF = G2dict.get("CIF_template")
    42684276        if defaultname:
    42694277            self.defaultname = G2obj.StripUnicode(defaultname)
     
    42824290        self.Add((-1,3))
    42834291
    4284         if not self.CIF: # empty or None
    4285             for pth in [os.getcwd()]+sys.path:
    4286                 fil = os.path.join(pth,self.defaultname)
    4287                 if os.path.exists(fil) and self.defaultname:
    4288                     self.CIF = fil
    4289                     CIFtxt = "Template: "+self.defaultname
    4290                     break
     4292        # find default name for template
     4293        resetTemplate = None
     4294        localTemplate = None
     4295        for pth in sys.path:           # -- search with default name
     4296            fil = os.path.join(pth,templateDefName)
     4297            if os.path.exists(fil):
     4298                resetTemplate = fil
     4299                break
     4300        if not resetTemplate:    # this should not happen!
     4301            print("Default CIF template file",templateDefName,
     4302                          'not found in path!\nProblem with GSAS-II installation?')
     4303        for pth in [os.getcwd()]+sys.path: # -- search with name based on hist/phase
     4304            fil = os.path.join(pth,self.defaultname)
     4305            if os.path.exists(fil) and self.defaultname:
     4306                localTemplate = fil
     4307                break
     4308
     4309        if G2dict.get("CIF_template") == localTemplate and localTemplate:
     4310            self.CIF = localTemplate
     4311            CIFtxt = "Customized template: "+os.path.split(self.CIF)[1]
     4312        elif G2dict.get("CIF_template") == resetTemplate and resetTemplate:
     4313            self.CIF = resetTemplate
     4314            CIFtxt = "Default template: "+os.path.split(self.CIF)[1]
     4315        elif not G2dict.get("CIF_template"): # empty or None
     4316            if localTemplate:
     4317                G2dict["CIF_template"] = self.CIF = localTemplate
     4318                CIFtxt = "Customized template: "+os.path.split(self.CIF)[1]
     4319            elif resetTemplate:
     4320                G2dict["CIF_template"] = self.CIF = resetTemplate
     4321                CIFtxt = "Default template: "+os.path.split(self.CIF)[1]
    42914322            else:
    4292                 for pth in sys.path:
    4293                     fil = os.path.join(pth,templateDefName)
    4294                     if os.path.exists(fil):
    4295                         self.CIF = fil
    4296                         CIFtxt = "Template: "+templateDefName
    4297                         break
    4298                 else:
    4299                     print("Default CIF template "+self.defaultname+' not found in path!')
    4300                     self.CIF = None
    4301                     CIFtxt = "none! (No template found)"
    4302         elif type(self.CIF) is not list and type(self.CIF) is not tuple:
    4303             if not os.path.exists(self.CIF):
    4304                 print("Error: template file has disappeared: "+self.CIF)
     4323                G2dict["CIF_template"] = self.CIF = None
     4324                CIFtxt = "none (Template not found!)"
     4325        elif type(G2dict["CIF_template"]) is not list and type(
     4326                G2dict["CIF_template"]) is not tuple:
     4327            if not os.path.exists(G2dict["CIF_template"]):
     4328                print("Warning: saved template file,",
     4329                          os.path.abspath(G2dict["CIF_template"]),
     4330                          ' not found!\nWas this file moved or deleted?')
    43054331                self.CIF = None
    43064332                CIFtxt = "none! (file not found)"
     4333                if resetTemplate:
     4334                    G2dict["CIF_template"] = None
     4335                    wx.CallLater(100,self.repaint)
     4336                    return
    43074337            else:
    4308                 if len(self.CIF) < 50:
    4309                     CIFtxt = "File: "+self.CIF
    4310                 else:
    4311                     CIFtxt = "File: ..."+self.CIF[-50:]
     4338                CIFtxt = "Edited template: "+os.path.split(G2dict["CIF_template"])[1]
     4339                if GSASIIpath.GetConfigValue('debug'):
     4340                    print('Template file found',os.path.abspath(G2dict["CIF_template"]))
    43124341        else:
    4313             CIFtxt = "Template is customized"
     4342            self.CIF = G2dict["CIF_template"]
     4343            CIFtxt = "Customized template is reloaded"
    43144344        # show template source
    43154345        self.Add(wx.StaticText(panel,wx.ID_ANY,CIFtxt))
     
    43224352        but.Bind(wx.EVT_BUTTON,self._onEditTemplateContents)
    43234353        if self.CIF is None: but.Disable() # nothing to edit!
     4354        if resetTemplate and not CIFtxt.startswith('Default'):
     4355            hbox.Add(but,0,0,2)
     4356            but = wx.Button(panel,wx.ID_ANY,"Reset to default template")
     4357            but.Bind(wx.EVT_BUTTON,_onResetTemplate)
    43244358        hbox.Add(but,0,0,2)
    43254359        self.Add(hbox)
     
    43444378                raise Exception('Error, CIF Template has more than one block: '+fil)
    43454379            self.dict["CIF_template"] = fil
    4346             self.repaint() #EditCIFDefaults()
     4380            wx.CallAfter(self.repaint)
    43474381
    43484382    def _onEditTemplateContents(self,event):
     
    43604394            else:
    43614395                self.dict["CIF_template"] = [dlg.cifblk,dlg.loopstructure]
    4362             self.repaint() #EditCIFDefaults() # note that this does a dlg.Destroy()
     4396            wx.CallAfter(self.repaint) #EditCIFDefaults() # note that this does a dlg.Destroy()
    43634397        else:
    43644398            dlg.Destroy()
  • trunk/versioninfo.txt

    r5038 r5047  
    2727sequential fits and treats cases not
    2828previously allowed, such as where both refined and unrefined
    29 parameters appear in a constraint. %%%Please contact Brian if you find a
     29parameters appear in a constraint. %%%%Please contact Brian if you find a
    3030case where a set of constraints that used to work, but now fails.
Note: See TracChangeset for help on using the changeset viewer.