source: sasview/src/sas/qtgui/SlicerParameters.py @ b789967

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since b789967 was b789967, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

More minor fixes to plotting

  • Property mode set to 100644
File size: 2.5 KB
Line 
1"""
2Allows users to modify the box slicer parameters.
3"""
4from PyQt4 import QtGui
5from PyQt4 import QtCore
6
7# Local UI
8from sas.qtgui.UI.SlicerParametersUI import Ui_SlicerParametersUI
9
10class SlicerParameters(QtGui.QDialog, Ui_SlicerParametersUI):
11    """
12    Interaction between the QTableView and the underlying model,
13    passed from a slicer instance.
14    """
15    def __init__(self, parent=None, model=None):
16        super(SlicerParameters, self).__init__()
17
18        self.setupUi(self)
19        assert isinstance(model, QtGui.QStandardItemModel)
20
21        self.model = model
22
23        # Define a proxy model so cell enablement can be finegrained.
24        self.proxy = ProxyModel(self)
25        self.proxy.setSourceModel(self.model)
26
27        # Set the proxy model for display in the Table View.
28        self.lstParams.setModel(self.proxy)
29
30        # Disallow edit of the parameter name column.
31        self.lstParams.model().setColumnReadOnly(0, True)
32
33        # Disable row number display
34        self.lstParams.verticalHeader().setVisible(False)
35
36        # Specify the validator on the parameter value column.
37        self.lstParams.setItemDelegate(ValidatedItemDelegate())
38
39class ProxyModel(QtGui.QIdentityProxyModel):
40    """
41    Trivial proxy model with custom column edit flag
42    """
43    def __init__(self, parent=None):
44        super(ProxyModel, self).__init__(parent)
45        self._columns = set()
46
47    def columnReadOnly(self, column):
48        return column in self._columns
49
50    def setColumnReadOnly(self, column, readonly=True):
51        if readonly:
52            self._columns.add(column)
53        else:
54            self._columns.discard(column)
55
56    def flags(self, index):
57        flags = super(ProxyModel, self).flags(index)
58        if self.columnReadOnly(index.column()):
59            flags &= ~QtCore.Qt.ItemIsEditable
60        return flags
61
62
63class ValidatedItemDelegate(QtGui.QStyledItemDelegate):
64    """
65    Simple delegate enabling adding a validator to a cell editor.
66    """
67    def createEditor(self, widget, option, index):
68        if not index.isValid():
69            return 0
70        if index.column() == 1: # Edir only cells in the second column
71            editor = QtGui.QLineEdit(widget)
72            validator = QtGui.QDoubleValidator()
73            # Don't use the scientific notation, cause 'e'.
74            validator.setNotation(QtGui.QDoubleValidator.StandardNotation)
75            editor.setValidator(validator)
76            return editor
77        return super(ValidatedItemDelegate, self).createEditor(widget, option, index)
Note: See TracBrowser for help on using the repository browser.