-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
bpo-42721: Improve using simple dialogs without root window #23897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
serhiy-storchaka
merged 4 commits into
python:master
from
serhiy-storchaka:simple-common-dialog-temporary-root
Dec 25, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2460120
bpo-42721: Improve using simple dialogs without root window
serhiy-storchaka 2611e2b
Update Lib/tkinter/commondialog.py
serhiy-storchaka 2dac97c
Update the NEWS entry for NoDefaultRoot() and rewrite implementation …
serhiy-storchaka 08c7fd8
Merge branch 'master' into simple-common-dialog-temporary-root
serhiy-storchaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import unittest | ||
| import tkinter | ||
| from test.support import requires, run_unittest, swap_attr | ||
| from tkinter.test.support import AbstractDefaultRootTest | ||
| from tkinter.commondialog import Dialog | ||
| from tkinter.colorchooser import askcolor | ||
|
|
||
| requires('gui') | ||
|
|
||
|
|
||
| class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase): | ||
|
|
||
| def test_askcolor(self): | ||
| def test_callback(dialog, master): | ||
| nonlocal ismapped | ||
| master.update() | ||
| ismapped = master.winfo_ismapped() | ||
| raise ZeroDivisionError | ||
|
|
||
| with swap_attr(Dialog, '_test_callback', test_callback): | ||
| ismapped = None | ||
| self.assertRaises(ZeroDivisionError, askcolor) | ||
| #askcolor() | ||
| self.assertEqual(ismapped, False) | ||
|
|
||
| root = tkinter.Tk() | ||
| ismapped = None | ||
| self.assertRaises(ZeroDivisionError, askcolor) | ||
| self.assertEqual(ismapped, True) | ||
| root.destroy() | ||
|
|
||
| tkinter.NoDefaultRoot() | ||
| self.assertRaises(RuntimeError, askcolor) | ||
|
|
||
|
|
||
| tests_gui = (DefaultRootTest,) | ||
|
|
||
| if __name__ == "__main__": | ||
| run_unittest(*tests_gui) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import unittest | ||
| import tkinter | ||
| from test.support import requires, run_unittest, swap_attr | ||
| from tkinter.test.support import AbstractDefaultRootTest | ||
| from tkinter.commondialog import Dialog | ||
| from tkinter.messagebox import showinfo | ||
|
|
||
| requires('gui') | ||
|
|
||
|
|
||
| class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase): | ||
|
|
||
| def test_showinfo(self): | ||
| def test_callback(dialog, master): | ||
| nonlocal ismapped | ||
| master.update() | ||
| ismapped = master.winfo_ismapped() | ||
| raise ZeroDivisionError | ||
|
|
||
| with swap_attr(Dialog, '_test_callback', test_callback): | ||
| ismapped = None | ||
| self.assertRaises(ZeroDivisionError, showinfo, "Spam", "Egg Information") | ||
| self.assertEqual(ismapped, False) | ||
|
|
||
| root = tkinter.Tk() | ||
| ismapped = None | ||
| self.assertRaises(ZeroDivisionError, showinfo, "Spam", "Egg Information") | ||
| self.assertEqual(ismapped, True) | ||
| root.destroy() | ||
|
|
||
| tkinter.NoDefaultRoot() | ||
| self.assertRaises(RuntimeError, showinfo, "Spam", "Egg Information") | ||
|
|
||
|
|
||
| tests_gui = (DefaultRootTest,) | ||
|
|
||
| if __name__ == "__main__": | ||
| run_unittest(*tests_gui) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
Misc/NEWS.d/next/Library/2020-12-22-22-47-22.bpo-42721.I5Ai5L.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| When simple query dialogs (:mod:`tkinter.simpledialog`), message boxes | ||
| (:mod:`tkinter.messagebox`) or color choose dialog | ||
| (:mod:`tkinter.colorchooser`) are created without arguments *master* and | ||
| *parent*, and the default root window is not yet created, and | ||
| :func:`~tkinter.NoDefaultRoot` was not called, a new temporal | ||
| hidden root window will be created automatically. It will not be set as the | ||
| default root window and will be destroyed right after closing the dialog | ||
|
terryjreedy marked this conversation as resolved.
|
||
| window. It will help to use these simple dialog windows in programs which | ||
| do not need other GUI. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.