Skip to content

Commit 493160c

Browse files
Merge remote-tracking branch 'upstream/main' into tkinter-tk-caret-appname
# Conflicts: # Doc/library/tkinter.rst # Doc/whatsnew/3.16.rst # Lib/test/test_tkinter/test_misc.py # Lib/tkinter/__init__.py
2 parents b6de1d5 + 34eca5a commit 493160c

24 files changed

Lines changed: 692 additions & 40 deletions

Doc/library/runpy.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ The :mod:`!runpy` module provides two functions:
106106

107107
Execute the code at the named filesystem location and return the resulting
108108
module's globals dictionary. As with a script name supplied to the CPython
109-
command line, *file_path* may refer to a Python source file, a
109+
command line, *path_name* may refer to a Python source file, a
110110
compiled bytecode file or a valid :data:`sys.path` entry containing a
111111
:mod:`__main__` module
112112
(e.g. a zipfile containing a top-level :file:`__main__.py` file).
@@ -134,20 +134,20 @@ The :mod:`!runpy` module provides two functions:
134134
``__name__`` is set to *run_name* if this optional argument is not
135135
:const:`None` and to ``'<run_path>'`` otherwise.
136136

137-
If *file_path* directly references a script file (whether as source
137+
If *path_name* directly references a script file (whether as source
138138
or as precompiled byte code), then ``__file__`` will be set to
139-
*file_path*, and ``__spec__``, ``__loader__`` and
139+
*path_name*, and ``__spec__``, ``__loader__`` and
140140
``__package__`` will all be set to :const:`None`.
141141

142-
If *file_path* is a reference to a valid :data:`sys.path` entry, then
142+
If *path_name* is a reference to a valid :data:`sys.path` entry, then
143143
``__spec__`` will be set appropriately for the imported :mod:`__main__`
144144
module (that is, ``__spec__.name`` will always be ``__main__``).
145145
``__file__``, ``__loader__`` and ``__package__`` will be
146146
:ref:`set as normal <import-mod-attrs>` based on the module spec.
147147

148148
A number of alterations are also made to the :mod:`sys` module. Firstly,
149149
:data:`sys.path` may be altered as described above. ``sys.argv[0]`` is updated
150-
with the value of *file_path* and ``sys.modules[__name__]`` is updated
150+
with the value of *path_name* and ``sys.modules[__name__]`` is updated
151151
with a temporary module object for the module being executed. All
152152
modifications to items in :mod:`sys` are reverted before the function
153153
returns.

Doc/library/tkinter.rst

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,25 @@ Base and mixin classes
19861986

19871987
.. versionadded:: next
19881988

1989+
.. method:: tk_scaling(number=None, *, displayof=0)
1990+
1991+
Query or set the scaling factor used by Tk to convert between physical
1992+
units (such as points, inches or millimeters) and pixels, expressed as
1993+
the number of pixels per point (where a point is 1/72 inch).
1994+
With no argument, return the current factor; otherwise set it to the
1995+
floating-point *number*.
1996+
1997+
.. versionadded:: next
1998+
1999+
.. method:: tk_inactive(reset=False, *, displayof=0)
2000+
2001+
Return the number of milliseconds since the last time the user interacted
2002+
with the system, or ``-1`` if the windowing system does not support this.
2003+
If *reset* is true, reset the inactivity timer to zero instead and return
2004+
``None``.
2005+
2006+
.. versionadded:: next
2007+
19892008
.. method:: busy(**kw)
19902009
:no-typesetting:
19912010

@@ -3775,6 +3794,15 @@ Widget classes
37753794
*yOrigin* changes by a factor of *yScale* (a factor of ``1.0`` leaves the
37763795
coordinate unchanged).
37773796

3797+
.. method:: rotate(tagOrId, xOrigin, yOrigin, angle, /)
3798+
3799+
Rotate the coordinates of all items given by *tagOrId* in canvas
3800+
coordinate space about the origin (*xOrigin*, *yOrigin*) by *angle*
3801+
degrees anticlockwise.
3802+
Negative values of *angle* rotate clockwise.
3803+
3804+
.. versionadded:: next
3805+
37783806
.. method:: delete(*tagOrIds)
37793807

37803808
Delete each of the items given by the *tagOrIds* arguments.
@@ -3794,6 +3822,17 @@ Widget classes
37943822
For line and polygon items *string* must be a valid sequence of
37953823
coordinates.
37963824

3825+
.. method:: rchars(tagOrId, first, last, string, /)
3826+
3827+
Replace the characters (for text items) or coordinates (for line and
3828+
polygon items) in the range from *first* to *last* inclusive of each of
3829+
the items given by *tagOrId* with *string*.
3830+
For line and polygon items *string* must be a valid sequence of
3831+
coordinates.
3832+
Items that do not support indexing ignore this operation.
3833+
3834+
.. versionadded:: next
3835+
37973836
.. method:: itemcget(tagOrId, option)
37983837

37993838
Return the current value of the configuration option *option* for the
@@ -4739,6 +4778,15 @@ Widget classes
47394778
If the *postcommand* option has been specified, it is evaluated before
47404779
the menu is posted.
47414780

4781+
.. method:: postcascade(index)
4782+
4783+
Post the submenu associated with the cascade entry given by *index*,
4784+
unposting any previously posted submenu.
4785+
This has no effect if *index* does not name a cascade entry or if the
4786+
menu itself is not posted.
4787+
4788+
.. versionadded:: next
4789+
47424790
.. method:: tk_popup(x, y, entry='')
47434791

47444792
Post the menu as a popup at the root-window coordinates *x* and *y*.
@@ -6059,6 +6107,14 @@ Image classes
60596107
it is displayed as transparent and the background of whatever window it
60606108
is displayed in shows through.
60616109

6110+
.. method:: redither()
6111+
6112+
Recalculate the dithered image in each window where it is displayed.
6113+
This is useful when the image data was supplied in pieces, in which case
6114+
the dithered image may not be exactly correct.
6115+
6116+
.. versionadded:: next
6117+
60626118
.. method:: cget(option)
60636119

60646120
Return the current value of the configuration option *option*.
@@ -6126,7 +6182,7 @@ Image classes
61266182

61276183

61286184
.. method:: data(format=None, *, from_coords=None, background=None, \
6129-
grayscale=False)
6185+
grayscale=False, metadata=None)
61306186

61316187
Return the image data.
61326188

@@ -6150,16 +6206,27 @@ Image classes
61506206
If *grayscale* is true, the data does not contain color information; all
61516207
pixel data is transformed into grayscale.
61526208

6209+
*metadata* is a dictionary passed to the image format driver.
6210+
It requires Tcl/Tk 9.0 or newer.
6211+
61536212
.. versionadded:: 3.13
61546213

6214+
.. versionchanged:: next
6215+
Added the *metadata* parameter.
61556216

6156-
.. method:: get(x, y)
6217+
6218+
.. method:: get(x, y, *, withalpha=False)
61576219

61586220
Return the color of the pixel at coordinates (*x*, *y*) as an
61596221
``(r, g, b)`` tuple of three integers between 0 and 255, representing the
61606222
red, green and blue components respectively.
6223+
If *withalpha* is true, the returned tuple has a fourth element giving
6224+
the alpha (opacity) value of the pixel.
6225+
6226+
.. versionchanged:: next
6227+
Added the *withalpha* parameter, which requires Tcl/Tk 9.0 or newer.
61616228

6162-
.. method:: put(data, to=None)
6229+
.. method:: put(data, to=None, *, format=None, metadata=None)
61636230

61646231
Set pixels of the image to the colors given in *data*, which must be a
61656232
string or a nested sequence of horizontal rows of pixel colors (for
@@ -6172,13 +6239,25 @@ Image classes
61726239
bottom-right corner, of the region.
61736240
The default position is ``(0, 0)``.
61746241

6242+
*format* specifies the format of the image *data*, so that only image
6243+
file format handlers whose names begin with it are tried.
6244+
6245+
*metadata* is a dictionary passed to the image format driver.
6246+
It requires Tcl/Tk 9.0 or newer.
6247+
6248+
.. versionchanged:: next
6249+
Added the *format* and *metadata* parameters.
6250+
61756251
.. method:: read(filename, format=None, *, from_coords=None, to=None, \
6176-
shrink=False)
6252+
shrink=False, metadata=None)
61776253

61786254
Read image data from the file named *filename* into the image.
61796255

61806256
*format* specifies the format of the image data in the file.
61816257

6258+
*metadata* is a dictionary passed to the image format driver.
6259+
It requires Tcl/Tk 9.0 or newer.
6260+
61826261
*from_coords* specifies a rectangular sub-region of the image file data
61836262
to be copied to the destination image.
61846263
It must be a tuple or a list of 1 to 4 integers ``(x1, y1, x2, y2)``.
@@ -6199,6 +6278,9 @@ Image classes
61996278

62006279
.. versionadded:: 3.13
62016280

6281+
.. versionchanged:: next
6282+
Added the *metadata* parameter.
6283+
62026284

62036285
.. method:: subsample(x, y='', *, from_coords=None)
62046286

@@ -6231,7 +6313,7 @@ Image classes
62316313

62326314

62336315
.. method:: write(filename, format=None, from_coords=None, *, \
6234-
background=None, grayscale=False)
6316+
background=None, grayscale=False, metadata=None)
62356317

62366318
Write image data from the image to the file named *filename*.
62376319

@@ -6253,9 +6335,15 @@ Image classes
62536335
If *grayscale* is true, the data does not contain color information; all
62546336
pixel data is transformed into grayscale.
62556337

6338+
*metadata* is a dictionary passed to the image format driver.
6339+
It requires Tcl/Tk 9.0 or newer.
6340+
62566341
.. versionchanged:: 3.13
62576342
Added the *background* and *grayscale* parameters.
62586343

6344+
.. versionchanged:: next
6345+
Added the *metadata* parameter.
6346+
62596347

62606348
.. method:: zoom(x, y='', *, from_coords=None)
62616349

Doc/library/venv.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ containing a copy or symlink of the Python executable
7777
It also creates a :file:`lib/pythonX.Y/site-packages` subdirectory
7878
(on Windows, this is :file:`Lib\\site-packages`).
7979
If an existing directory is specified, it will be re-used.
80+
Reusing an existing directory does not leave it unchanged: ``venv`` may create,
81+
update, or replace files in the target directory. Use a dedicated directory for
82+
the virtual environment, and avoid placing project files directly inside it.
8083

8184
.. versionchanged:: 3.5
8285
The use of ``venv`` is now recommended for creating virtual environments.
@@ -126,7 +129,9 @@ The command, if run with ``-h``, will show the available options::
126129

127130
.. option:: --clear
128131

129-
Delete the contents of the environment directory if it already exists, before environment creation.
132+
Delete all contents of the environment directory if it already exists,
133+
including files that were not created by ``venv``,
134+
before environment creation.
130135

131136
.. option:: --upgrade
132137

Doc/whatsnew/3.16.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,22 @@ tkinter
173173
synchronization of the displayed view with the underlying text.
174174
(Contributed by Serhiy Storchaka in :gh:`151675`.)
175175

176+
* Added new :class:`!tkinter.Canvas` methods :meth:`~tkinter.Canvas.rchars`
177+
which replaces the text or coordinates of canvas items, and
178+
:meth:`~tkinter.Canvas.rotate` which rotates the coordinates of canvas items.
179+
(Contributed by Serhiy Storchaka in :gh:`151876`.)
180+
176181
* Added a :meth:`!validate` method to the :class:`!tkinter.Entry` and
177182
:class:`!tkinter.Spinbox` widgets, which forces an evaluation of the
178183
validation command.
179184
(Contributed by Serhiy Storchaka in :gh:`151878`.)
180185

186+
* Added the :meth:`tkinter.Menu.postcascade` method, and the
187+
:meth:`~tkinter.Misc.tk_scaling` and :meth:`~tkinter.Misc.tk_inactive`
188+
methods which respectively query or set the display scaling factor and
189+
report the user idle time.
190+
(Contributed by Serhiy Storchaka in :gh:`151881`.)
191+
181192
* Added new window-management methods :meth:`~tkinter.Misc.winfo_isdark`
182193
(dark mode detection), :meth:`~tkinter.Wm.wm_iconbadge` (application icon
183194
badge) and :meth:`~tkinter.Wm.wm_stackorder` (toplevel stacking order).
@@ -189,6 +200,17 @@ tkinter
189200
the input method caret location.
190201
(Contributed by Serhiy Storchaka in :gh:`151886`.)
191202

203+
* Added support for more options in :class:`!tkinter.PhotoImage` methods: the
204+
*format* parameter of :meth:`~tkinter.PhotoImage.put`, the *metadata*
205+
parameter of :meth:`~tkinter.PhotoImage.put`, :meth:`~tkinter.PhotoImage.read`,
206+
:meth:`~tkinter.PhotoImage.write` and :meth:`~tkinter.PhotoImage.data`, and
207+
the *withalpha* parameter of :meth:`~tkinter.PhotoImage.get`.
208+
(Contributed by Serhiy Storchaka in :gh:`151890`.)
209+
210+
* Added the :meth:`~tkinter.PhotoImage.redither` method which recalculates the
211+
dithered image when its data was supplied in pieces.
212+
(Contributed by Serhiy Storchaka in :gh:`151888`.)
213+
192214

193215
xml
194216
---

Lib/site.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,7 @@ def _venv(state):
982982
if candidate_conf:
983983
virtual_conf = candidate_conf
984984
system_site = "true"
985+
version, version_info = None, None
985986
# Issue 25185: Use UTF-8, as that's what the venv module uses when
986987
# writing the file.
987988
with open(virtual_conf, encoding='utf-8') as f:
@@ -994,6 +995,35 @@ def _venv(state):
994995
system_site = value.lower()
995996
elif key == 'home':
996997
sys._home = value
998+
elif key == 'version':
999+
version = value
1000+
elif key == 'version_info':
1001+
version_info = value
1002+
1003+
for field_name, field_value in [
1004+
('version',version), ('version_info',version_info)
1005+
]:
1006+
if field_value is not None:
1007+
try:
1008+
major, minor = map(int, field_value.split(".")[:2])
1009+
except (ValueError, AttributeError):
1010+
_warn(
1011+
f"Malformed {field_name} string in pyvenv.cfg: {field_value!r}",
1012+
RuntimeWarning,
1013+
)
1014+
else:
1015+
if (
1016+
major == sys.version_info.major
1017+
and minor != sys.version_info.minor
1018+
):
1019+
_warn(
1020+
f"This virtual environment was created for Python {major}.{minor}, "
1021+
f"but the current interpreter is Python "
1022+
f"{sys.version_info.major}.{sys.version_info.minor}. "
1023+
"Consider running `python -m venv --upgrade` to update the environment.",
1024+
RuntimeWarning,
1025+
)
1026+
break
9971027

9981028
if sys.prefix != site_prefix:
9991029
_warn(

Lib/sysconfig/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ def joinuser(*args):
182182
_CONFIG_VARS = None
183183
# True iff _CONFIG_VARS has been fully initialized.
184184
_CONFIG_VARS_INITIALIZED = False
185+
_config_vars_cached_prefix = None
186+
_config_vars_cached_exec_prefix = None
185187
_USER_BASE = None
186188

187189

@@ -600,16 +602,20 @@ def get_config_vars(*args):
600602
each argument in the configuration variable dictionary.
601603
"""
602604
global _CONFIG_VARS_INITIALIZED
605+
global _config_vars_cached_prefix
606+
global _config_vars_cached_exec_prefix
603607

604608
# Avoid claiming the lock once initialization is complete.
609+
prefix = os.path.normpath(sys.prefix)
610+
exec_prefix = os.path.normpath(sys.exec_prefix)
605611
if _CONFIG_VARS_INITIALIZED:
606612
# GH-126789: If sys.prefix or sys.exec_prefix were updated, invalidate the cache.
607-
prefix = os.path.normpath(sys.prefix)
608-
exec_prefix = os.path.normpath(sys.exec_prefix)
609-
if _CONFIG_VARS['prefix'] != prefix or _CONFIG_VARS['exec_prefix'] != exec_prefix:
613+
if _config_vars_cached_prefix != prefix or _config_vars_cached_exec_prefix != exec_prefix:
610614
with _CONFIG_VARS_LOCK:
611615
_CONFIG_VARS_INITIALIZED = False
612616
_init_config_vars()
617+
_config_vars_cached_prefix = prefix
618+
_config_vars_cached_exec_prefix = exec_prefix
613619
else:
614620
# Initialize the config_vars cache.
615621
with _CONFIG_VARS_LOCK:
@@ -619,6 +625,8 @@ def get_config_vars(*args):
619625
# don't re-enter init_config_vars().
620626
if _CONFIG_VARS is None:
621627
_init_config_vars()
628+
_config_vars_cached_prefix = prefix
629+
_config_vars_cached_exec_prefix = exec_prefix
622630

623631
if args:
624632
vals = []

Lib/test/test_importlib/resources/util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pathlib
77
import sys
88
import types
9+
from importlib.abc import Loader, MetaPathFinder
910
from importlib.machinery import ModuleSpec
1011
from importlib.resources.abc import ResourceReader, Traversable, TraversableResources
1112

@@ -218,7 +219,7 @@ def augment_sys_metapath(self, module):
218219
yield
219220
sys.meta_path.remove(finder_instance)
220221

221-
class MemoryFinder(importlib.abc.MetaPathFinder):
222+
class MemoryFinder(MetaPathFinder):
222223
def __init__(self, module):
223224
self._module = module
224225

@@ -232,7 +233,7 @@ def find_spec(self, fullname, path, target=None):
232233
is_package=True,
233234
)
234235

235-
class MemoryLoader(importlib.abc.Loader):
236+
class MemoryLoader(Loader):
236237
def __init__(self, module):
237238
self._module = module
238239

0 commit comments

Comments
 (0)