Skip to content

Commit

Permalink
Add a stop button when running
Browse files Browse the repository at this point in the history
This solves issue #3.
  • Loading branch information
kleag committed Aug 25, 2024
1 parent b08b922 commit 3be2dfd
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/yaas/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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)
Expand Down

0 comments on commit 3be2dfd

Please sign in to comment.