mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
bpo-34864: warn if "Prefer tabs when opening documents" set to "Always" (#10464)
* bpo-34864: warn if "Prefer tabs when opening documents" set to "Always" * add NEWS entry * address code review comments * address second code review comments * Add entry for idlelib/NEWS.txt.
This commit is contained in:
parent
16501b7082
commit
9ebe8794f0
5 changed files with 69 additions and 9 deletions
|
@ -3,6 +3,12 @@ Released on 2019-10-20?
|
||||||
======================================
|
======================================
|
||||||
|
|
||||||
|
|
||||||
|
bpo-34864: When starting IDLE on MacOS, warn if the system setting
|
||||||
|
"Prefer tabs when opening documents" is "Always". As previous
|
||||||
|
documented for this issue, running IDLE with this setting causes
|
||||||
|
problems. If the setting is changed while IDLE is running,
|
||||||
|
there will be no warning until IDLE is restarted.
|
||||||
|
|
||||||
bpo-35213: Where appropriate, use 'macOS' in idlelib.
|
bpo-35213: Where appropriate, use 'macOS' in idlelib.
|
||||||
|
|
||||||
bpo-34864: Document two IDLE on MacOS issues. The System Preferences
|
bpo-34864: Document two IDLE on MacOS issues. The System Preferences
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
"""
|
"""
|
||||||
A number of functions that enhance IDLE on macOS.
|
A number of functions that enhance IDLE on macOS.
|
||||||
"""
|
"""
|
||||||
|
from os.path import expanduser
|
||||||
|
import plistlib
|
||||||
from sys import platform # Used in _init_tk_type, changed by test.
|
from sys import platform # Used in _init_tk_type, changed by test.
|
||||||
|
|
||||||
import tkinter
|
import tkinter
|
||||||
|
@ -79,14 +81,47 @@ def tkVersionWarning(root):
|
||||||
patchlevel = root.tk.call('info', 'patchlevel')
|
patchlevel = root.tk.call('info', 'patchlevel')
|
||||||
if patchlevel not in ('8.5.7', '8.5.9'):
|
if patchlevel not in ('8.5.7', '8.5.9'):
|
||||||
return False
|
return False
|
||||||
return (r"WARNING: The version of Tcl/Tk ({0}) in use may"
|
return ("WARNING: The version of Tcl/Tk ({0}) in use may"
|
||||||
r" be unstable.\n"
|
" be unstable.\n"
|
||||||
r"Visit http://www.python.org/download/mac/tcltk/"
|
"Visit http://www.python.org/download/mac/tcltk/"
|
||||||
r" for current information.".format(patchlevel))
|
" for current information.".format(patchlevel))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def readSystemPreferences():
|
||||||
|
"""
|
||||||
|
Fetch the macOS system preferences.
|
||||||
|
"""
|
||||||
|
if platform != 'darwin':
|
||||||
|
return None
|
||||||
|
|
||||||
|
plist_path = expanduser('~/Library/Preferences/.GlobalPreferences.plist')
|
||||||
|
try:
|
||||||
|
with open(plist_path, 'rb') as plist_file:
|
||||||
|
return plistlib.load(plist_file)
|
||||||
|
except OSError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def preferTabsPreferenceWarning():
|
||||||
|
"""
|
||||||
|
Warn if "Prefer tabs when opening documents" is set to "Always".
|
||||||
|
"""
|
||||||
|
if platform != 'darwin':
|
||||||
|
return None
|
||||||
|
|
||||||
|
prefs = readSystemPreferences()
|
||||||
|
if prefs and prefs.get('AppleWindowTabbingMode') == 'always':
|
||||||
|
return (
|
||||||
|
'WARNING: The system preference "Prefer tabs when opening'
|
||||||
|
' documents" is set to "Always". This will cause various problems'
|
||||||
|
' with IDLE. For the best experience, change this setting when'
|
||||||
|
' running IDLE (via System Preferences -> Dock).'
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
## Fix the menu and related functions.
|
## Fix the menu and related functions.
|
||||||
|
|
||||||
def addOpenEventSupport(root, flist):
|
def addOpenEventSupport(root, flist):
|
||||||
|
|
|
@ -109,7 +109,7 @@ class OutputWindow(EditorWindow):
|
||||||
Return:
|
Return:
|
||||||
Length of text inserted.
|
Length of text inserted.
|
||||||
"""
|
"""
|
||||||
if isinstance(s, (bytes, bytes)):
|
if isinstance(s, bytes):
|
||||||
s = s.decode(iomenu.encoding, "replace")
|
s = s.decode(iomenu.encoding, "replace")
|
||||||
self.text.insert(mark, s, tags)
|
self.text.insert(mark, s, tags)
|
||||||
self.text.see(mark)
|
self.text.see(mark)
|
||||||
|
|
|
@ -38,6 +38,7 @@ from platform import python_version
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from textwrap import TextWrapper
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import tokenize
|
import tokenize
|
||||||
|
@ -1273,6 +1274,14 @@ class PyShell(OutputWindow):
|
||||||
self.set_line_and_column()
|
self.set_line_and_column()
|
||||||
self.io.reset_undo()
|
self.io.reset_undo()
|
||||||
|
|
||||||
|
def show_warning(self, msg):
|
||||||
|
width = self.interp.tkconsole.width
|
||||||
|
wrapper = TextWrapper(width=width, tabsize=8, expand_tabs=True)
|
||||||
|
wrapped_msg = '\n'.join(wrapper.wrap(msg))
|
||||||
|
if not wrapped_msg.endswith('\n'):
|
||||||
|
wrapped_msg += '\n'
|
||||||
|
self.per.bottom.insert("iomark linestart", wrapped_msg, "stderr")
|
||||||
|
|
||||||
def resetoutput(self):
|
def resetoutput(self):
|
||||||
source = self.text.get("iomark", "end-1c")
|
source = self.text.get("iomark", "end-1c")
|
||||||
if self.history:
|
if self.history:
|
||||||
|
@ -1541,12 +1550,20 @@ def main():
|
||||||
shell.interp.execfile(script)
|
shell.interp.execfile(script)
|
||||||
elif shell:
|
elif shell:
|
||||||
# If there is a shell window and no cmd or script in progress,
|
# If there is a shell window and no cmd or script in progress,
|
||||||
# check for problematic OS X Tk versions and print a warning
|
# check for problematic issues and print warning message(s) in
|
||||||
# message in the IDLE shell window; this is less intrusive
|
# the IDLE shell window; this is less intrusive than always
|
||||||
# than always opening a separate window.
|
# opening a separate window.
|
||||||
|
|
||||||
|
# Warn if using a problematic OS X Tk version.
|
||||||
tkversionwarning = macosx.tkVersionWarning(root)
|
tkversionwarning = macosx.tkVersionWarning(root)
|
||||||
if tkversionwarning:
|
if tkversionwarning:
|
||||||
shell.interp.runcommand("print('%s')" % tkversionwarning)
|
shell.show_warning(tkversionwarning)
|
||||||
|
|
||||||
|
# Warn if the "Prefer tabs when opening documents" system
|
||||||
|
# preference is set to "Always".
|
||||||
|
prefer_tabs_preference_warning = macosx.preferTabsPreferenceWarning()
|
||||||
|
if prefer_tabs_preference_warning:
|
||||||
|
shell.show_warning(prefer_tabs_preference_warning)
|
||||||
|
|
||||||
while flist.inversedict: # keep IDLE running while files are open.
|
while flist.inversedict: # keep IDLE running while files are open.
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
On macOS, warn if the system preference "Prefer tabs when opening documents"
|
||||||
|
is set to "Always".
|
Loading…
Add table
Add a link
Reference in a new issue