[Python-checkins] cpython: Issue #24759: IDLE requires tk 8.5 and availability ttk widgets.

terry.reedy python-checkins at python.org
Thu Jun 9 21:09:27 EDT 2016


https://hg.python.org/cpython/rev/76f831e4b806
changeset:   101839:76f831e4b806
user:        Terry Jan Reedy <tjreedy at udel.edu>
date:        Thu Jun 09 21:09:15 2016 -0400
summary:
  Issue #24759: IDLE requires tk 8.5 and availability ttk widgets.
Delete now unneeded tk version tests and code for older versions.

files:
  Lib/idlelib/__init__.py           |   1 +
  Lib/idlelib/colorizer.py          |  11 +++----
  Lib/idlelib/config.py             |  20 ++++++---------
  Lib/idlelib/editor.py             |  11 +++-----
  Lib/idlelib/idle_test/__init__.py |   2 +
  Lib/idlelib/macosx.py             |   6 ----
  Lib/idlelib/pyshell.py            |  25 ++++++++++++------
  Lib/test/test_idle.py             |   2 +
  8 files changed, 38 insertions(+), 40 deletions(-)


diff --git a/Lib/idlelib/__init__.py b/Lib/idlelib/__init__.py
--- a/Lib/idlelib/__init__.py
+++ b/Lib/idlelib/__init__.py
@@ -1,6 +1,7 @@
 """The idlelib package implements the Idle application.
 
 Idle includes an interactive shell and editor.
+Starting with Python 3.6, IDLE requires tcl/tk 8.5 or later.
 Use the files named idle.* to start Idle.
 
 The other files are private implementations.  Their details are subject to
diff --git a/Lib/idlelib/colorizer.py b/Lib/idlelib/colorizer.py
--- a/Lib/idlelib/colorizer.py
+++ b/Lib/idlelib/colorizer.py
@@ -2,7 +2,6 @@
 import re
 import keyword
 import builtins
-from tkinter import TkVersion
 from idlelib.delegator import Delegator
 from idlelib.config import idleConf
 
@@ -49,11 +48,8 @@
         insertbackground=cursor_color,
         selectforeground=select_colors['foreground'],
         selectbackground=select_colors['background'],
-        )
-    if TkVersion >= 8.5:
-        text.config(
-            inactiveselectbackground=select_colors['background'])
-
+        inactiveselectbackground=select_colors['background'],  # new in 8.5
+    )
 
 class ColorDelegator(Delegator):
 
@@ -277,5 +273,8 @@
     p.insertfilter(d)
 
 if __name__ == "__main__":
+    import unittest
+    unittest.main('idlelib.idle_test.test_colorizer',
+                  verbosity=2, exit=False)
     from idlelib.idle_test.htest import run
     run(_color_delegator)
diff --git a/Lib/idlelib/config.py b/Lib/idlelib/config.py
--- a/Lib/idlelib/config.py
+++ b/Lib/idlelib/config.py
@@ -22,7 +22,6 @@
 import sys
 
 from configparser import ConfigParser
-from tkinter import TkVersion
 from tkinter.font import Font, nametofont
 
 class InvalidConfigType(Exception): pass
@@ -713,16 +712,13 @@
         bold = self.GetOption(configType, section, 'font-bold', default=0,
                               type='bool')
         if (family == 'TkFixedFont'):
-            if TkVersion < 8.5:
-                family = 'Courier'
-            else:
-                f = Font(name='TkFixedFont', exists=True, root=root)
-                actualFont = Font.actual(f)
-                family = actualFont['family']
-                size = actualFont['size']
-                if size <= 0:
-                    size = 10  # if font in pixels, ignore actual size
-                bold = actualFont['weight']=='bold'
+            f = Font(name='TkFixedFont', exists=True, root=root)
+            actualFont = Font.actual(f)
+            family = actualFont['family']
+            size = actualFont['size']
+            if size <= 0:
+                size = 10  # if font in pixels, ignore actual size
+            bold = actualFont['weight'] == 'bold'
         return (family, size, 'bold' if bold else 'normal')
 
     def LoadCfgFiles(self):
@@ -740,7 +736,7 @@
 idleConf = IdleConf()
 
 # TODO Revise test output, write expanded unittest
-### module test
+#
 if __name__ == '__main__':
     def dumpCfg(cfg):
         print('\n', cfg, '\n')
diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py
--- a/Lib/idlelib/editor.py
+++ b/Lib/idlelib/editor.py
@@ -110,13 +110,10 @@
                 'wrap': 'none',
                 'highlightthickness': 0,
                 'width': self.width,
-                'height': idleConf.GetOption('main', 'EditorWindow',
-                                             'height', type='int')}
-        if TkVersion >= 8.5:
-            # Starting with tk 8.5 we have to set the new tabstyle option
-            # to 'wordprocessor' to achieve the same display of tabs as in
-            # older tk versions.
-            text_options['tabstyle'] = 'wordprocessor'
+                'tabstyle': 'wordprocessor',  # new in 8.5
+                'height': idleConf.GetOption(
+                        'main', 'EditorWindow', 'height', type='int'),
+                }
         self.text = text = MultiCallCreator(Text)(text_frame, **text_options)
         self.top.focused_widget = self.text
 
diff --git a/Lib/idlelib/idle_test/__init__.py b/Lib/idlelib/idle_test/__init__.py
--- a/Lib/idlelib/idle_test/__init__.py
+++ b/Lib/idlelib/idle_test/__init__.py
@@ -1,6 +1,8 @@
 '''idlelib.idle_test is a private implementation of test.test_idle,
 which tests the IDLE application as part of the stdlib test suite.
 Run IDLE tests alone with "python -m test.test_idle".
+Starting with Python 3.6, IDLE requires tcl/tk 8.5 or later.
+
 This package and its contained modules are subject to change and
 any direct use is at your own risk.
 '''
diff --git a/Lib/idlelib/macosx.py b/Lib/idlelib/macosx.py
--- a/Lib/idlelib/macosx.py
+++ b/Lib/idlelib/macosx.py
@@ -199,12 +199,6 @@
                 ('About IDLE', '<<about-idle>>'),
                     None,
                 ]))
-        tkversion = root.tk.eval('info patchlevel')
-        if tuple(map(int, tkversion.split('.'))) < (8, 4, 14):
-            # for earlier AquaTk versions, supply a Preferences menu item
-            mainmenu.menudefs[0][1].append(
-                    ('_Preferences....', '<<open-config-dialog>>'),
-                )
     if isCocoaTk():
         # replace default About dialog with About IDLE one
         root.createcommand('tkAboutDialog', about_dialog)
diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py
--- a/Lib/idlelib/pyshell.py
+++ b/Lib/idlelib/pyshell.py
@@ -1,5 +1,20 @@
 #! /usr/bin/env python3
 
+try:
+    from tkinter import *
+except ImportError:
+    print("** IDLE can't import Tkinter.\n"
+          "Your Python may not be configured for Tk. **", file=sys.__stderr__)
+    sys.exit(1)
+import tkinter.messagebox as tkMessageBox
+if TkVersion < 8.5:
+    root = Tk()  # otherwise create root in main
+    root.withdraw()
+    tkMessageBox.showerror("Idle Cannot Start",
+            "Idle requires tcl/tk 8.5+, not $s." % TkVersion,
+            parent=root)
+    sys.exit(1)
+
 import getopt
 import os
 import os.path
@@ -16,14 +31,6 @@
 from code import InteractiveInterpreter
 from platform import python_version, system
 
-try:
-    from tkinter import *
-except ImportError:
-    print("** IDLE can't import Tkinter.\n"
-          "Your Python may not be configured for Tk. **", file=sys.__stderr__)
-    sys.exit(1)
-import tkinter.messagebox as tkMessageBox
-
 from idlelib.editor import EditorWindow, fixwordbreaks
 from idlelib.filelist import FileList
 from idlelib.colorizer import ColorDelegator
@@ -1536,7 +1543,7 @@
     if system() == 'Windows':
         iconfile = os.path.join(icondir, 'idle.ico')
         root.wm_iconbitmap(default=iconfile)
-    elif TkVersion >= 8.5:
+    else:
         ext = '.png' if TkVersion >= 8.6 else '.gif'
         iconfiles = [os.path.join(icondir, 'idle_%d%s' % (size, ext))
                      for size in (16, 32, 48)]
diff --git a/Lib/test/test_idle.py b/Lib/test/test_idle.py
--- a/Lib/test/test_idle.py
+++ b/Lib/test/test_idle.py
@@ -4,6 +4,8 @@
 # Skip test if _thread or _tkinter wasn't built or idlelib was deleted.
 import_module('threading')  # imported by PyShell, imports _thread
 tk = import_module('tkinter')  # imports _tkinter
+if tk.TkVersion < 8.5:
+    raise unittest.SkipTest("IDLE requires tk 8.5 or later.")
 idletest = import_module('idlelib.idle_test')
 
 # Without test_main present, regrtest.runtest_inner (line1219) calls

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list