mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Issue #22236: Tkinter tests now don't reuse default root window. New root
window is created for every test class. Fixed Tkinter images copying operations in NoDefaultRoot mode. Tcl command names generated for "after" callbacks now contains a name of original function.
This commit is contained in:
parent
ee55826072
commit
d00aff2f62
15 changed files with 231 additions and 271 deletions
|
@ -3,30 +3,43 @@ import tkinter
|
|||
import unittest
|
||||
from test.support import requires
|
||||
|
||||
def get_tk_root():
|
||||
requires('gui') # raise exception if tk unavailable
|
||||
try:
|
||||
root = tkinter._default_root
|
||||
except AttributeError:
|
||||
# it is possible to disable default root in Tkinter, although
|
||||
# I haven't seen people doing it (but apparently someone did it
|
||||
# here).
|
||||
root = None
|
||||
class AbstractTkTest:
|
||||
|
||||
if root is None:
|
||||
# create a new master only if there isn't one already
|
||||
root = tkinter.Tk()
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls._old_support_default_root = tkinter._support_default_root
|
||||
destroy_default_root()
|
||||
tkinter.NoDefaultRoot()
|
||||
cls.root = tkinter.Tk()
|
||||
cls.wantobjects = cls.root.wantobjects()
|
||||
# De-maximize main window.
|
||||
# Some window managers can maximize new windows.
|
||||
cls.root.wm_state('normal')
|
||||
try:
|
||||
cls.root.wm_attributes('-zoomed', False)
|
||||
except tkinter.TclError:
|
||||
pass
|
||||
|
||||
return root
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.root.destroy()
|
||||
cls.root = None
|
||||
tkinter._default_root = None
|
||||
tkinter._support_default_root = cls._old_support_default_root
|
||||
|
||||
def root_deiconify():
|
||||
root = get_tk_root()
|
||||
root.deiconify()
|
||||
def setUp(self):
|
||||
self.root.deiconify()
|
||||
|
||||
def root_withdraw():
|
||||
root = get_tk_root()
|
||||
root.withdraw()
|
||||
def tearDown(self):
|
||||
for w in self.root.winfo_children():
|
||||
w.destroy()
|
||||
self.root.withdraw()
|
||||
|
||||
def destroy_default_root():
|
||||
if getattr(tkinter, '_default_root', None):
|
||||
tkinter._default_root.update_idletasks()
|
||||
tkinter._default_root.destroy()
|
||||
tkinter._default_root = None
|
||||
|
||||
def simulate_mouse_click(widget, x, y):
|
||||
"""Generate proper events to click at the x, y position (tries to act
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue