Guards on running cells
# -*- coding: utf-8 -*-
import re
-from thonny.globals import get_workbench
+from thonny.globals import get_workbench, get_runner
from thonny.codeview import CodeViewText
from thonny import ui_utils
@@ -83,6 +83,7 @@ def _patch_perform_return():
and (ui_utils.shift_is_pressed(event.state)
or ui_utils.control_is_pressed(event.state))):
+ if run_enabled():
code = text.get(ranges[0], ranges[1]).strip()
_submit_code(code)
@@ -139,7 +140,9 @@ def run_selection(event=None):
_submit_code(code)
def run_enabled():
- return True
+ widget = get_workbench().focus_get()
+ return (isinstance(widget, CodeViewText)
+ and get_runner().get_state() == "waiting_toplevel_command")
def load_early_plugin():
wb = get_workbench()
