コード例 #1
0
ファイル: menu.py プロジェクト: shdwdln/NodeGraphQt
    def set_shortcut(self, shortcut=None):
        """
        Sets the shortcut key combination for the menu command.

        Args:
            shortcut (str): shortcut key.
        """
        shortcut = shortcut or QtGui.QKeySequence()
        self.qaction.setShortcut(shortcut)
コード例 #2
0
ファイル: graph.py プロジェクト: shdwdln/NodeGraphQt
    def __init__(self, parent=None):
        super(NodeGraph, self).__init__(parent)
        self.setObjectName('NodeGraphQt')
        self._widget = None
        self._model = NodeGraphModel()
        self._viewer = NodeViewer()
        self._node_factory = NodeFactory()
        self._undo_stack = QtWidgets.QUndoStack(self)

        tab = QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Tab), self._viewer)
        tab.activated.connect(self._toggle_tab_search)
        self._viewer.need_show_tab_search.connect(self._toggle_tab_search)

        self._wire_signals()
        self.widget.setAcceptDrops(True)
コード例 #3
0
    def setupMenuBar(self, graph: NodeGraph):
        rootMenu = graph.context_menu()

        fileMenu = rootMenu.add_menu('&File')
        editMenu = rootMenu.add_menu('&Edit')

        # create "File" menu.
        fileMenu.add_command('Open Graph...',
                             lambda: actions._open_session(graph),
                             QtGui.QKeySequence.Open)
        fileMenu.add_command('Export Graph As...',
                             lambda: actions._save_session_as(graph),
                             'Alt+Shift+s')
        fileMenu.add_command('Clear', lambda: actions._clear_session(graph))

        fileMenu.add_separator()

        fileMenu.add_command('Zoom In', lambda: actions._zoom_in(graph), '=')
        fileMenu.add_command('Zoom Out', lambda: actions._zoom_out(graph), '-')
        fileMenu.add_command('Reset Zoom', graph.reset_zoom, 'h')

        # create "Edit" menu.
        undo_actn = graph.undo_stack().createUndoAction(
            graph.viewer(), '&Undo')
        if LooseVersion(QtCore.qVersion()) >= LooseVersion('5.10'):
            undo_actn.setShortcutVisibleInContextMenu(True)
        undo_actn.setShortcuts(QtGui.QKeySequence.Undo)
        editMenu.qmenu.addAction(undo_actn)

        redo_actn = graph.undo_stack().createRedoAction(
            graph.viewer(), '&Redo')
        if LooseVersion(QtCore.qVersion()) >= LooseVersion('5.10'):
            redo_actn.setShortcutVisibleInContextMenu(True)
        redo_actn.setShortcuts(QtGui.QKeySequence.Redo)
        editMenu.qmenu.addAction(redo_actn)

        editMenu.add_separator()
        editMenu.add_command('Clear Undo History',
                             lambda: actions._clear_undo(graph))
        editMenu.add_separator()

        editMenu.add_command('Copy', graph.copy_nodes, QtGui.QKeySequence.Copy)
        editMenu.add_command('Paste', graph.paste_nodes,
                             QtGui.QKeySequence.Paste)
        editMenu.add_command(
            'Delete', lambda: graph.delete_nodes(graph.selected_nodes()),
            QtGui.QKeySequence.Delete)

        editMenu.add_separator()

        editMenu.add_command('Select all', graph.select_all, 'Ctrl+A')
        editMenu.add_command('Deselect all', graph.clear_selection,
                             'Ctrl+Shift+A')
        editMenu.add_command(
            'Enable/Disable',
            lambda: graph.disable_nodes(graph.selected_nodes()), 'd')

        editMenu.add_command(
            'Duplicate', lambda: graph.duplicate_nodes(graph.selected_nodes()),
            'Alt+c')
        editMenu.add_command('Center Selection', graph.fit_to_selection, 'f')

        editMenu.add_separator()

        menuBar = QtWidgets.QMenuBar()
        sessionMenu = QtWidgets.QMenu("Session")

        menuBar.addMenu(fileMenu.qmenu)
        menuBar.addMenu(editMenu.qmenu)
        menuBar.addMenu(sessionMenu)

        self.saveAction = QtWidgets.QAction("Save")
        self.saveAction.setShortcut(QtGui.QKeySequence.Save)
        self.saveAction.triggered.connect(self.onSave)

        self.saveAsAction = QtWidgets.QAction("Save As...")
        self.saveAsAction.setShortcut("Ctrl+Shift+S")
        self.saveAsAction.triggered.connect(self.onSaveAs)

        self.loadAction = QtWidgets.QAction("Load")
        self.loadAction.triggered.connect(self.onLoad)

        self.runAction = QtWidgets.QAction("Run")
        self.runAction.triggered.connect(self.onRun)
        self.runAction.setShortcut(QtGui.QKeySequence("R"))

        self.openInCode = QtWidgets.QAction("Show Code In Visual Studio Code")
        self.openInCode.triggered.connect(self.onOpenInVisualStudioCode)
        self.openInCode.setShortcut(QtGui.QKeySequence("Q"))

        sessionMenu.addAction(self.saveAction)
        sessionMenu.addAction(self.saveAsAction)
        sessionMenu.addAction(self.loadAction)
        sessionMenu.addAction(self.runAction)
        sessionMenu.addAction(self.openInCode)
        self.sessionMenu = sessionMenu

        self.viewMenu = QtWidgets.QMenu("View")
        menuBar.addMenu(self.viewMenu)

        self.window.verticalLayout.insertWidget(0, menuBar)