Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed New Project Dialog #44

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 65 additions & 78 deletions src/staticwordpress/gui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,44 +209,24 @@ def clean_output_directory(self):
msgBox.setText(
f"Existing content in Output folder will be delete?<br> {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):
Expand Down Expand Up @@ -278,18 +258,20 @@ def closeEvent(self, event):
msgBox.setText(
"Do you really want to exit?.<br>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
Expand Down Expand Up @@ -431,7 +413,7 @@ def open_project(self):
)

self.update_widgets()
self._project.save()
# self._project.save()

@logging_decorator
def show_project(self):
Expand All @@ -455,18 +437,19 @@ def close_project(self):
msgBox.setText(
"Are you sure to close current project and open new one?.<br>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()

Expand All @@ -481,20 +464,21 @@ def start_batch_process(self):
msgBox.setText(
f"Following Output Folder doesnt not exit?.<br>{self._project.output}<br>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
Expand All @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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?<br>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()

Expand Down
35 changes: 35 additions & 0 deletions src/staticwordpress/gui/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
)

from ..core.utils import is_url_valid
from ..gui.workflow import WorkflowGUI

# +++++++++++++++++++++++++++++++++++++++++++++++++++++
# IMPLEMENATIONS
Expand All @@ -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")
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
Expand Down
Loading