Skip to content

Commit

Permalink
added progressbar to project check/verify
Browse files Browse the repository at this point in the history
  • Loading branch information
seowings committed Dec 23, 2023
1 parent 5804a68 commit c7ccb0a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/staticwordpress/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions src/staticwordpress/gui/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
QMessageBox,
QFileDialog,
QPushButton,
QProgressBar,
)
from PyQt5.QtCore import Qt, QSettings, QSize, QThread
from PyQt5.QtGui import QIcon
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()):
Expand All @@ -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']}"
Expand All @@ -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']}"
Expand All @@ -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():
Expand All @@ -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(),
]
):
Expand Down

0 comments on commit c7ccb0a

Please sign in to comment.