From c7ccb0ace42e66252a830faa9c35f9a7179d4d8c Mon Sep 17 00:00:00 2001 From: Faisal Shahzad <84210709+seowings@users.noreply.github.com> Date: Sat, 23 Dec 2023 01:22:06 +0100 Subject: [PATCH] added progressbar to project check/verify --- src/staticwordpress/gui/main.py | 18 +++++++++--------- src/staticwordpress/gui/project.py | 23 +++++++++++++++++++++-- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/staticwordpress/gui/main.py b/src/staticwordpress/gui/main.py index a55c7f4..8c5315f 100644 --- a/src/staticwordpress/gui/main.py +++ b/src/staticwordpress/gui/main.py @@ -104,12 +104,12 @@ def __init__(self): self.setCentralWidget(self.text_edit_logging.plaintext_edit) self.statusBar().showMessage(f"{CONFIGS['APPLICATION_NAME']} is Ready") - self.progress_bar = QProgressBar() - self.progress_bar.setAlignment(Qt.AlignCenter) - self.progress_bar.setFormat("No Brackground Process is running") - self.progress_bar.setFixedSize(QSize(300, 25)) - self.progress_bar.setValue(0) - self.statusBar().addPermanentWidget(self.progress_bar) + self.progressbar = QProgressBar() + self.progressbar.setAlignment(Qt.AlignCenter) + self.progressbar.setFormat("No Brackground Process is running") + self.progressbar.setFixedSize(QSize(300, 25)) + self.progressbar.setValue(0) + self.statusBar().addPermanentWidget(self.progressbar) # ALL menus for current_menu in GUI_SETTINGS["MENUS"]: @@ -775,13 +775,13 @@ def publish_repository(self) -> None: def update_statusbar(self, message_: str = "", percent_: int = 0) -> None: if percent_ >= 0: - self.progress_bar.setValue(percent_) + self.progressbar.setValue(percent_) self.statusBar().showMessage(message_) else: - self.progress_bar.setFormat(message_) + self.progressbar.setFormat(message_) if percent_ >= 100: - self.progress_bar.setFormat(message_) + self.progressbar.setFormat(message_) def update_widgets(self) -> None: # Show Menus diff --git a/src/staticwordpress/gui/project.py b/src/staticwordpress/gui/project.py index f678858..533ef8c 100644 --- a/src/staticwordpress/gui/project.py +++ b/src/staticwordpress/gui/project.py @@ -53,6 +53,7 @@ QMessageBox, QFileDialog, QPushButton, + QProgressBar, ) from PyQt5.QtCore import Qt, QSettings, QSize, QThread from PyQt5.QtGui import QIcon @@ -334,8 +335,16 @@ def __init__(self, parent, project_, title_="Project Settings"): self.pushbutton_cancel.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg")) self.pushbutton_cancel.clicked.connect(self.reject) + self.progressbar = QProgressBar(self) + self.progressbar.setMinimumWidth(150) + self.progressbar.setMinimum(0) + self.progressbar.setMaximum(100) + self.progressbar.setValue(0) + self.progressbar.hide() + horizontal_layout_buttons = QHBoxLayout() horizontal_layout_buttons.addWidget(self.pushbutton_verify) + horizontal_layout_buttons.addWidget(self.progressbar) horizontal_layout_buttons.addStretch() horizontal_layout_buttons.addWidget(self.pushbutton_save) horizontal_layout_buttons.addWidget(self.pushbutton_cancel) @@ -395,15 +404,21 @@ def get_sitemap_location(self): self._bg_worker.moveToThread(self._bg_thread) self._bg_thread.finished.connect(self._bg_worker.deleteLater) self._bg_thread.started.connect(self._bg_worker.find_sitemap) + self._bg_worker.emit_progress.connect(self.update_sitemap_progress) self._bg_worker.emit_sitemap_location.connect(self.update_sitemap_location) self._bg_thread.start() + self.progressbar.show() - def update_sitemap_location(self, sitemap_location_): + def update_sitemap_location(self, sitemap_location_: str = "/sitemap.xml"): if sitemap_location_: self.lineedit_sitemap.setText(sitemap_location_) + def update_sitemap_progress(self, message_: str = "", progress_: int = 0): + self.progressbar.setValue(progress_) + def verify_project_settings(self): """""" + self.progressbar.show() # TODO: Add checks for WP_API and Gh_API and if not present then disable them. # TODO: Move these checks to background thread e.g. for WP_API or SRC_URL or SRC or DST Path if not (self.lineedit_wp_api_token.text() and self.lineedit_wp_user.text()): @@ -418,6 +433,8 @@ def verify_project_settings(self): f"background-color: {CONFIGS['COLOR']['ERROR']}" ) + self.progressbar.setValue(40) + if is_url_valid(self.lineedit_src_url.text()): self.lineedit_src_url.setStyleSheet( f"background-color: {CONFIGS['COLOR']['SUCCESS']}" @@ -427,6 +444,8 @@ def verify_project_settings(self): f"background-color: {CONFIGS['COLOR']['ERROR']}" ) + self.progressbar.setValue(70) + if self.lineedit_output.text() and Path(self.lineedit_output.text()).is_dir(): self.lineedit_output.setStyleSheet( f"background-color: {CONFIGS['COLOR']['SUCCESS']}" @@ -435,6 +454,7 @@ def verify_project_settings(self): self.lineedit_output.setStyleSheet( f"background-color: {CONFIGS['COLOR']['ERROR']}" ) + self.progressbar.setValue(100) def reject(self) -> None: if self._bg_thread.isRunning(): @@ -456,7 +476,6 @@ def accept(self) -> None: [ self.lineedit_project_name.text(), self.lineedit_output.text(), - # is_url_valid(self.lineedit_src_url.text()), Path(self.lineedit_output.text()).is_dir(), ] ):