From ba688de15a22108173064929037a87450fa2b8b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Andr=C3=A9s=20Margffoy=20Tuay?= Date: Mon, 16 Jan 2017 19:35:08 -0500 Subject: [PATCH 01/11] Added shortcut and menu options to re-run last cell --- spyder/config/main.py | 4 ++++ spyder/plugins/editor.py | 25 ++++++++++++++++++++++--- spyder/utils/icon_manager.py | 2 ++ spyder/widgets/editor.py | 14 +++++++++++++- spyder/widgets/sourcecode/base.py | 21 ++++++++++++++++++--- spyder/widgets/sourcecode/codeeditor.py | 11 +++++++++-- 6 files changed, 68 insertions(+), 9 deletions(-) diff --git a/spyder/config/main.py b/spyder/config/main.py index a666d94562e..5bd9009efab 100755 --- a/spyder/config/main.py +++ b/spyder/config/main.py @@ -57,10 +57,13 @@ # Run cell shortcuts if sys.platform == 'darwin': RUN_CELL_SHORTCUT = 'Meta+Return' + RE_RUN_LAST_CELL_SHORTCUT = 'Meta+Shift+R' else: RUN_CELL_SHORTCUT = 'Ctrl+Return' + RE_RUN_LAST_CELL_SHORTCUT = 'Ctrl+Shift+R' RUN_CELL_AND_ADVANCE_SHORTCUT = 'Shift+Return' + # ============================================================================= # Defaults # ============================================================================= @@ -424,6 +427,7 @@ 'editor/close file 2': "Ctrl+F4", 'editor/run cell': RUN_CELL_SHORTCUT, 'editor/run cell and advance': RUN_CELL_AND_ADVANCE_SHORTCUT, + 'editor/re-run last cell': RE_RUN_LAST_CELL_SHORTCUT, # -- In plugins/editor.py 'editor/show/hide outline': "Ctrl+Alt+O", # -- In Breakpoints diff --git a/spyder/plugins/editor.py b/spyder/plugins/editor.py index e6d8670dab7..16d5afb5a75 100644 --- a/spyder/plugins/editor.py +++ b/spyder/plugins/editor.py @@ -839,6 +839,17 @@ def get_plugin_actions(self): triggered=self.run_cell_and_advance, context=Qt.WidgetShortcut) + re_run_last_cell_action = create_action(self, + _("Re-run last cell"), + icon=ima.icon('re_run_last_cell'), + tip=_("Re run last cell "), + triggered=self.re_run_last_cell, + context=Qt.WidgetShortcut) + self.register_shortcut(re_run_last_cell_action, + context="Editor", + name='re-run last cell', + add_sc_to_tip=True) + # --- Source code Toolbar --- self.todo_list_action = create_action(self, _("Show todo list"), icon=ima.icon('todo_list'), @@ -1046,13 +1057,14 @@ def get_plugin_actions(self): # ---- Run menu/toolbar construction ---- run_menu_actions = [run_action, run_cell_action, - run_cell_advance_action, MENU_SEPARATOR, + run_cell_advance_action, + re_run_last_cell_action, MENU_SEPARATOR, run_selected_action, re_run_action, configure_action, MENU_SEPARATOR] self.main.run_menu_actions += run_menu_actions run_toolbar_actions = [run_action, run_cell_action, - run_cell_advance_action, re_run_action, - configure_action] + run_cell_advance_action, re_run_last_cell_action, + re_run_action, configure_action] self.main.run_toolbar_actions += run_toolbar_actions # ---- Debug menu/toolbar construction ---- @@ -1120,6 +1132,7 @@ def get_plugin_actions(self): debug_action, run_selected_action, run_cell_action, run_cell_advance_action, + re_run_last_cell_action, blockcomment_action, unblockcomment_action, self.winpdb_action] @@ -2408,6 +2421,12 @@ def run_cell_and_advance(self): editorstack = self.get_current_editorstack() editorstack.run_cell_and_advance() + @Slot() + def re_run_last_cell(self): + """Run last executed cell.""" + editorstack = self.get_current_editorstack() + editorstack.re_run_last_cell() + #------ Zoom in/out/reset def zoom(self, factor): """Zoom in/out/reset""" diff --git a/spyder/utils/icon_manager.py b/spyder/utils/icon_manager.py index b7550e794ac..33104dffdf5 100644 --- a/spyder/utils/icon_manager.py +++ b/spyder/utils/icon_manager.py @@ -61,6 +61,8 @@ 'run_selection': [('spyder.run-selection',), {}], 'run_cell': [('spyder.cell-code', 'spyder.cell-border', 'spyder.cell-play'), {'options': [{'color': '#fff683'}, {}, {'color': 'green'}]}], + 're_run_last_cell': [('spyder.cell-code', 'spyder.cell-border', 'fa.repeat', 'spyder.cell-play'), + {'options': [{'color': '#fff683'}, {}, {'offset':(0.0, -0.05)}, {'color': 'green', 'offset':(0, 0.3), 'scale_factor':0.9}]}], 'run_cell_advance': [('spyder.cell-code', 'spyder.cell-border', 'spyder.cell-play', 'spyder.cell-next'), {'options': [{'color': '#fff683'}, {}, {'color': 'green'}, {'color': 'red'}]}], 'todo_list': [('fa.th-list', 'fa.check'), {'options': [{'color': '#999999'}, {'offset': (0.0, 0.2), 'color': '#3775a9', 'color_disabled': '#748fa6'}]}], diff --git a/spyder/widgets/editor.py b/spyder/widgets/editor.py index dbc30eed3e1..8df7c064792 100644 --- a/spyder/widgets/editor.py +++ b/spyder/widgets/editor.py @@ -510,13 +510,18 @@ def create_shortcuts(self): context="Editor", name="run cell and advance", parent=self) + re_run_last_cell = config_shortcut(self.re_run_last_cell, + context="Editor", + name="re-run last cell", + parent=self) # Return configurable ones return [inspect, set_breakpoint, set_cond_breakpoint, gotoline, tab, tabshift, run_selection, new_file, open_file, save_file, save_all, save_as, close_all, prev_edit_pos, prev_cursor, next_cursor, zoom_in_1, zoom_in_2, zoom_out, zoom_reset, - close_file_1, close_file_2, run_cell, run_cell_and_advance] + close_file_1, close_file_2, run_cell, run_cell_and_advance, + re_run_last_cell] def get_shortcut_data(self): """ @@ -1740,6 +1745,7 @@ def create_new_editor(self, fname, enc, txt, set_current, new=False, editor.run_selection.connect(self.run_selection) editor.run_cell.connect(self.run_cell) editor.run_cell_and_advance.connect(self.run_cell_and_advance) + editor.re_run_last_cell.connect(self.re_run_last_cell) editor.sig_new_file.connect(self.sig_new_file.emit) language = get_file_language(fname, txt) editor.setup_editor( @@ -1931,6 +1937,12 @@ def run_cell_and_advance(self): self.get_current_editor().go_to_next_cell() term.setFocus() + def re_run_last_cell(self): + text = self.get_current_editor().get_last_cell_as_executable_code() + finfo = self.get_current_finfo() + if finfo.editor.is_python() and text: + self.exec_in_extconsole.emit(text, self.focus_to_editor) + #------ Drag and drop def dragEnterEvent(self, event): """Reimplement Qt method diff --git a/spyder/widgets/sourcecode/base.py b/spyder/widgets/sourcecode/base.py index 7b4c35d59be..6750cb22d46 100644 --- a/spyder/widgets/sourcecode/base.py +++ b/spyder/widgets/sourcecode/base.py @@ -272,6 +272,8 @@ def __init__(self, parent=None): self.matched_p_color = QColor(Qt.green) self.unmatched_p_color = QColor(Qt.red) + self.last_cursor_cell = None + def setup_completion(self): size = CONF.get('main', 'completion/size') font = get_font() @@ -621,16 +623,29 @@ def get_selection_as_executable_code(self): return ls.join(lines) - def get_cell_as_executable_code(self): - """Return cell contents as executable code""" + def __exec_cell(self): + init_cur = QTextCursor(self.textCursor()) start_pos, end_pos = self.__save_selection() cursor, whole_file_selected = self.select_current_cell() if not whole_file_selected: self.setTextCursor(cursor) text = self.get_selection_as_executable_code() + self.last_cursor_cell = init_cur self.__restore_selection(start_pos, end_pos) return text + def get_cell_as_executable_code(self): + """Return cell contents as executable code""" + return self.__exec_cell() + + def get_last_cell_as_executable_code(self): + text = None + if self.last_cursor_cell: + self.setTextCursor(self.last_cursor_cell) + self.highlight_current_cell() + text = self.__exec_cell() + return text + def is_cell_separator(self, cursor=None, block=None): """Return True if cursor (or text block) is on a block separator""" assert cursor is not None or block is not None @@ -689,7 +704,7 @@ def select_current_cell(self): prev_pos = cur_pos cell_at_file_end = cursor.atEnd() return cursor, cell_at_file_start and cell_at_file_end - + def select_current_cell_in_visible_portion(self): """Select cell under cursor in the visible portion of the file cell = group of lines separated by CELL_SEPARATORS diff --git a/spyder/widgets/sourcecode/codeeditor.py b/spyder/widgets/sourcecode/codeeditor.py index e03fa320809..7322a6c2196 100644 --- a/spyder/widgets/sourcecode/codeeditor.py +++ b/spyder/widgets/sourcecode/codeeditor.py @@ -352,6 +352,7 @@ class CodeEditor(TextEditBaseWidget): run_selection = Signal() run_cell_and_advance = Signal() run_cell = Signal() + re_run_last_cell = Signal() go_to_definition_regex = Signal(int) sig_cursor_position_changed = Signal(int, int) focus_changed = Signal() @@ -2604,6 +2605,10 @@ def setup_context_menu(self): 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.re_run_last_cell_action = create_action( + self, _("Re-run last cell"), icon=ima.icon('re_run_last_cell'), + shortcut=get_shortcut('editor', 're-run last cell'), + triggered=self.re_run_last_cell.emit) self.run_selection_action = create_action( self, _("Run &selection or current line"), icon=ima.icon('run_selection'), @@ -2626,8 +2631,9 @@ def setup_context_menu(self): # Build menu self.menu = QMenu(self) actions_1 = [self.run_cell_action, self.run_cell_and_advance_action, - self.run_selection_action, self.gotodef_action, None, - self.undo_action, self.redo_action, None, self.cut_action, + self.re_run_last_cell_action, self.run_selection_action, + self.gotodef_action, None, self.undo_action, + self.redo_action, None, self.cut_action, self.copy_action, self.paste_action, selectall_action] actions_2 = [None, zoom_in_action, zoom_out_action, zoom_reset_action, None, toggle_comment_action] @@ -2908,6 +2914,7 @@ def contextMenuEvent(self, event): self.run_cell_action.setVisible(self.is_python()) self.run_cell_and_advance_action.setVisible(self.is_python()) self.run_selection_action.setVisible(self.is_python()) + self.re_run_last_cell_action.setVisible(self.is_python()) self.gotodef_action.setVisible(self.go_to_definition_enabled \ and self.is_python_like()) From caa9696c6589ce551dd09ba13123d8787d5b2cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Andr=C3=A9s=20Margffoy=20Tuay?= Date: Mon, 16 Jan 2017 19:39:16 -0500 Subject: [PATCH 02/11] PEP8 style corrections --- spyder/plugins/editor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spyder/plugins/editor.py b/spyder/plugins/editor.py index 16d5afb5a75..5fe155b46aa 100644 --- a/spyder/plugins/editor.py +++ b/spyder/plugins/editor.py @@ -1063,7 +1063,8 @@ def get_plugin_actions(self): configure_action, MENU_SEPARATOR] self.main.run_menu_actions += run_menu_actions run_toolbar_actions = [run_action, run_cell_action, - run_cell_advance_action, re_run_last_cell_action, + run_cell_advance_action, + re_run_last_cell_action, re_run_action, configure_action] self.main.run_toolbar_actions += run_toolbar_actions From 5759aa4a83618ea7c217a6122e86f31c059f0506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Andr=C3=A9s=20Margffoy=20Tuay?= Date: Sat, 25 Feb 2017 23:59:50 -0500 Subject: [PATCH 03/11] Changed default shortcut --- spyder/config/main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spyder/config/main.py b/spyder/config/main.py index 3aa23fbcc5b..4485ec10a88 100755 --- a/spyder/config/main.py +++ b/spyder/config/main.py @@ -57,10 +57,9 @@ # Run cell shortcuts if sys.platform == 'darwin': RUN_CELL_SHORTCUT = 'Meta+Return' - RE_RUN_LAST_CELL_SHORTCUT = 'Meta+Shift+R' else: RUN_CELL_SHORTCUT = 'Ctrl+Return' - RE_RUN_LAST_CELL_SHORTCUT = 'Ctrl+Shift+R' +RE_RUN_LAST_CELL_SHORTCUT = 'Alt+Shift+R' RUN_CELL_AND_ADVANCE_SHORTCUT = 'Shift+Return' From 585865afa80db445cff57236d3f1f911aad856fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Andr=C3=A9s=20Margffoy=20Tuay?= Date: Mon, 27 Feb 2017 09:46:54 -0500 Subject: [PATCH 04/11] Toolbar shortcut removed --- spyder/config/main.py | 2 +- spyder/plugins/editor.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/spyder/config/main.py b/spyder/config/main.py index 4485ec10a88..e5537079bc3 100755 --- a/spyder/config/main.py +++ b/spyder/config/main.py @@ -59,7 +59,7 @@ RUN_CELL_SHORTCUT = 'Meta+Return' else: RUN_CELL_SHORTCUT = 'Ctrl+Return' -RE_RUN_LAST_CELL_SHORTCUT = 'Alt+Shift+R' +RE_RUN_LAST_CELL_SHORTCUT = 'Alt+Return' RUN_CELL_AND_ADVANCE_SHORTCUT = 'Shift+Return' diff --git a/spyder/plugins/editor.py b/spyder/plugins/editor.py index 6cfd6d13516..dd69efc5b84 100644 --- a/spyder/plugins/editor.py +++ b/spyder/plugins/editor.py @@ -1065,7 +1065,6 @@ def get_plugin_actions(self): self.main.run_menu_actions += run_menu_actions run_toolbar_actions = [run_action, run_cell_action, run_cell_advance_action, - re_run_last_cell_action, re_run_action, configure_action] self.main.run_toolbar_actions += run_toolbar_actions From b813bdd6e48fed95e3b5e4ba2c83837e8948490d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Andr=C3=A9s=20Margffoy=20Tuay?= Date: Mon, 27 Feb 2017 09:52:58 -0500 Subject: [PATCH 05/11] Icon definition removed from main icon file --- spyder/plugins/editor.py | 2 +- spyder/utils/icon_manager.py | 2 -- spyder/widgets/sourcecode/codeeditor.py | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/spyder/plugins/editor.py b/spyder/plugins/editor.py index dd69efc5b84..73b51f4b50b 100644 --- a/spyder/plugins/editor.py +++ b/spyder/plugins/editor.py @@ -842,7 +842,7 @@ def get_plugin_actions(self): re_run_last_cell_action = create_action(self, _("Re-run last cell"), - icon=ima.icon('re_run_last_cell'), + icon=ima.icon('run_cell'), tip=_("Re run last cell "), triggered=self.re_run_last_cell, context=Qt.WidgetShortcut) diff --git a/spyder/utils/icon_manager.py b/spyder/utils/icon_manager.py index 33104dffdf5..b7550e794ac 100644 --- a/spyder/utils/icon_manager.py +++ b/spyder/utils/icon_manager.py @@ -61,8 +61,6 @@ 'run_selection': [('spyder.run-selection',), {}], 'run_cell': [('spyder.cell-code', 'spyder.cell-border', 'spyder.cell-play'), {'options': [{'color': '#fff683'}, {}, {'color': 'green'}]}], - 're_run_last_cell': [('spyder.cell-code', 'spyder.cell-border', 'fa.repeat', 'spyder.cell-play'), - {'options': [{'color': '#fff683'}, {}, {'offset':(0.0, -0.05)}, {'color': 'green', 'offset':(0, 0.3), 'scale_factor':0.9}]}], 'run_cell_advance': [('spyder.cell-code', 'spyder.cell-border', 'spyder.cell-play', 'spyder.cell-next'), {'options': [{'color': '#fff683'}, {}, {'color': 'green'}, {'color': 'red'}]}], 'todo_list': [('fa.th-list', 'fa.check'), {'options': [{'color': '#999999'}, {'offset': (0.0, 0.2), 'color': '#3775a9', 'color_disabled': '#748fa6'}]}], diff --git a/spyder/widgets/sourcecode/codeeditor.py b/spyder/widgets/sourcecode/codeeditor.py index 9e5ba003367..04b78daabe9 100644 --- a/spyder/widgets/sourcecode/codeeditor.py +++ b/spyder/widgets/sourcecode/codeeditor.py @@ -2645,7 +2645,7 @@ def setup_context_menu(self): shortcut=QKeySequence(RUN_CELL_AND_ADVANCE_SHORTCUT), triggered=self.run_cell_and_advance.emit) self.re_run_last_cell_action = create_action( - self, _("Re-run last cell"), icon=ima.icon('re_run_last_cell'), + self, _("Re-run last cell"), icon=ima.icon('run_cell'), shortcut=get_shortcut('editor', 're-run last cell'), triggered=self.re_run_last_cell.emit) self.run_selection_action = create_action( From 34776c1952a6f58189f5d47053a30b9f1a1c201c Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Tue, 28 Feb 2017 08:53:24 -0500 Subject: [PATCH 06/11] Backport PR 4210 --- spyder/utils/syntaxhighlighters.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spyder/utils/syntaxhighlighters.py b/spyder/utils/syntaxhighlighters.py index 4ae0edc67e7..9e72a708707 100644 --- a/spyder/utils/syntaxhighlighters.py +++ b/spyder/utils/syntaxhighlighters.py @@ -509,13 +509,17 @@ def rehighlight(self): #============================================================================== # Cython syntax highlighter #============================================================================== -C_TYPES = 'bool char double enum float int long mutable short signed struct unsigned void' +C_TYPES = 'bool char double enum float int long mutable short signed struct unsigned void NULL' class CythonSH(PythonSH): """Cython Syntax Highlighter""" - ADDITIONAL_KEYWORDS = ["cdef", "ctypedef", "cpdef", "inline", "cimport", - "DEF"] - ADDITIONAL_BUILTINS = C_TYPES.split() + ADDITIONAL_KEYWORDS = [ + "cdef", "ctypedef", "cpdef", "inline", "cimport", "extern", + "include", "begin", "end", "by", "gil", "nogil", "const", "public", + "readonly", "fused ", "static", "api", "DEF", "IF", "ELIF", "ELSE"] + + ADDITIONAL_BUILTINS = C_TYPES.split() + [ + "array", "bint", "Py_ssize_t", "intern", "reload", "sizeof"] PROG = re.compile(make_python_patterns(ADDITIONAL_KEYWORDS, ADDITIONAL_BUILTINS), re.S) IDPROG = re.compile(r"\s+([\w\.]+)", re.S) From ee18550c54d1614c85dc5d4cfec5a1094f317d42 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Tue, 28 Feb 2017 13:06:40 -0500 Subject: [PATCH 07/11] Some fixes for the Cython highlighter --- spyder/utils/syntaxhighlighters.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spyder/utils/syntaxhighlighters.py b/spyder/utils/syntaxhighlighters.py index 9e72a708707..9a2e8b38555 100644 --- a/spyder/utils/syntaxhighlighters.py +++ b/spyder/utils/syntaxhighlighters.py @@ -509,17 +509,17 @@ def rehighlight(self): #============================================================================== # Cython syntax highlighter #============================================================================== -C_TYPES = 'bool char double enum float int long mutable short signed struct unsigned void NULL' +C_TYPES = 'bool char double enum float int long mutable short signed struct unsigned void' class CythonSH(PythonSH): """Cython Syntax Highlighter""" ADDITIONAL_KEYWORDS = [ "cdef", "ctypedef", "cpdef", "inline", "cimport", "extern", "include", "begin", "end", "by", "gil", "nogil", "const", "public", - "readonly", "fused ", "static", "api", "DEF", "IF", "ELIF", "ELSE"] + "readonly", "fused", "static", "api", "DEF", "IF", "ELIF", "ELSE"] ADDITIONAL_BUILTINS = C_TYPES.split() + [ - "array", "bint", "Py_ssize_t", "intern", "reload", "sizeof"] + "array", "bint", "Py_ssize_t", "intern", "reload", "sizeof", "NULL"] PROG = re.compile(make_python_patterns(ADDITIONAL_KEYWORDS, ADDITIONAL_BUILTINS), re.S) IDPROG = re.compile(r"\s+([\w\.]+)", re.S) From 5067a03f61c33808a63446887144cca266dd8756 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Tue, 28 Feb 2017 13:09:25 -0500 Subject: [PATCH 08/11] Remove tabs from utils/syntaxhighlighters --- spyder/utils/syntaxhighlighters.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spyder/utils/syntaxhighlighters.py b/spyder/utils/syntaxhighlighters.py index 9a2e8b38555..9b0d872d7bd 100644 --- a/spyder/utils/syntaxhighlighters.py +++ b/spyder/utils/syntaxhighlighters.py @@ -515,9 +515,9 @@ class CythonSH(PythonSH): """Cython Syntax Highlighter""" ADDITIONAL_KEYWORDS = [ "cdef", "ctypedef", "cpdef", "inline", "cimport", "extern", - "include", "begin", "end", "by", "gil", "nogil", "const", "public", - "readonly", "fused", "static", "api", "DEF", "IF", "ELIF", "ELSE"] - + "include", "begin", "end", "by", "gil", "nogil", "const", "public", + "readonly", "fused", "static", "api", "DEF", "IF", "ELIF", "ELSE"] + ADDITIONAL_BUILTINS = C_TYPES.split() + [ "array", "bint", "Py_ssize_t", "intern", "reload", "sizeof", "NULL"] PROG = re.compile(make_python_patterns(ADDITIONAL_KEYWORDS, From b71d468062222c4dffe6dad889dcec3c470562f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Andr=C3=A9s=20Margffoy=20Tuay?= Date: Fri, 3 Mar 2017 12:11:55 -0500 Subject: [PATCH 09/11] Removed wrong instructions introduced via a failed merge --- spyder/plugins/editor.py | 9 +-------- spyder/widgets/sourcecode/base.py | 4 ++-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/spyder/plugins/editor.py b/spyder/plugins/editor.py index 73b51f4b50b..49d20d49592 100644 --- a/spyder/plugins/editor.py +++ b/spyder/plugins/editor.py @@ -105,12 +105,9 @@ def setup_page(self): interface_group = QGroupBox(_("Interface")) newcb = self.create_checkbox - fpsorting_box = newcb(_("Sort files according to full path"), - 'fullpath_sorting') showtabbar_box = newcb(_("Show tab bar"), 'show_tab_bar') interface_layout = QVBoxLayout() - interface_layout.addWidget(fpsorting_box) interface_layout.addWidget(showtabbar_box) interface_group.setLayout(interface_layout) @@ -542,9 +539,6 @@ def restore_scrollbar_position(self): def get_plugin_title(self): """Return widget title""" title = _('Editor') - filename = self.get_current_filename() - if filename: - title += ' - '+to_text_string(filename) return title def get_plugin_icon(self): @@ -842,7 +836,6 @@ def get_plugin_actions(self): re_run_last_cell_action = create_action(self, _("Re-run last cell"), - icon=ima.icon('run_cell'), tip=_("Re run last cell "), triggered=self.re_run_last_cell, context=Qt.WidgetShortcut) @@ -1065,7 +1058,7 @@ def get_plugin_actions(self): self.main.run_menu_actions += run_menu_actions run_toolbar_actions = [run_action, run_cell_action, run_cell_advance_action, - re_run_action, configure_action] + re_run_action] self.main.run_toolbar_actions += run_toolbar_actions # ---- Debug menu/toolbar construction ---- diff --git a/spyder/widgets/sourcecode/base.py b/spyder/widgets/sourcecode/base.py index c8b1300a18e..cd25d4810c5 100644 --- a/spyder/widgets/sourcecode/base.py +++ b/spyder/widgets/sourcecode/base.py @@ -624,13 +624,13 @@ def get_selection_as_executable_code(self): return ls.join(lines) def __exec_cell(self): - init_cur = QTextCursor(self.textCursor()) + init_cursor = QTextCursor(self.textCursor()) start_pos, end_pos = self.__save_selection() cursor, whole_file_selected = self.select_current_cell() if not whole_file_selected: self.setTextCursor(cursor) text = self.get_selection_as_executable_code() - self.last_cursor_cell = init_cur + self.last_cursor_cell = init_cursor self.__restore_selection(start_pos, end_pos) if text is not None: text = text.rstrip() From 58fc05eff52103617a41cf7fc666f8aebe14711c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Andr=C3=A9s=20Margffoy=20Tuay?= Date: Fri, 3 Mar 2017 16:06:18 -0500 Subject: [PATCH 10/11] Revert editor toolbar modifications --- spyder/plugins/editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/plugins/editor.py b/spyder/plugins/editor.py index 49d20d49592..6c7d508a1ef 100644 --- a/spyder/plugins/editor.py +++ b/spyder/plugins/editor.py @@ -1057,7 +1057,7 @@ def get_plugin_actions(self): configure_action, MENU_SEPARATOR] self.main.run_menu_actions += run_menu_actions run_toolbar_actions = [run_action, run_cell_action, - run_cell_advance_action, + run_cell_advance_action, run_selected_action, re_run_action] self.main.run_toolbar_actions += run_toolbar_actions From 3655f3437b19a559684c9d32dc99e69db52f0173 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sat, 4 Mar 2017 16:53:02 -0500 Subject: [PATCH 11/11] Testing: Add a test for re-run last cell --- spyder/app/tests/test_mainwindow.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index c69418e1431..1dd9c736799 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -195,6 +195,30 @@ def test_run_code(main_window, qtbot): qtbot.keyClick(code_editor, Qt.Key_Return, modifier=Qt.ControlModifier) assert nsb.editor.model.rowCount() == 1 + reset_run_code(qtbot, shell, code_editor, nsb) + + # ---- Re-run last cell ---- + # Run the first two cells in file + qtbot.keyClick(code_editor, Qt.Key_Return, modifier=Qt.ShiftModifier) + qtbot.keyClick(code_editor, Qt.Key_Return, modifier=Qt.ShiftModifier) + + # Wait until objects have appeared in the variable explorer + qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 2, timeout=EVAL_TIMEOUT) + + # Clean namespace + shell.execute('%reset -f') + + # Wait until there are no objects in the variable explorer + qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 0, timeout=EVAL_TIMEOUT) + + # Re-run last cell + qtbot.keyClick(code_editor, Qt.Key_Return, modifier=Qt.AltModifier) + + # Wait until the object has appeared in the variable explorer + qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 1, timeout=EVAL_TIMEOUT) + assert shell.get_value('li') == [1, 2, 3] + + # ---- Closing test file ---- main_window.editor.close_file()