Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1080d13

Browse files
committed
Issue #24759: IDLE requires tk 8.5 and availability ttk widgets.
Delete now unneeded tk version tests and code for older versions.
1 parent 82ae155 commit 1080d13

8 files changed

Lines changed: 38 additions & 40 deletions

File tree

Lib/idlelib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""The idlelib package implements the Idle application.
22
33
Idle includes an interactive shell and editor.
4+
Starting with Python 3.6, IDLE requires tcl/tk 8.5 or later.
45
Use the files named idle.* to start Idle.
56
67
The other files are private implementations. Their details are subject to

Lib/idlelib/colorizer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import re
33
import keyword
44
import builtins
5-
from tkinter import TkVersion
65
from idlelib.delegator import Delegator
76
from idlelib.config import idleConf
87

@@ -49,11 +48,8 @@ def color_config(text): # Called from htest, Editor, and Turtle Demo.
4948
insertbackground=cursor_color,
5049
selectforeground=select_colors['foreground'],
5150
selectbackground=select_colors['background'],
52-
)
53-
if TkVersion >= 8.5:
54-
text.config(
55-
inactiveselectbackground=select_colors['background'])
56-
51+
inactiveselectbackground=select_colors['background'], # new in 8.5
52+
)
5753

5854
class ColorDelegator(Delegator):
5955

@@ -277,5 +273,8 @@ def _color_delegator(parent): # htest #
277273
p.insertfilter(d)
278274

279275
if __name__ == "__main__":
276+
import unittest
277+
unittest.main('idlelib.idle_test.test_colorizer',
278+
verbosity=2, exit=False)
280279
from idlelib.idle_test.htest import run
281280
run(_color_delegator)

Lib/idlelib/config.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import sys
2323

2424
from configparser import ConfigParser
25-
from tkinter import TkVersion
2625
from tkinter.font import Font, nametofont
2726

2827
class InvalidConfigType(Exception): pass
@@ -713,16 +712,13 @@ def GetFont(self, root, configType, section):
713712
bold = self.GetOption(configType, section, 'font-bold', default=0,
714713
type='bool')
715714
if (family == 'TkFixedFont'):
716-
if TkVersion < 8.5:
717-
family = 'Courier'
718-
else:
719-
f = Font(name='TkFixedFont', exists=True, root=root)
720-
actualFont = Font.actual(f)
721-
family = actualFont['family']
722-
size = actualFont['size']
723-
if size <= 0:
724-
size = 10 # if font in pixels, ignore actual size
725-
bold = actualFont['weight']=='bold'
715+
f = Font(name='TkFixedFont', exists=True, root=root)
716+
actualFont = Font.actual(f)
717+
family = actualFont['family']
718+
size = actualFont['size']
719+
if size <= 0:
720+
size = 10 # if font in pixels, ignore actual size
721+
bold = actualFont['weight'] == 'bold'
726722
return (family, size, 'bold' if bold else 'normal')
727723

728724
def LoadCfgFiles(self):
@@ -740,7 +736,7 @@ def SaveUserCfgFiles(self):
740736
idleConf = IdleConf()
741737

742738
# TODO Revise test output, write expanded unittest
743-
### module test
739+
#
744740
if __name__ == '__main__':
745741
def dumpCfg(cfg):
746742
print('\n', cfg, '\n')

Lib/idlelib/editor.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,10 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
110110
'wrap': 'none',
111111
'highlightthickness': 0,
112112
'width': self.width,
113-
'height': idleConf.GetOption('main', 'EditorWindow',
114-
'height', type='int')}
115-
if TkVersion >= 8.5:
116-
# Starting with tk 8.5 we have to set the new tabstyle option
117-
# to 'wordprocessor' to achieve the same display of tabs as in
118-
# older tk versions.
119-
text_options['tabstyle'] = 'wordprocessor'
113+
'tabstyle': 'wordprocessor', # new in 8.5
114+
'height': idleConf.GetOption(
115+
'main', 'EditorWindow', 'height', type='int'),
116+
}
120117
self.text = text = MultiCallCreator(Text)(text_frame, **text_options)
121118
self.top.focused_widget = self.text
122119

Lib/idlelib/idle_test/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'''idlelib.idle_test is a private implementation of test.test_idle,
22
which tests the IDLE application as part of the stdlib test suite.
33
Run IDLE tests alone with "python -m test.test_idle".
4+
Starting with Python 3.6, IDLE requires tcl/tk 8.5 or later.
5+
46
This package and its contained modules are subject to change and
57
any direct use is at your own risk.
68
'''

Lib/idlelib/macosx.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,6 @@ def help_dialog(event=None):
199199
('About IDLE', '<<about-idle>>'),
200200
None,
201201
]))
202-
tkversion = root.tk.eval('info patchlevel')
203-
if tuple(map(int, tkversion.split('.'))) < (8, 4, 14):
204-
# for earlier AquaTk versions, supply a Preferences menu item
205-
mainmenu.menudefs[0][1].append(
206-
('_Preferences....', '<<open-config-dialog>>'),
207-
)
208202
if isCocoaTk():
209203
# replace default About dialog with About IDLE one
210204
root.createcommand('tkAboutDialog', about_dialog)

Lib/idlelib/pyshell.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
#! /usr/bin/env python3
22

3+
try:
4+
from tkinter import *
5+
except ImportError:
6+
print("** IDLE can't import Tkinter.\n"
7+
"Your Python may not be configured for Tk. **", file=sys.__stderr__)
8+
sys.exit(1)
9+
import tkinter.messagebox as tkMessageBox
10+
if TkVersion < 8.5:
11+
root = Tk() # otherwise create root in main
12+
root.withdraw()
13+
tkMessageBox.showerror("Idle Cannot Start",
14+
"Idle requires tcl/tk 8.5+, not $s." % TkVersion,
15+
parent=root)
16+
sys.exit(1)
17+
318
import getopt
419
import os
520
import os.path
@@ -16,14 +31,6 @@
1631
from code import InteractiveInterpreter
1732
from platform import python_version, system
1833

19-
try:
20-
from tkinter import *
21-
except ImportError:
22-
print("** IDLE can't import Tkinter.\n"
23-
"Your Python may not be configured for Tk. **", file=sys.__stderr__)
24-
sys.exit(1)
25-
import tkinter.messagebox as tkMessageBox
26-
2734
from idlelib.editor import EditorWindow, fixwordbreaks
2835
from idlelib.filelist import FileList
2936
from idlelib.colorizer import ColorDelegator
@@ -1536,7 +1543,7 @@ def main():
15361543
if system() == 'Windows':
15371544
iconfile = os.path.join(icondir, 'idle.ico')
15381545
root.wm_iconbitmap(default=iconfile)
1539-
elif TkVersion >= 8.5:
1546+
else:
15401547
ext = '.png' if TkVersion >= 8.6 else '.gif'
15411548
iconfiles = [os.path.join(icondir, 'idle_%d%s' % (size, ext))
15421549
for size in (16, 32, 48)]

Lib/test/test_idle.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# Skip test if _thread or _tkinter wasn't built or idlelib was deleted.
55
import_module('threading') # imported by PyShell, imports _thread
66
tk = import_module('tkinter') # imports _tkinter
7+
if tk.TkVersion < 8.5:
8+
raise unittest.SkipTest("IDLE requires tk 8.5 or later.")
79
idletest = import_module('idlelib.idle_test')
810

911
# Without test_main present, regrtest.runtest_inner (line1219) calls

0 commit comments

Comments
 (0)