Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 57e5113

Browse files
authored
bpo-42508: Keep IDLE running on macOS (GH-23577)
Remove obsolete workaround that prevented running files with shortcuts when using new universal2 installers built on macOS 11. Ignore buggy 2nd run_module_event call.
1 parent 752cdf2 commit 57e5113

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

Lib/idlelib/NEWS.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Released on 2021-10-04?
33
======================================
44

55

6+
bpo-42508: Keep IDLE running on macOS. Remove obsolete workaround
7+
that prevented running files with shortcuts when using new universal2
8+
installers built on macOS 11.
9+
610
bpo-42426: Fix reporting offset of the RE error in searchengine.
711

812
bpo-42416: Get docstrings for IDLE calltips more often

Lib/idlelib/runscript.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212
import os
1313
import tabnanny
14+
import time
1415
import tokenize
1516

1617
import tkinter.messagebox as tkMessageBox
@@ -42,9 +43,7 @@ def __init__(self, editwin):
4243
self.root = self.editwin.root
4344
# cli_args is list of strings that extends sys.argv
4445
self.cli_args = []
45-
46-
if macosx.isCocoaTk():
47-
self.editwin.text_frame.bind('<<run-module-event-2>>', self._run_module_event)
46+
self.perf = 0.0 # Workaround for macOS 11 Uni2; see bpo-42508.
4847

4948
def check_module_event(self, event):
5049
if isinstance(self.editwin, outwin.OutputWindow):
@@ -107,24 +106,10 @@ def checksyntax(self, filename):
107106
finally:
108107
shell.set_warning_stream(saved_stream)
109108

110-
def run_module_event(self, event):
111-
if macosx.isCocoaTk():
112-
# Tk-Cocoa in MacOSX is broken until at least
113-
# Tk 8.5.9, and without this rather
114-
# crude workaround IDLE would hang when a user
115-
# tries to run a module using the keyboard shortcut
116-
# (the menu item works fine).
117-
self.editwin.text_frame.after(200,
118-
lambda: self.editwin.text_frame.event_generate(
119-
'<<run-module-event-2>>'))
120-
return 'break'
121-
else:
122-
return self._run_module_event(event)
123-
124109
def run_custom_event(self, event):
125-
return self._run_module_event(event, customize=True)
110+
return self.run_module_event(event, customize=True)
126111

127-
def _run_module_event(self, event, *, customize=False):
112+
def run_module_event(self, event, *, customize=False):
128113
"""Run the module after setting up the environment.
129114
130115
First check the syntax. Next get customization. If OK, make
@@ -133,6 +118,8 @@ def _run_module_event(self, event, *, customize=False):
133118
module being executed and also add that directory to its
134119
sys.path if not already included.
135120
"""
121+
if macosx.isCocoaTk() and (time.perf_counter() - self.perf < .05):
122+
return 'break'
136123
if isinstance(self.editwin, outwin.OutputWindow):
137124
self.editwin.text.bell()
138125
return 'break'
@@ -218,6 +205,7 @@ def errorbox(self, title, message):
218205
# XXX This should really be a function of EditorWindow...
219206
tkMessageBox.showerror(title, message, parent=self.editwin.text)
220207
self.editwin.text.focus_set()
208+
self.perf = time.perf_counter()
221209

222210

223211
if __name__ == "__main__":
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Keep IDLE running on macOS. Remove obsolete workaround that prevented
2+
running files with shortcuts when using new universal2 installers built
3+
on macOS 11.

0 commit comments

Comments
 (0)