wizard-tk-bridge 1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wizard_tk_bridge-1.3/LICENSE.txt +21 -0
- wizard_tk_bridge-1.3/PKG-INFO +212 -0
- wizard_tk_bridge-1.3/README_pypi.md +186 -0
- wizard_tk_bridge-1.3/pyproject.toml +31 -0
- wizard_tk_bridge-1.3/setup.cfg +4 -0
- wizard_tk_bridge-1.3/setup.py +15 -0
- wizard_tk_bridge-1.3/src/wizard_tk_bridge/__init__.py +15 -0
- wizard_tk_bridge-1.3/src/wizard_tk_bridge/_no_text_io.py +99 -0
- wizard_tk_bridge-1.3/src/wizard_tk_bridge/auto_scroll.py +37 -0
- wizard_tk_bridge-1.3/src/wizard_tk_bridge/close_binding.py +47 -0
- wizard_tk_bridge-1.3/src/wizard_tk_bridge/gui_style.py +70 -0
- wizard_tk_bridge-1.3/src/wizard_tk_bridge/py.typed +0 -0
- wizard_tk_bridge-1.3/src/wizard_tk_bridge/tk_bridge.py +181 -0
- wizard_tk_bridge-1.3/src/wizard_tk_bridge/wizard_calendar.py +189 -0
- wizard_tk_bridge-1.3/src/wizard_tk_bridge/wizard_form.py +640 -0
- wizard_tk_bridge-1.3/src/wizard_tk_bridge/wizard_path.py +113 -0
- wizard_tk_bridge-1.3/src/wizard_tk_bridge/wizard_pick_row.py +154 -0
- wizard_tk_bridge-1.3/src/wizard_tk_bridge/wizard_table.py +259 -0
- wizard_tk_bridge-1.3/src/wizard_tk_bridge/wizard_typed.py +289 -0
- wizard_tk_bridge-1.3/src/wizard_tk_bridge/wizard_window.py +440 -0
- wizard_tk_bridge-1.3/wizard_tk_bridge.egg-info/PKG-INFO +212 -0
- wizard_tk_bridge-1.3/wizard_tk_bridge.egg-info/SOURCES.txt +23 -0
- wizard_tk_bridge-1.3/wizard_tk_bridge.egg-info/dependency_links.txt +1 -0
- wizard_tk_bridge-1.3/wizard_tk_bridge.egg-info/requires.txt +1 -0
- wizard_tk_bridge-1.3/wizard_tk_bridge.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tom Björkholm
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wizard-tk-bridge
|
|
3
|
+
Version: 1.3
|
|
4
|
+
Summary: User interface Tk bridge for wizards asking a user questions.
|
|
5
|
+
Author: Tom Björkholm
|
|
6
|
+
Author-email: Tom Björkholm <klausuler_linnet0q@icloud.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Source code, https://github.com/tom-bjorkholm/wizard-ui-bridge
|
|
9
|
+
Project-URL: Documentation, https://github.com/tom-bjorkholm/wizard-ui-bridge/tree/master/doc
|
|
10
|
+
Keywords: wizard,user interface,gui,tk,tkinter,form
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE.txt
|
|
21
|
+
Requires-Dist: wizard-ui-bridge>=1.3
|
|
22
|
+
Dynamic: author
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
Dynamic: requires-dist
|
|
25
|
+
Dynamic: requires-python
|
|
26
|
+
|
|
27
|
+
# wizard-tk-bridge
|
|
28
|
+
|
|
29
|
+
[wizard-ui-bridge](https://pypi.org/project/wizard-ui-bridge/) is
|
|
30
|
+
the user-interface-independent way for a wizard to ask a user questions.
|
|
31
|
+
|
|
32
|
+
`wizard-tk-bridge` is the Tk (Tkinter) implementation of this
|
|
33
|
+
user-interface-independent way for a wizard to ask a user questions.
|
|
34
|
+
A wizard written for `wizard-ui-bridge` works out of the box if
|
|
35
|
+
passed a `wizard-tk-bridge` as bridge.
|
|
36
|
+
|
|
37
|
+
## Is this package for you?
|
|
38
|
+
|
|
39
|
+
This package is a good fit when one or more of these apply:
|
|
40
|
+
|
|
41
|
+
- You have a wizard written for `wizard-ui-bridge` and want to run it in
|
|
42
|
+
a graphical user interface, without changing a line of the wizard.
|
|
43
|
+
- Your application is a Tkinter application, and its questions belong in
|
|
44
|
+
real widgets rather than in a terminal.
|
|
45
|
+
- You want what a console cannot offer: a native file and directory
|
|
46
|
+
picker, a month calendar for dates, help texts as hover tooltips, an
|
|
47
|
+
editable table with add-row and remove-row buttons, and a whole form
|
|
48
|
+
on one screen that the user fills in any order.
|
|
49
|
+
- Your program is otherwise a plain command-line tool, and you want to
|
|
50
|
+
ask through a window without writing any Tkinter code of your own.
|
|
51
|
+
- You want to decide where the wizard appears: in a window of its own
|
|
52
|
+
over your application, or inside a panel your application built.
|
|
53
|
+
|
|
54
|
+
This package is probably not the right one when:
|
|
55
|
+
|
|
56
|
+
- Your program runs in a terminal, or on a machine with no display. Use
|
|
57
|
+
the console or Textual bridge of
|
|
58
|
+
[wizard-ui-bridge](https://pypi.org/project/wizard-ui-bridge/).
|
|
59
|
+
- Your application uses another graphical toolkit, such as Qt, wxPython
|
|
60
|
+
or GTK. Write a bridge for that toolkit instead, by subclassing
|
|
61
|
+
`WizardUiBridge`.
|
|
62
|
+
- You want a general widget toolkit. Use Tkinter directly.
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
`wizard-tk-bridge` requires Python 3.12 or newer, and the standard
|
|
67
|
+
library module `tkinter`.
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
pip install --upgrade wizard-tk-bridge
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
This installs
|
|
74
|
+
[wizard-ui-bridge](https://pypi.org/project/wizard-ui-bridge/) as well,
|
|
75
|
+
since a Tk bridge is a `WizardUiBridge`.
|
|
76
|
+
|
|
77
|
+
`tkinter` belongs to the standard library, but it is not a pure Python
|
|
78
|
+
module, and several Linux distributions leave it out of their base
|
|
79
|
+
Python package. A standard library module is not something `pip` can
|
|
80
|
+
install, so add it with the system package manager instead:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
sudo apt install python3-tk # Debian, Ubuntu
|
|
84
|
+
sudo dnf install python3-tkinter # Fedora, RHEL
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The usual CPython installers for Windows and macOS already include it.
|
|
88
|
+
|
|
89
|
+
## Quick start
|
|
90
|
+
|
|
91
|
+
Ask a few questions from a program that has no window of its own:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from wizard_tk_bridge import WizardUiBridgeTk
|
|
95
|
+
|
|
96
|
+
bridge = WizardUiBridgeTk()
|
|
97
|
+
try:
|
|
98
|
+
name = bridge.ask_text('Your name?', nullable=True)
|
|
99
|
+
topping = bridge.ask_choice('Favorite topping?',
|
|
100
|
+
choices=('Mushroom', 'Pepperoni', 'Olive'))
|
|
101
|
+
cheese = bridge.ask_yes_no('Extra cheese?', default=False)
|
|
102
|
+
finally:
|
|
103
|
+
bridge.close()
|
|
104
|
+
print(f'{name or "Anonymous"} orders {topping}, extra cheese: {cheese}')
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Every ask method blocks until the user answers, so the wizard stays
|
|
108
|
+
straight-line code. No `mainloop()` call is needed: the ask methods pump
|
|
109
|
+
the Tk event loop themselves and return as soon as the answer is in, and
|
|
110
|
+
the program is not left running an event loop once the wizard closes.
|
|
111
|
+
All questions of one session are asked in the same reused window, so the
|
|
112
|
+
session does not jump around the display.
|
|
113
|
+
|
|
114
|
+
Every question also carries **Back**, **Out one level** and **Abort**
|
|
115
|
+
buttons, which raise `WizardBack`, `WizardCancelLevel` and `WizardAbort`
|
|
116
|
+
instead of returning an answer. Closing the wizard's own window, or
|
|
117
|
+
pressing Cmd-W (Ctrl-W on Windows) in it, is an abort as well. The short
|
|
118
|
+
example above catches none of them and simply lets them propagate.
|
|
119
|
+
|
|
120
|
+
## Where the wizard appears
|
|
121
|
+
|
|
122
|
+
That is the one question the Tk bridge adds to the wizard-ui-bridge API,
|
|
123
|
+
and the constructor answers it:
|
|
124
|
+
|
|
125
|
+
| Your application | Arguments | What the bridge builds |
|
|
126
|
+
| ---------------- | --------- | ---------------------- |
|
|
127
|
+
| A command-line program with no Tkinter code | neither | a hidden root, and the wizard's own window over it |
|
|
128
|
+
| Has windows of its own | `parent=widget` | a new window over the widget's window |
|
|
129
|
+
| Has a container set aside for the wizard | `area=container` | the wizard's widgets inside that container |
|
|
130
|
+
|
|
131
|
+
`parent` and `area` are mutually exclusive; giving both raises
|
|
132
|
+
`ValueError`. The visible part is built on the first question, so a
|
|
133
|
+
bridge that is never asked anything puts nothing on the screen.
|
|
134
|
+
|
|
135
|
+
`modal` (default `True`) decides whether the wizard grabs its window —
|
|
136
|
+
or the window containing `area` — for the whole session, leaving the
|
|
137
|
+
rest of that window unusable meanwhile. Only the application knows
|
|
138
|
+
whether its other content should stay usable, which is why it decides.
|
|
139
|
+
An embedded wizard normally passes `modal=False`, since keeping the rest
|
|
140
|
+
of the window usable is the reason to embed rather than pop up.
|
|
141
|
+
|
|
142
|
+
`close()` is not optional. It releases the modal grab, destroys the
|
|
143
|
+
wizard's own window or clears its area, and destroys the hidden root
|
|
144
|
+
when the bridge owns one. Call it from a `finally`, because a wizard's
|
|
145
|
+
normal way of ending is often a `WizardNavigation` exception rather than
|
|
146
|
+
a `return`. Calling it twice is harmless.
|
|
147
|
+
|
|
148
|
+
## What the user gets
|
|
149
|
+
|
|
150
|
+
`WizardUiBridgeTk` overrides every ask method, the inheritable ones
|
|
151
|
+
included — above all `ask_path()` and `ask_form()`, where a graphical
|
|
152
|
+
interface beats the base class fallback outright:
|
|
153
|
+
|
|
154
|
+
| Ask method | What the user gets |
|
|
155
|
+
| ---------- | ------------------ |
|
|
156
|
+
| `ask_text` | a text entry, masked when `sensitive` |
|
|
157
|
+
| `ask_int` | a numeric entry, re-asked until the value parses and fits its bounds |
|
|
158
|
+
| `ask_path` | an entry with a **Browse** button opening the native file or directory picker |
|
|
159
|
+
| `ask_yes_no` | a **Yes** and a **No** button |
|
|
160
|
+
| `ask_choice` / `ask_multi` | a single- / multi-selection list |
|
|
161
|
+
| `ask_table` | an editable grid, with **Add row** and **Remove row** when the question allows a variable number of rows |
|
|
162
|
+
| `ask_form` | every field of the form on one screen, answered in any order |
|
|
163
|
+
|
|
164
|
+
In a form, a field's `help_text` becomes a hover tooltip rather than an
|
|
165
|
+
extra printed line, the float, time and duration fields show their
|
|
166
|
+
accepted format as greyed placeholder text, and a date or date-time
|
|
167
|
+
field adds a **Pick** button opening a month calendar.
|
|
168
|
+
|
|
169
|
+
`show()` appends to a message area kept above the current question, so
|
|
170
|
+
earlier messages stay readable as the wizard moves on. They disappear
|
|
171
|
+
with the window, so a final message needs a question after it to be seen
|
|
172
|
+
at all — exactly as on the Textual bridge.
|
|
173
|
+
|
|
174
|
+
A graphical interface has no console to write side notes to, so
|
|
175
|
+
`error_file()` returns a stream that discards what is written to it.
|
|
176
|
+
Pass `WizardUiBridgeTk(log=stream)` to send those diagnostics somewhere
|
|
177
|
+
real, such as an open log file.
|
|
178
|
+
|
|
179
|
+
## Relation to wizard-ui-bridge
|
|
180
|
+
|
|
181
|
+
`wizard-tk-bridge` and `wizard-ui-bridge` are built from the same
|
|
182
|
+
repository and released together, so a version of this package requires
|
|
183
|
+
the matching version of `wizard-ui-bridge`, or newer.
|
|
184
|
+
|
|
185
|
+
This Tk bridge started out inside one application that used
|
|
186
|
+
`wizard-ui-bridge`. It was moved into a package of its own so that it
|
|
187
|
+
can be developed alongside `wizard-ui-bridge` and used by any other
|
|
188
|
+
application.
|
|
189
|
+
|
|
190
|
+
## Documentation
|
|
191
|
+
|
|
192
|
+
- Teaching examples and walkthroughs: [wizard_tk_bridge/example/src/wizard_tk_example/README.md](https://github.com/tom-bjorkholm/wizard-ui-bridge/blob/master/wizard_tk_bridge/example/src/wizard_tk_example/README.md)
|
|
193
|
+
|
|
194
|
+
- Public API notes: [doc/wizard_tk_bridge_api.md](https://github.com/tom-bjorkholm/wizard-ui-bridge/blob/master/doc/wizard_tk_bridge_api.md)
|
|
195
|
+
|
|
196
|
+
- Protected/internal API notes: [doc/wizard_tk_bridge_protected_api.md](https://github.com/tom-bjorkholm/wizard-ui-bridge/blob/master/doc/wizard_tk_bridge_protected_api.md)
|
|
197
|
+
|
|
198
|
+
- Source repository: [wizard-ui-bridge](https://github.com/tom-bjorkholm/wizard-ui-bridge/)
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
MIT
|
|
203
|
+
|
|
204
|
+
## Test summary
|
|
205
|
+
|
|
206
|
+
- Test result: 1051 passed, 9 deselected in 38s
|
|
207
|
+
- No flake8 warnings.
|
|
208
|
+
- No mypy errors found.
|
|
209
|
+
- No pylint warnings.
|
|
210
|
+
- No python layout warnings.
|
|
211
|
+
- Built version(s): 1.3
|
|
212
|
+
- Build and test using Python 3.14.6
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# wizard-tk-bridge
|
|
2
|
+
|
|
3
|
+
[wizard-ui-bridge](https://pypi.org/project/wizard-ui-bridge/) is
|
|
4
|
+
the user-interface-independent way for a wizard to ask a user questions.
|
|
5
|
+
|
|
6
|
+
`wizard-tk-bridge` is the Tk (Tkinter) implementation of this
|
|
7
|
+
user-interface-independent way for a wizard to ask a user questions.
|
|
8
|
+
A wizard written for `wizard-ui-bridge` works out of the box if
|
|
9
|
+
passed a `wizard-tk-bridge` as bridge.
|
|
10
|
+
|
|
11
|
+
## Is this package for you?
|
|
12
|
+
|
|
13
|
+
This package is a good fit when one or more of these apply:
|
|
14
|
+
|
|
15
|
+
- You have a wizard written for `wizard-ui-bridge` and want to run it in
|
|
16
|
+
a graphical user interface, without changing a line of the wizard.
|
|
17
|
+
- Your application is a Tkinter application, and its questions belong in
|
|
18
|
+
real widgets rather than in a terminal.
|
|
19
|
+
- You want what a console cannot offer: a native file and directory
|
|
20
|
+
picker, a month calendar for dates, help texts as hover tooltips, an
|
|
21
|
+
editable table with add-row and remove-row buttons, and a whole form
|
|
22
|
+
on one screen that the user fills in any order.
|
|
23
|
+
- Your program is otherwise a plain command-line tool, and you want to
|
|
24
|
+
ask through a window without writing any Tkinter code of your own.
|
|
25
|
+
- You want to decide where the wizard appears: in a window of its own
|
|
26
|
+
over your application, or inside a panel your application built.
|
|
27
|
+
|
|
28
|
+
This package is probably not the right one when:
|
|
29
|
+
|
|
30
|
+
- Your program runs in a terminal, or on a machine with no display. Use
|
|
31
|
+
the console or Textual bridge of
|
|
32
|
+
[wizard-ui-bridge](https://pypi.org/project/wizard-ui-bridge/).
|
|
33
|
+
- Your application uses another graphical toolkit, such as Qt, wxPython
|
|
34
|
+
or GTK. Write a bridge for that toolkit instead, by subclassing
|
|
35
|
+
`WizardUiBridge`.
|
|
36
|
+
- You want a general widget toolkit. Use Tkinter directly.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
`wizard-tk-bridge` requires Python 3.12 or newer, and the standard
|
|
41
|
+
library module `tkinter`.
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
pip install --upgrade wizard-tk-bridge
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
This installs
|
|
48
|
+
[wizard-ui-bridge](https://pypi.org/project/wizard-ui-bridge/) as well,
|
|
49
|
+
since a Tk bridge is a `WizardUiBridge`.
|
|
50
|
+
|
|
51
|
+
`tkinter` belongs to the standard library, but it is not a pure Python
|
|
52
|
+
module, and several Linux distributions leave it out of their base
|
|
53
|
+
Python package. A standard library module is not something `pip` can
|
|
54
|
+
install, so add it with the system package manager instead:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
sudo apt install python3-tk # Debian, Ubuntu
|
|
58
|
+
sudo dnf install python3-tkinter # Fedora, RHEL
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The usual CPython installers for Windows and macOS already include it.
|
|
62
|
+
|
|
63
|
+
## Quick start
|
|
64
|
+
|
|
65
|
+
Ask a few questions from a program that has no window of its own:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from wizard_tk_bridge import WizardUiBridgeTk
|
|
69
|
+
|
|
70
|
+
bridge = WizardUiBridgeTk()
|
|
71
|
+
try:
|
|
72
|
+
name = bridge.ask_text('Your name?', nullable=True)
|
|
73
|
+
topping = bridge.ask_choice('Favorite topping?',
|
|
74
|
+
choices=('Mushroom', 'Pepperoni', 'Olive'))
|
|
75
|
+
cheese = bridge.ask_yes_no('Extra cheese?', default=False)
|
|
76
|
+
finally:
|
|
77
|
+
bridge.close()
|
|
78
|
+
print(f'{name or "Anonymous"} orders {topping}, extra cheese: {cheese}')
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Every ask method blocks until the user answers, so the wizard stays
|
|
82
|
+
straight-line code. No `mainloop()` call is needed: the ask methods pump
|
|
83
|
+
the Tk event loop themselves and return as soon as the answer is in, and
|
|
84
|
+
the program is not left running an event loop once the wizard closes.
|
|
85
|
+
All questions of one session are asked in the same reused window, so the
|
|
86
|
+
session does not jump around the display.
|
|
87
|
+
|
|
88
|
+
Every question also carries **Back**, **Out one level** and **Abort**
|
|
89
|
+
buttons, which raise `WizardBack`, `WizardCancelLevel` and `WizardAbort`
|
|
90
|
+
instead of returning an answer. Closing the wizard's own window, or
|
|
91
|
+
pressing Cmd-W (Ctrl-W on Windows) in it, is an abort as well. The short
|
|
92
|
+
example above catches none of them and simply lets them propagate.
|
|
93
|
+
|
|
94
|
+
## Where the wizard appears
|
|
95
|
+
|
|
96
|
+
That is the one question the Tk bridge adds to the wizard-ui-bridge API,
|
|
97
|
+
and the constructor answers it:
|
|
98
|
+
|
|
99
|
+
| Your application | Arguments | What the bridge builds |
|
|
100
|
+
| ---------------- | --------- | ---------------------- |
|
|
101
|
+
| A command-line program with no Tkinter code | neither | a hidden root, and the wizard's own window over it |
|
|
102
|
+
| Has windows of its own | `parent=widget` | a new window over the widget's window |
|
|
103
|
+
| Has a container set aside for the wizard | `area=container` | the wizard's widgets inside that container |
|
|
104
|
+
|
|
105
|
+
`parent` and `area` are mutually exclusive; giving both raises
|
|
106
|
+
`ValueError`. The visible part is built on the first question, so a
|
|
107
|
+
bridge that is never asked anything puts nothing on the screen.
|
|
108
|
+
|
|
109
|
+
`modal` (default `True`) decides whether the wizard grabs its window —
|
|
110
|
+
or the window containing `area` — for the whole session, leaving the
|
|
111
|
+
rest of that window unusable meanwhile. Only the application knows
|
|
112
|
+
whether its other content should stay usable, which is why it decides.
|
|
113
|
+
An embedded wizard normally passes `modal=False`, since keeping the rest
|
|
114
|
+
of the window usable is the reason to embed rather than pop up.
|
|
115
|
+
|
|
116
|
+
`close()` is not optional. It releases the modal grab, destroys the
|
|
117
|
+
wizard's own window or clears its area, and destroys the hidden root
|
|
118
|
+
when the bridge owns one. Call it from a `finally`, because a wizard's
|
|
119
|
+
normal way of ending is often a `WizardNavigation` exception rather than
|
|
120
|
+
a `return`. Calling it twice is harmless.
|
|
121
|
+
|
|
122
|
+
## What the user gets
|
|
123
|
+
|
|
124
|
+
`WizardUiBridgeTk` overrides every ask method, the inheritable ones
|
|
125
|
+
included — above all `ask_path()` and `ask_form()`, where a graphical
|
|
126
|
+
interface beats the base class fallback outright:
|
|
127
|
+
|
|
128
|
+
| Ask method | What the user gets |
|
|
129
|
+
| ---------- | ------------------ |
|
|
130
|
+
| `ask_text` | a text entry, masked when `sensitive` |
|
|
131
|
+
| `ask_int` | a numeric entry, re-asked until the value parses and fits its bounds |
|
|
132
|
+
| `ask_path` | an entry with a **Browse** button opening the native file or directory picker |
|
|
133
|
+
| `ask_yes_no` | a **Yes** and a **No** button |
|
|
134
|
+
| `ask_choice` / `ask_multi` | a single- / multi-selection list |
|
|
135
|
+
| `ask_table` | an editable grid, with **Add row** and **Remove row** when the question allows a variable number of rows |
|
|
136
|
+
| `ask_form` | every field of the form on one screen, answered in any order |
|
|
137
|
+
|
|
138
|
+
In a form, a field's `help_text` becomes a hover tooltip rather than an
|
|
139
|
+
extra printed line, the float, time and duration fields show their
|
|
140
|
+
accepted format as greyed placeholder text, and a date or date-time
|
|
141
|
+
field adds a **Pick** button opening a month calendar.
|
|
142
|
+
|
|
143
|
+
`show()` appends to a message area kept above the current question, so
|
|
144
|
+
earlier messages stay readable as the wizard moves on. They disappear
|
|
145
|
+
with the window, so a final message needs a question after it to be seen
|
|
146
|
+
at all — exactly as on the Textual bridge.
|
|
147
|
+
|
|
148
|
+
A graphical interface has no console to write side notes to, so
|
|
149
|
+
`error_file()` returns a stream that discards what is written to it.
|
|
150
|
+
Pass `WizardUiBridgeTk(log=stream)` to send those diagnostics somewhere
|
|
151
|
+
real, such as an open log file.
|
|
152
|
+
|
|
153
|
+
## Relation to wizard-ui-bridge
|
|
154
|
+
|
|
155
|
+
`wizard-tk-bridge` and `wizard-ui-bridge` are built from the same
|
|
156
|
+
repository and released together, so a version of this package requires
|
|
157
|
+
the matching version of `wizard-ui-bridge`, or newer.
|
|
158
|
+
|
|
159
|
+
This Tk bridge started out inside one application that used
|
|
160
|
+
`wizard-ui-bridge`. It was moved into a package of its own so that it
|
|
161
|
+
can be developed alongside `wizard-ui-bridge` and used by any other
|
|
162
|
+
application.
|
|
163
|
+
|
|
164
|
+
## Documentation
|
|
165
|
+
|
|
166
|
+
- Teaching examples and walkthroughs: [wizard_tk_bridge/example/src/wizard_tk_example/README.md](https://github.com/tom-bjorkholm/wizard-ui-bridge/blob/master/wizard_tk_bridge/example/src/wizard_tk_example/README.md)
|
|
167
|
+
|
|
168
|
+
- Public API notes: [doc/wizard_tk_bridge_api.md](https://github.com/tom-bjorkholm/wizard-ui-bridge/blob/master/doc/wizard_tk_bridge_api.md)
|
|
169
|
+
|
|
170
|
+
- Protected/internal API notes: [doc/wizard_tk_bridge_protected_api.md](https://github.com/tom-bjorkholm/wizard-ui-bridge/blob/master/doc/wizard_tk_bridge_protected_api.md)
|
|
171
|
+
|
|
172
|
+
- Source repository: [wizard-ui-bridge](https://github.com/tom-bjorkholm/wizard-ui-bridge/)
|
|
173
|
+
|
|
174
|
+
## License
|
|
175
|
+
|
|
176
|
+
MIT
|
|
177
|
+
|
|
178
|
+
## Test summary
|
|
179
|
+
|
|
180
|
+
- Test result: 1051 passed, 9 deselected in 38s
|
|
181
|
+
- No flake8 warnings.
|
|
182
|
+
- No mypy errors found.
|
|
183
|
+
- No pylint warnings.
|
|
184
|
+
- No python layout warnings.
|
|
185
|
+
- Built version(s): 1.3
|
|
186
|
+
- Build and test using Python 3.14.6
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=83.0.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "wizard-tk-bridge"
|
|
7
|
+
authors = [
|
|
8
|
+
{ name="Tom Björkholm", email="klausuler_linnet0q@icloud.com" },
|
|
9
|
+
]
|
|
10
|
+
description = "User interface Tk bridge for wizards asking a user questions."
|
|
11
|
+
readme = "README_pypi.md"
|
|
12
|
+
requires-python = ">=3.12"
|
|
13
|
+
license = "MIT"
|
|
14
|
+
license-files = ["LICENSE.txt"]
|
|
15
|
+
keywords = [
|
|
16
|
+
"wizard", "user interface", "gui", "tk", "tkinter", "form"
|
|
17
|
+
]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Programming Language :: Python :: 3.14",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"Typing :: Typed"
|
|
26
|
+
]
|
|
27
|
+
dynamic = ["dependencies", "optional-dependencies", "version"]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
"Source code" = "https://github.com/tom-bjorkholm/wizard-ui-bridge"
|
|
31
|
+
"Documentation" = "https://github.com/tom-bjorkholm/wizard-ui-bridge/tree/master/doc"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#! /usr/local/bin/python3
|
|
2
|
+
"""Setup file specifying build of .whl."""
|
|
3
|
+
|
|
4
|
+
from setuptools import setup # type: ignore[import-untyped]
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name='wizard-tk-bridge', version='1.3',
|
|
8
|
+
description='User interface Tk bridge for wizards asking a user questions.',
|
|
9
|
+
author='Tom Björkholm', author_email='klausuler_linnet0q@icloud.com',
|
|
10
|
+
python_requires='>=3.12', packages=['wizard_tk_bridge'],
|
|
11
|
+
package_dir={'wizard_tk_bridge': 'src/wizard_tk_bridge'},
|
|
12
|
+
package_data={'wizard_tk_bridge': ['py.typed']},
|
|
13
|
+
install_requires=[
|
|
14
|
+
'wizard-ui-bridge >= 1.3',
|
|
15
|
+
])
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#! /usr/bin/env python3
|
|
2
|
+
"""Public API for the wizard user interface Tk bridge.
|
|
3
|
+
|
|
4
|
+
WizardUiBridgeTk is a WizardUiBridge that asks every question through
|
|
5
|
+
real Tkinter widgets, in a window of its own or embedded in an area an
|
|
6
|
+
application already built. See wizard_tk_bridge.tk_bridge for the three
|
|
7
|
+
ways an application can show the wizard.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
# Copyright (c) 2026 Tom Björkholm
|
|
11
|
+
# MIT License
|
|
12
|
+
|
|
13
|
+
from wizard_tk_bridge.tk_bridge import WizardUiBridgeTk
|
|
14
|
+
|
|
15
|
+
__all__ = ['WizardUiBridgeTk']
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#! /usr/local/bin/python3
|
|
2
|
+
"""NoTextIO can be used as a TextIO object that does nothing."""
|
|
3
|
+
|
|
4
|
+
# Copyright (c) 2026 Tom Björkholm
|
|
5
|
+
# MIT License
|
|
6
|
+
|
|
7
|
+
from typing import Optional, override
|
|
8
|
+
from collections.abc import Iterable
|
|
9
|
+
from types import TracebackType
|
|
10
|
+
import io
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class NoTextIO(io.StringIO):
|
|
14
|
+
"""NoTextIO can be used as a TextIO object that does nothing.
|
|
15
|
+
|
|
16
|
+
When a function expects a TextIO object for output, you can pass in
|
|
17
|
+
a NoTextIO object and no output will be produced.
|
|
18
|
+
The difference compared to using StringIO to suppress output is that
|
|
19
|
+
the NoTextIO does not store any data, so no matter how much is
|
|
20
|
+
written to it, you do not risk running out of memory.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
@override
|
|
24
|
+
def write(self, s: str) -> int:
|
|
25
|
+
"""Write a string to the NoTextIO object.
|
|
26
|
+
|
|
27
|
+
This method does nothing and returns length of the string.
|
|
28
|
+
"""
|
|
29
|
+
return len(s)
|
|
30
|
+
|
|
31
|
+
@override
|
|
32
|
+
def writelines(self, # type: ignore[override]
|
|
33
|
+
lines: Iterable[str]) -> None:
|
|
34
|
+
"""Write a list of strings to the NoTextIO object.
|
|
35
|
+
|
|
36
|
+
This method does nothing and returns None.
|
|
37
|
+
"""
|
|
38
|
+
_ = lines
|
|
39
|
+
|
|
40
|
+
@override
|
|
41
|
+
def flush(self) -> None:
|
|
42
|
+
"""Flush the NoTextIO object.
|
|
43
|
+
|
|
44
|
+
This method does nothing and returns None.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
@override
|
|
48
|
+
def close(self) -> None:
|
|
49
|
+
"""Close the NoTextIO object.
|
|
50
|
+
|
|
51
|
+
This method does nothing and returns None.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
@override
|
|
55
|
+
def seek(self, offset: int, whence: int = io.SEEK_SET, /) -> int:
|
|
56
|
+
"""Seek to a position in the NoTextIO object.
|
|
57
|
+
|
|
58
|
+
This method does nothing and returns 0.
|
|
59
|
+
"""
|
|
60
|
+
_ = offset
|
|
61
|
+
_ = whence
|
|
62
|
+
return 0
|
|
63
|
+
|
|
64
|
+
@override
|
|
65
|
+
def tell(self) -> int:
|
|
66
|
+
"""Get the current position in the NoTextIO object.
|
|
67
|
+
|
|
68
|
+
This method does nothing and returns 0.
|
|
69
|
+
"""
|
|
70
|
+
return 0
|
|
71
|
+
|
|
72
|
+
@override
|
|
73
|
+
def truncate(self, size: Optional[int] = None, /) -> int:
|
|
74
|
+
"""Truncate the NoTextIO object.
|
|
75
|
+
|
|
76
|
+
This method does nothing and returns 0.
|
|
77
|
+
"""
|
|
78
|
+
_ = size
|
|
79
|
+
return 0
|
|
80
|
+
|
|
81
|
+
@override
|
|
82
|
+
def __enter__(self) -> 'NoTextIO':
|
|
83
|
+
"""Enter the NoTextIO object.
|
|
84
|
+
|
|
85
|
+
This method does nothing and returns the NoTextIO object.
|
|
86
|
+
"""
|
|
87
|
+
return self
|
|
88
|
+
|
|
89
|
+
@override
|
|
90
|
+
def __exit__(self, exc_type: Optional[type[BaseException]],
|
|
91
|
+
exc_value: Optional[BaseException],
|
|
92
|
+
traceback: Optional[TracebackType]) -> None:
|
|
93
|
+
"""Exit the NoTextIO object.
|
|
94
|
+
|
|
95
|
+
This method does nothing.
|
|
96
|
+
"""
|
|
97
|
+
_ = exc_type
|
|
98
|
+
_ = exc_value
|
|
99
|
+
_ = traceback
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#! /usr/local/bin/python3
|
|
2
|
+
"""A scroll command that shows a scrollbar only while it can scroll.
|
|
3
|
+
|
|
4
|
+
A table that fits its area needs no scrollbar, and a scrollbar that is
|
|
5
|
+
always shown wastes space and hints at hidden content that is not there.
|
|
6
|
+
:func:`auto_hide` returns the scroll command for a scrolling widget: the
|
|
7
|
+
command hides the scrollbar while the whole range is visible and shows it
|
|
8
|
+
again once the widget grows past its area. It works for any widget that
|
|
9
|
+
reports its position through an ``xscrollcommand`` or ``yscrollcommand``,
|
|
10
|
+
so a wizard table's canvas and any other scrolling widget can share it.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
# Copyright (c) 2026 Tom Björkholm
|
|
14
|
+
# MIT License
|
|
15
|
+
|
|
16
|
+
from tkinter import ttk
|
|
17
|
+
from typing import Callable
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def auto_hide(scrollbar: ttk.Scrollbar
|
|
21
|
+
) -> Callable[[float | str, float | str], None]:
|
|
22
|
+
"""Return a scroll command that hides the scrollbar when it is full.
|
|
23
|
+
|
|
24
|
+
The result is used as a widget's ``xscrollcommand`` or
|
|
25
|
+
``yscrollcommand``. Tk reports the position as two fractions, which it
|
|
26
|
+
passes as strings, so the command accepts either a number or its
|
|
27
|
+
string form. The scrollbar must be laid out with the grid manager,
|
|
28
|
+
whose ``grid_remove`` remembers its cell across the hide.
|
|
29
|
+
"""
|
|
30
|
+
def command(first: float | str, last: float | str) -> None:
|
|
31
|
+
"""Hide or show the scrollbar, then move its thumb to the view."""
|
|
32
|
+
if float(first) <= 0.0 and float(last) >= 1.0:
|
|
33
|
+
scrollbar.grid_remove()
|
|
34
|
+
else:
|
|
35
|
+
scrollbar.grid()
|
|
36
|
+
scrollbar.set(first, last)
|
|
37
|
+
return command
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#! /usr/local/bin/python3
|
|
2
|
+
"""Bind the close-window key to a secondary window's close action.
|
|
3
|
+
|
|
4
|
+
On macOS the Tk toolkit does not close a window when the user presses
|
|
5
|
+
Cmd-W, so every secondary window binds that key here. Cmd-W is bound on
|
|
6
|
+
every platform, where it is harmless without a Command key, and Ctrl-W is
|
|
7
|
+
added on Windows, its customary close-window shortcut. The bound action
|
|
8
|
+
defaults to destroying the window but may be the window's own cancel or
|
|
9
|
+
abort handler, so the key behaves exactly like the window close button.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
# Copyright (c) 2026 Tom Björkholm
|
|
13
|
+
# MIT License
|
|
14
|
+
|
|
15
|
+
import sys
|
|
16
|
+
import tkinter as tk
|
|
17
|
+
from typing import Callable, Optional
|
|
18
|
+
|
|
19
|
+
CLOSE_ACCELERATOR = 'Command-W'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _close_events() -> list[str]:
|
|
23
|
+
"""Return the key patterns that close a window on this platform."""
|
|
24
|
+
if sys.platform.startswith('win'):
|
|
25
|
+
return ['<Command-w>', '<Control-w>']
|
|
26
|
+
return ['<Command-w>']
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _perform_close(win: tk.Toplevel,
|
|
30
|
+
on_close: Optional[Callable[[], None]]) -> str:
|
|
31
|
+
"""Run the window's close action and stop further event handling."""
|
|
32
|
+
(win.destroy if on_close is None else on_close)()
|
|
33
|
+
return 'break'
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def bind_close(win: tk.Toplevel,
|
|
37
|
+
on_close: Optional[Callable[[], None]] = None) -> None:
|
|
38
|
+
"""Bind the close-window key to run the window's close action.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
win: The secondary window to close on the key press.
|
|
42
|
+
on_close: The close action, defaulting to destroying the window.
|
|
43
|
+
A window that cancels or aborts on close passes its own
|
|
44
|
+
handler, so the key matches its window close button.
|
|
45
|
+
"""
|
|
46
|
+
for event in _close_events():
|
|
47
|
+
win.bind(event, lambda _event: _perform_close(win, on_close))
|