Changeset 72ecbdf2 in sasview for src/sas


Ignore:
Timestamp:
May 2, 2018 6:59:34 AM (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:
b0ba43e
Parents:
6da860a
Message:

Add a stop calculations button to P(r). Plus unit tests.

Location:
src/sas/qtgui/Perspectives/Inversion
Files:
4 edited

Legend:

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

    r6da860a r72ecbdf2  
    153153        if plotter == "χ²/dof": 
    154154            ys = chi2 
    155             y_label = "\chi^2/dof" 
     155            y_label = "\\chi^2/dof" 
    156156            y_unit = "a.u." 
    157157        elif plotter == "I(Q=0)": 
    158158            ys = iq0 
    159159            y_label = "I(q=0)" 
    160             y_unit = "\AA^{-1}" 
     160            y_unit = "\\AA^{-1}" 
    161161        elif plotter == "Rg": 
    162162            ys = rg 
    163163            y_label = "R_g" 
    164             y_unit = "\AA" 
     164            y_unit = "\\AA" 
    165165        elif plotter == "Oscillation parameter": 
    166166            ys = osc 
     
    170170            ys = bck 
    171171            y_label = "Bckg" 
    172             y_unit = "\AA^{-1}" 
     172            y_unit = "\\AA^{-1}" 
    173173        elif plotter == "Positive Fraction": 
    174174            ys = pos 
     
    177177        else: 
    178178            ys = pos_err 
    179             y_label = "P^{+}_{1\sigma}" 
     179            y_label = "P^{+}_{1\\sigma}" 
    180180            y_unit = "a.u." 
    181181 
  • src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py

    r6da860a r72ecbdf2  
    7979        self.estimationThread = None 
    8080        self.estimationThreadNT = None 
     81        self.isCalculating = False 
    8182 
    8283        # Mapping for all data items 
     
    167168        self.calculateAllButton.clicked.connect(self.startThreadAll) 
    168169        self.calculateThisButton.clicked.connect(self.startThread) 
     170        self.stopButton.clicked.connect(self.stopCalculation) 
    169171        self.removeButton.clicked.connect(self.removeData) 
    170172        self.helpButton.clicked.connect(self.help) 
     
    301303        """ 
    302304        self.calculateAllButton.setEnabled(len(self._dataList) > 1 
    303                                            and not self.isBatch) 
     305                                           and not self.isBatch 
     306                                           and not self.isCalculating) 
    304307        self.calculateThisButton.setEnabled(self.logic.data_is_loaded 
    305                                             and not self.isBatch) 
     308                                            and not self.isBatch 
     309                                            and not self.isCalculating) 
    306310        self.removeButton.setEnabled(self.logic.data_is_loaded) 
    307311        self.explorerButton.setEnabled(self.logic.data_is_loaded) 
     312        self.stopButton.setVisible(self.isCalculating) 
    308313        self.regConstantSuggestionButton.setEnabled( 
    309314            self.logic.data_is_loaded and 
     
    413418            self.batchResultsWindow.setupTable(self.batchResults) 
    414419        self.batchResultsWindow.show() 
     420 
     421    def stopCalculation(self): 
     422        """ Stop all threads, return to the base state and update GUI """ 
     423        if self.calcThread: 
     424            self.calcThread.stop() 
     425        if self.estimationThread: 
     426            self.estimationThread.stop() 
     427        if self.estimationThreadNT: 
     428            self.estimationThreadNT.stop() 
     429        # Show any batch calculations that successfully completed 
     430        if self.isBatch and self.batchResultsWindow is not None: 
     431            self.showBatchOutput() 
     432        self.isBatch = False 
     433        self.isCalculating = False 
     434        self.updateGuiValues() 
    415435 
    416436    ###################################################################### 
     
    571591 
    572592    def startThreadAll(self): 
     593        self.isCalculating = True 
    573594        self.isBatch = True 
    574595        self.batchComplete = [] 
     
    592613        else: 
    593614            # If no data sets left, end batch calculation 
     615            self.isCalculating = False 
    594616            self.batchComplete = [] 
    595617            self.calculateAllButton.setText("Calculate All") 
     
    604626 
    605627        # Set data before running the calculations 
     628        self.isCalculating = True 
     629        self.enableButtons() 
    606630        self.updateCalculator() 
    607631        # Disable calculation buttons to prevent thread interference 
    608         self.calculateAllButton.setEnabled(False) 
    609         self.calculateThisButton.setEnabled(False) 
    610632 
    611633        # If a thread is already started, stop it 
     
    744766        # Udpate internals and GUI 
    745767        self.updateDataList(self._data) 
    746         self.updateGuiValues() 
    747768        if self.isBatch: 
    748769            self.batchComplete.append(self.dataList.currentIndex()) 
    749770            self.startNextBatchItem() 
     771        else: 
     772            self.isCalculating = False 
     773        self.updateGuiValues() 
    750774 
    751775    def _threadError(self, error): 
  • src/sas/qtgui/Perspectives/Inversion/UI/TabbedInversionUI.ui

    rd744767 r72ecbdf2  
    317317           <widget class="QLabel" name="label_22"> 
    318318            <property name="text"> 
    319              <string>      </string> 
     319             <string/> 
    320320            </property> 
    321321           </widget> 
     
    754754     </item> 
    755755     <item> 
     756      <widget class="QPushButton" name="stopButton"> 
     757       <property name="text"> 
     758        <string>Stop P(r)</string> 
     759       </property> 
     760      </widget> 
     761     </item> 
     762     <item> 
    756763      <spacer name="horizontalSpacer"> 
    757764       <property name="orientation"> 
  • src/sas/qtgui/Perspectives/Inversion/UnitTesting/InversionPerspectiveTest.py

    r6bd0d81 r72ecbdf2  
    5858        self.assertEqual(self.widget.windowTitle(), "P(r) Inversion Perspective") 
    5959        self.assertFalse(self.widget.isClosable()) 
     60        self.assertFalse(self.widget.isCalculating) 
    6061        # mapper 
    6162        self.assertIsInstance(self.widget.mapper, QtWidgets.QDataWidgetMapper) 
     
    7677        self.assertFalse(self.widget.calculateThisButton.isEnabled()) 
    7778        self.assertFalse(self.widget.removeButton.isEnabled()) 
     79        self.assertTrue(self.widget.stopButton.isEnabled()) 
     80        self.assertFalse(self.widget.stopButton.isVisible()) 
    7881        self.assertFalse(self.widget.regConstantSuggestionButton.isEnabled()) 
    7982        self.assertFalse(self.widget.noOfTermsSuggestionButton.isEnabled()) 
     
    154157        self.twoDataSetState() 
    155158        self.widget.calculateAllButton.click() 
     159        self.assertTrue(self.widget.isCalculating) 
     160        self.assertTrue(self.widget.isBatch) 
     161        self.assertTrue(self.widget.stopButton.isVisible()) 
     162        self.assertTrue(self.widget.stopButton.isEnabled()) 
    156163        self.assertIsNotNone(self.widget.batchResultsWindow) 
    157164        self.assertTrue(self.widget.batchResultsWindow.cmdHelp.isEnabled()) 
    158165        self.assertEqual(self.widget.batchResultsWindow.tblParams.columnCount(), 9) 
    159166        self.assertEqual(self.widget.batchResultsWindow.tblParams.rowCount(), 2) 
    160         if self.widget.isBatch: 
    161             self.widget.isBatch = False 
     167        # Test stop button 
     168        self.widget.stopButton.click() 
     169        self.assertTrue(self.widget.batchResultsWindow.isVisible()) 
     170        self.assertFalse(self.widget.stopButton.isVisible()) 
     171        self.assertTrue(self.widget.stopButton.isEnabled()) 
     172        self.assertFalse(self.widget.isBatch) 
     173        self.assertFalse(self.widget.isCalculating) 
    162174        self.widget.batchResultsWindow.close() 
    163175        self.assertIsNone(self.widget.batchResultsWindow) 
    164176        # Last test 
    165         self.widget.removeData() 
    166177        self.removeAllData() 
    167178        self.baseBatchState() 
     
    218229            self.widget.noOfTermsInput.setText("") 
    219230            n = self.widget.getNFunc() 
    220             self.assertEqual(cm.output, ['ERROR:root:Incorrect number of terms specified: ']) 
     231            self.assertEqual(cm.output, ['ERROR:sas.qtgui.Perspectives.Inversion.InversionPerspective:Incorrect number of terms specified: ']) 
    221232        self.assertEqual(self.widget.getNFunc(), 10) 
    222233        # string 
     
    224235            self.widget.noOfTermsInput.setText("Nordvest Pizza") 
    225236            n = self.widget.getNFunc() 
    226             self.assertEqual(cm.output, ['ERROR:root:Incorrect number of terms specified: Nordvest Pizza']) 
     237            self.assertEqual(cm.output, ['ERROR:sas.qtgui.Perspectives.Inversion.InversionPerspective:Incorrect number of terms specified: Nordvest Pizza']) 
    227238        self.assertEqual(self.widget.getNFunc(), 10) 
    228239        self.removeAllData() 
Note: See TracChangeset for help on using the changeset viewer.