Skip to content

Commit

Permalink
Stop progress bar when cancel job; consistent cb_bar method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
laggykiller committed Mar 6, 2024
1 parent f0121ff commit 78f4750
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/sticker_convert/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ def cancel_job(self):
if self.job:
self.cb_msg(msg="Cancelling job...")
self.job.cancel()
self.cb_bar(set_progress_mode="clear")

def set_inputs(self, state: str):
# state: 'normal', 'disabled'
Expand Down Expand Up @@ -630,9 +631,22 @@ def cb_msg_block(

return self.response

def cb_bar(self, *args: Any, **kwargs: Any):
def cb_bar(
self,
set_progress_mode: Optional[str] = None,
steps: int = 0,
update_bar: bool = False,
*args: Any,
**kwargs: Any
):
with self.bar_lock:
self.progress_frame.update_progress_bar(*args, **kwargs)
self.progress_frame.update_progress_bar(
set_progress_mode,
steps,
update_bar,
*args,
**kwargs
)

def highlight_fields(self) -> bool:
if not self.init_done:
Expand Down
7 changes: 5 additions & 2 deletions src/sticker_convert/gui_components/frames/progress_frame.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Optional

from tqdm import tqdm
from ttkbootstrap import LabelFrame, Progressbar # type: ignore
Expand Down Expand Up @@ -32,7 +32,10 @@ def __init__(self, gui: "GUI", *args: Any, **kwargs: Any):
self.progress_bar.pack(expand=True, fill="x")

def update_progress_bar(
self, set_progress_mode: str = "", steps: int = 0, update_bar: bool = False
self,
set_progress_mode: Optional[str] = None,
steps: int = 0,
update_bar: bool = False,
):
if update_bar and self.progress_bar_cli:
self.progress_bar_cli.update()
Expand Down
2 changes: 1 addition & 1 deletion src/sticker_convert/utils/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def cb_msg(self, *args: Any, **kwargs: Any):
def cb_bar(
self,
set_progress_mode: Optional[str] = None,
steps: Optional[int] = None,
steps: int = 0,
update_bar: bool = False,
):
if self.silent:
Expand Down

0 comments on commit 78f4750

Please sign in to comment.