From 3be2dfdb2331dfb82738f22ff3fddce6a446baf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20de=20Chalendar?= Date: Sun, 25 Aug 2024 16:58:49 +0200 Subject: [PATCH] Add a stop button when running This solves issue #3. --- src/yaas/app.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/yaas/app.py b/src/yaas/app.py index 6c0c8bd..369981d 100644 --- a/src/yaas/app.py +++ b/src/yaas/app.py @@ -55,6 +55,11 @@ def __init__(self): self.start_button.clicked.connect(self.start_process) self.layout.addWidget(self.start_button) + self.stop_button = QPushButton("Stop") + self.stop_button.clicked.connect(self.stop_process) + self.layout.addWidget(self.stop_button) + self.stop_button.hide() + self.status_output = QTextEdit() self.status_output.setReadOnly(True) self.status_output.setFixedHeight(70) # Approximately 3 lines @@ -100,7 +105,6 @@ def parse_args(self) -> argparse.Namespace: return parser.parse_args() - def start_process(self): # url = self.url_input.text() url = self.browser.url().url() @@ -113,11 +117,20 @@ def start_process(self): self.worker.extraction_done.connect(self.extraction_done) self.worker.extraction_failed.connect(self.extraction_failed) self.worker.start() + self.start_button.hide() + self.stop_button.show() + + def stop_process(self): + # Restore the cursor to normal + QApplication.restoreOverrideCursor() + self.worker.terminate() + self.start_button.show() + self.stop_button.hide() + pass def update_status(self, message): self.status_output.append(message) - def ex_exit(self, ex: BaseException, exit_code: int = 1) -> NoReturn: """ Exit with an exception @@ -139,6 +152,8 @@ def url_changed(self): def extraction_done(self): # Restore the cursor to normal QApplication.restoreOverrideCursor() + self.start_button.show() + self.stop_button.hide() # Optional: Notify the user that the operation has finished self.update_status("Extraction done") @@ -147,6 +162,8 @@ def extraction_done(self): def extraction_failed(self, message: str): # Restore the cursor to normal QApplication.restoreOverrideCursor() + self.start_button.show() + self.stop_button.hide() # Optional: Notify the user that the operation has finished print(f"Extraction failed: {message}", file=sys.stderr)