11
11
"""
12
12
import os
13
13
import tabnanny
14
+ import time
14
15
import tokenize
15
16
16
17
import tkinter .messagebox as tkMessageBox
@@ -42,9 +43,7 @@ def __init__(self, editwin):
42
43
self .root = self .editwin .root
43
44
# cli_args is list of strings that extends sys.argv
44
45
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.
48
47
49
48
def check_module_event (self , event ):
50
49
if isinstance (self .editwin , outwin .OutputWindow ):
@@ -107,24 +106,10 @@ def checksyntax(self, filename):
107
106
finally :
108
107
shell .set_warning_stream (saved_stream )
109
108
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
-
124
109
def run_custom_event (self , event ):
125
- return self ._run_module_event (event , customize = True )
110
+ return self .run_module_event (event , customize = True )
126
111
127
- def _run_module_event (self , event , * , customize = False ):
112
+ def run_module_event (self , event , * , customize = False ):
128
113
"""Run the module after setting up the environment.
129
114
130
115
First check the syntax. Next get customization. If OK, make
@@ -133,6 +118,8 @@ def _run_module_event(self, event, *, customize=False):
133
118
module being executed and also add that directory to its
134
119
sys.path if not already included.
135
120
"""
121
+ if macosx .isCocoaTk () and (time .perf_counter () - self .perf < .05 ):
122
+ return 'break'
136
123
if isinstance (self .editwin , outwin .OutputWindow ):
137
124
self .editwin .text .bell ()
138
125
return 'break'
@@ -218,6 +205,7 @@ def errorbox(self, title, message):
218
205
# XXX This should really be a function of EditorWindow...
219
206
tkMessageBox .showerror (title , message , parent = self .editwin .text )
220
207
self .editwin .text .focus_set ()
208
+ self .perf = time .perf_counter ()
221
209
222
210
223
211
if __name__ == "__main__" :
0 commit comments