Changeset e43fc91 in sasview


Ignore:
Timestamp:
Aug 25, 2017 6:37:30 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
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:
4d1eff2
Parents:
b2a5042
git-author:
Piotr Rozyczko <rozyczko@…> (08/25/17 06:31:37)
git-committer:
Piotr Rozyczko <rozyczko@…> (08/25/17 06:37:30)
Message:

Fixed a crash when the file open dialog would lose reference to the underlying listview cell on cell losing focus SASVIEW-625

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sasview/sasview.spec

    r377ade1 re43fc91  
    2525    UPX=True 
    2626 
    27 SCRIPT_TO_SOURCE = 'run.py' 
     27SCRIPT_TO_SOURCE = 'sasview.py' 
    2828 
    2929# Warning! pyinstaller/py2exe etc. don't have the __file__ attribute 
  • src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py

    r689222c re43fc91  
    159159    model.setHeaderData(5, QtCore.Qt.Horizontal, QtCore.QVariant("Nsigs")) 
    160160    model.setHeaderData(6, QtCore.Qt.Horizontal, QtCore.QVariant("Function")) 
     161    model.setHeaderData(7, QtCore.Qt.Horizontal, QtCore.QVariant("Filename")) 
    161162 
    162163def addErrorPolyHeadersToModel(model): 
     
    172173    model.setHeaderData(6, QtCore.Qt.Horizontal, QtCore.QVariant("Nsigs")) 
    173174    model.setHeaderData(7, QtCore.Qt.Horizontal, QtCore.QVariant("Function")) 
     175    model.setHeaderData(8, QtCore.Qt.Horizontal, QtCore.QVariant("Filename")) 
    174176 
    175177def addShellsToModel(parameters, model, index): 
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r457d961 re43fc91  
    286286        # Polydispersity function combo response 
    287287        self.lstPoly.itemDelegate().combo_updated.connect(self.onPolyComboIndexChange) 
     288        self.lstPoly.itemDelegate().filename_updated.connect(self.onPolyFilenameChange) 
    288289 
    289290        # Magnetism model displayed in magnetism list 
     
    566567            # name of the function - just pass 
    567568            return 
     569        elif model_column == self.lstPoly.itemDelegate().poly_filename: 
     570            # filename for array - just pass 
     571            return 
    568572        else: 
    569573            try: 
     
    14881492 
    14891493        header.ResizeMode(QtGui.QHeaderView.Interactive) 
    1490         # Resize column 0 and 6 to content 
     1494        # Resize column 0 and 7 to content 
    14911495        header.setResizeMode(0, QtGui.QHeaderView.ResizeToContents) 
    1492         header.setResizeMode(6, QtGui.QHeaderView.ResizeToContents) 
     1496        header.setResizeMode(7, QtGui.QHeaderView.ResizeToContents) 
    14931497 
    14941498    def setPolyModel(self): 
     
    15001504        self._poly_model.clear() 
    15011505 
    1502         [self.setPolyModelParameters(param) for _, param in \ 
     1506        [self.setPolyModelParameters(i, param) for i, param in \ 
    15031507            enumerate(self.model_parameters.form_volume_parameters) if param.polydisperse] 
    15041508        FittingUtilities.addPolyHeadersToModel(self._poly_model) 
    15051509 
    1506     def setPolyModelParameters(self, param): 
     1510    def setPolyModelParameters(self, i, param): 
    15071511        """ 
    15081512        Standard of multishell poly parameter driver 
     
    15191523                    # Remove [n] and add the shell numeral 
    15201524                    name = param_name[0:param_name.index('[')] + str(ishell) 
    1521                     self.addNameToPolyModel(name) 
     1525                    self.addNameToPolyModel(i, name) 
    15221526        else: 
    15231527            # Just create a simple param entry 
    1524             self.addNameToPolyModel(param_name) 
    1525  
    1526     def addNameToPolyModel(self, param_name): 
     1528            self.addNameToPolyModel(i, param_name) 
     1529 
     1530    def addNameToPolyModel(self, i, param_name): 
    15271531        """ 
    15281532        Creates a checked row in the poly model with param_name 
     
    15391543        checked_list = ["Distribution of " + param_name, str(width), 
    15401544                        str(min), str(max), 
    1541                         str(npts), str(nsigs), "gaussian      "] 
     1545                        str(npts), str(nsigs), "gaussian      ",''] 
    15421546        FittingUtilities.addCheckedListToModel(self._poly_model, checked_list) 
    15431547 
     
    15451549        func = QtGui.QComboBox() 
    15461550        func.addItems([str(name_disp) for name_disp in POLYDISPERSITY_MODELS.iterkeys()]) 
    1547         # set the default index 
     1551        # Set the default index 
    15481552        func.setCurrentIndex(func.findText(DEFAULT_POLYDISP_FUNCTION)) 
     1553        ind = self._poly_model.index(i,self.lstPoly.itemDelegate().poly_function) 
     1554        self.lstPoly.setIndexWidget(ind, func) 
     1555        func.currentIndexChanged.connect(lambda: self.onPolyComboIndexChange(str(func.currentText()), i)) 
     1556 
     1557    def onPolyFilenameChange(self, row_index): 
     1558        """ 
     1559        Respond to filename_updated signal from the delegate 
     1560        """ 
     1561        # For the given row, invoke the "array" combo handler 
     1562        array_caption = 'array' 
     1563        self.onPolyComboIndexChange(array_caption, row_index) 
     1564        # Get the combo box reference 
     1565        ind = self._poly_model.index(row_index, self.lstPoly.itemDelegate().poly_function) 
     1566        widget = self.lstPoly.indexWidget(ind) 
     1567        # Update the combo box so it displays "array" 
     1568        widget.blockSignals(True) 
     1569        widget.setCurrentIndex(self.lstPoly.itemDelegate().POLYDISPERSE_FUNCTIONS.index(array_caption)) 
     1570        widget.blockSignals(False) 
    15491571 
    15501572    def onPolyComboIndexChange(self, combo_string, row_index): 
     
    15541576        # Get npts/nsigs for current selection 
    15551577        param = self.model_parameters.form_volume_parameters[row_index] 
     1578        file_index = self._poly_model.index(row_index, self.lstPoly.itemDelegate().poly_function) 
     1579        combo_box = self.lstPoly.indexWidget(file_index) 
     1580        orig_index = combo_box.currentIndex() 
    15561581 
    15571582        def updateFunctionCaption(row): 
     
    15651590        if combo_string == 'array': 
    15661591            try: 
    1567                 self.loadPolydispArray() 
     1592                self.loadPolydispArray(row_index) 
    15681593                # Update main model for display 
    15691594                self.iterateOverModel(updateFunctionCaption) 
    1570             except (ValueError, IOError): 
    1571                 # Don't do anything if file lookup failed 
     1595                # disable the row 
     1596                lo = self.lstPoly.itemDelegate().poly_pd 
     1597                hi = self.lstPoly.itemDelegate().poly_function 
     1598                [self._poly_model.item(row_index, i).setEnabled(False) for i in xrange(lo, hi)] 
    15721599                return 
    1573             # disable the row 
    1574             [self._poly_model.item(row_index, i).setEnabled(False) for i in xrange(6)] 
    1575             return 
     1600            except IOError: 
     1601                combo_box.setCurrentIndex(orig_index) 
     1602                # Pass for cancel/bad read 
     1603                pass 
    15761604 
    15771605        # Enable the row in case it was disabled by Array 
    15781606        self._poly_model.blockSignals(True) 
    1579         [self._poly_model.item(row_index, i).setEnabled(True) for i in xrange(6)] 
     1607        max_range = self.lstPoly.itemDelegate().poly_filename 
     1608        [self._poly_model.item(row_index, i).setEnabled(True) for i in xrange(7)] 
     1609        file_index = self._poly_model.index(row_index, self.lstPoly.itemDelegate().poly_filename) 
     1610        self._poly_model.setData(file_index, QtCore.QVariant("")) 
    15801611        self._poly_model.blockSignals(False) 
    15811612 
     
    15911622        self.iterateOverModel(updateFunctionCaption) 
    15921623 
    1593     def loadPolydispArray(self): 
     1624    def loadPolydispArray(self, row_index): 
    15941625        """ 
    15951626        Show the load file dialog and loads requested data into state 
     
    15991630            None, QtGui.QFileDialog.DontUseNativeDialog) 
    16001631 
    1601         if datafile is None: 
     1632        if datafile is None or str(datafile)=='': 
    16021633            logging.info("No weight data chosen.") 
    16031634            raise IOError 
     
    16231654        self.disp_model = POLYDISPERSITY_MODELS['array']() 
    16241655        self.disp_model.set_weights(np.array(values), np.array(weights)) 
     1656        # + update the cell with filename 
     1657        fname = os.path.basename(str(datafile)) 
     1658        fname_index = self._poly_model.index(row_index, self.lstPoly.itemDelegate().poly_filename) 
     1659        self._poly_model.setData(fname_index, QtCore.QVariant(fname)) 
    16251660 
    16261661    def setMagneticModel(self): 
  • src/sas/qtgui/Perspectives/Fitting/ViewDelegate.py

    r377ade1 re43fc91  
    8585    Custom delegate for appearance and behavior control of the polydispersity view 
    8686    """ 
    87     #POLYDISPERSE_FUNCTIONS = ['rectangle', 'array', 'lognormal', 'gaussian', 'schulz'] 
    88     POLYDISPERSE_FUNCTIONS = ['rectangle', 'lognormal', 'gaussian', 'schulz'] 
     87    POLYDISPERSE_FUNCTIONS = ['rectangle', 'array', 'lognormal', 'gaussian', 'schulz'] 
     88    #POLYDISPERSE_FUNCTIONS = ['rectangle', 'lognormal', 'gaussian', 'schulz'] 
    8989 
    9090    combo_updated = QtCore.pyqtSignal(str, int) 
     91    filename_updated = QtCore.pyqtSignal(int) 
    9192 
    9293    def __init__(self, parent=None): 
     
    103104        self.poly_nsigs = 5 
    104105        self.poly_function = 6 
     106        self.poly_filename = 7 
    105107 
    106108    def editableParameters(self): 
     
    126128        self.poly_nsigs = 6 
    127129        self.poly_function = 7 
     130        self.poly_filename = 8 
    128131 
    129132    def createEditor(self, widget, option, index): 
    130133        # Remember the current choice 
    131         current_text = index.data().toString() 
    132134        if not index.isValid(): 
    133135            return 0 
    134         if index.column() == self.poly_function: 
    135             editor = QtGui.QComboBox(widget) 
    136             for function in self.POLYDISPERSE_FUNCTIONS: 
    137                 editor.addItem(function) 
    138             current_index = editor.findText(current_text) 
    139             editor.setCurrentIndex(current_index if current_index>-1 else 3) 
    140             editor.currentIndexChanged.connect(lambda: self.combo_updated.emit(str(editor.currentText()), index.row())) 
    141             return editor 
     136        elif index.column() == self.poly_filename: 
     137            # Notify the widget that we want to change the filename 
     138            self.filename_updated.emit(index.row()) 
     139            return None 
    142140        elif index.column() in self.editableParameters(): 
    143             editor = QtGui.QLineEdit(widget) 
     141            self.editor = QtGui.QLineEdit(widget) 
    144142            validator = QtGui.QDoubleValidator() 
    145             editor.setValidator(validator) 
    146             return editor 
     143            self.editor.setValidator(validator) 
     144            return self.editor 
    147145        else: 
    148146            QtGui.QStyledItemDelegate.createEditor(self, widget, option, index) 
Note: See TracChangeset for help on using the changeset viewer.