コード例 #1
0
ファイル: tabview.py プロジェクト: xyt556/argos
    def __init__(self, tableModel=None, parent=None):
        """ Constructor.
        """
        super(TableEditWidget, self).__init__(parent=parent)

        self.setFocusPolicy(Qt.NoFocus)

        self.mainLayout = QtWidgets.QHBoxLayout()
        self.mainLayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.mainLayout)

        self.tableView = BaseTableView(tableModel)
        self.mainLayout.addWidget(self.tableView)

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

        iconDir = icons_directory()
        iconSize = QtCore.QSize(20, 20)

        self.addButton = QtWidgets.QPushButton()
        self.addButton.setToolTip("Add new row.")
        self.addButton.setIcon(
            QtGui.QIcon(os.path.join(iconDir, 'plus-sign-l.svg')))
        self.addButton.setIconSize(iconSize)
        self.addButton.clicked.connect(self.addRow)
        buttonLayout.addWidget(self.addButton)

        self.removeButton = QtWidgets.QPushButton()
        self.removeButton.setToolTip("Remove row.")
        self.removeButton.setIcon(
            QtGui.QIcon(os.path.join(iconDir, 'minus-sign-l.svg')))
        self.removeButton.setIconSize(iconSize)
        self.removeButton.clicked.connect(self.removeRow)
        buttonLayout.addWidget(self.removeButton)
        buttonLayout.addSpacing(25)

        self.moveUpButton = QtWidgets.QPushButton()
        self.moveUpButton.setToolTip("Move row up")
        self.moveUpButton.setIcon(
            QtGui.QIcon(os.path.join(iconDir, 'circle-arrow-up-l.svg')))
        self.moveUpButton.setIconSize(iconSize)
        self.moveUpButton.clicked.connect(lambda: self.moveRow(-1))
        buttonLayout.addWidget(self.moveUpButton)

        self.moveDownButton = QtWidgets.QPushButton()
        self.moveDownButton.setToolTip("Move row down")
        self.moveDownButton.setIcon(
            QtGui.QIcon(os.path.join(iconDir, 'circle-arrow-down-l.svg')))
        self.moveDownButton.setIconSize(iconSize)
        self.moveDownButton.clicked.connect(lambda: self.moveRow(+1))
        buttonLayout.addWidget(self.moveDownButton)

        buttonLayout.addStretch()

        self.tableView.selectionModel().currentChanged.connect(
            self.onCurrentChanged)
        self.tableView.setFocus(Qt.NoFocusReason)
        self.updateWidgets()
コード例 #2
0
ファイル: example_plugin.py プロジェクト: xyt556/argos
class TestFileRti(BaseRti):
    """ Repository tree item for testing
    """
    _label = "HDF File"
    _iconOpen = QtGui.QIcon(
        os.path.join(ICONS_DIRECTORY, 'memory.folder-open.svg'))
    _iconClosed = QtGui.QIcon(
        os.path.join(ICONS_DIRECTORY, 'memory.folder-closed.svg'))

    def __init__(self, nodeName='', fileName=''):
        """ Constructor
        """
        super(TestFileRti, self).__init__(nodeName=nodeName, fileName=fileName)
        self._checkFileExists()
コード例 #3
0
    def createIconFromSvg(self, svg, color=None, colorsToBeReplaced=None):
        """ Creates a QIcon given an SVG string.

            Optionally replaces the colors in colorsToBeReplaced by color.

            :param svg: string containing Scalable Vector Graphics XML
            :param color: '#RRGGBB' string (e.g. '#FF0000' for red)
            :param colorsToBeReplaced: optional list of colors to be replaced by color
                If None, it will be set to the fill colors of the snip-icon libary
            :return: QtGui.QIcon
        """
        if colorsToBeReplaced is None:
            colorsToBeReplaced = self.colorsToBeReplaced

        if color:
            for oldColor in colorsToBeReplaced:
                svg = svg.replace(oldColor, color)

        # From http://stackoverflow.com/questions/15123544/change-the-color-of-an-svg-in-qt
        qByteArray = QtCore.QByteArray()
        qByteArray.append(svg)
        svgRenderer = QtSvg.QSvgRenderer(qByteArray)
        icon = QtGui.QIcon()
        for size in self.renderSizes:
            pixMap = QtGui.QPixmap(QtCore.QSize(size, size))
            pixMap.fill(Qt.transparent)
            pixPainter = QtGui.QPainter(pixMap)
            pixPainter.setRenderHint(QtGui.QPainter.TextAntialiasing, True)
            pixPainter.setRenderHint(QtGui.QPainter.Antialiasing, True)
            svgRenderer.render(pixPainter)
            pixPainter.end()
            icon.addPixmap(pixMap)

        return icon
コード例 #4
0
ファイル: abstractcti.py プロジェクト: xyt556/argos
    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)
コード例 #5
0
    def __init__(self, label, registry,  parent=None):
        """ Constructor
        """
        super(PluginsDialog, self).__init__(parent=parent)
        check_class(registry, BaseRegistry)

        self._label = label
        self._orgRegistry = registry
        self._registry = copy.deepcopy(registry)  # make copy so changes can be canceled
        self._tableModel = self._registry.createTableModel(parent=self)
        self.mapper = QtWidgets.QDataWidgetMapper(parent=self)
        self.mapper.setModel(self._tableModel)

        self.setWindowTitle("Argos {} Plugins".format(label))

        layout = QtWidgets.QVBoxLayout(self)

        self.verSplitter = QtWidgets.QSplitter(Qt.Vertical)
        #self.verSplitter.setCollapsible(1, False)
        self.verSplitter.setChildrenCollapsible(False)
        layout.addWidget(self.verSplitter)

        self.tableWidget = TableEditWidget(self._tableModel)
        self.verSplitter.addWidget(self.tableWidget)

        self._tableView = self.tableWidget.tableView
        self._tableView.installEventFilter(self)

        # Form
        self.horSplitter = QtWidgets.QSplitter(Qt.Horizontal)
        self.horSplitter.setChildrenCollapsible(False)

        self.verSplitter.addWidget(self.horSplitter)

        self.formWidget = QtWidgets.QWidget()
        self.formLayout = QtWidgets.QFormLayout()
        self.formLayout.setContentsMargins(0, 0, 0, 0)
        self.formWidget.setLayout(self.formLayout)
        self.horSplitter.addWidget(self.formWidget)

        self._editWidgets = []
        itemCls = registry.ITEM_CLASS
        assert len(itemCls.LABELS) == len(itemCls.TYPES), \
            "Regtype Mismatch: {} != {}".format(len(itemCls.LABELS), len(itemCls.TYPES))
        for col, (label, regType) in enumerate(zip(itemCls.LABELS, itemCls.TYPES)):

            if regType == RegType.String:
                editWidget = QtWidgets.QLineEdit()
                self.mapper.addMapping(editWidget, col)
            elif regType == RegType.ShortCut:
                editWidget = ShortCutEditor()
                self.mapper.addMapping(editWidget, col)
            elif regType == RegType.ColorStr:
                editWidget = ColorSelectWidget()
                self.mapper.addMapping(editWidget.lineEditor, col)
            else:
                raise AssertionError("Unexpected regType: {}".format(regType))
            editWidget.installEventFilter(self)
            self.formLayout.addRow(label, editWidget)
            self._editWidgets.append(editWidget)

        # Detail info widget
        font = QtGui.QFont()
        font.setFamily(MONO_FONT)
        font.setFixedPitch(True)
        font.setPointSize(FONT_SIZE)

        self.editor = QtWidgets.QTextEdit()
        self.editor.setReadOnly(True)
        #self.editor.setFocusPolicy(Qt.NoFocus) # Allow focus so that user can copy text from it.
        #self.editor.setFont(font)
        self.editor.setWordWrapMode(QtGui.QTextOption.WordWrap)
        self.editor.clear()
        self.horSplitter.addWidget(self.editor)

        self.horSplitter.setStretchFactor(0, 2)
        self.horSplitter.setStretchFactor(1, 3)
        self.verSplitter.setSizes([300, 150])

        # Reset/Cancel/Save Buttons

        self.saveButton = QtWidgets.QPushButton("Save")
        self.saveButton.clicked.connect(self.accept)

        self.cancelButton = QtWidgets.QPushButton("Cancel")
        self.cancelButton.clicked.connect(self.reject)

        self.resetButton = QtWidgets.QPushButton("Reset Table to Defaults...")
        self.resetButton.clicked.connect(self.resetToDefaults)
        self.resetButton.setIcon(QtGui.QIcon(os.path.join(icons_directory(), 'reset-l.svg')))

        # We use a button layout instead of a QButtonBox because there always will be a default
        # button (e.g. the Save button) that will light up, even if another widget has the focus.
        # From https://doc.qt.io/archives/qt-4.8/qdialogbuttonbox.html#details
        #   However, if there is no default button set and to preserve which button is the default
        #   button across platforms when using the QPushButton::autoDefault property, the first
        #   push button with the accept role is made the default button when the QDialogButtonBox
        #   is shown,

        self.buttonLayout = QtWidgets.QHBoxLayout()
        self.buttonLayout.addWidget(self.resetButton)
        self.buttonLayout.addStretch()
        if sys.platform == 'darwin':
            self.buttonLayout.addWidget(self.cancelButton)
            self.buttonLayout.addWidget(self.saveButton)
        else:
            self.buttonLayout.addWidget(self.saveButton)
            self.buttonLayout.addWidget(self.cancelButton)
        layout.addLayout(self.buttonLayout)

        # Connect signals and populate

        self.tableWidget.tableView.selectionModel().currentChanged.connect(self.currentItemChanged)
        self.tableWidget.tableView.model().sigItemChanged.connect(self._updateEditor)

        self.resize(QtCore.QSize(1100, 700))
        self.tableWidget.tableView.setFocus(Qt.NoFocusReason)

        self.tryImportAllPlugins()
コード例 #6
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)