bpo-34864: warn if "Prefer tabs when opening documents" set to "Alway… · python/cpython@9ebe879
@@ -38,6 +38,7 @@
3838import re
3939import socket
4040import subprocess
41+from textwrap import TextWrapper
4142import threading
4243import time
4344import tokenize
@@ -1273,6 +1274,14 @@ def showprompt(self):
12731274self.set_line_and_column()
12741275self.io.reset_undo()
127512761277+def show_warning(self, msg):
1278+width = self.interp.tkconsole.width
1279+wrapper = TextWrapper(width=width, tabsize=8, expand_tabs=True)
1280+wrapped_msg = '\n'.join(wrapper.wrap(msg))
1281+if not wrapped_msg.endswith('\n'):
1282+wrapped_msg += '\n'
1283+self.per.bottom.insert("iomark linestart", wrapped_msg, "stderr")
1284+12761285def resetoutput(self):
12771286source = self.text.get("iomark", "end-1c")
12781287if self.history:
@@ -1541,12 +1550,20 @@ def main():
15411550shell.interp.execfile(script)
15421551elif shell:
15431552# If there is a shell window and no cmd or script in progress,
1544-# check for problematic OS X Tk versions and print a warning
1545-# message in the IDLE shell window; this is less intrusive
1546-# than always opening a separate window.
1553+# check for problematic issues and print warning message(s) in
1554+# the IDLE shell window; this is less intrusive than always
1555+# opening a separate window.
1556+1557+# Warn if using a problematic OS X Tk version.
15471558tkversionwarning = macosx.tkVersionWarning(root)
15481559if tkversionwarning:
1549-shell.interp.runcommand("print('%s')" % tkversionwarning)
1560+shell.show_warning(tkversionwarning)
1561+1562+# Warn if the "Prefer tabs when opening documents" system
1563+# preference is set to "Always".
1564+prefer_tabs_preference_warning = macosx.preferTabsPreferenceWarning()
1565+if prefer_tabs_preference_warning:
1566+shell.show_warning(prefer_tabs_preference_warning)
1550156715511568while flist.inversedict: # keep IDLE running while files are open.
15521569root.mainloop()