Skip to content

Commit a090aab

Browse files
authored
Changelog (#18)
* Add extra parameters to the execution window (#17) * Add extra parameters to the window * Fix typing * Bump version * Changelog
1 parent b1d8110 commit a090aab

File tree

4 files changed

+73
-11
lines changed

4 files changed

+73
-11
lines changed

docs/source/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ Glossary
3434
Releases
3535
---------------------
3636

37+
v1.4.0
38+
==================
39+
- Added extra parameters: ``window_title``, ``window_resizable``, ``stdout_labe_prefix``, ``show_progress_bar``.
40+
41+
3742
v1.3.2
3843
==================
3944
- Fixed ``AttributeError: 'NoneType' object has no attribute 'write'`` exception when using PyInstaller with

tk_async_execute/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2828
SOFTWARE.
2929
"""
30-
VERSION = "1.3.2"
30+
VERSION = "1.4.0"
3131

3232
from .utils import *
3333
from .widget import ExecutingAsyncWindow

tk_async_execute/utils.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
SOFTWARE.
2727
"""
2828

29-
from typing import Coroutine, Optional, Callable, Union
29+
from typing import Coroutine, Optional, Callable, Union, Tuple
3030
from threading import Thread
3131
from concurrent.futures import Future as TFuture
3232

@@ -124,6 +124,11 @@ def async_execute(
124124
show_exceptions: bool = True,
125125
message: Optional[Union[str, Callable[[str], str]]] = lambda name: f"Executing {name}",
126126
show_stdout: bool = True,
127+
# Tkinter-specific parameters
128+
window_title: str = "Async execution window",
129+
window_resizable: Tuple[bool, bool] = (False, False),
130+
stdout_label_prefix: str = "Last status: ",
131+
show_progress_bar: bool = True,
127132
**kwargs
128133
):
129134
"""
@@ -165,7 +170,22 @@ def async_execute(
165170
If True, any write to stdout (e.g., the ``print()`` function) will be displayed in the window when
166171
the execution window is shown (``visible=True``).
167172
Defaults to True.
168-
**kwargs
173+
window_title: Optional[str]
174+
The title of this window. Defaults to "Async execution window".
175+
window_resizable: Optional[tuple[bool, bool]]
176+
Controls whether the window is resizable. The first component of this tuple represents
177+
the resizable-in-width and second resizable-in-height.
178+
Defaults to (False, False), meaning the window is not resizable in any direction.
179+
stdout_label_prefix: Optional[str],
180+
Only has an effect if the `show_stdout` parameter is set to `True`.
181+
Each time a message is printed via stdout, the window will show it.
182+
This parameter controls the text that is added in front of all messages.
183+
Defaults to "Last status: ".
184+
show_progress_bar: Opional[bool],
185+
Whether to show the progress bar (gauge). Note that this is only a free-running progress bar
186+
and it is meant to have a visual effect. It doesn't allow actual progress to be displayed.
187+
Defaults to `True`.
188+
kwargs: Any
169189
Any tkinter specific parameters to the TopLevel widget.
170190
171191
Returns
@@ -178,7 +198,20 @@ def async_execute(
178198
Exception
179199
Exception that occurred in ``coro`` (if it ocurred). Only raised if ``wait`` is True.
180200
"""
181-
window = ExecutingAsyncWindow(coro, visible, pop_up, callback, show_exceptions, message, show_stdout, **kwargs)
201+
window = ExecutingAsyncWindow(
202+
coro,
203+
visible,
204+
pop_up,
205+
callback,
206+
show_exceptions,
207+
message,
208+
show_stdout,
209+
window_title,
210+
window_resizable,
211+
stdout_label_prefix,
212+
show_progress_bar,
213+
**kwargs
214+
)
182215
if wait:
183216
window.wait_window()
184217

tk_async_execute/widget.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2626
SOFTWARE.
2727
"""
28-
from typing import Coroutine, Callable, Optional, Union
28+
from typing import Coroutine, Callable, Optional, Union, Tuple
2929
from threading import current_thread
3030
from concurrent.futures import Future
3131

@@ -79,6 +79,21 @@ class ExecutingAsyncWindow(tk.Toplevel):
7979
If True, any write to stdout (e.g., the ``print()`` function) will be displayed in the window when
8080
the execution window is shown (``visible=True``).
8181
Defaults to True.
82+
window_title: Optional[str]
83+
The title of this window. Defaults to "Async execution window".
84+
window_resizable: Optional[tuple[bool, bool]]
85+
Controls whether the window is resizable. The first component of this tuple represents
86+
the resizable-in-width and second resizable-in-height.
87+
Defaults to (False, False), meaning the window is not resizable in any direction.
88+
stdout_label_prefix: Optional[str],
89+
Only has an effect if the `show_stdout` parameter is set to `True`.
90+
Each time a message is printed via stdout, the window will show it.
91+
This parameter controls the text that is added in front of all messages.
92+
Defaults to "Last status: ".
93+
show_progress_bar: Opional[bool],
94+
Whether to show the progress bar (gauge). Note that this is only a free-running progress bar
95+
and it is meant to have a visual effect. It doesn't allow actual progress to be displayed.
96+
Defaults to `True`.
8297
kwargs: Any
8398
Other keyword arguments passed to :class:`tkinter.Toplevel`
8499
@@ -98,6 +113,11 @@ def __init__(
98113
show_exceptions: bool = True,
99114
message: Optional[Union[str, Callable[[str], str]]] = lambda name: f"Executing {name}",
100115
show_stdout: bool = True,
116+
# Tkinter-specific parameters
117+
window_title: str = "Async execution window",
118+
window_resizable: Tuple[bool, bool] = (True, False),
119+
stdout_label_prefix: str = "Last status: ",
120+
show_progress_bar: bool = True,
101121
**kwargs
102122
):
103123
loop = self.loop
@@ -106,8 +126,8 @@ def __init__(
106126

107127
super().__init__(**kwargs)
108128
self.show_exceptions = show_exceptions
109-
self.title("Async execution window")
110-
self.resizable(False, False)
129+
self.title(window_title)
130+
self.resizable(*window_resizable)
111131
frame_main = ttk.Frame(self, padding=(10, 10))
112132
frame_main.pack(fill=tk.BOTH, expand=True)
113133

@@ -118,16 +138,20 @@ def __init__(
118138
self.old_stdout = sys.stdout
119139
if show_stdout:
120140
sys.stdout = self
121-
ttk.Label(frame_stdout, text="Last status: ").grid(row=0, column=0)
141+
ttk.Label(frame_stdout, text=stdout_label_prefix).grid(row=0, column=0)
122142
ttk.Label(frame_stdout, textvariable=self.status_var).grid(row=0, column=1)
123143

124144
if callable(message):
125145
message = message(coro.__name__)
126146

127147
ttk.Label(frame_main, text=message).pack(fill=tk.X)
128-
gauge = ttk.Progressbar(frame_main)
129-
gauge.start()
130-
gauge.pack(fill=tk.BOTH)
148+
if show_progress_bar:
149+
self.gauge = ttk.Progressbar(frame_main)
150+
self.gauge.pack(fill=tk.BOTH)
151+
self.gauge.start()
152+
else:
153+
self.gauge = None
154+
131155
self.protocol("WM_DELETE_WINDOW", lambda: None)
132156

133157
if not visible:

0 commit comments

Comments
 (0)