Skip to content

Commit

Permalink
Merge pull request #58 from seowings/main
Browse files Browse the repository at this point in the history
Improved Projects Management
  • Loading branch information
seowings authored Dec 23, 2023
2 parents 6757eb3 + c7ccb0a commit 3aedd26
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
48 changes: 29 additions & 19 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 @@ -177,6 +177,7 @@ def __init__(self):
"Loaded static-wordpress Successfully. Open/Create a Project to get started"
)
logging.info("".join(140 * ["-"]))
self.update_widgets()
self.show()

# decorators
Expand Down Expand Up @@ -310,7 +311,7 @@ def set_expert_mode(self):
for widget_name in expert_widgets:
self.findChild(QAction, widget_name).setVisible(self.sender().isChecked())

self.findChild(QAction, "action_wordpress_additional_files").setVisible(
self.findChild(QAction, "action_wordpress_crawl_additional_files").setVisible(
self.sender().isChecked() and self._project.src_type != SOURCE.ZIP
)

Expand Down Expand Up @@ -772,15 +773,15 @@ def publish_repository(self) -> None:
self._bg_thread.started.connect(self._bg_worker.publish_github_repositoy)
self._bg_thread.start()

def update_statusbar(self, message_, percent_) -> 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 All @@ -799,7 +800,8 @@ def update_widgets(self) -> None:
self._project.has_github()
)
self.findChild(QToolBar, "toolbar_wordpres").setEnabled(
self._project.has_wordpress() or self._project.can_crawl()
self._project.is_open()
and (self._project.has_wordpress() or self._project.can_crawl())
)

# Show Menubar Icons
Expand All @@ -820,15 +822,23 @@ def update_widgets(self) -> None:
self.findChild(QAction, "action_edit_set_expert_mode").isChecked()
)

for project_tool in [
"action_tools_clean_output_folder",
]:
self.findChild(QAction, project_tool).setVisible(self._project.is_open())
self.findChild(QAction, "action_wordpress_crawl_additional_files").setVisible(
self.findChild(QAction, "action_edit_set_expert_mode").isChecked()
)

new_window_title = (
f"{self._project.name} - {CONFIGS['APPLICATION_NAME']} Version - {VERISON}"
self.findChild(QAction, "action_project_show_project_settings").setEnabled(
self._project.is_open()
)
self.setWindowTitle(new_window_title)
self.findChild(QAction, "action_project_close_project").setEnabled(
self._project.is_open()
)

if self._project.is_open():
self.setWindowTitle(
f"{self._project.name} - {CONFIGS['APPLICATION_NAME']} Version - {VERISON}"
)
else:
self.setWindowTitle(f"{CONFIGS['APPLICATION_NAME']} Version - {VERISON}")


def main():
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 3aedd26

Please sign in to comment.