From 415c52e4b41fe67748cb624850e39dc0c74ba9ec Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Fri, 15 Jul 2016 09:10:43 +0100 Subject: [PATCH 1/3] Editor: Add shortcuts to context menu. --- spyderlib/widgets/sourcecode/codeeditor.py | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/spyderlib/widgets/sourcecode/codeeditor.py b/spyderlib/widgets/sourcecode/codeeditor.py index 257fa6741f7..dd82267cb29 100644 --- a/spyderlib/widgets/sourcecode/codeeditor.py +++ b/spyderlib/widgets/sourcecode/codeeditor.py @@ -2455,21 +2455,33 @@ def autoinsert_quotes(self, key): def setup_context_menu(self): """Setup context menu""" self.undo_action = create_action(self, _("Undo"), - icon=ima.icon('undo'), triggered=self.undo) + icon=ima.icon('undo'), + shortcut=get_shortcut('editor', 'undo'), + triggered=self.undo) self.redo_action = create_action(self, _("Redo"), - icon=ima.icon('redo'), triggered=self.redo) + icon=ima.icon('redo'), + shortcut=get_shortcut('editor', 'redo'), + triggered=self.redo) self.cut_action = create_action(self, _("Cut"), - icon=ima.icon('editcut'), triggered=self.cut) + icon=ima.icon('editcut'), + shortcut=get_shortcut('editor', 'cut'), + triggered=self.cut) self.copy_action = create_action(self, _("Copy"), - icon=ima.icon('editcopy'), triggered=self.copy) + icon=ima.icon('editcopy'), + shortcut=get_shortcut('editor', 'copy'), + triggered=self.copy) self.paste_action = create_action(self, _("Paste"), - icon=ima.icon('editpaste'), triggered=self.paste) + icon=ima.icon('editpaste'), + shortcut=get_shortcut('editor', 'paste'), + triggered=self.paste) selectall_action = create_action(self, _("Select All"), icon=ima.icon('selectall'), + shortcut=get_shortcut('editor', 'select all'), triggered=self.selectAll) toggle_comment_action = create_action(self, _("Comment")+"/"+_("Uncomment"), icon=ima.icon('comment'), + shortcut=get_shortcut('editor', 'toggle comment'), triggered=self.toggle_comment) self.clear_all_output_action = create_action(self, _("Clear all ouput"), icon=ima.icon('ipython_console'), @@ -2479,7 +2491,8 @@ def setup_context_menu(self): triggered=self.convert_notebook, icon=ima.icon('python')) self.gotodef_action = create_action(self, _("Go to definition"), - triggered=self.go_to_definition_from_cursor) + shortcut=get_shortcut('editor', 'go to definition'), + triggered=self.go_to_definition_from_cursor) # Run actions self.run_cell_action = create_action(self, @@ -2495,6 +2508,7 @@ def setup_context_menu(self): self.run_selection_action = create_action(self, _("Run &selection or current line"), icon=ima.icon('run_selection'), + shortcut=get_shortcut('editor', 'run selection'), triggered=lambda: self.run_selection.emit()) # Zoom actions From b131781bd5e0e86633c9aa500397473b55109f8d Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Fri, 15 Jul 2016 09:30:51 +0100 Subject: [PATCH 2/3] editor: Add 'cut' to list returned by create_shortcuts() . --- spyderlib/widgets/sourcecode/codeeditor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyderlib/widgets/sourcecode/codeeditor.py b/spyderlib/widgets/sourcecode/codeeditor.py index dd82267cb29..5673b480bbd 100644 --- a/spyderlib/widgets/sourcecode/codeeditor.py +++ b/spyderlib/widgets/sourcecode/codeeditor.py @@ -617,7 +617,7 @@ def cursor_move_event(): unblockcomment, line_start, line_end, prev_line, next_line, prev_char, next_char, prev_word, next_word, kill_line_end, kill_line_start, yank, kill_ring_rotate, kill_prev_word, - kill_next_word, start_doc, end_doc, undo, redo, copy, + kill_next_word, start_doc, end_doc, undo, redo, cut, copy, paste, delete, select_all] def get_shortcut_data(self): From 4b44b20c114f725a995b8a6d3928edacd5a7c6e3 Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Tue, 19 Jul 2016 22:16:20 +0100 Subject: [PATCH 3/3] Editor: pep8-ify hanging indents in setup_context_menu() . --- spyderlib/widgets/sourcecode/codeeditor.py | 122 ++++++++++----------- 1 file changed, 57 insertions(+), 65 deletions(-) diff --git a/spyderlib/widgets/sourcecode/codeeditor.py b/spyderlib/widgets/sourcecode/codeeditor.py index 5673b480bbd..59e1229289e 100644 --- a/spyderlib/widgets/sourcecode/codeeditor.py +++ b/spyderlib/widgets/sourcecode/codeeditor.py @@ -2454,75 +2454,67 @@ def autoinsert_quotes(self, key): #=============================================================================== def setup_context_menu(self): """Setup context menu""" - self.undo_action = create_action(self, _("Undo"), - icon=ima.icon('undo'), - shortcut=get_shortcut('editor', 'undo'), - triggered=self.undo) - self.redo_action = create_action(self, _("Redo"), - icon=ima.icon('redo'), - shortcut=get_shortcut('editor', 'redo'), - triggered=self.redo) - self.cut_action = create_action(self, _("Cut"), - icon=ima.icon('editcut'), - shortcut=get_shortcut('editor', 'cut'), - triggered=self.cut) - self.copy_action = create_action(self, _("Copy"), - icon=ima.icon('editcopy'), - shortcut=get_shortcut('editor', 'copy'), - triggered=self.copy) - self.paste_action = create_action(self, _("Paste"), - icon=ima.icon('editpaste'), - shortcut=get_shortcut('editor', 'paste'), - triggered=self.paste) - selectall_action = create_action(self, _("Select All"), - icon=ima.icon('selectall'), - shortcut=get_shortcut('editor', 'select all'), - triggered=self.selectAll) - toggle_comment_action = create_action(self, - _("Comment")+"/"+_("Uncomment"), - icon=ima.icon('comment'), - shortcut=get_shortcut('editor', 'toggle comment'), - triggered=self.toggle_comment) - self.clear_all_output_action = create_action(self, - _("Clear all ouput"), icon=ima.icon('ipython_console'), - triggered=self.clear_all_output) - self.ipynb_convert_action = create_action(self, - _("Convert to Python script"), - triggered=self.convert_notebook, - icon=ima.icon('python')) - self.gotodef_action = create_action(self, _("Go to definition"), - shortcut=get_shortcut('editor', 'go to definition'), - triggered=self.go_to_definition_from_cursor) + self.undo_action = create_action( + self, _("Undo"), icon=ima.icon('undo'), + shortcut=get_shortcut('editor', 'undo'), triggered=self.undo) + self.redo_action = create_action( + self, _("Redo"), icon=ima.icon('redo'), + shortcut=get_shortcut('editor', 'redo'), triggered=self.redo) + self.cut_action = create_action( + self, _("Cut"), icon=ima.icon('editcut'), + shortcut=get_shortcut('editor', 'cut'), triggered=self.cut) + self.copy_action = create_action( + self, _("Copy"), icon=ima.icon('editcopy'), + shortcut=get_shortcut('editor', 'copy'), triggered=self.copy) + self.paste_action = create_action( + self, _("Paste"), icon=ima.icon('editpaste'), + shortcut=get_shortcut('editor', 'paste'), triggered=self.paste) + selectall_action = create_action( + self, _("Select All"), icon=ima.icon('selectall'), + shortcut=get_shortcut('editor', 'select all'), + triggered=self.selectAll) + toggle_comment_action = create_action( + self, _("Comment")+"/"+_("Uncomment"), icon=ima.icon('comment'), + shortcut=get_shortcut('editor', 'toggle comment'), + triggered=self.toggle_comment) + self.clear_all_output_action = create_action( + self, _("Clear all ouput"), icon=ima.icon('ipython_console'), + triggered=self.clear_all_output) + self.ipynb_convert_action = create_action( + self, _("Convert to Python script"), icon=ima.icon('python'), + triggered=self.convert_notebook) + self.gotodef_action = create_action( + self, _("Go to definition"), + shortcut=get_shortcut('editor', 'go to definition'), + triggered=self.go_to_definition_from_cursor) # Run actions - self.run_cell_action = create_action(self, - _("Run cell"), - icon=ima.icon('run_cell'), - shortcut=QKeySequence(RUN_CELL_SHORTCUT), - triggered=lambda: self.run_cell.emit()) - self.run_cell_and_advance_action = create_action(self, - _("Run cell and advance"), - icon=ima.icon('run_cell'), - shortcut=QKeySequence(RUN_CELL_AND_ADVANCE_SHORTCUT), - triggered=lambda: self.run_cell_and_advance.emit()) - self.run_selection_action = create_action(self, - _("Run &selection or current line"), - icon=ima.icon('run_selection'), - shortcut=get_shortcut('editor', 'run selection'), - triggered=lambda: self.run_selection.emit()) + self.run_cell_action = create_action( + self, _("Run cell"), icon=ima.icon('run_cell'), + shortcut=QKeySequence(RUN_CELL_SHORTCUT), + triggered=self.run_cell.emit) + self.run_cell_and_advance_action = create_action( + self, _("Run cell and advance"), icon=ima.icon('run_cell'), + shortcut=QKeySequence(RUN_CELL_AND_ADVANCE_SHORTCUT), + triggered=self.run_cell_and_advance.emit) + self.run_selection_action = create_action( + self, _("Run &selection or current line"), + icon=ima.icon('run_selection'), + shortcut=get_shortcut('editor', 'run selection'), + triggered=self.run_selection.emit) # Zoom actions - zoom_in_action = create_action(self, _("Zoom in"), - QKeySequence(QKeySequence.ZoomIn), - icon=ima.icon('zoom_in'), - triggered=lambda: self.zoom_in.emit()) - zoom_out_action = create_action(self, _("Zoom out"), - QKeySequence(QKeySequence.ZoomOut), - icon=ima.icon('zoom_out'), - triggered=lambda: self.zoom_out.emit()) - zoom_reset_action = create_action(self, _("Zoom reset"), - QKeySequence("Ctrl+0"), - triggered=lambda: self.zoom_reset.emit()) + zoom_in_action = create_action( + self, _("Zoom in"), icon=ima.icon('zoom_in'), + shortcut=QKeySequence(QKeySequence.ZoomIn), + triggered=self.zoom_in.emit) + zoom_out_action = create_action( + self, _("Zoom out"), icon=ima.icon('zoom_out'), + shortcut=QKeySequence(QKeySequence.ZoomOut), + triggered=self.zoom_out.emit) + zoom_reset_action = create_action( + self, _("Zoom reset"), shortcut=QKeySequence("Ctrl+0"), + triggered=self.zoom_reset.emit) # Build menu self.menu = QMenu(self)