Пример #1
0
    def test_dialog(self):
        d = WelcomeDialog()
        loader = icon_loader()
        icon = loader.get("icons/default-widget.svg")
        action1 = QAction(decorate_welcome_icon(icon, "light-green"),
                          "one", self.app)
        action2 = QAction(decorate_welcome_icon(icon, "orange"),
                          "two", self.app)
        d.addRow([action1, action2])

        action3 = QAction(decorate_welcome_icon(icon, "light-green"),
                          "three", self.app)
        d.addRow([action3])

        self.assertTrue(d.buttonAt(1, 0).defaultAction() == action3)

        d.show()
        action = [None]

        def p(a):
            print(str(a.text()))
            action[0] = a

        d.triggered.connect(p)
        self.app.exec_()
        self.assertIs(action[0], d.triggeredAction())
Пример #2
0
    def test_dynamic_toolbar(self):
        logging.basicConfig(level=logging.DEBUG)

        w = toolbar.DynamicResizeToolBar(None)
        w.setStyleSheet("QToolButton { border: 1px solid red; }")

        w.addAction(QAction("1", w))
        w.addAction(QAction("2", w))
        w.addAction(QAction("A long name", w))
        actions = list(w.actions())

        self.assertSequenceEqual([str(action.text()) for action in actions],
                                 ["1", "2", "A long name"])

        w.resize(100, 30)
        w.show()

        w.raise_()

        w.removeAction(actions[1])
        w.insertAction(actions[2], actions[1])

        self.assertSequenceEqual(actions,
                                 list(w.actions()),
                                 msg="insertAction does not preserve "
                                 "action order")

        self.singleShot(2000, lambda: w.setOrientation(Qt.Vertical))
        self.singleShot(5000, lambda: w.removeAction(actions[1]))

        self.app.exec_()
Пример #3
0
    def create_action_for_item(self, item):
        """
        Create a QAction instance for the widget description item.
        """
        name = item.text()
        tooltip = item.toolTip()
        whatsThis = item.whatsThis()
        icon = item.icon()
        if icon:
            action = QAction(icon,
                             name,
                             self,
                             toolTip=tooltip,
                             whatsThis=whatsThis,
                             statusTip=name)
        else:
            action = QAction(name,
                             self,
                             toolTip=tooltip,
                             whatsThis=whatsThis,
                             statusTip=name)

        widget_desc = item.data(self.WIDGET_DESC_ROLE)
        action.setData(widget_desc)
        action.setProperty("item", item)
        return action
Пример #4
0
    def _setup_words_box(self):
        self.words_view = ListView()
        self.words_view.drop_finished.connect(self.__on_words_data_changed)
        self.words_view.setModel(self.words_model)
        self.words_view.selectionModel().selectionChanged.connect(
            self.__on_words_selection_changed)

        self.words_model.dataChanged.connect(self.__on_words_data_changed)

        self.__words_box.layout().setSpacing(1)
        self.__words_box.layout().addWidget(self.words_view)

        actions_widget = ModelActionsWidget()
        actions_widget.layout().setSpacing(1)

        action = QAction("+", self.words_view, toolTip="Add a new word")
        action.triggered.connect(self.__on_add_word)
        actions_widget.addAction(action)
        self.__add_word_action = action

        action = QAction("\N{MINUS SIGN}", self, toolTip="Remove word")
        action.triggered.connect(self.__on_remove_word)
        actions_widget.addAction(action)
        self.__remove_word_action = action

        gui.rubber(actions_widget)

        action = QAction("Sort", self)
        action.setToolTip("Sort words alphabetically")
        action.triggered.connect(self.__on_apply_sorting)
        actions_widget.addAction(action)

        self.__words_box.layout().addWidget(actions_widget)
Пример #5
0
    def zoom_actions(self, parent):
        def zoom(s):
            """
            Zoom in/out by factor `s`.
            scaleBy scales the view's bounds (the axis range)
            """
            self.view_box.scaleBy((1 / s, 1 / s))

        def fit_to_view():
            self.viewbox.autoRange()

        zoom_in = QAction("Zoom in", parent, triggered=lambda: zoom(1.25))
        zoom_in.setShortcuts([
            QKeySequence(QKeySequence.ZoomIn),
            QKeySequence(parent.tr("Ctrl+="))
        ])
        zoom_out = QAction("Zoom out",
                           parent,
                           shortcut=QKeySequence.ZoomOut,
                           triggered=lambda: zoom(1 / 1.25))
        zoom_fit = QAction("Fit in view",
                           parent,
                           shortcut=QKeySequence(Qt.ControlModifier
                                                 | Qt.Key_0),
                           triggered=fit_to_view)
        parent.addActions([zoom_in, zoom_out, zoom_fit])
Пример #6
0
    def __init__(self, *args):
        super().__init__(*args)
        self.setAlignment(Qt.AlignTop | Qt.AlignLeft)

        self.__backgroundIcon = QIcon()

        self.__autoScroll = False
        self.__autoScrollMargin = 16
        self.__autoScrollTimer = QTimer(self)
        self.__autoScrollTimer.timeout.connect(self.__autoScrollAdvance)

        # scale factor accumulating partial increments from wheel events
        self.__zoomLevel = 100
        # effective scale level(rounded to whole integers)
        self.__effectiveZoomLevel = 100

        self.__zoomInAction = QAction(
            self.tr("Zoom in"),
            self,
            objectName="action-zoom-in",
            shortcut=QKeySequence.ZoomIn,
            triggered=self.zoomIn,
        )

        self.__zoomOutAction = QAction(self.tr("Zoom out"),
                                       self,
                                       objectName="action-zoom-out",
                                       shortcut=QKeySequence.ZoomOut,
                                       triggered=self.zoomOut)
        self.__zoomResetAction = QAction(
            self.tr("Reset Zoom"),
            self,
            objectName="action-zoom-reset",
            triggered=self.zoomReset,
            shortcut=QKeySequence(Qt.ControlModifier | Qt.Key_0))
Пример #7
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.show_report_action = QAction(
            "Show report",
            self,
            objectName="action-show-report",
            toolTip="Show a report window",
            shortcut=QKeySequence(Qt.ShiftModifier | Qt.Key_R),
            enabled=HAVE_REPORT,
        )
        self.show_report_action.triggered.connect(self.show_report_view)
        self.open_report_action = QAction(
            "Open Report...",
            self,
            objectName="action-open-report",
            toolTip="Open a saved report",
            enabled=HAVE_REPORT,
        )
        self.open_report_action.triggered.connect(self.open_report)
        self.reset_widget_settings_action = QAction(
            self.tr("Reset Widget Settings..."),
            self,
            triggered=self.reset_widget_settings)

        menubar = self.menuBar()
        # Insert the 'Load report' in the File menu ...
        _insert_action(menubar, "file-menu", "open-actions-separator",
                       self.open_report_action)
        # ... and 'Show report' in the View menu.
        _insert_action(menubar, "view-menu", "view-visible-actions-separator",
                       self.show_report_action)

        _insert_action(menubar, "options-menu", "canvas-addons-action",
                       self.reset_widget_settings_action)
Пример #8
0
    def test_tooltree(self):
        tree = ToolTree()
        role = tree.actionRole()
        model = QStandardItemModel()
        tree.setModel(model)
        item = QStandardItem("One")
        item.setData(QAction("One", tree), role)
        model.appendRow([item])

        cat = QStandardItem("A Category")
        item = QStandardItem("Two")
        item.setData(QAction("Two", tree), role)
        cat.appendRow([item])
        item = QStandardItem("Three")
        item.setData(QAction("Three", tree), role)
        cat.appendRow([item])

        model.appendRow([cat])

        def p(action):
            print("triggered", action.text())

        tree.triggered.connect(p)

        tree.show()

        self.qWait()
    def _setup_gui_labels(self):
        vlayout = QVBoxLayout()
        vlayout.setContentsMargins(0, 0, 0, 0)
        vlayout.setSpacing(1)

        self.labels_edit = QTreeView()
        self.labels_edit.setEditTriggers(QTreeView.CurrentChanged)
        self.labels_edit.setRootIsDecorated(False)

        self.labels_model = DictItemsModel()
        self.labels_edit.setModel(self.labels_model)

        self.labels_edit.selectionModel().selectionChanged.connect(
            self.on_label_selection_changed)

        # Necessary signals to know when the labels change
        self.labels_model.dataChanged.connect(self.on_labels_changed)
        self.labels_model.rowsInserted.connect(self.on_labels_changed)
        self.labels_model.rowsRemoved.connect(self.on_labels_changed)

        vlayout.addWidget(self.labels_edit)
        hlayout = QHBoxLayout()
        hlayout.setContentsMargins(0, 0, 0, 0)
        hlayout.setSpacing(1)
        self.add_label_action = QAction(
            "+",
            self,
            toolTip="Add a new label.",
            triggered=self.on_add_label,
            enabled=False,
            shortcut=QKeySequence(QKeySequence.New),
        )

        self.remove_label_action = QAction(
            unicodedata.lookup("MINUS SIGN"),
            self,
            toolTip="Remove selected label.",
            triggered=self.on_remove_label,
            enabled=False,
            shortcut=QKeySequence(QKeySequence.Delete),
        )

        button_size = gui.toolButtonSizeHint()
        button_size = QSize(button_size, button_size)

        button = QToolButton(self)
        button.setFixedSize(button_size)
        button.setDefaultAction(self.add_label_action)
        hlayout.addWidget(button)

        button = QToolButton(self)
        button.setFixedSize(button_size)
        button.setDefaultAction(self.remove_label_action)
        hlayout.addWidget(button)
        hlayout.addStretch(10)
        vlayout.addLayout(hlayout)

        self.main_form.addRow("Labels:", vlayout)
Пример #10
0
    def __call__(self, master, model_selected, model_other):
        self.master = master

        params_view = {
            "sizePolicy": QSizePolicy(*SIZE_POLICY_ADAPTING),
            "selectionMode": QListView.ExtendedSelection,
            "dragEnabled": True,
            "defaultDropAction": Qt.MoveAction,
            "dragDropOverwriteMode": False,
            "dragDropMode": QListView.DragDrop,
        }

        self.view_selected = view = gui.listView(widget=master.controlArea,
                                                 master=master,
                                                 box="Displayed Axes",
                                                 **params_view)
        view.box.setMinimumHeight(120)
        view.viewport().setAcceptDrops(True)

        delete = QAction(
            "Delete",
            view,
            shortcut=QKeySequence(Qt.Key_Delete),
            triggered=self.__deactivate_selection,
        )
        view.addAction(delete)

        self.model_selected = model = model_selected

        model.rowsInserted.connect(master.invalidate_plot)
        model.rowsRemoved.connect(master.invalidate_plot)
        model.rowsMoved.connect(master.invalidate_plot)

        view.setModel(model)

        addClassLabel = QAction("+",
                                master,
                                toolTip="Add new class label",
                                triggered=self._action_add)
        removeClassLabel = QAction(
            unicodedata.lookup("MINUS SIGN"),
            master,
            toolTip="Remove selected class label",
            triggered=self.__deactivate_selection,
        )

        add_remove = itemmodels.ModelActionsWidget(
            [addClassLabel, removeClassLabel], master)
        add_remove.layout().addStretch(10)
        add_remove.layout().setSpacing(1)
        add_remove.setSizePolicy(*SIZE_POLICY_FIXED)
        view.box.layout().addWidget(add_remove)

        self.add_remove = add_remove
        self.box = add_remove.buttons[1]

        self.model_other = model_other
Пример #11
0
    def __init__(self, *args, widgetResizable=False, **kwargs):
        super().__init__(*args, **kwargs)
        self.__widgetResizable = widgetResizable
        self.__zoomFactor = 100

        zoomin = QAction(
            "Zoom in",
            self,
            objectName="zoom-in-action",
            shortcut=QKeySequence.ZoomIn,
        )
        zoomout = QAction(
            "Zoom out",
            self,
            objectName="zoom-out-action",
            shortcut=QKeySequence.ZoomOut,
        )
        zoomreset = QAction(
            "Actual Size",
            self,
            objectName="zoom-reset-action",
            shortcut=QKeySequence(Qt.ControlModifier | Qt.Key_0),
        )
        fit = QAction(
            "Zoom to fit",
            self,
            objectName="zoom-to-fit-action",
            shortcut=QKeySequence(Qt.ControlModifier | Qt.Key_9),
            checkable=True,
        )

        if hasattr(QAction, "setShortcutVisibleInContextMenu"):  # Qt 5.10
            for a in [zoomin, zoomout, zoomreset, fit]:
                a.setShortcutVisibleInContextMenu(True)

        @zoomin.triggered.connect
        def _():
            self.setZoomFactor(self.__zoomFactor + 10)

        @zoomout.triggered.connect
        def _():
            self.setZoomFactor(self.__zoomFactor - 10)

        @zoomreset.triggered.connect
        def _():
            self.__zoomFactor = -1
            self.setZoomFactor(100.)

        @fit.toggled.connect
        def _(state):
            self.setFitInView(state)

        self.addActions([zoomin, zoomout, zoomreset, fit])
        self._actions = SimpleNamespace(zoomin=zoomin,
                                        zoomout=zoomout,
                                        zoomreset=zoomreset,
                                        fit=fit)
Пример #12
0
    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self.__stack: List = []
        self.__stack_index: int = -1

        def push_on_data_changed(_, __, roles):
            if Qt.EditRole in roles:
                self._push_data()

        self.__model = QStandardItemModel()
        self.__model.dataChanged.connect(self.dataChanged)
        self.__model.dataChanged.connect(push_on_data_changed)
        self.__root: QStandardItem = self.__model.invisibleRootItem()

        self.__tree = TreeView(self.dataChanged)
        self.__tree.drop_finished.connect(self.dataChanged)
        self.__tree.drop_finished.connect(self._push_data)
        self.__tree.setModel(self.__model)
        self.__tree.selectionModel().selectionChanged.connect(
            self.selectionChanged)

        actions_widget = ModelActionsWidget()
        actions_widget.layout().setSpacing(1)

        action = QAction("+", self, toolTip="Add a new word")
        action.triggered.connect(self.__on_add)
        actions_widget.addAction(action)

        action = QAction("\N{MINUS SIGN}", self, toolTip="Remove word")
        action.triggered.connect(self.__on_remove)
        actions_widget.addAction(action)

        action = QAction("\N{MINUS SIGN}R", self,
                         toolTip="Remove word recursively (incl. children)")
        action.triggered.connect(self.__on_remove_recursive)
        actions_widget.addAction(action)

        gui.rubber(actions_widget)

        self.__undo_action = action = QAction("Undo", self, toolTip="Undo")
        action.triggered.connect(self.__on_undo)
        actions_widget.addAction(action)

        self.__redo_action = action = QAction("Redo", self, toolTip="Redo")
        action.triggered.connect(self.__on_redo)
        actions_widget.addAction(action)

        self._enable_undo_redo()

        layout = QVBoxLayout()
        layout.setSpacing(1)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.__tree)
        layout.addWidget(actions_widget)
        self.setLayout(layout)
Пример #13
0
    def _tods_run(self):

        self.run_pipeline_action = QAction(
            self.tr("Run"),
            self,
            objectName="run-action",
            toolTip=self.tr("Run Pipeline"),
            triggered=self.run_pipeline,
        )

        self.build_pipeline_action = QAction(
            self.tr("Build"),
            self,
            objectName="build-action",
            toolTip=self.tr("Build Pipeline"),
            triggered=self.run_pipeline,
        )

        # self.zoom_in_action.setIcon(canvas_icons("arrow-right.svg"))
        # self.welcome_action.setIcon(canvas_icons("arrow-right.svg"))
        self.run_pipeline_action.setIcon(canvas_icons("arrow-right.svg"))
        self.build_pipeline_action.setIcon(canvas_icons("default-widget.svg"))

        dock_actions = [
            self.show_properties_action,
            self.canvas_align_to_grid_action,
            self.canvas_text_action,
            self.canvas_arrow_action,
            self.freeze_action,
            self.dock_help_action,
            # self.zoom_in_action,
            # self.welcome_action,
            self.build_pipeline_action,
            self.run_pipeline_action,
        ]

        # Tool bar in the collapsed dock state (has the same actions as
        # the tool bar in the CanvasToolDock
        actions_toolbar = QToolBar(orientation=Qt.Vertical)
        actions_toolbar.setFixedWidth(38)
        actions_toolbar.layout().setSpacing(0)

        actions_toolbar.setToolButtonStyle(Qt.ToolButtonIconOnly)

        for action in dock_actions:
            self.canvas_toolbar.addAction(action)
            button = self.canvas_toolbar.widgetForAction(action)
            button.setPopupMode(QToolButton.DelayedPopup)

            actions_toolbar.addAction(action)
            button = actions_toolbar.widgetForAction(action)
            button.setFixedSize(38, 30)
            button.setPopupMode(QToolButton.DelayedPopup)
Пример #14
0
    def _setup_gui_values(self):
        vlayout = QVBoxLayout()
        vlayout.setContentsMargins(0, 0, 0, 0)
        vlayout.setSpacing(1)

        self.values_edit = QListView()
        self.values_edit.setEditTriggers(QTreeView.CurrentChanged)
        self.values_model = itemmodels.PyListModel(flags=Qt.ItemIsSelectable | \
                                        Qt.ItemIsEnabled | Qt.ItemIsEditable)
        self.values_edit.setModel(self.values_model)

        self.values_edit.selectionModel().selectionChanged.connect(
            self.on_value_selection_changed)

        self.values_model.dataChanged.connect(self.on_values_changed)

        vlayout.addWidget(self.values_edit)
        hlayout = QHBoxLayout()
        hlayout.setContentsMargins(0, 0, 0, 0)
        hlayout.setSpacing(1)
        self.move_value_up = QAction(unicodedata.lookup("UPWARDS ARROW"),
                                     self,
                                     toolTip="Move up.",
                                     triggered=self.move_up,
                                     enabled=False,
                                     shortcut=QKeySequence(QKeySequence.New))

        self.move_value_down = QAction(unicodedata.lookup("DOWNWARDS ARROW"),
                                       self,
                                       toolTip="Move down.",
                                       triggered=self.move_down,
                                       enabled=False,
                                       shortcut=QKeySequence(
                                           QKeySequence.Delete))

        button_size = gui.toolButtonSizeHint()
        button_size = QSize(button_size, button_size)

        button = QToolButton(self)
        button.setFixedSize(button_size)
        button.setDefaultAction(self.move_value_up)
        hlayout.addWidget(button)

        button = QToolButton(self)
        button.setFixedSize(button_size)
        button.setDefaultAction(self.move_value_down)
        hlayout.addWidget(button)
        hlayout.addStretch(10)
        vlayout.addLayout(hlayout)

        self.main_form.addRow("Values:", vlayout)
Пример #15
0
        def __init__(self, parent=None, widget=None, title=None, **kwargs):

            super().__init__(parent, **kwargs)
            self.setFeatures(QDockWidget.DockWidgetClosable)
            self.setAllowedAreas(Qt.NoDockWidgetArea)

            self.__title = ""
            self.__icon = ""
            self.__focusframe = None

            self.__deleteaction = QAction("Remove",
                                          self,
                                          shortcut=QKeySequence.Delete,
                                          enabled=False,
                                          triggered=self.closeRequested)
            self.addAction(self.__deleteaction)

            if widget is not None:
                self.setWidget(widget)
            self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)

            if title:
                self.setTitle(title)

            self.setFocusPolicy(Qt.StrongFocus)
    def actions(self, entry, marked_objects=[]):
        actions = []
        type = entry.type
        if marked_objects:
            action = QAction("View genes on kegg website", None)
            org = {s.split(":")[0] for s in marked_objects}.pop()
            genes = [s.split(":")[-1] for s in marked_objects]
            address = "http://www.genome.jp/dbget-bin/www_bget?" + "+".join([org] + genes)

            action.triggered.connect(partial(webbrowser.open, address))
            actions.append(action)
        elif hasattr(entry, "link"):
            action = QAction("View %s on KEGG website" % str(type), None)
            action.triggered.connect(partial(webbrowser.open, entry.link))
            actions.append(action)
        return actions
Пример #17
0
def main(argv=[]):
    app = QApplication(argv)

    toolbox = ToolGrid(columns=3)
    icon = app.style().standardIcon(QStyle.SP_FileIcon)
    actions = [
        QAction("A", None, icon=icon),
        QAction("B", None, icon=icon),
        QAction("This one is longer.", icon=icon),
        QAction("Not done yet!", icon=icon),
        QAction("The quick brown fox ... does something I guess", icon=icon),
    ]

    toolbox.addActions(actions)
    toolbox.show()
    return app.exec()
Пример #18
0
	def add_popup_menu_option(self, label, function_action=None, key=None, icon=None, submenu=None):
		"""
		Add an option to the Control popup menu
		@param label:           label of the option.
		@param function_action:  function called when the option is selected.
		@param key:             shortcut key
		@param icon:            icon
		"""
		self.__create_popup_menu()

		menu = submenu if submenu else self._popup_menu

		if label == "-":
			return menu.addSeparator()
		else:
			action = QAction(label, self.form)
			if icon is not None:
				action.setIconVisibleInMenu(True)
				action.setIcon(icon if isinstance(icon, QIcon) else QIcon(icon) )
			if key != None:
				action.setShortcut(QKeySequence(key))
			if function_action:
				action.triggered.connect(function_action)
				menu.addAction(action)
			return action
    def actions_for_context_menu(self, node):
        # type: (SchemeNode) -> List[QAction]
        """
        Reimplemented from WidgetManager.actions_for_context_menu.

        Parameters
        ----------
        node : SchemeNode

        Returns
        -------
        actions : List[QAction]
        """
        actions = []
        widget = self.widget_for_node(node)
        if widget is not None:
            actions = [
                a for a in widget.actions()
                if a.property("ext-workflow-node-menu-action") is True
            ]
            if log.isEnabledFor(logging.DEBUG):
                ac = QAction(
                    self.tr("Show settings"),
                    widget,
                    objectName="show-settings",
                    toolTip=self.tr("Show widget settings"),
                )
                ac.setData(node)
                ac.triggered.connect(self.__dump_settings)
                actions.append(ac)
        return super().actions_for_context_menu(node) + actions
Пример #20
0
    def add_popup_menu_option(self, label, function_action=None, key=None, icon=None, menu=None):
        """
        Add an option to the Control popup menu.  

        :param str label: Label of the option  
        :param function function_action: The function that should be executed when the menu is selected.  
        :param str key: Short key.  
        :param QIcon or str icon: Icon.  
        :param QMenu submenu: Parent submenu to which the option should be added. If no value is set, then the option will be added to the main popup menu.  
        
        .. code:: python

            control.add_popup_menu_option('option 0', function_action=self._do_something)
            submenu1 = control.add_popup_submenu('menu 1')
            submenu2 = control.add_popup_submenu('menu 2', submenu=submenu1)
            control.add_popup_menu_option('option 1', function_action=self._do_something, key='Control+Q', submenu=submenu2)
        """
        self.__create_popup_menu()

        menu = menu if menu else self._popup_menu

        if label == "-":
            return menu.addSeparator()
        else:
            action = QAction(label, self.form)
            if icon is not None:
                action.setIconVisibleInMenu(True)
                action.setIcon(icon if isinstance(icon, QIcon) else QIcon(icon) )
            if key != None:
                action.setShortcut(QKeySequence(key))
            if function_action:
                action.triggered.connect(function_action)
                menu.addAction(action)
            return action
Пример #21
0
def main(argv):
    app = QApplication(argv)
    mw = QMainWindow()
    dock = CollapsibleDockWidget()

    w1 = QTreeView()
    w1.header().hide()

    w2 = QToolButton()
    w2.setFixedSize(38, 200)

    dock.setExpandedWidget(w1)
    dock.setCollapsedWidget(w2)

    mw.addDockWidget(Qt.LeftDockWidgetArea, dock)
    mw.setCentralWidget(QTextEdit())
    mw.show()

    a = QAction("Expand",
                mw,
                checkable=True,
                shortcut=QKeySequence(Qt.ControlModifier | Qt.Key_D))
    a.triggered[bool].connect(dock.setExpanded)
    mw.addAction(a)
    return app.exec()
Пример #22
0
    def createTabButton(self, widget, text, icon=None, toolTip=None):
        """
        Create the tab button for `widget`.
        """
        action = QAction(text, self)
        action.setCheckable(True)

        if icon:
            action.setIcon(icon)

        if toolTip:
            action.setToolTip(toolTip)
        self.__tabActionGroup.addAction(action)
        self.__actionMapper.setMapping(action, action)
        action.toggled.connect(self.__actionMapper.map)

        button = ToolBoxTabButton(self, objectName="toolbox-tab-button")
        button.setDefaultAction(action)
        button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        button.setSizePolicy(QSizePolicy.Ignored,
                             QSizePolicy.Fixed)

        if self.__tabIconSize.isValid():
            button.setIconSize(self.__tabIconSize)

        if self.__tabButtonHeight > 0:
            button.setFixedHeight(self.__tabButtonHeight)

        return button
Пример #23
0
def main(args):  # pragma: no cover
    # pylint: disable=import-outside-toplevel,protected-access
    from AnyQt.QtWidgets import QApplication, QAction
    from AnyQt.QtGui import QKeySequence
    app = QApplication(args)
    view = StickyGraphicsView()
    scene = QGraphicsScene(view)
    scene.setBackgroundBrush(QBrush(Qt.lightGray, Qt.CrossPattern))
    view.setScene(scene)
    scene.addRect(QRectF(0, 0, 300, 20), Qt.red,
                  QBrush(Qt.red, Qt.BDiagPattern))
    scene.addRect(QRectF(0, 25, 300, 100))
    scene.addRect(QRectF(0, 130, 300, 20), Qt.darkGray,
                  QBrush(Qt.darkGray, Qt.BDiagPattern))
    view.setHeaderSceneRect(QRectF(0, 0, 300, 20))
    view.setFooterSceneRect(QRectF(0, 130, 300, 20))
    view.show()
    zoomin = QAction("Zoom in", view, shortcut=QKeySequence.ZoomIn)
    zoomout = QAction("Zoom out", view, shortcut=QKeySequence.ZoomOut)
    zoomreset = QAction("Reset",
                        view,
                        shortcut=QKeySequence(Qt.ControlModifier | Qt.Key_0))
    view._zoom = 100

    def set_zoom(zoom):
        if view._zoom != zoom:
            view._zoom = zoom
            view.setTransform(QTransform.fromScale(*(view._zoom / 100, ) * 2))
            zoomout.setEnabled(zoom >= 20)
            zoomin.setEnabled(zoom <= 300)

    @zoomin.triggered.connect
    def _():
        set_zoom(view._zoom + 10)

    @zoomout.triggered.connect
    def _():
        set_zoom(view._zoom - 10)

    @zoomreset.triggered.connect
    def _():
        set_zoom(100)

    view.addActions([zoomin, zoomout, zoomreset])

    return app.exec()
Пример #24
0
 def _create_actions(self, index: QModelIndex) -> List[QAction]:
     actions = []
     for name in self.ACTIONS:
         action = QAction(name.capitalize(), self)
         action.triggered.connect(
             lambda *args, fun=name: self._initialize_values(fun, [index]))
         actions.append(action)
     return actions
Пример #25
0
 def createActionForItem(self, item):
     """Create the QAction instance for item.
     """
     action = QAction(item.icon(),
                      item.text(),
                      self,
                      toolTip=item.toolTip())
     action.setData(item)
     return action
Пример #26
0
 def add_zoom_actions(self, menu):
     zoom_in = QAction(
         "Zoom in", self, triggered=self.plot.vb.set_mode_zooming
     )
     zoom_in.setShortcuts([Qt.Key_Z, QKeySequence(QKeySequence.ZoomIn)])
     zoom_in.setShortcutContext(Qt.WidgetWithChildrenShortcut)
     self.addAction(zoom_in)
     if menu:
         menu.addAction(zoom_in)
     zoom_fit = QAction(
         "Zoom to fit", self,
         triggered=lambda x: (self.plot.vb.autoRange(), self.plot.vb.set_mode_panning())
     )
     zoom_fit.setShortcuts([Qt.Key_Backspace, QKeySequence(Qt.ControlModifier | Qt.Key_0)])
     zoom_fit.setShortcutContext(Qt.WidgetWithChildrenShortcut)
     self.addAction(zoom_fit)
     if menu:
         menu.addAction(zoom_fit)
Пример #27
0
 def createActionForItem(self, index):
     """Create the QAction instance for item at `index` (`QModelIndex`).
     """
     action = QAction(item_icon(index),
                      item_text(index),
                      self,
                      toolTip=item_tooltip(index))
     action.setData(QPersistentModelIndex(index))
     return action
Пример #28
0
    def __setupUi(self):
        vlayout = QVBoxLayout()
        vlayout.setContentsMargins(0, 0, 0, 0)
        top_layout = QHBoxLayout()
        top_layout.setContentsMargins(12, 12, 12, 12)

        # Top row with full text description and a large preview
        # image.
        self.__label = QLabel(
            self,
            objectName="description-label",
            wordWrap=True,
            alignment=Qt.AlignTop | Qt.AlignLeft,
        )

        self.__label.setWordWrap(True)
        self.__label.setFixedSize(220, PREVIEW_SIZE[1])

        self.__image = QSvgWidget(self, objectName="preview-image")
        self.__image.setFixedSize(*PREVIEW_SIZE)

        self.__imageFrame = DropShadowFrame(self)
        self.__imageFrame.setWidget(self.__image)

        # Path text below the description and image
        path_layout = QHBoxLayout()
        path_layout.setContentsMargins(12, 0, 12, 0)
        path_label = QLabel("<b>{0!s}</b>".format(self.tr("Path:")),
                            self,
                            objectName="path-label")

        self.__path = TextLabel(self, objectName="path-text")

        path_layout.addWidget(path_label)
        path_layout.addWidget(self.__path)

        self.__selectAction = QAction(self.tr("Select"),
                                      self,
                                      objectName="select-action")

        top_layout.addWidget(self.__label,
                             1,
                             alignment=Qt.AlignTop | Qt.AlignLeft)
        top_layout.addWidget(self.__image,
                             1,
                             alignment=Qt.AlignTop | Qt.AlignRight)

        vlayout.addLayout(top_layout)
        vlayout.addLayout(path_layout)

        # An list view with small preview icons.
        self.__previewList = LinearIconView(objectName="preview-list-view")
        self.__previewList.doubleClicked.connect(self.__onDoubleClicked)

        vlayout.addWidget(self.__previewList)
        self.setLayout(vlayout)
Пример #29
0
 def __init__(self, parent, plot):
     super().__init__(parent, plot)
     self._item = None
     self._start_pos = None
     self._selection_rect = None
     self._mouse_dragging = False
     self._delete_action = QAction(
         "Delete", self, shortcutContext=Qt.WindowShortcut
     )
     self._delete_action.setShortcuts([QKeySequence.Delete,
                                       QKeySequence("Backspace")])
     self._delete_action.triggered.connect(self.delete)
Пример #30
0
    def __insertItem(self, index, item):
        """
        Insert a widget action (from a `QStandardItem`) at index.
        """
        value = item.data(self.__actionRole)
        if value is not None:
            action = value
        else:
            action = QAction(item.text(), self)
            action.setIcon(item.icon())

        self.insertAction(index, action)