(self)
Init shortcuts for text editing
Init shortcuts for text editing
Init shortcuts for text editing
def _initActions(self):
        """Init shortcuts for text editing
        """

        def createAction(text, shortcut, slot, iconFileName=None):
            """Create QAction with given parameters and add to the widget
            """
            action = QAction(text, self)
            # if iconFileName is not None:
            #     action.setIcon(getIcon(iconFileName))

            keySeq = shortcut if isinstance(shortcut, QKeySequence) else QKeySequence(shortcut)
            action.setShortcut(keySeq)
            action.setShortcutContext(Qt.WidgetShortcut)
            action.triggered.connect(slot)

            self.addAction(action)

            return action

        # custom Orange actions
        self.commentLine = createAction('Toggle comment line', 'Ctrl+/', self._onToggleCommentLine)

        # scrolling
        self.scrollUpAction = createAction('Scroll up', 'Ctrl+Up',
                                           lambda: self._onShortcutScroll(down=False),
                                           'go-up')
        self.scrollDownAction = createAction('Scroll down', 'Ctrl+Down',
                                             lambda: self._onShortcutScroll(down=True),
                                             'go-down')
        self.selectAndScrollUpAction = createAction('Select and scroll Up', 'Ctrl+Shift+Up',
                                                    lambda: self._onShortcutSelectAndScroll(
                                                        down=False))
        self.selectAndScrollDownAction = createAction('Select and scroll Down', 'Ctrl+Shift+Down',
                                                      lambda: self._onShortcutSelectAndScroll(
                                                          down=True))

        # indentation
        self.increaseIndentAction = createAction('Increase indentation', 'Tab',
                                                 self._onShortcutIndent,
                                                 'format-indent-more')
        self.decreaseIndentAction = \
            createAction('Decrease indentation', 'Shift+Tab',
                         lambda: self._indenter.onChangeSelectedBlocksIndent(
                             increase=False),
                         'format-indent-less')
        self.autoIndentLineAction = \
            createAction('Autoindent line', 'Ctrl+I',
                         self._indenter.onAutoIndentTriggered)
        self.indentWithSpaceAction = \
            createAction('Indent with 1 space', 'Ctrl+Shift+Space',
                         lambda: self._indenter.onChangeSelectedBlocksIndent(
                             increase=True,
                             withSpace=True))
        self.unIndentWithSpaceAction = \
            createAction('Unindent with 1 space', 'Ctrl+Shift+Backspace',
                         lambda: self._indenter.onChangeSelectedBlocksIndent(
                             increase=False,
                             withSpace=True))

        # editing
        self.undoAction = createAction('Undo', QKeySequence.Undo,
                                       self.undo, 'edit-undo')
        self.redoAction = createAction('Redo', QKeySequence.Redo,
                                       self.redo, 'edit-redo')

        self.moveLineUpAction = createAction('Move line up', 'Alt+Up',
                                             lambda: self._onShortcutMoveLine(down=False),
                                             'go-up')
        self.moveLineDownAction = createAction('Move line down', 'Alt+Down',
                                               lambda: self._onShortcutMoveLine(down=True),
                                               'go-down')
        self.deleteLineAction = createAction('Delete line', 'Alt+Del',
                                             self._onShortcutDeleteLine, 'edit-delete')
        self.cutLineAction = createAction('Cut line', 'Alt+X',
                                          self._onShortcutCutLine, 'edit-cut')
        self.copyLineAction = createAction('Copy line', 'Alt+C',
                                           self._onShortcutCopyLine, 'edit-copy')
        self.pasteLineAction = createAction('Paste line', 'Alt+V',
                                            self._onShortcutPasteLine, 'edit-paste')
        self.duplicateLineAction = createAction('Duplicate line', 'Alt+D',
                                                self._onShortcutDuplicateLine)
def _initActions ( self ) : def createAction ( text , shortcut , slot , iconFileName = None ) : """Create QAction with given parameters and add to the widget
            """ action = QAction ( text , self ) # if iconFileName is not None: #     action.setIcon(getIcon(iconFileName)) keySeq = shortcut if isinstance ( shortcut , QKeySequence ) else QKeySequence ( shortcut ) action . setShortcut ( keySeq ) action . setShortcutContext ( Qt . WidgetShortcut ) action . triggered . connect ( slot ) self . addAction ( action ) return action # custom Orange actions self . commentLine = createAction ( 'Toggle comment line' , 'Ctrl+/' , self . _onToggleCommentLine ) # scrolling self . scrollUpAction = createAction ( 'Scroll up' , 'Ctrl+Up' , lambda : self . _onShortcutScroll ( down = False ) , 'go-up' ) self . scrollDownAction = createAction ( 'Scroll down' , 'Ctrl+Down' , lambda : self . _onShortcutScroll ( down = True ) , 'go-down' ) self . selectAndScrollUpAction = createAction ( 'Select and scroll Up' , 'Ctrl+Shift+Up' , lambda : self . _onShortcutSelectAndScroll ( down = False ) ) self . selectAndScrollDownAction = createAction ( 'Select and scroll Down' , 'Ctrl+Shift+Down' , lambda : self . _onShortcutSelectAndScroll ( down = True ) ) # indentation self . increaseIndentAction = createAction ( 'Increase indentation' , 'Tab' , self . _onShortcutIndent , 'format-indent-more' ) self . decreaseIndentAction = createAction ( 'Decrease indentation' , 'Shift+Tab' , lambda : self . _indenter . onChangeSelectedBlocksIndent ( increase = False ) , 'format-indent-less' ) self . autoIndentLineAction = createAction ( 'Autoindent line' , 'Ctrl+I' , self . _indenter . onAutoIndentTriggered ) self . indentWithSpaceAction = createAction ( 'Indent with 1 space' , 'Ctrl+Shift+Space' , lambda : self . _indenter . onChangeSelectedBlocksIndent ( increase = True , withSpace = True ) ) self . unIndentWithSpaceAction = createAction ( 'Unindent with 1 space' , 'Ctrl+Shift+Backspace' , lambda : self . _indenter . onChangeSelectedBlocksIndent ( increase = False , withSpace = True ) ) # editing self . undoAction = createAction ( 'Undo' , QKeySequence . Undo , self . undo , 'edit-undo' ) self . redoAction = createAction ( 'Redo' , QKeySequence . Redo , self . redo , 'edit-redo' ) self . moveLineUpAction = createAction ( 'Move line up' , 'Alt+Up' , lambda : self . _onShortcutMoveLine ( down = False ) , 'go-up' ) self . moveLineDownAction = createAction ( 'Move line down' , 'Alt+Down' , lambda : self . _onShortcutMoveLine ( down = True ) , 'go-down' ) self . deleteLineAction = createAction ( 'Delete line' , 'Alt+Del' , self . _onShortcutDeleteLine , 'edit-delete' ) self . cutLineAction = createAction ( 'Cut line' , 'Alt+X' , self . _onShortcutCutLine , 'edit-cut' ) self . copyLineAction = createAction ( 'Copy line' , 'Alt+C' , self . _onShortcutCopyLine , 'edit-copy' ) self . pasteLineAction = createAction ( 'Paste line' , 'Alt+V' , self . _onShortcutPasteLine , 'edit-paste' ) self . duplicateLineAction = createAction ( 'Duplicate line' , 'Alt+D' , self . _onShortcutDuplicateLine )