From 609d9aeb0793f07ab289d996223d925eb427e516 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Mon, 30 Nov 2020 19:51:07 -0500 Subject: [PATCH 1/2] bpo-42508: Keep IDLE running on macOS Remove obsolete workaround that prevented running files with shortcuts when using new universal2 installers built on macOS 11. --- Lib/idlelib/NEWS.txt | 4 ++++ Lib/idlelib/runscript.py | 21 ++----------------- .../2020-11-30-19-46-05.bpo-42508.fE7w4M.rst | 3 +++ 3 files changed, 9 insertions(+), 19 deletions(-) create mode 100644 Misc/NEWS.d/next/IDLE/2020-11-30-19-46-05.bpo-42508.fE7w4M.rst diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt index 34f28d6084f7a4..7167314ca7e598 100644 --- a/Lib/idlelib/NEWS.txt +++ b/Lib/idlelib/NEWS.txt @@ -3,6 +3,10 @@ Released on 2021-10-04? ====================================== +bpo-42508: Keep IDLE running on macOS. Remove obsolete workaround +that prevented running files with shortcuts when using new universal2 +installers built on macOS 11. + bpo-42426: Fix reporting offset of the RE error in searchengine. bpo-42416: Get docstrings for IDLE calltips more often diff --git a/Lib/idlelib/runscript.py b/Lib/idlelib/runscript.py index a54108794ab595..c47965e560ffef 100644 --- a/Lib/idlelib/runscript.py +++ b/Lib/idlelib/runscript.py @@ -43,9 +43,6 @@ def __init__(self, editwin): # cli_args is list of strings that extends sys.argv self.cli_args = [] - if macosx.isCocoaTk(): - self.editwin.text_frame.bind('<>', self._run_module_event) - def check_module_event(self, event): if isinstance(self.editwin, outwin.OutputWindow): self.editwin.text.bell() @@ -107,24 +104,10 @@ def checksyntax(self, filename): finally: shell.set_warning_stream(saved_stream) - def run_module_event(self, event): - if macosx.isCocoaTk(): - # Tk-Cocoa in MacOSX is broken until at least - # Tk 8.5.9, and without this rather - # crude workaround IDLE would hang when a user - # tries to run a module using the keyboard shortcut - # (the menu item works fine). - self.editwin.text_frame.after(200, - lambda: self.editwin.text_frame.event_generate( - '<>')) - return 'break' - else: - return self._run_module_event(event) - def run_custom_event(self, event): - return self._run_module_event(event, customize=True) + return self.run_module_event(event, customize=True) - def _run_module_event(self, event, *, customize=False): + def run_module_event(self, event, *, customize=False): """Run the module after setting up the environment. First check the syntax. Next get customization. If OK, make diff --git a/Misc/NEWS.d/next/IDLE/2020-11-30-19-46-05.bpo-42508.fE7w4M.rst b/Misc/NEWS.d/next/IDLE/2020-11-30-19-46-05.bpo-42508.fE7w4M.rst new file mode 100644 index 00000000000000..b449351f7f458e --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2020-11-30-19-46-05.bpo-42508.fE7w4M.rst @@ -0,0 +1,3 @@ +Keep IDLE running on macOS. Remove obsolete workaround that prevented +running files with shortcuts when using new universal2 installers built +on macOS 11. From 9a3dfe096c7edd92a88063f6e14012b25413ed10 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Thu, 3 Dec 2020 12:57:44 -0500 Subject: [PATCH 2/2] Ignore buggy 2nd run_module_event call. --- Lib/idlelib/runscript.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/idlelib/runscript.py b/Lib/idlelib/runscript.py index c47965e560ffef..028b0dbd21dfe6 100644 --- a/Lib/idlelib/runscript.py +++ b/Lib/idlelib/runscript.py @@ -11,6 +11,7 @@ """ import os import tabnanny +import time import tokenize import tkinter.messagebox as tkMessageBox @@ -42,6 +43,7 @@ def __init__(self, editwin): self.root = self.editwin.root # cli_args is list of strings that extends sys.argv self.cli_args = [] + self.perf = 0.0 # Workaround for macOS 11 Uni2; see bpo-42508. def check_module_event(self, event): if isinstance(self.editwin, outwin.OutputWindow): @@ -116,6 +118,8 @@ def run_module_event(self, event, *, customize=False): module being executed and also add that directory to its sys.path if not already included. """ + if macosx.isCocoaTk() and (time.perf_counter() - self.perf < .05): + return 'break' if isinstance(self.editwin, outwin.OutputWindow): self.editwin.text.bell() return 'break' @@ -201,6 +205,7 @@ def errorbox(self, title, message): # XXX This should really be a function of EditorWindow... tkMessageBox.showerror(title, message, parent=self.editwin.text) self.editwin.text.focus_set() + self.perf = time.perf_counter() if __name__ == "__main__":