From 52c35bbe38d3c6ea04a4fd1e81345a65d900b90f Mon Sep 17 00:00:00 2001 From: Faisal Shahzad <84210709+seowings@users.noreply.github.com> Date: Sun, 22 Oct 2023 15:23:44 +0200 Subject: [PATCH] fixed New Project Dialog --- src/staticwordpress/gui/mainwindow.py | 143 ++++++++++++-------------- src/staticwordpress/gui/project.py | 35 +++++++ 2 files changed, 100 insertions(+), 78 deletions(-) diff --git a/src/staticwordpress/gui/mainwindow.py b/src/staticwordpress/gui/mainwindow.py index 67d3989..499900b 100644 --- a/src/staticwordpress/gui/mainwindow.py +++ b/src/staticwordpress/gui/mainwindow.py @@ -209,44 +209,24 @@ def clean_output_directory(self): msgBox.setText( f"Existing content in Output folder will be delete?
{self._project.output}", ) - msgBox.addButton(QMessageBox.Ok).setIcon( - QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg") - ) - msgBox.addButton(QMessageBox.Cancel).setIcon( - QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg") - ) + pushbuttonOk = msgBox.addButton("OK", QMessageBox.YesRole) + pushbuttonOk.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg")) + + pushbuttonNo = msgBox.addButton("Cancel", QMessageBox.NoRole) + pushbuttonNo.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg")) + + msgBox.setDefaultButton(pushbuttonOk) + msgBox.setWindowIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")) - msgBox.setDefaultButton(QMessageBox.Ok) msgBox.setTextFormat(Qt.RichText) msgBox.exec_() - if msgBox.clickedButton().text() == "&OK": + if msgBox.clickedButton() == pushbuttonOk: rm_dir_tree(self._project.output) logging.info( f"Content of output folder at {self._project.output} are deleted" ) - @is_new_project - @logging_decorator - def get_sitemap_location(self): - """ """ - if self._bg_thread.isRunning(): - self._bg_thread.quit() - - self._bg_thread = QThread(parent=self) - self._bg_worker = WorkflowGUI() - self._bg_worker.set_project(project_=self._project) - 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.signalSitemapLocation.connect(self.update_sitemap_location) - self._bg_thread.start() - - def update_sitemap_location(self, sitemap_location): - self._project.sitemap = sitemap_location - logging.info(f"Found Sitemap location: {sitemap_location}") - self.update_widgets() - @is_new_project @logging_decorator def extract_url_from_raw_text(self): @@ -278,18 +258,20 @@ def closeEvent(self, event): msgBox.setText( "Do you really want to exit?.
Any unsaved changes will be lost!", ) - msgBox.addButton(QMessageBox.Ok).setIcon( - QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg") - ) - msgBox.addButton(QMessageBox.Cancel).setIcon( - QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg") - ) - msgBox.setDefaultButton(QMessageBox.Ok) + + pushbuttonOk = msgBox.addButton("OK", QMessageBox.YesRole) + pushbuttonOk.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg")) + + pushbuttonNo = msgBox.addButton("Cancel", QMessageBox.NoRole) + pushbuttonNo.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg")) + + msgBox.setDefaultButton(pushbuttonOk) + msgBox.setWindowIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")) msgBox.setTextFormat(Qt.RichText) msgBox.exec_() - if msgBox.clickedButton().text() == "&OK": + if msgBox.clickedButton() == pushbuttonOk: if self._bg_thread.isRunning(): self._bg_thread.quit() del self._bg_thread @@ -431,7 +413,7 @@ def open_project(self): ) self.update_widgets() - self._project.save() + # self._project.save() @logging_decorator def show_project(self): @@ -455,18 +437,19 @@ def close_project(self): msgBox.setText( "Are you sure to close current project and open new one?.
All existing project properties will be lost!", ) - msgBox.addButton(QMessageBox.Ok).setIcon( - QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg") - ) - msgBox.addButton(QMessageBox.Cancel).setIcon( - QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg") - ) - msgBox.setDefaultButton(QMessageBox.Ok) + pushbuttonOk = msgBox.addButton("OK", QMessageBox.YesRole) + pushbuttonOk.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg")) + + pushbuttonNo = msgBox.addButton("Cancel", QMessageBox.NoRole) + pushbuttonNo.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg")) + + msgBox.setDefaultButton(pushbuttonOk) + msgBox.setWindowIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")) msgBox.setTextFormat(Qt.RichText) msgBox.exec_() - if msgBox.clickedButton().text() == "&OK": + if msgBox.clickedButton() == pushbuttonOk: self._project = Project() self.update_widgets() @@ -481,20 +464,21 @@ def start_batch_process(self): msgBox.setText( f"Following Output Folder doesnt not exit?.
{self._project.output}
Do You want to create it now?", ) - msgBox.addButton(QMessageBox.Ok).setIcon( - QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg") - ) - msgBox.addButton(QMessageBox.Cancel).setIcon( - QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg") - ) + pushbuttonOk = msgBox.addButton("OK", QMessageBox.YesRole) + pushbuttonOk.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg")) + + pushbuttonNo = msgBox.addButton("Cancel", QMessageBox.NoRole) + pushbuttonNo.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg")) + + msgBox.setDefaultButton(pushbuttonOk) + msgBox.setWindowIcon( QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg") ) - msgBox.setDefaultButton(QMessageBox.Ok) msgBox.setTextFormat(Qt.RichText) msgBox.exec_() - if msgBox.clickedButton().text() == "&OK": + if msgBox.clickedButton() == pushbuttonOk: os.mkdir(self._project.output) else: return @@ -513,20 +497,21 @@ def start_batch_process(self): msgBox.setText( "ZIP File not found. Please check your project configurations?", ) - msgBox.addButton(QMessageBox.Ok).setIcon( - QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg") - ) - msgBox.addButton(QMessageBox.Cancel).setIcon( - QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg") - ) + pushbuttonOk = msgBox.addButton("OK", QMessageBox.YesRole) + pushbuttonOk.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg")) + + pushbuttonNo = msgBox.addButton("Cancel", QMessageBox.NoRole) + pushbuttonNo.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg")) + + msgBox.setDefaultButton(pushbuttonOk) + msgBox.setWindowIcon( QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg") ) - msgBox.setDefaultButton(QMessageBox.Ok) msgBox.setTextFormat(Qt.RichText) msgBox.exec_() - if msgBox.clickedButton().text() == "&OK": + if msgBox.clickedButton() == pushbuttonOk: return self._bg_thread = QThread(parent=self) @@ -544,20 +529,21 @@ def stop_process(self) -> None: msgBox.setText( "Do you really want to Stop Crawling Thread?", ) - msgBox.addButton(QMessageBox.Ok).setIcon( - QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg") - ) - msgBox.addButton(QMessageBox.Cancel).setIcon( - QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg") - ) + pushbuttonOk = msgBox.addButton("OK", QMessageBox.YesRole) + pushbuttonOk.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg")) + + pushbuttonNo = msgBox.addButton("Cancel", QMessageBox.NoRole) + pushbuttonNo.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg")) + + msgBox.setDefaultButton(pushbuttonOk) + msgBox.setWindowIcon( QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg") ) msgBox.setTextFormat(Qt.RichText) - msgBox.setDefaultButton(QMessageBox.Ok) msgBox.exec_() - if msgBox.clickedButton().text() == "&OK": + if msgBox.clickedButton() == pushbuttonOk: self._bg_worker.stop_calcualations() self.update_statusbar("Stoping Processing", 100) @@ -669,18 +655,19 @@ def delete_github_repository(self) -> None: msgBox.setText( f"Do you really want to delete {self._project.gh_repo} on GitHub?
This deletion is not reversible.", ) - msgBox.addButton(QMessageBox.Ok).setIcon( - QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg") - ) - msgBox.addButton(QMessageBox.Cancel).setIcon( - QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg") - ) - msgBox.setDefaultButton(QMessageBox.Ok) + pushbuttonOk = msgBox.addButton("OK", QMessageBox.YesRole) + pushbuttonOk.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg")) + + pushbuttonNo = msgBox.addButton("Cancel", QMessageBox.NoRole) + pushbuttonNo.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg")) + + msgBox.setDefaultButton(pushbuttonOk) + msgBox.setWindowIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")) msgBox.setTextFormat(Qt.RichText) msgBox.exec_() - if msgBox.clickedButton().text() == "&OK": + if msgBox.clickedButton() == pushbuttonOk: if self._bg_thread.isRunning(): self._bg_thread.quit() diff --git a/src/staticwordpress/gui/project.py b/src/staticwordpress/gui/project.py index 304ae2a..5afdffe 100644 --- a/src/staticwordpress/gui/project.py +++ b/src/staticwordpress/gui/project.py @@ -71,6 +71,7 @@ ) from ..core.utils import is_url_valid +from ..gui.workflow import WorkflowGUI # +++++++++++++++++++++++++++++++++++++++++++++++++++++ # IMPLEMENATIONS @@ -84,6 +85,9 @@ def __init__(self, parent, project_, title_="Project Settings"): CONFIGS["APPLICATION_NAME"], CONFIGS["APPLICATION_NAME"] ) + self._bg_thread = QThread(parent=self) + self._bg_worker = WorkflowGUI() + self._project = project_ vertical_layout_project = QVBoxLayout() groupbox_general_settings = QGroupBox("General Settings") @@ -231,6 +235,7 @@ def __init__(self, parent, project_, title_="Project Settings"): self.toolbutton_output_sitemap.setIcon( QIcon(f"{SHARE_FOLDER_PATH}/icons/search.svg") ) + self.toolbutton_output_sitemap.clicked.connect(self.get_sitemap_location) horizontal_Layout_sitemap.addWidget(self.lineedit_sitemap) horizontal_Layout_sitemap.addWidget(self.toolbutton_output_sitemap) form_layout_static_website_properties.addRow( @@ -379,6 +384,22 @@ def get_output_directory(self): self.lineedit_output.setText(output_directory) self.appConfigurations.setValue("last-project", output_directory) + def get_sitemap_location(self): + if self._bg_thread.isRunning(): + self._bg_thread.quit() + + self._bg_thread = QThread(parent=self) + self._bg_worker = WorkflowGUI() + self._bg_worker.set_project(project_=self._project) + 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.signalSitemapLocation.connect(self.update_sitemap_location) + self._bg_thread.start() + + def update_sitemap_location(self, sitemap_location): + self.lineedit_sitemap.setText(sitemap_location) + def check_project(self): """""" # TODO: Add checks for WP_API and Gh_API and if not present then disable them. @@ -413,8 +434,22 @@ def check_project(self): f"background-color: {CONFIGS['COLOR']['ERROR']}" ) + def reject(self) -> None: + if self._bg_thread.isRunning(): + self._bg_thread.quit() + del self._bg_thread + del self._bg_worker + + return super().reject() + def accept(self) -> None: """""" + + if self._bg_thread.isRunning(): + self._bg_thread.quit() + del self._bg_thread + del self._bg_worker + if all( [ self.lineedit_project_name.text(),