Changeset 0c468bf in sasview for src/sas


Ignore:
Timestamp:
Oct 19, 2017 7:55:59 AM (7 years ago)
Author:
celinedurniak <celine.durniak@…>
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:
1420066
Parents:
f0bb711
Message:

Corrected Data Operation Panel: disabling compute button when incompatible data

Location:
src/sas/qtgui/Calculators
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Calculators/DataOperationUtilityPanel.py

    rf0bb711 r0c468bf  
    126126    def onCompute(self): 
    127127        """ perform calculation """ 
    128         # check compatibility of datasets before calculation 
    129         if self.onCheckChosenData(): 
    130             # set operator to be applied 
    131             operator = self.cbOperator.currentText() 
    132             # calculate and send data to DataExplorer 
    133             output = None 
    134             try: 
    135                 data1 = self.data1 
    136                 data2 = self.data2 
    137                 exec "output = data1 %s data2" % operator 
    138             except: 
    139                 raise 
    140  
    141             self.output = output 
    142  
    143             # if outputname was unused, write output result to it 
    144             # and display plot 
    145             if self.onCheckOutputName(): 
    146                 # add outputname to self.filenames 
    147                 self.list_data_items.append(str(self.txtOutputData.text())) 
    148                 # send result to DataExplorer 
    149                 self.onPrepareOutputData() 
    150                 # plot result 
    151                 self.updatePlot(self.graphOutput, self.layoutOutput, self.output) 
     128        # set operator to be applied 
     129        operator = self.cbOperator.currentText() 
     130        # calculate and send data to DataExplorer 
     131        output = None 
     132        try: 
     133            data1 = self.data1 
     134            data2 = self.data2 
     135            exec "output = data1 %s data2" % operator 
     136        except: 
     137            raise 
     138 
     139        self.output = output 
     140 
     141        # if outputname was unused, write output result to it 
     142        # and display plot 
     143        if self.onCheckOutputName(): 
     144            # add outputname to self.filenames 
     145            self.list_data_items.append(str(self.txtOutputData.text())) 
     146            # send result to DataExplorer 
     147            self.onPrepareOutputData() 
     148            # plot result 
     149            self.updatePlot(self.graphOutput, self.layoutOutput, self.output) 
    152150 
    153151    def onPrepareOutputData(self): 
     
    207205            self.data1 = None 
    208206            self.data1OK = False 
    209             self.cmdCompute.setEnabled(False) 
    210             self.onCheckChosenData() 
     207            self.cmdCompute.setEnabled(False) # self.onCheckChosenData()) 
    211208            return 
    212209 
    213210        else: 
    214             # Enable Compute button only if Data2 is defined 
    215             self.cmdCompute.setEnabled(self.data2OK) 
    216211            self.data1OK = True 
    217             self.onCheckChosenData() 
    218212            # get Data1 
    219213            key_id1 = self._findId(choice_data1) 
     
    223217            # plot default for output graph 
    224218            self.newPlot(self.graphOutput, self.layoutOutput) 
    225  
     219            # Enable Compute button only if Data2 is defined and data compatible 
     220            self.cmdCompute.setEnabled(self.onCheckChosenData()) 
    226221 
    227222    def onSelectData2(self): 
     
    235230            self.data2OK = False 
    236231            self.onCheckChosenData() 
     232            self.cmdCompute.setEnabled(False) 
    237233            return 
    238234 
     
    242238            self.data2 = float(self.txtNumber.text()) 
    243239 
    244             # Enable Compute button only if Data1 is defined 
    245             self.cmdCompute.setEnabled(self.data1OK) 
     240            # Enable Compute button only if Data1 defined and compatible data 
     241            self.cmdCompute.setEnabled(self.onCheckChosenData()) 
    246242            # Display value of coefficient in graphData2 
    247243            self.updatePlot(self.graphData2, self.layoutData2, self.data2) 
     
    251247 
    252248        else: 
    253             self.cmdCompute.setEnabled(self.data1OK) 
     249            self.txtNumber.setEnabled(False) 
    254250            self.data2OK = True 
    255             self.txtNumber.setEnabled(False) 
    256251            key_id2 = self._findId(choice_data2) 
    257252            self.data2 = self._extractData(key_id2) 
     253            self.cmdCompute.setEnabled(self.onCheckChosenData()) 
     254 
    258255            # plot Data2 
    259256            self.updatePlot(self.graphData2, self.layoutData2, self.data2) 
    260257            # plot default for output graph 
    261258            self.newPlot(self.graphOutput, self.layoutOutput) 
    262             self.onCheckChosenData() 
    263259 
    264260    def onInputCoefficient(self): 
     
    285281 
    286282    def onCheckChosenData(self): 
    287         """ Before running compute, check that data1 and 2 are compatible """ 
    288  
    289         if self.cbData2.currentText() == 'Number': 
    290             self.cbData1.setStyleSheet(QtCore.QString(BG_WHITE)) 
    291             self.cbData2.setStyleSheet(QtCore.QString(BG_WHITE)) 
    292             return True 
    293  
    294         elif self.data1.__class__.__name__ != self.data2.__class__.__name__: 
    295             self.cbData1.setStyleSheet(QtCore.QString(BG_RED)) 
    296             self.cbData2.setStyleSheet(QtCore.QString(BG_RED)) 
    297             logging.info('Cannot compute data of different dimensions') 
     283        """ check that data1 and data2 are compatible """ 
     284 
     285        if not all([self.data1OK, self.data2OK]): 
    298286            return False 
    299  
    300         elif self.data1.__class__.__name__ == 'Data1D'\ 
    301                 and (len(self.data2.x) != len(self.data1.x) or 
    302                          not all(i == j for i, j in zip(self.data1.x, self.data2.x))): 
    303             logging.info('Cannot compute 1D data of different lengths') 
    304             self.cbData1.setStyleSheet(QtCore.QString(BG_RED)) 
    305             self.cbData2.setStyleSheet(QtCore.QString(BG_RED)) 
    306             return False 
    307  
    308         elif self.data1.__class__.__name__ == 'Data2D' \ 
    309                 and (len(self.data2.qx_data) != len(self.data1.qx_data) \ 
    310                 or len(self.data2.qy_data) != len(self.data1.qy_data) 
    311                 or not all(i == j for i, j in 
    312                                  zip(self.data1.qx_data, self.data2.qx_data)) 
    313                 or not all(i == j for i, j in 
    314                             zip(self.data1.qy_data, self.data2.qy_data)) 
    315                      ): 
    316             self.cbData1.setStyleSheet(QtCore.QString(BG_RED)) 
    317             self.cbData2.setStyleSheet(QtCore.QString(BG_RED)) 
    318             logging.info('Cannot compute 2D data of different lengths') 
    319             return False 
    320  
    321287        else: 
    322             self.cbData1.setStyleSheet(QtCore.QString(BG_WHITE)) 
    323             self.cbData2.setStyleSheet(QtCore.QString(BG_WHITE)) 
    324             return True 
     288            if self.cbData2.currentText() == 'Number': 
     289                self.cbData1.setStyleSheet(QtCore.QString(BG_WHITE)) 
     290                self.cbData2.setStyleSheet(QtCore.QString(BG_WHITE)) 
     291                return True 
     292 
     293            elif self.data1.__class__.__name__ != self.data2.__class__.__name__: 
     294                self.cbData1.setStyleSheet(QtCore.QString(BG_RED)) 
     295                self.cbData2.setStyleSheet(QtCore.QString(BG_RED)) 
     296                print self.data1.__class__.__name__ != self.data2.__class__.__name__ 
     297                logging.info('Cannot compute data of different dimensions') 
     298                return False 
     299 
     300            elif self.data1.__class__.__name__ == 'Data1D'\ 
     301                    and (len(self.data2.x) != len(self.data1.x) or 
     302                             not all(i == j for i, j in zip(self.data1.x, self.data2.x))): 
     303                logging.info('Cannot compute 1D data of different lengths') 
     304                self.cbData1.setStyleSheet(QtCore.QString(BG_RED)) 
     305                self.cbData2.setStyleSheet(QtCore.QString(BG_RED)) 
     306                return False 
     307 
     308            elif self.data1.__class__.__name__ == 'Data2D' \ 
     309                    and (len(self.data2.qx_data) != len(self.data1.qx_data) \ 
     310                    or len(self.data2.qy_data) != len(self.data1.qy_data) 
     311                    or not all(i == j for i, j in 
     312                                     zip(self.data1.qx_data, self.data2.qx_data)) 
     313                    or not all(i == j for i, j in 
     314                                zip(self.data1.qy_data, self.data2.qy_data)) 
     315                         ): 
     316                self.cbData1.setStyleSheet(QtCore.QString(BG_RED)) 
     317                self.cbData2.setStyleSheet(QtCore.QString(BG_RED)) 
     318                logging.info('Cannot compute 2D data of different lengths') 
     319                return False 
     320 
     321            else: 
     322                self.cbData1.setStyleSheet(QtCore.QString(BG_WHITE)) 
     323                self.cbData2.setStyleSheet(QtCore.QString(BG_WHITE)) 
     324                return True 
    325325 
    326326    def onCheckOutputName(self): 
  • src/sas/qtgui/Calculators/UnitTesting/DataOperationUtilityTest.py

    rd5c5d3d r0c468bf  
    135135 
    136136 
    137     # @patch('DataOperationUtilityPanel.') 
    138137    def testOnCompute(self): 
    139138        """ Test onCompute function """ 
     
    163162 
    164163        self.assertTrue(self.widget.onPrepareOutputData.called_once()) 
    165  
    166         # GuiManager.updateModelFromDataOperationPanel 
    167164 
    168165    def testOnSelectData1(self): 
     
    283280    def testCheckChosenData(self): 
    284281        """ Test check of data compatibility """ 
     282        # set the 2 following to True since we want to check 
     283        # the compatibility of dimensions 
     284        self.widget.data1OK = True 
     285        self.widget.data2OK = True 
     286 
    285287        # Case 1: incompatible dimensions 
    286288        self.widget.data1 = Data1D(x=[1.0, 2.0, 3.0], y=[11.0, 12.0, 13.0], 
Note: See TracChangeset for help on using the changeset viewer.