Mailing List Archive

bpo-32839: Add the after_info() method for Tkinter widgets (GH-5664)
https://github.com/python/cpython/commit/194fd17bc6cb73138e2fe8eb5ca34b19a6c3b25a
commit: 194fd17bc6cb73138e2fe8eb5ca34b19a6c3b25a
branch: main
author: Cheryl Sabella <cheryl.sabella@gmail.com>
committer: serhiy-storchaka <storchaka@gmail.com>
date: 2024-04-27T00:27:58+03:00
summary:

bpo-32839: Add the after_info() method for Tkinter widgets (GH-5664)

files:
A Misc/NEWS.d/next/Library/2018-02-13-10-02-54.bpo-32839.McbVz3.rst
M Doc/whatsnew/3.13.rst
M Lib/test/test_tkinter/test_misc.py
M Lib/tkinter/__init__.py

diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst
index ad107aad5db3bd..083a70ce2405e3 100644
--- a/Doc/whatsnew/3.13.rst
+++ b/Doc/whatsnew/3.13.rst
@@ -791,6 +791,9 @@ tkinter
:class:`tkinter.ttk.Style`.
(Contributed by Serhiy Storchaka in :gh:`68166`.)

+* Add the :meth:`!after_info` method for Tkinter widgets.
+ (Contributed by Cheryl Sabella in :gh:`77020`.)
+
traceback
---------

diff --git a/Lib/test/test_tkinter/test_misc.py b/Lib/test/test_tkinter/test_misc.py
index 81a20b698a72eb..6dca2a3920e06a 100644
--- a/Lib/test/test_tkinter/test_misc.py
+++ b/Lib/test/test_tkinter/test_misc.py
@@ -232,6 +232,46 @@ def callback():
with self.assertRaises(tkinter.TclError):
root.tk.call('after', 'info', idle1)

+ def test_after_info(self):
+ root = self.root
+
+ # No events.
+ self.assertEqual(root.after_info(), ())
+
+ # Add timer.
+ timer = root.after(1, lambda: 'break')
+
+ # With no parameter, it returns a tuple of the event handler ids.
+ self.assertEqual(root.after_info(), (timer, ))
+ root.after_cancel(timer)
+
+ timer1 = root.after(5000, lambda: 'break')
+ timer2 = root.after(5000, lambda: 'break')
+ idle1 = root.after_idle(lambda: 'break')
+ # Only contains new events and not 'timer'.
+ self.assertEqual(root.after_info(), (idle1, timer2, timer1))
+
+ # With a parameter returns a tuple of (script, type).
+ timer1_info = root.after_info(timer1)
+ self.assertEqual(len(timer1_info), 2)
+ self.assertEqual(timer1_info[1], 'timer')
+ idle1_info = root.after_info(idle1)
+ self.assertEqual(len(idle1_info), 2)
+ self.assertEqual(idle1_info[1], 'idle')
+
+ root.after_cancel(timer1)
+ with self.assertRaises(tkinter.TclError):
+ root.after_info(timer1)
+ root.after_cancel(timer2)
+ with self.assertRaises(tkinter.TclError):
+ root.after_info(timer2)
+ root.after_cancel(idle1)
+ with self.assertRaises(tkinter.TclError):
+ root.after_info(idle1)
+
+ # No events.
+ self.assertEqual(root.after_info(), ())
+
def test_clipboard(self):
root = self.root
root.clipboard_clear()
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index fd7b48e3519990..70a1ed46fd0774 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -897,6 +897,21 @@ def after_cancel(self, id):
pass
self.tk.call('after', 'cancel', id)

+ def after_info(self, id=None):
+ """Return information about existing event handlers.
+
+ With no argument, return a tuple of the identifiers for all existing
+ event handlers created by the after and after_idle commands for this
+ interpreter. If id is supplied, it specifies an existing handler; id
+ must have been the return value from some previous call to after or
+ after_idle and it must not have triggered yet or been canceled. If the
+ id doesn't exist, a TclError is raised. Otherwise, the return value is
+ a tuple containing (script, type) where script is a reference to the
+ function to be called by the event handler and type is either 'idle'
+ or 'timer' to indicate what kind of event handler it is.
+ """
+ return self.tk.splitlist(self.tk.call('after', 'info', id))
+
def bell(self, displayof=0):
"""Ring a display's bell."""
self.tk.call(('bell',) + self._displayof(displayof))
diff --git a/Misc/NEWS.d/next/Library/2018-02-13-10-02-54.bpo-32839.McbVz3.rst b/Misc/NEWS.d/next/Library/2018-02-13-10-02-54.bpo-32839.McbVz3.rst
new file mode 100644
index 00000000000000..0a2e3e3c540c48
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-02-13-10-02-54.bpo-32839.McbVz3.rst
@@ -0,0 +1 @@
+Add the :meth:`after_info` method for Tkinter widgets.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-leave@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: list-python-checkins@lists.gossamer-threads.com