Skip to content

Commit

Permalink
Clean up for missing templates for devices. Styling fix for export pa…
Browse files Browse the repository at this point in the history
…th length. Removed redundant rc file. Run button updates based off thread
  • Loading branch information
Rexeh committed Feb 29, 2024
1 parent 3768949 commit 35b867f
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 161 deletions.
8 changes: 8 additions & 0 deletions joystick_diagrams/db/db_device_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 19 additions & 2 deletions joystick_diagrams/ui/device_setup_controller.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]:
Expand Down
7 changes: 5 additions & 2 deletions joystick_diagrams/ui/export_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}"
)
Expand Down
23 changes: 20 additions & 3 deletions joystick_diagrams/ui/plugins_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
40 changes: 31 additions & 9 deletions joystick_diagrams/ui/qt_designer/export_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -71,14 +72,30 @@ 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)

self.export_location_container.addLayout(self.verticalLayout_2)

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)

Expand All @@ -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)
Expand All @@ -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)
Expand Down
21 changes: 9 additions & 12 deletions joystick_diagrams/ui/qt_designer/export_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
108 changes: 0 additions & 108 deletions joystick_diagrams/ui/qt_designer/resources_rc.py

This file was deleted.

Loading

0 comments on commit 35b867f

Please sign in to comment.