Changeset edd6720 in sasview for src/sas


Ignore:
Timestamp:
Apr 8, 2018 7:33:14 PM (6 years ago)
Author:
krzywon
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
bb6b037
Parents:
441a03f
Message:

Fix gui updates when new item selected in P(r) data list.

File:
1 edited

Legend:

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

    r441a03f redd6720  
    2828BACKGROUND_INPUT = 0.0 
    2929MAX_DIST = 140.0 
    30 DICT_KEYS = ["Calculator", "PrPlot", "DataPlot", "DMaxWindow", "NFuncEst"] 
    31  
    32  
    33 # TODO: Explore window not working 
     30DICT_KEYS = ["Calculator", "PrPlot", "DataPlot"] 
     31 
     32 
    3433# TODO: Update help with batch capabilities 
    3534# TODO: Method to export results in some meaningful way 
     
    6160        # current QStandardItem showing on the panel 
    6261        self._data = None 
    63         # current Data1D as referenced by self._data 
    64         self._data_set = None 
    6562        # Reference to Dmax window for self._data 
    6663        self.dmaxWindow = None 
     
    7875        self.calc_thread = None 
    7976        self.estimation_thread = None 
     77        self.estimation_thread_nt = None 
    8078 
    8179        # Mapping for all data items 
     
    303301            self.regConstantSuggestionButton.text())) 
    304302 
    305     def displayChange(self): 
     303    def displayChange(self, data_index=0): 
    306304        """Switch to another item in the data list""" 
    307         ref_item = self.dataList.itemData(self.dataList.currentIndex()) 
    308         self.updateDataList(ref_item) 
    309         self.setCurrentData(ref_item) 
     305        self.updateDataList(self._data) 
     306        self.setCurrentData(self.dataList.itemData(data_index)) 
    310307 
    311308    ###################################################################### 
     
    314311    def update_calculator(self): 
    315312        """Update all p(r) params""" 
    316         self._calculator.set_x(self._data_set.x) 
    317         self._calculator.set_y(self._data_set.y) 
    318         self._calculator.set_err(self._data_set.dy) 
     313        self._calculator.set_x(self.logic.data.x) 
     314        self._calculator.set_y(self.logic.data.y) 
     315        self._calculator.set_err(self.logic.data.dy) 
    319316        self.set_background(self.backgroundInput.text()) 
    320317 
     
    342339            self.dmaxWindow.nfunc = self.getNFunc() 
    343340            self.dmaxWindow.modelChanged() 
    344         self.mapper.toFirst() 
     341        self.mapper.toLast() 
    345342 
    346343    def help(self): 
     
    359356        Toggle the background between manual and estimated 
    360357        """ 
    361         sender = self.sender() 
    362         if sender is self.estimateBgd: 
     358        if self.estimateBgd.isChecked(): 
     359            self.manualBgd.setChecked(False) 
    363360            self.backgroundInput.setEnabled(False) 
    364361            self._calculator.set_est_bck = True 
    365         elif sender is self.manualBgd: 
     362        elif self.manualBgd.isChecked(): 
     363            self.estimateBgd.setChecked(False) 
    366364            self.backgroundInput.setEnabled(True) 
    367365            self._calculator.set_est_bck = False 
     
    395393            if data in self._data_list.keys(): 
    396394                # Don't add data if it's already in 
    397                 return 
     395                continue 
    398396            # Create initial internal mappings 
    399             self._data_set = GuiUtils.dataFromItem(data) 
    400             self.logic = InversionLogic(self._data_set) 
    401             self.populateDataComboBox(self._data_set.filename, data) 
     397            self.logic.data = GuiUtils.dataFromItem(data) 
    402398            # Estimate q range 
    403399            qmin, qmax = self.logic.computeDataRange() 
     
    405401            self._calculator.set_qmax(qmax) 
    406402            self.updateDataList(data) 
    407             self.setCurrentData(data) 
    408             # Estimate initial values from data 
    409             self.performEstimate() 
    410         self.updateGuiValues() 
     403            self.populateDataComboBox(self.logic.data.filename, data) 
     404        self.dataList.setCurrentIndex(len(self.dataList) - 1) 
     405        self.setCurrentData(data) 
    411406 
    412407    def updateDataList(self, dataRef): 
     
    417412            DICT_KEYS[0]: self._calculator, 
    418413            DICT_KEYS[1]: self.pr_plot, 
    419             DICT_KEYS[2]: self.data_plot, 
    420             DICT_KEYS[3]: self.dmaxWindow, 
    421             DICT_KEYS[4]: self.nTermsSuggested 
     414            DICT_KEYS[2]: self.data_plot 
    422415        } 
    423416 
     
    427420            nfunc = int(self.noOfTermsInput.text()) 
    428421        except ValueError: 
    429             logging.error("Incorrect number of terms specified: %s" %self.noOfTermsInput.text()) 
     422            logging.error("Incorrect number of terms specified: %s" 
     423                          %self.noOfTermsInput.text()) 
    430424            self.noOfTermsInput.setText(str(NUMBER_OF_TERMS)) 
    431425            nfunc = NUMBER_OF_TERMS 
     
    441435        # Data references 
    442436        self._data = data_ref 
    443         self._data_set = GuiUtils.dataFromItem(data_ref) 
     437        self.logic.data = GuiUtils.dataFromItem(data_ref) 
    444438        self._calculator = self._data_list[data_ref].get(DICT_KEYS[0]) 
    445439        self.pr_plot = self._data_list[data_ref].get(DICT_KEYS[1]) 
    446440        self.data_plot = self._data_list[data_ref].get(DICT_KEYS[2]) 
    447         self.dmaxWindow = self._data_list[data_ref].get(DICT_KEYS[3]) 
    448         self.nTermsSuggested = self._data_list[data_ref].get(DICT_KEYS[4]) 
    449         self.logic.set_data = self._data_set 
    450         self.updateGuiValues() 
     441        self.performEstimate() 
    451442 
    452443    def updateGuiValues(self): 
     
    456447        elapsed = self._calculator.elapsed 
    457448        alpha = self._calculator.suggested_alpha 
    458         nterms = self._calculator.nfunc 
    459449        self.model.setItem(WIDGETS.W_QMIN, 
    460450                           QtGui.QStandardItem("{:.4g}".format(pr.get_qmin()))) 
     
    496486        """Remove the existing data reference from the P(r) Persepective""" 
    497487        if self.dmaxWindow is not None: 
    498             self.dmaxWindow.done() 
     488            self.dmaxWindow.close() 
    499489            self.dmaxWindow = None 
    500490        self.dataList.removeItem(self.dataList.currentIndex()) 
     
    502492        # Last file removed 
    503493        if len(self._data_list) == 0: 
    504             self._data = None 
    505             self._data_set = None 
    506494            self.pr_plot = None 
    507495            self.data_plot = None 
    508496            self._calculator = Invertor() 
    509             self.logic.data = self._data_set 
     497            self.logic.data = None 
    510498            self.nTermsSuggested = NUMBER_OF_TERMS 
    511499            self.noOfTermsSuggestionButton.setText("{:n}".format( 
     
    513501            self.regConstantSuggestionButton.setText("{:-3.2g}".format( 
    514502                REGULARIZATION)) 
    515             self.enableButtons() 
     503            self.updateGuiValues() 
    516504            self.setupModel() 
    517505        else: 
     
    553541        from .Thread import EstimateNT 
    554542 
     543        self.update_calculator() 
     544 
    555545        # If a thread is already started, stop it 
    556         if (self.estimation_thread is not None and 
    557                 self.estimation_thread.isrunning()): 
    558             self.estimation_thread.stop() 
     546        if (self.estimation_thread_nt is not None and 
     547                self.estimation_thread_nt.isrunning()): 
     548            self.estimation_thread_nt.stop() 
    559549        pr = self._calculator.clone() 
    560550        # Skip the slit settings for the estimation 
     
    564554        nfunc = self.getNFunc() 
    565555 
    566         self.estimation_thread = EstimateNT(pr, nfunc, 
     556        self.estimation_thread_nt = EstimateNT(pr, nfunc, 
    567557                                            error_func=self._threadError, 
    568558                                            completefn=self._estimateNTCompleted, 
    569559                                            updatefn=None) 
    570         self.estimation_thread.queue() 
    571         self.estimation_thread.ready(2.5) 
     560        self.estimation_thread_nt.queue() 
     561        self.estimation_thread_nt.ready(2.5) 
    572562 
    573563    def performEstimate(self): 
     
    576566        """ 
    577567        from .Thread import EstimatePr 
    578  
    579         self.startThread() 
    580568 
    581569        # If a thread is already started, stop it 
     
    583571                self.estimation_thread.isrunning()): 
    584572            self.estimation_thread.stop() 
    585         pr = self._calculator.clone() 
    586         nfunc = self.getNFunc() 
    587         self.estimation_thread = EstimatePr(pr, nfunc, 
     573        self.estimation_thread = EstimatePr(self._calculator.clone(), 
     574                                            self.getNFunc(), 
    588575                                            error_func=self._threadError, 
    589576                                            completefn=self._estimateCompleted, 
Note: See TracChangeset for help on using the changeset viewer.