Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/test_tkinter/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ def require_mapped(self, widget, timeout=None):
f'(timed out after {timeout:g}s)')


class AbstractDialogTest(AbstractTkTest):
# Tk delivers generated keyboard events to the window which has the
# focus. Hide the root window, otherwise the window manager can take
# the focus back from the dialog (gh-154357).

def setUp(self):
super().setUp()
self.root.withdraw()


class AbstractDefaultRootTest:

def setUp(self):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_tkinter/test_filedialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tkinter.commondialog import Dialog
from test.support import requires, swap_attr
from test.test_tkinter.support import setUpModule # noqa: F401
from test.test_tkinter.support import AbstractTkTest
from test.test_tkinter.support import AbstractDialogTest, AbstractTkTest

requires('gui')

Expand Down Expand Up @@ -72,7 +72,7 @@ def test_results_preserved(self):
('/a', '/b'))


class FileDialogTest(AbstractTkTest, unittest.TestCase):
class FileDialogTest(AbstractDialogTest, unittest.TestCase):
# The pure-Python FileDialog runs its own modal loop in go(); its logic is
# exercised here without entering the loop.

Expand Down
6 changes: 4 additions & 2 deletions Lib/test/test_tkinter/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from test.test_tkinter.support import setUpModule # noqa: F401
from test.test_tkinter.support import (AbstractTkTest, AbstractDefaultRootTest,
requires_tk, get_tk_patchlevel,
tcl_version, tk_version)
tcl_version, tk_version,
wait_until_mapped)

support.requires('gui')

Expand Down Expand Up @@ -1321,7 +1322,8 @@ def test_wm_stackorder(self):
t2 = tkinter.Toplevel(self.root)
t1.deiconify()
t2.deiconify()
self.root.update()
wait_until_mapped(t1)
wait_until_mapped(t2)
t1.lift(t2) # Raise t1 above t2.
self.root.update()
order = self.root.wm_stackorder()
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_tkinter/test_simpledialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tkinter import messagebox, ttk
from test.support import requires, swap_attr
from test.test_tkinter.support import setUpModule # noqa: F401
from test.test_tkinter.support import AbstractDefaultRootTest, AbstractTkTest
from test.test_tkinter.support import AbstractDefaultRootTest, AbstractDialogTest
from tkinter.simpledialog import (Dialog, SimpleDialog,
askinteger, askfloat, askstring,
_QueryInteger, _QueryFloat, _QueryString,
Expand All @@ -12,7 +12,7 @@
requires('gui')


class SimpleDialogTest(AbstractTkTest, unittest.TestCase):
class SimpleDialogTest(AbstractDialogTest, unittest.TestCase):
# SimpleDialog's modal loop is in go(); its bindings are exercised here by
# generating events on the constructed dialog, without entering the loop.

Expand Down Expand Up @@ -246,7 +246,7 @@ def test_go(self):
self.assertEqual(d.go(), 0)


class DialogTest(AbstractTkTest, unittest.TestCase):
class DialogTest(AbstractDialogTest, unittest.TestCase):
# Dialog's button box is modelled on tk::MessageBox.

def open(self, **kw):
Expand Down Expand Up @@ -432,7 +432,7 @@ def mock_wait_window(w):
self.assertRaises(RuntimeError, askinteger, "Go To Line", "Line number")


class QueryDialogTest(AbstractTkTest, unittest.TestCase):
class QueryDialogTest(AbstractDialogTest, unittest.TestCase):
# The query dialogs are modal: their __init__ blocks in wait_window().
# Mock that out so the dialog stays alive and can be driven with generated
# events, exercising the <Return>/<Escape> bindings and the validation.
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_ttk/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2024,19 +2024,23 @@ def test_virtual_events(self):
lambda e: selects.append(self.tv.selection()))
self.tv.bind('<<TreeviewOpen>>', lambda e: opens.append(self.tv.focus()))
self.tv.bind('<<TreeviewClose>>', lambda e: closes.append(self.tv.focus()))
self.tv.focus_force()
self.tv.focus(parent)
self.tv.selection_set(parent)
self.tv.update()

# Force the focus right before generating the event: the window
# manager can take it back while the events are processed.
self.tv.focus_force()
self.tv.event_generate('<Right>') # Open the focused parent.
self.tv.update()
self.assertEqual(opens, [parent])

self.tv.focus_force()
self.tv.event_generate('<Left>') # Close it again.
self.tv.update()
self.assertEqual(closes, [parent])

self.tv.focus_force()
self.tv.event_generate('<Down>') # Move the selection.
self.tv.update()
self.assertEqual(self.tv.selection(), (item2,))
Expand Down
Loading