From 35b867fcf86dca21d84f947c375a2e3fd471a53c Mon Sep 17 00:00:00 2001
From: Rob <5183487+Rexeh@users.noreply.github.com>
Date: Thu, 29 Feb 2024 10:35:26 +0000
Subject: [PATCH] Clean up for missing templates for devices. Styling fix for
export path length. Removed redundant rc file. Run button updates based off
thread
---
joystick_diagrams/db/db_device_management.py | 8 ++
.../ui/device_setup_controller.py | 21 +++-
joystick_diagrams/ui/export_page.py | 7 +-
joystick_diagrams/ui/plugins_page.py | 23 +++-
.../ui/qt_designer/export_settings.py | 40 +++++--
joystick_diagrams/ui/qt_designer/export_ui.py | 21 ++--
.../ui/qt_designer/resources_rc.py | 108 ------------------
.../ui/qt_designer/setting_page_ui.py | 12 +-
qt_ui/export_settings_ui.py | 35 ++++--
qt_ui/export_ui.py | 10 +-
qt_ui/setup_page_widget_ui.py | 8 +-
theme/custom.css | 13 ++-
12 files changed, 145 insertions(+), 161 deletions(-)
delete mode 100644 joystick_diagrams/ui/qt_designer/resources_rc.py
diff --git a/joystick_diagrams/db/db_device_management.py b/joystick_diagrams/db/db_device_management.py
index 6a02ad2..3b5a383 100644
--- a/joystick_diagrams/db/db_device_management.py
+++ b/joystick_diagrams/db/db_device_management.py
@@ -24,6 +24,14 @@ def get_device_templates() -> list:
return cur.fetchall()
+def remove_template_path_from_device(guid: str):
+ path = os.path.join(os.getcwd(), DB_DIR, DB_NAME)
+ connection = connect(path)
+ cur = connection.cursor()
+ cur.execute("UPDATE devices SET template_path = NULL WHERE guid = ?", (guid,))
+ connection.commit()
+
+
def add_update_device_template_path(guid: str, template_path: str) -> bool:
path = os.path.join(os.getcwd(), DB_DIR, DB_NAME)
connection = connect(path)
diff --git a/joystick_diagrams/ui/device_setup_controller.py b/joystick_diagrams/ui/device_setup_controller.py
index b1a5784..ab2aa12 100644
--- a/joystick_diagrams/ui/device_setup_controller.py
+++ b/joystick_diagrams/ui/device_setup_controller.py
@@ -1,8 +1,12 @@
import logging
+from pathlib import Path
from typing import Union
from joystick_diagrams.app_state import AppState
-from joystick_diagrams.db.db_device_management import get_device_template_path
+from joystick_diagrams.db.db_device_management import (
+ get_device_template_path,
+ remove_template_path_from_device,
+)
from joystick_diagrams.exceptions import JoystickDiagramsError
from joystick_diagrams.export_device import ExportDevice
from joystick_diagrams.profile_wrapper import ProfileWrapper
@@ -45,7 +49,20 @@ def get_export_devices() -> list[ExportDevice]:
def get_template_for_device(device_guid: str) -> Union[Template, None]:
"""Retrieves a device template from storage"""
template = get_device_template_path(device_guid)
- return Template(template) if template else None
+
+ if not template:
+ return None
+
+ exists = Path(template).exists()
+
+ if not exists:
+ _logger.warning(
+ f"Template was retrieved for {device_guid} resulting in {template} but item doesn't exist at the path so it will be removed from database"
+ )
+ remove_template_path_from_device(device_guid)
+ return None
+
+ return Template(template)
def get_processed_profiles() -> list[ProfileWrapper]:
diff --git a/joystick_diagrams/ui/export_page.py b/joystick_diagrams/ui/export_page.py
index 1710b89..ec15d9b 100644
--- a/joystick_diagrams/ui/export_page.py
+++ b/joystick_diagrams/ui/export_page.py
@@ -5,6 +5,7 @@
import qtawesome as qta # type: ignore
from PySide6.QtCore import QObject, QRunnable, QSize, Qt, QThreadPool, Signal, Slot
+from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QFileDialog, QMainWindow, QMessageBox, QTreeWidgetItem
from joystick_diagrams.app_state import AppState
@@ -13,7 +14,7 @@
)
from joystick_diagrams.export import export
from joystick_diagrams.export_device import ExportDevice
-from joystick_diagrams.ui import main_window
+from joystick_diagrams.ui import main_window, ui_consts
from joystick_diagrams.ui.device_setup import DeviceSetup
from joystick_diagrams.ui.export_settings import ExportSettings
from joystick_diagrams.ui.qt_designer import export_ui
@@ -67,6 +68,7 @@ def __init__(self, *args, **kwargs):
self.export_settings_widget = ExportSettings()
self.export_settings_container.addWidget(self.export_settings_widget)
self.export_bottom_section.setProperty("class", "export-bottom-container")
+ self.export_settings_container.setProperty("class", "export-settings-container")
# Defaults
self.update_export_button_state(0) # Set the export button state
@@ -133,7 +135,8 @@ def export_finished(self, data):
main_window_inst.statusLabel.setText("Waiting...")
msg_box = QMessageBox()
- msg_box.setWindowFlags(Qt.WindowType.FramelessWindowHint)
+ msg_box.setWindowIcon(QIcon(ui_consts.JD_ICON))
+ msg_box.setWindowTitle("Export Completed")
msg_box.setText(
f"{data} items were exported to {self.export_settings_widget.export_location}"
)
diff --git a/joystick_diagrams/ui/plugins_page.py b/joystick_diagrams/ui/plugins_page.py
index 0771252..e5fcc69 100644
--- a/joystick_diagrams/ui/plugins_page.py
+++ b/joystick_diagrams/ui/plugins_page.py
@@ -104,7 +104,7 @@ def __init__(self, *args, **kwargs):
self.installPlugin.setIcon(qta.icon("fa5s.file-import"))
self.installPlugin.setToolTip("Available in future version")
self.pluginTreeHelpLabel.setText(
- "Enable and setup the plugins you want to create diagrams for."
+ "Enable and setup the plugins you want to create diagrams for. Run the plugins when ready to begin."
)
self.runPluginsButton.setProperty("class", "run-button")
@@ -138,7 +138,10 @@ def update_run_button_state(self):
self.runPluginsButton.setEnabled(False)
if self.plugins_ready > 0:
- self.runPluginsButton.setText(f"Run {self.plugins_ready} plugins")
+ plugin_button_text = "plugins" if self.plugins_ready > 1 else "plugin"
+ self.runPluginsButton.setText(
+ f"Run {self.plugins_ready} {plugin_button_text}"
+ )
self.runPluginsButton.setEnabled(True)
else:
self.runPluginsButton.setText("No plugins ready")
@@ -389,6 +392,19 @@ def open_file_dialog(self, plugin_object: PluginWrapper) -> Path | None:
return None
+ def update_run_button_on_start(self):
+ animation = qta.Spin(self.runPluginsButton)
+ spin_icon = qta.icon(
+ "fa5s.spinner", color="white", color_active="white", animation=animation
+ )
+ self.runPluginsButton.setIconSize(QSize(35, 35))
+ self.runPluginsButton.setIcon(spin_icon)
+ self.runPluginsButton.setDisabled(True)
+
+ def update_run_button_on_finish(self):
+ self.runPluginsButton.setIcon(QIcon())
+ self.runPluginsButton.setDisabled(False)
+
def call_plugin_runner(self):
# Emit parsed 0 to update buttons
self.total_parsed_profiles.emit(0)
@@ -397,8 +413,9 @@ def call_plugin_runner(self):
# TODO handle started event/button disable
- # worker.signals.started.connect(self.lock_export_button)
+ worker.signals.started.connect(self.update_run_button_on_start)
worker.signals.finished.connect(self.calculate_total_profile_count)
+ worker.signals.finished.connect(self.update_run_button_on_finish)
worker.signals.finished.connect(self.profileCollectionChange.emit)
worker.signals.processed.connect(self.update_plugin_execute_state)
self.threadPool.start(worker)
diff --git a/joystick_diagrams/ui/qt_designer/export_settings.py b/joystick_diagrams/ui/qt_designer/export_settings.py
index 453413a..ca3b6a5 100644
--- a/joystick_diagrams/ui/qt_designer/export_settings.py
+++ b/joystick_diagrams/ui/qt_designer/export_settings.py
@@ -26,21 +26,21 @@ class Ui_Form(object):
def setupUi(self, Form):
if not Form.objectName():
Form.setObjectName("Form")
- Form.resize(500, 150)
- sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
- sizePolicy.setHorizontalStretch(0)
- sizePolicy.setVerticalStretch(0)
+ Form.resize(550, 150)
+ sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
+ sizePolicy.setHorizontalStretch(1)
+ sizePolicy.setVerticalStretch(1)
sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
Form.setSizePolicy(sizePolicy)
- Form.setMinimumSize(QSize(500, 150))
- Form.setMaximumSize(QSize(500, 150))
+ Form.setMinimumSize(QSize(550, 150))
+ Form.setMaximumSize(QSize(550, 150))
Form.setBaseSize(QSize(500, 150))
self.verticalLayoutWidget = QWidget(Form)
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
- self.verticalLayoutWidget.setGeometry(QRect(9, 9, 481, 111))
+ self.verticalLayoutWidget.setGeometry(QRect(9, 9, 531, 131))
self.verticalLayout = QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setObjectName("verticalLayout")
- self.verticalLayout.setSizeConstraint(QLayout.SetDefaultConstraint)
+ self.verticalLayout.setSizeConstraint(QLayout.SetMaximumSize)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.label = QLabel(self.verticalLayoutWidget)
self.label.setObjectName("label")
@@ -54,6 +54,7 @@ def setupUi(self, Form):
self.verticalLayout_2 = QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.verticalLayout_2.setSizeConstraint(QLayout.SetMaximumSize)
+ self.verticalLayout_2.setContentsMargins(-1, -1, 10, -1)
self.export_location_label_2 = QLabel(self.verticalLayoutWidget)
self.export_location_label_2.setObjectName("export_location_label_2")
sizePolicy1 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)
@@ -71,7 +72,15 @@ def setupUi(self, Form):
self.export_location_directory = QLabel(self.verticalLayoutWidget)
self.export_location_directory.setObjectName("export_location_directory")
+ sizePolicy2 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
+ sizePolicy2.setHorizontalStretch(0)
+ sizePolicy2.setVerticalStretch(0)
+ sizePolicy2.setHeightForWidth(
+ self.export_location_directory.sizePolicy().hasHeightForWidth()
+ )
+ self.export_location_directory.setSizePolicy(sizePolicy2)
self.export_location_directory.setWordWrap(True)
+ self.export_location_directory.setMargin(2)
self.verticalLayout_2.addWidget(self.export_location_directory)
@@ -79,6 +88,14 @@ def setupUi(self, Form):
self.setExportLocationButton = QPushButton(self.verticalLayoutWidget)
self.setExportLocationButton.setObjectName("setExportLocationButton")
+ sizePolicy3 = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Expanding)
+ sizePolicy3.setHorizontalStretch(0)
+ sizePolicy3.setVerticalStretch(0)
+ sizePolicy3.setHeightForWidth(
+ self.setExportLocationButton.sizePolicy().hasHeightForWidth()
+ )
+ self.setExportLocationButton.setSizePolicy(sizePolicy3)
+ self.setExportLocationButton.setMaximumSize(QSize(200, 100))
self.export_location_container.addWidget(self.setExportLocationButton)
@@ -96,11 +113,16 @@ def setupUi(self, Form):
self.export_format = QComboBox(self.verticalLayoutWidget)
self.export_format.addItem("")
self.export_format.setObjectName("export_format")
+ self.export_format.setMaximumSize(QSize(200, 16777215))
self.export_format_container.addWidget(self.export_format)
self.verticalLayout.addLayout(self.export_format_container)
+ self.verticalLayout.setStretch(0, 1)
+ self.verticalLayout.setStretch(1, 1)
+ self.verticalLayout.setStretch(2, 1)
+
self.retranslateUi(Form)
QMetaObject.connectSlotsByName(Form)
@@ -120,7 +142,7 @@ def retranslateUi(self, Form):
QCoreApplication.translate("Form", "Export Location", None)
)
self.export_location_directory.setText(
- QCoreApplication.translate("Form", "TextLabel", None)
+ QCoreApplication.translate("Form", "Export Path", None)
)
self.setExportLocationButton.setText(
QCoreApplication.translate("Form", "Set Location", None)
diff --git a/joystick_diagrams/ui/qt_designer/export_ui.py b/joystick_diagrams/ui/qt_designer/export_ui.py
index 5bce019..da7a9ec 100644
--- a/joystick_diagrams/ui/qt_designer/export_ui.py
+++ b/joystick_diagrams/ui/qt_designer/export_ui.py
@@ -8,15 +8,8 @@
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
-from PySide6.QtCore import (
- QCoreApplication,
- QMetaObject,
- QRect,
- QSize,
-)
-from PySide6.QtGui import (
- QFont,
-)
+from PySide6.QtCore import QCoreApplication, QMetaObject, QRect, QSize
+from PySide6.QtGui import QFont
from PySide6.QtWidgets import (
QFrame,
QHBoxLayout,
@@ -114,11 +107,12 @@ def setupUi(self, Form):
self.export_bottom_section = QHBoxLayout()
self.export_bottom_section.setObjectName("export_bottom_section")
- self.export_bottom_section.setSizeConstraint(QLayout.SetDefaultConstraint)
- self.export_bottom_section.setContentsMargins(-1, 0, -1, -1)
+ self.export_bottom_section.setSizeConstraint(QLayout.SetMaximumSize)
+ self.export_bottom_section.setContentsMargins(-1, 10, -1, 10)
self.export_settings_container = QHBoxLayout()
self.export_settings_container.setObjectName("export_settings_container")
- self.export_settings_container.setContentsMargins(-1, -1, 50, -1)
+ self.export_settings_container.setSizeConstraint(QLayout.SetMaximumSize)
+ self.export_settings_container.setContentsMargins(-1, -1, 100, -1)
self.export_bottom_section.addLayout(self.export_settings_container)
@@ -136,6 +130,9 @@ def setupUi(self, Form):
self.export_bottom_section.addWidget(self.ExportButton)
+ self.export_bottom_section.setStretch(0, 1)
+ self.export_bottom_section.setStretch(1, 1)
+
self.verticalLayout.addLayout(self.export_bottom_section)
self.retranslateUi(Form)
diff --git a/joystick_diagrams/ui/qt_designer/resources_rc.py b/joystick_diagrams/ui/qt_designer/resources_rc.py
deleted file mode 100644
index 0efa57b..0000000
--- a/joystick_diagrams/ui/qt_designer/resources_rc.py
+++ /dev/null
@@ -1,108 +0,0 @@
-# Resource object code (Python 3)
-# Created by: object code
-# Created by: The Resource Compiler for Qt version 6.6.1
-# WARNING! All changes made in this file will be lost!
-
-from PySide6 import QtCore
-
-qt_resource_data = b"\
-\x00\x00\x01\xa6\
-<\
-svg xmlns=\x22http:\
-//www.w3.org/200\
-0/svg\x22 viewBox=\x22\
-0 0 512 512\x22>
Export Settings
", None)) self.export_location_label_2.setText(QCoreApplication.translate("Form", u"Export Location", None)) - self.export_location_directory.setText(QCoreApplication.translate("Form", u"TextLabel", None)) + self.export_location_directory.setText(QCoreApplication.translate("Form", u"Export Path", None)) self.setExportLocationButton.setText(QCoreApplication.translate("Form", u"Set Location", None)) self.export_format_label.setText(QCoreApplication.translate("Form", u"Export Format", None)) self.export_format.setItemText(0, QCoreApplication.translate("Form", u"SVG", None)) diff --git a/qt_ui/export_ui.py b/qt_ui/export_ui.py index b88683e..aab1075 100644 --- a/qt_ui/export_ui.py +++ b/qt_ui/export_ui.py @@ -18,7 +18,6 @@ from PySide6.QtWidgets import (QApplication, QFrame, QHBoxLayout, QLabel, QLayout, QPushButton, QSizePolicy, QVBoxLayout, QWidget) -import resources_rc class Ui_Form(object): def setupUi(self, Form): @@ -109,11 +108,12 @@ def setupUi(self, Form): self.export_bottom_section = QHBoxLayout() self.export_bottom_section.setObjectName(u"export_bottom_section") - self.export_bottom_section.setSizeConstraint(QLayout.SetDefaultConstraint) - self.export_bottom_section.setContentsMargins(-1, 0, -1, -1) + self.export_bottom_section.setSizeConstraint(QLayout.SetMaximumSize) + self.export_bottom_section.setContentsMargins(-1, 10, -1, 10) self.export_settings_container = QHBoxLayout() self.export_settings_container.setObjectName(u"export_settings_container") - self.export_settings_container.setContentsMargins(-1, -1, 50, -1) + self.export_settings_container.setSizeConstraint(QLayout.SetMaximumSize) + self.export_settings_container.setContentsMargins(-1, -1, 100, -1) self.export_bottom_section.addLayout(self.export_settings_container) @@ -129,6 +129,8 @@ def setupUi(self, Form): self.export_bottom_section.addWidget(self.ExportButton) + self.export_bottom_section.setStretch(0, 1) + self.export_bottom_section.setStretch(1, 1) self.verticalLayout.addLayout(self.export_bottom_section) diff --git a/qt_ui/setup_page_widget_ui.py b/qt_ui/setup_page_widget_ui.py index 1a5d628..0f3a885 100644 --- a/qt_ui/setup_page_widget_ui.py +++ b/qt_ui/setup_page_widget_ui.py @@ -105,15 +105,15 @@ def setupUi(self, Form): self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setObjectName(u"horizontalLayout") + self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) + + self.horizontalLayout.addItem(self.horizontalSpacer_2) + self.runPluginsButton = QPushButton(self.verticalLayoutWidget) self.runPluginsButton.setObjectName(u"runPluginsButton") self.horizontalLayout.addWidget(self.runPluginsButton) - self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Preferred, QSizePolicy.Minimum) - - self.horizontalLayout.addItem(self.horizontalSpacer_2) - self.verticalLayout_2.addLayout(self.horizontalLayout) diff --git a/theme/custom.css b/theme/custom.css index cfa63f4..ac4bcd9 100644 --- a/theme/custom.css +++ b/theme/custom.css @@ -100,6 +100,14 @@ QWidget {{ .run-button {{ padding: 25px; + width: 500px; + margin-right: 5px; + margin-top: 10px; + border: none; +}} + +.run-button:icon {{ + color:white; }} .run-button:enabled {{ @@ -108,7 +116,7 @@ QWidget {{ }} .run-button:disabled {{ - background: #C5283D; + background: #C5283D; color: white; }} @@ -138,7 +146,8 @@ QWidget {{ .plugin-setup-button {{ background: #C5283D; - color:white + color: white; + border: none; }} .plugin-setup-button:checked {{