25
25
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
26
SOFTWARE.
27
27
"""
28
- from typing import Coroutine , Callable , Optional , Union
28
+ from typing import Coroutine , Callable , Optional , Union , Tuple
29
29
from threading import current_thread
30
30
from concurrent .futures import Future
31
31
@@ -79,6 +79,21 @@ class ExecutingAsyncWindow(tk.Toplevel):
79
79
If True, any write to stdout (e.g., the ``print()`` function) will be displayed in the window when
80
80
the execution window is shown (``visible=True``).
81
81
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`.
82
97
kwargs: Any
83
98
Other keyword arguments passed to :class:`tkinter.Toplevel`
84
99
@@ -98,6 +113,11 @@ def __init__(
98
113
show_exceptions : bool = True ,
99
114
message : Optional [Union [str , Callable [[str ], str ]]] = lambda name : f"Executing { name } " ,
100
115
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 ,
101
121
** kwargs
102
122
):
103
123
loop = self .loop
@@ -106,8 +126,8 @@ def __init__(
106
126
107
127
super ().__init__ (** kwargs )
108
128
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 )
111
131
frame_main = ttk .Frame (self , padding = (10 , 10 ))
112
132
frame_main .pack (fill = tk .BOTH , expand = True )
113
133
@@ -118,16 +138,20 @@ def __init__(
118
138
self .old_stdout = sys .stdout
119
139
if show_stdout :
120
140
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 )
122
142
ttk .Label (frame_stdout , textvariable = self .status_var ).grid (row = 0 , column = 1 )
123
143
124
144
if callable (message ):
125
145
message = message (coro .__name__ )
126
146
127
147
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
+
131
155
self .protocol ("WM_DELETE_WINDOW" , lambda : None )
132
156
133
157
if not visible :
0 commit comments