2525OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2626SOFTWARE.
2727"""
28- from typing import Coroutine , Callable , Optional , Union
28+ from typing import Coroutine , Callable , Optional , Union , Tuple
2929from threading import current_thread
3030from 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