Changeset 4136


Ignore:
Timestamp:
Sep 4, 2019 5:06:31 PM (2 years ago)
Author:
toby
Message:

fix cancel in refine dialog, tested w/wx2.8,3.0 & 4.0

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIdataGUI.py

    r4118 r4136  
    48324832            dlg.SetSize((int(Size[0]*1.2),Size[1])) # increase size a bit along x
    48334833        dlg.CenterOnParent()
     4834        dlg.Show()
    48344835        # find 1st histogram to be refined
    48354836        if 'Seq Data' in Controls:
  • trunk/GSASIIobj.py

    r4073 r4136  
    27642764
    27652765class G2Exception(Exception):
     2766    'A generic GSAS-II exception class'
    27662767    def __init__(self,msg):
    27672768        self.msg = msg
     
    27692770        return repr(self.msg)
    27702771
     2772class G2RefineCancel(Exception):
     2773    'Raised when Cancel is pressed in a refinement dialog'
     2774    def __init__(self,msg):
     2775        self.msg = msg
     2776    def __str__(self):
     2777        return repr(self.msg)
     2778   
    27712779def HowDidIgetHere(wherecalledonly=False):
    27722780    '''Show a traceback with calls that brought us to the current location.
  • trunk/GSASIIstrMain.py

    r4133 r4136  
    251251    printFile.write('\n Refinement results:\n')
    252252    printFile.write(135*'-'+'\n')
    253     if True:
    254 #    try:
     253    try:
    255254        covData = {}
    256255        IfOK,Rvals,result,covMatrix,sig = RefineCore(Controls,Histograms,Phases,restraintDict,
     
    280279            G2fil.G2Print ('****ERROR - Refinement failed')
    281280            raise G2obj.G2Exception('****ERROR - Refinement failed')
    282 #    except G2obj.G2Exception(Msg):
    283 #        printFile.close()
    284 #        return False,Msg.msg
     281    except G2obj.G2RefineCancel as Msg:
     282        printFile.close()
     283        G2fil.G2Print (' ***** Refinement stopped *****')
     284        return False,Msg.msg
     285    except G2obj.G2Exception as Msg:  # cell metric error, others?
     286        printFile.close()
     287        G2fil.G2Print (' ***** Refinement error *****')
     288        return False,Msg.msg
    285289
    286290#for testing purposes, create a file for testderiv
     
    497501        printFile.write('\n Refinement results for histogram: %s\n'%histogram)
    498502        printFile.write(135*'-'+'\n')
    499         if True:
    500 #        try:
     503        try:
    501504            IfOK,Rvals,result,covMatrix,sig = RefineCore(Controls,Histo,Phases,restraintDict,
    502505                rigidbodyDict,parmDict,varyList,calcControls,pawleyLookup,ifSeq,printFile,dlg,
     
    547550                        NewparmDict[parm] = parmDict[parm]
    548551                   
    549 #        except G2obj.G2Exception(Msg):
    550 #            printFile.close()
    551 #            G2fil.G2Print (' ***** Refinement aborted *****')
    552 #            return False,Msg.msg
     552        except G2obj.G2RefineCancel as Msg:
     553            printFile.close()
     554            G2fil.G2Print (' ***** Refinement stopped *****')
     555            return False,Msg.msg
     556        except G2obj.G2Exception as Msg:  # cell metric error, others?
     557            printFile.close()
     558            G2fil.G2Print (' ***** Refinement error *****')
     559            return False,Msg.msg
    553560        if GSASIIpath.GetConfigValue('Show_timing'):
    554561            t2 = time.time()
  • trunk/GSASIIstrMath.py

    r4135 r4136  
    38973897            dMdvh *= Wt
    38983898            if dlg:
    3899                 dlg.Update(Histogram['Residuals']['wR'],newmsg='Hessian for histogram %d\nAll data Rw=%8.3f%s'%(hId,Histogram['Residuals']['wR'],'%'))
     3899                GoOn = dlg.Update(Histogram['Residuals']['wR'],newmsg='Hessian for histogram %d\nAll data Rw=%8.3f%s'%(hId,Histogram['Residuals']['wR'],'%'))
     3900                if type(GoOn) is tuple:
     3901                    if not GoOn[0]:
     3902                        raise G2obj.G2RefineCancel('Cancel pressed')
     3903                elif not GoOn:
     3904                    raise G2obj.G2RefineCancel('Cancel pressed')
    39003905                dlg.Raise()
    39013906            if len(Hess):
     
    39203925
    39213926            if dlg:
    3922                 dlg.Update(Histogram['Residuals']['wR'],newmsg='Hessian for histogram %d Rw=%8.3f%s'%(hId,Histogram['Residuals']['wR'],'%'))[0]
     3927                GoOn = dlg.Update(Histogram['Residuals']['wR'],newmsg='Hessian for histogram %d Rw=%8.3f%s'%(hId,Histogram['Residuals']['wR'],'%'))
     3928                if type(GoOn) is tuple:
     3929                    if not GoOn[0]:
     3930                        raise G2obj.G2RefineCancel('Cancel pressed')
     3931                elif not GoOn:
     3932                    raise G2obj.G2RefineCancel('Cancel pressed')
    39233933                dlg.Raise()
    39243934            if len(Hess):
     
    40014011            Histogram['Residuals']['wRmin'] = min(100.,100.*ma.sqrt(Histogram['Residuals']['Nobs']/Histogram['Residuals']['sumwYo']))
    40024012            if dlg:
    4003                 dlg.Update(Histogram['Residuals']['wR'],newmsg='For histogram %d Rw=%8.3f%s'%(hId,Histogram['Residuals']['wR'],'%'))[0]
     4013                GoOn = dlg.Update(Histogram['Residuals']['wR'],newmsg='For histogram %d Rw=%8.3f%s'%(hId,Histogram['Residuals']['wR'],'%'))
     4014                if type(GoOn) is tuple:
     4015                    if not GoOn[0]:
     4016                        raise G2obj.G2RefineCancel('Cancel pressed')
     4017                elif not GoOn:
     4018                    raise G2obj.G2RefineCancel('Cancel pressed')
    40044019                dlg.Raise()
    40054020            M = np.concatenate((M,wdy))
     
    41454160            Next += next
    41464161            if dlg:
    4147                 dlg.Update(Histogram['Residuals']['wR'],newmsg='For histogram %d Rw=%8.3f%s'%(hId,Histogram['Residuals']['wR'],'%'))[0]
     4162                GoOn = dlg.Update(Histogram['Residuals']['wR'],newmsg='For histogram %d Rw=%8.3f%s'%(hId,Histogram['Residuals']['wR'],'%'))
     4163                if type(GoOn) is tuple:
     4164                    if not GoOn[0]:
     4165                        raise G2obj.G2RefineCancel('Cancel pressed')
     4166                elif not GoOn:
     4167                    raise G2obj.G2RefineCancel('Cancel pressed')
    41484168                dlg.Raise()
    41494169            M = np.concatenate((M,wtFactor*df))
     
    41564176    Rw = min(100.,np.sqrt(np.sum(M**2)/SumwYo)*100.)
    41574177    if dlg:
    4158         GoOn = dlg.Update(Rw,newmsg='%s%8.3f%s'%('All data Rw =',Rw,'%'))[0]
    4159         if not GoOn:
     4178        GoOn = dlg.Update(Rw,newmsg='%s%8.3f%s'%('All data Rw =',Rw,'%'))
     4179        if type(GoOn) is tuple:
     4180            if not GoOn[0]:
     4181                parmDict['saved values'] = values
     4182                raise G2obj.G2RefineCancel('Cancel pressed')
     4183        elif not GoOn:
    41604184            parmDict['saved values'] = values
    4161             dlg.Destroy()
    4162             raise G2obj.G2Exception('User abort')         #Abort!!
     4185            raise G2obj.G2RefineCancel('Cancel pressed')
     4186        dlg.Raise()
    41634187    pDict,pVals,pWt,pWsum,pWnum = penaltyFxn(HistoPhases,calcControls,parmDict,varylist)
    41644188    if len(pVals):
Note: See TracChangeset for help on using the changeset viewer.