示例#1
0
文件: qtctis.py 项目: whigg/argos
    def __init__(self, cti, delegate, parent=None):
        """ See the AbstractCtiEditor for more info on the parameters
        """
        super(FontCtiEditor, self).__init__(cti, delegate, parent=parent)

        pickButton = QtWidgets.QToolButton()
        pickButton.setText("...")
        pickButton.setToolTip("Open font dialog.")
        pickButton.setFocusPolicy(Qt.NoFocus)
        pickButton.clicked.connect(self.execFontDialog)

        self.pickButton = self.addSubEditor(pickButton)

        if DEBUGGING:
            self.label = self.addSubEditor(QtWidgets.QLabel(self.cti.displayValue))
            labelSizePolicy = self.label.sizePolicy()
            self.label.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                                     labelSizePolicy.verticalPolicy())
示例#2
0
    def __init__(self, cti, delegate, subEditors=None, parent=None):
        """ Wraps the child widgets in a horizontal layout and appends a reset button.

            Maintains a reference to the ConfigTreeItem (cti) and to delegate, this last reference
            is so that we can command the delegate to commit and close the editor.

            The subEditors must be a list of QWidgets. Note that the sub editors do not yet have
            to be initialized with editor data since setData will be called by the delegate
            after construction. There it can be taken care of.
        """
        super(AbstractCtiEditor, self).__init__(parent=parent)

        # Prevent underlying table cell from being visible if the editor doesn't fill the cell
        self.setAutoFillBackground(True)

        self._subEditors = []
        self.delegate = delegate
        self.cti = cti

        # From the QAbstractItemDelegate.createEditor docs: The returned editor widget should have
        # Qt.StrongFocus; otherwise, QMouseEvents received by the widget will propagate to the view.
        # The view's background will shine through unless the editor paints its own background
        # (e.g., with setAutoFillBackground()).
        self.setFocusPolicy(Qt.StrongFocus)

        self.hBoxLayout = QtWidgets.QHBoxLayout()
        self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
        self.hBoxLayout.setSpacing(0)
        self.setLayout(self.hBoxLayout)

        self.resetButton = QtWidgets.QToolButton()
        self.resetButton.setText("Reset")
        self.resetButton.setToolTip("Reset to default value.")
        self.resetButton.setIcon(
            QtGui.QIcon(os.path.join(icons_directory(), 'reset-l.svg')))
        self.resetButton.setFocusPolicy(Qt.NoFocus)
        self.resetButton.clicked.connect(self.resetEditorValue)
        self.hBoxLayout.addWidget(self.resetButton, alignment=Qt.AlignRight)

        self.cti.model.sigItemChanged.connect(self.modelItemChanged)

        for subEditor in (subEditors if subEditors is not None else []):
            self.addSubEditor(subEditor)
示例#3
0
文件: qtctis.py 项目: whigg/argos
    def __init__(self, cti, delegate, parent=None):
        """ See the AbstractCtiEditor for more info on the parameters
        """
        super(ColorCtiEditor, self).__init__(cti, delegate, parent=parent)

        lineEditor = QtWidgets.QLineEdit(parent)
        regExp = QtCore.QRegExp(r'#?[0-9A-F]{6}', Qt.CaseInsensitive)
        validator = QtGui.QRegExpValidator(regExp, parent=lineEditor)
        lineEditor.setValidator(validator)

        self.lineEditor = self.addSubEditor(lineEditor, isFocusProxy=True)

        pickButton = QtWidgets.QToolButton()
        pickButton.setText("...")
        pickButton.setToolTip("Open color dialog.")
        pickButton.setFocusPolicy(Qt.NoFocus)
        pickButton.clicked.connect(self.openColorDialog)

        self.pickButton = self.addSubEditor(pickButton)
示例#4
0
    def __init__(self, configTreeModel, parent=None):
        """ Constructor.
            :param parent:
        """
        super(ConfigWidget, self).__init__(parent=parent)

        # Actions that change the reset mode of the reset button
        self.modeActionGroup = QtWidgets.QActionGroup(self)
        self.modeActionGroup.setExclusive(True)

        self.modeAllAction = QtWidgets.QAction("Reset All",
                                               self.modeActionGroup)
        self.modeAllAction.setToolTip(
            "Changes button reset mode to reset all settings")
        self.modeAllAction.setCheckable(True)
        self.modeAllAction.triggered.connect(
            lambda: self.setResetMode(ResetMode.All))

        self.modeRangeAction = QtWidgets.QAction("Reset Ranges",
                                                 self.modeActionGroup)
        self.modeRangeAction.setToolTip(
            "Changes button reset mode to reset axes")
        self.modeRangeAction.setCheckable(True)
        self.modeRangeAction.triggered.connect(
            lambda: self.setResetMode(ResetMode.Ranges))

        # Sanity check that actions have been added to action group
        assert self.modeActionGroup.actions(
        ), "Sanity check. resetActionGroup is empty"

        # Actions that actually reset the settings

        self.resetAllAction = QtWidgets.QAction("Reset All", self)
        self.resetAllAction.setToolTip("Resets all settings.")
        self.resetAllAction.setIcon(
            QtGui.QIcon(os.path.join(icons_directory(), 'reset-l.svg')))
        self.resetAllAction.setShortcut("Ctrl+=")

        self.resetRangesAction = QtWidgets.QAction("Reset Ranges", self)
        self.resetRangesAction.setToolTip(
            "Resets range of all plots, color scales, table column/row sizes etc."
        )
        self.resetRangesAction.setIcon(
            QtGui.QIcon(os.path.join(icons_directory(), 'reset-l.svg')))
        self.resetRangesAction.setShortcut("Ctrl+0")

        self.resetButtonMenu = QtWidgets.QMenu()
        self.resetButtonMenu.addAction(self.resetAllAction)
        self.resetButtonMenu.addAction(self.resetRangesAction)
        self.resetButtonMenu.addSection("Default")
        self.resetButtonMenu.addAction(self.modeAllAction)
        self.resetButtonMenu.addAction(self.modeRangeAction)

        # Widgets

        self.mainLayout = QtWidgets.QVBoxLayout(self)
        self.mainLayout.setSpacing(5)
        self.mainLayout.setContentsMargins(DOCK_MARGIN, DOCK_MARGIN,
                                           DOCK_MARGIN, DOCK_MARGIN)

        self.configTreeView = ConfigTreeView(configTreeModel, parent=self)
        self.mainLayout.addWidget(self.configTreeView)

        self.buttonLayout = QtWidgets.QHBoxLayout()
        self.mainLayout.addLayout(self.buttonLayout)

        self.autoCheckBox = QtWidgets.QCheckBox("Auto")
        self.autoCheckBox.setToolTip(
            "Auto reset when a new item or axis is selected.")
        self.autoCheckBox.setChecked(True)

        self.resetButton = QtWidgets.QToolButton()
        self.resetButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.resetButton.setDefaultAction(self.resetButtonMenu.defaultAction())
        self.resetButton.setPopupMode(QtWidgets.QToolButton.MenuButtonPopup)
        self.resetButton.setMenu(self.resetButtonMenu)

        # Set font size to the same as used for push buttons
        dummyButton = QtWidgets.QPushButton("dummy")
        fontSize = dummyButton.font().pointSize()
        del dummyButton

        logger.debug(
            "Setting QToolButtons font size to: {} point".format(fontSize))
        font = self.resetButton.font()
        font.setPointSizeF(fontSize)
        self.resetButton.setFont(font)

        self.buttonLayout.addStretch()
        self.buttonLayout.addWidget(self.autoCheckBox)
        self.buttonLayout.addWidget(self.resetButton)
        self.buttonLayout.addStretch()

        self.autoCheckBox.stateChanged.connect(self.setAutoReset)
        self.resetRangesAction.triggered.connect(
            self.configTreeView.resetAllRanges)
        self.resetAllAction.triggered.connect(
            self.configTreeView.resetAllSettings)

        self.setResetMode(self.configTreeView.resetMode)