Changeset 34cf92c in sasview for src


Ignore:
Timestamp:
Sep 8, 2018 3:48:26 AM (6 years ago)
Author:
wojciech
Branches:
ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
e908916
Parents:
0c0491d
Message:

Dynamic text edit logic introduced

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py

    rb1f6063 r34cf92c  
    4343    estimateSignal = QtCore.pyqtSignal(tuple) 
    4444    estimateNTSignal = QtCore.pyqtSignal(tuple) 
     45    estimateDynamicNTSignal = QtCore.pyqtSignal(tuple) 
     46    estimateDynamicSignal = QtCore.pyqtSignal(tuple) 
    4547    calculateSignal = QtCore.pyqtSignal(tuple) 
    4648 
     
    194196        self.model.itemChanged.connect(self.model_changed) 
    195197        self.estimateNTSignal.connect(self._estimateNTUpdate) 
     198        self.estimateDynamicNTSignal.connect(self._estimateDynamicNTUpdate) 
     199        self.estimateDynamicSignal.connect(self._estimateDynamicUpdate) 
    196200        self.estimateSignal.connect(self._estimateUpdate) 
    197201        self.calculateSignal.connect(self._calculateUpdate) 
     202 
     203        self.maxDistanceInput.textEdited.connect(self.performEstimateDynamic) 
    198204 
    199205    def setupMapper(self): 
     
    500506        self.dataPlot = self._dataList[data_ref].get(DICT_KEYS[2]) 
    501507        self.performEstimate() 
     508 
     509    def updateDynamicGuiValues(self): 
     510        pr = self._calculator 
     511        alpha = self._calculator.suggested_alpha 
     512        self.model.setItem(WIDGETS.W_MAX_DIST, 
     513                            QtGui.QStandardItem("{:.4g}".format(pr.get_dmax()))) 
     514        self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha)) 
     515        self.noOfTermsSuggestionButton.setText( 
     516             "{:n}".format(self.nTermsSuggested)) 
     517 
     518        self.enableButtons() 
    502519 
    503520    def updateGuiValues(self): 
     
    673690        self.estimationThreadNT.ready(2.5) 
    674691 
     692    def performEstimateDynamicNT(self): 
     693        """ 
     694        Perform parameter estimation 
     695        """ 
     696        from .Thread import EstimateNT 
     697 
     698        self.updateCalculator() 
     699 
     700        # If a thread is already started, stop it 
     701        self.stopEstimateNTThread() 
     702 
     703        pr = self._calculator.clone() 
     704        # Skip the slit settings for the estimation 
     705        # It slows down the application and it doesn't change the estimates 
     706        pr.slit_height = 0.0 
     707        pr.slit_width = 0.0 
     708        nfunc = self.getNFunc() 
     709 
     710        self.estimationThreadNT = EstimateNT(pr, nfunc, 
     711                                             error_func=self._threadError, 
     712                                             completefn=self._estimateDynamicNTCompleted, 
     713                                             updatefn=None) 
     714        self.estimationThreadNT.queue() 
     715        self.estimationThreadNT.ready(2.5) 
     716 
    675717    def stopEstimateNTThread(self): 
    676718        if (self.estimationThreadNT is not None and 
     
    695737        self.estimationThread.ready(2.5) 
    696738 
     739    def performEstimateDynamic(self): 
     740        """ 
     741            Perform parameter estimation 
     742        """ 
     743        from .Thread import EstimatePr 
     744 
     745        # If a thread is already started, stop it 
     746        self.stopEstimationThread() 
     747 
     748        self.estimationThread = EstimatePr(self._calculator.clone(), 
     749                                           self.getNFunc(), 
     750                                           error_func=self._threadError, 
     751                                           completefn=self._estimateDynamicCompleted, 
     752                                           updatefn=None) 
     753        self.estimationThread.queue() 
     754        self.estimationThread.ready(2.5) 
     755 
    697756    def stopEstimationThread(self): 
    698757        """ Stop the estimation thread if it exists and is running """ 
     
    707766        ''' Send a signal to the main thread for model update''' 
    708767        self.estimateSignal.emit((alpha, message, elapsed)) 
     768 
     769    def _estimateDynamicCompleted(self, alpha, message, elapsed): 
     770        ''' Send a signal to the main thread for model update''' 
     771        self.estimateDynamicSignal.emit((alpha, message, elapsed)) 
    709772 
    710773    def _estimateUpdate(self, output_tuple): 
     
    723786        self.performEstimateNT() 
    724787 
     788    def _estimateDynamicUpdate(self, output_tuple): 
     789        """ 
     790        Parameter estimation completed, 
     791        display the results to the user 
     792 
     793        :param alpha: estimated best alpha 
     794        :param elapsed: computation time 
     795        """ 
     796        alpha, message, elapsed = output_tuple 
     797        self._calculator.alpha = alpha 
     798        self._calculator.elapsed += self._calculator.elapsed 
     799        if message: 
     800            logger.info(message) 
     801        self.performEstimateDynamicNT() 
     802 
    725803    def _estimateNTCompleted(self, nterms, alpha, message, elapsed): 
    726804        ''' Send a signal to the main thread for model update''' 
    727805        self.estimateNTSignal.emit((nterms, alpha, message, elapsed)) 
     806 
     807    def _estimateDynamicNTCompleted(self, nterms, alpha, message, elapsed): 
     808        ''' Send a signal to the main thread for model update''' 
     809        self.estimateDynamicNTSignal.emit((nterms, alpha, message, elapsed)) 
    728810 
    729811    def _estimateNTUpdate(self, output_tuple): 
     
    749831            self.startThread() 
    750832 
     833    def _estimateDynamicNTUpdate(self, output_tuple): 
     834        """ 
     835        Parameter estimation completed, 
     836        display the results to the user 
     837 
     838        :param alpha: estimated best alpha 
     839        :param nterms: estimated number of terms 
     840        :param elapsed: computation time 
     841        """ 
     842        nterms, alpha, message, elapsed = output_tuple 
     843        self._calculator.elapsed += elapsed 
     844        self._calculator.suggested_alpha = alpha 
     845        self.nTermsSuggested = nterms 
     846        # Save useful info 
     847        self.updateDynamicGuiValues() 
     848        if message: 
     849            logger.info(message) 
     850        if self.isBatch: 
     851            self.acceptAlpha() 
     852            self.acceptNoTerms() 
     853            self.startThread() 
     854 
    751855    def _calculateCompleted(self, out, cov, pr, elapsed): 
    752856        ''' Send a signal to the main thread for model update''' 
Note: See TracChangeset for help on using the changeset viewer.