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.
diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py
index 47eef43..81a97ef 100755
--- a/Lib/idlelib/pyshell.py
+++ b/Lib/idlelib/pyshell.py
@@ -38,6 +38,7 @@
import re
import socket
import subprocess
+from textwrap import TextWrapper
import threading
import time
import tokenize
@@ -1273,6 +1274,14 @@
self.set_line_and_column()
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):
source = self.text.get("iomark", "end-1c")
if self.history:
@@ -1541,12 +1550,20 @@
shell.interp.execfile(script)
elif shell:
# If there is a shell window and no cmd or script in progress,
- # check for problematic OS X Tk versions and print a warning
- # message in the IDLE shell window; this is less intrusive
- # than always opening a separate window.
+ # check for problematic issues and print warning message(s) in
+ # the IDLE shell window; this is less intrusive than always
+ # opening a separate window.
+
+ # Warn if using a problematic OS X Tk version.
tkversionwarning = macosx.tkVersionWarning(root)
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.
root.mainloop()