Skip to content

Commit

Permalink
New layout for plugin setup screen still WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexeh committed Feb 21, 2024
1 parent 7fb877a commit 9ecb8f3
Show file tree
Hide file tree
Showing 12 changed files with 557 additions and 414 deletions.
1 change: 1 addition & 0 deletions joystick_diagrams/app_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __new__(cls, *args, **kwargs):
def _init(self, plugin_manager: ParserPluginManager) -> None:
self.plugin_manager: ParserPluginManager = plugin_manager

self.main_window = None
# Profile map for Plugin Profiles for lookups
self.plugin_profile_map: dict[str, Profile_] = {}

Expand Down
53 changes: 41 additions & 12 deletions joystick_diagrams/plugin_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
@dataclass
class PluginWrapper:
plugin: PluginInterface
_enabled: bool = field(init=False)
_enabled: bool = False
ready: bool = False
plugin_profile_collection: ProfileCollection = field(init=False)
error: str = field(default_factory=str)

def __post_init__(self):
self.plugin_profile_collection = None
self._enabled = False
self.ready = False
self.setup_plugin()

# @handle_bare_exception
Expand All @@ -39,19 +39,34 @@ def process(self):

except JoystickDiagramsError as e:
_logger.error(e)
self.push_error(e)

def push_error(self, error: str):
self.error = ""
self.error = error

# @handle_bare_exception
def set_path(self, path: Path) -> bool:
"""Sets the path for a given plugin"""
try:
path_set = self.plugin.set_path(path)
self.ready = True if path_set else False
return self.ready
self.set_ready(path_set)
return path_set
except JoystickDiagramsError as e:
_logger.error(e)
self.set_ready(False)
self.push_error(str(e))

return False

def disable_plugin(self):
self.errors = ""
self.ready = False
self.push_error("Plugin is disabled")

def enable_plugin(self):
self.setup_plugin_path()

# @handle_bare_exception
def setup_plugin(self):
"""Sets up a pluging on first use or restores existing state"""
Expand All @@ -60,10 +75,10 @@ def setup_plugin(self):
# Load the plugins own settings
self.plugin.load_settings()

if not self.plugin.path:
self.push_error("Plugin has not been setup")
# Call the set_path to initialise the plugin correctly
if self.plugin.path:
path_set = self.set_path(self.plugin.path)
self.ready = True if path_set else False
self.setup_plugin_path()

# Retrieve stored state for the PluginWrapper
existing_configuration = self.get_plugin_configuration(self.plugin.name)
Expand All @@ -76,6 +91,14 @@ def setup_plugin(self):
except JoystickDiagramsError as e:
_logger.error(e)

def setup_plugin_path(self):
if self.plugin.path:
path_set = self.set_path(self.plugin.path)
self.set_ready(path_set)

def set_ready(self, state: bool):
self.ready = True if state else False

def get_plugin_configuration(self, plugin_name: str):
return db_plugin_data.get_plugin_configuration(plugin_name)

Expand Down Expand Up @@ -104,12 +127,18 @@ def path_type(self):

@property
def enabled(self) -> bool:
return self._enabled
return bool(self._enabled)

@enabled.setter
def enabled(self, value):
self._enabled = False if isinstance(value, property) else bool(value)
# TODO process the plugins syncronously on enable
# if self._enabled is True:
# self.process()

if self._enabled is True:
self.enable_plugin()

if self._enabled is False:
self.disable_plugin()

self.store_plugin_configuration()
print(self)
return self.enabled
4 changes: 1 addition & 3 deletions joystick_diagrams/profile_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,4 @@ def profile_key(self):


if __name__ == "__main__":
prof = Profile_("Test")

print(dict(prof))
pass
3 changes: 3 additions & 0 deletions joystick_diagrams/ui/device_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ def return_top_level_icon_state(
child_item = QTreeWidgetItem()
child_item.setData(0, Qt.ItemDataRole.UserRole, child)
child_item.setText(1, child.profile_wrapper.profile_name)
child_item.setIcon(
1, QIcon(child.profile_wrapper.profile_origin.icon)
)

# Add export option for child
child_item.setCheckState(0, Qt.CheckState.Unchecked)
Expand Down
39 changes: 33 additions & 6 deletions joystick_diagrams/ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

import qtawesome as qta # type: ignore
from PySide6.QtCore import QSize
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import (
QMainWindow,
)
from PySide6.QtGui import QAction, QDesktopServices, QIcon
from PySide6.QtWidgets import QMainWindow, QMenu

from joystick_diagrams import version
from joystick_diagrams.app_state import AppState
from joystick_diagrams.ui import configure_page, export_page, setting_page
from joystick_diagrams.ui import configure_page, export_page, plugins_page
from joystick_diagrams.ui.qt_designer import main_window
from joystick_diagrams.utils import install_root

Expand All @@ -27,6 +25,8 @@ def __init__(self, *args, **kwargs):
self.setupUi(self)
self.appState = AppState()

self.appState.main_window = self

window_icon = QIcon(JD_ICON)
self.setWindowIcon(window_icon)

Expand All @@ -35,6 +35,27 @@ def __init__(self, *args, **kwargs):
self.exportSectionButton.clicked.connect(self.load_export_page)
self.window_content = None

# Menu Bars

## Menu Icons
discord_icon = qta.icon("fa5b.discord", color="white")
web_icon = qta.icon("fa5s.globe", color="white")

# Menus
self.help_menu = QMenu("Help", self.menubar)

## Menu Actions
self.discord_link = QAction(discord_icon, "Visit our Discord")
self.help_menu.addAction(self.discord_link)

self.website_link = QAction(web_icon, "Visit our Website")
self.help_menu.addAction(self.website_link)

self.discord_link.triggered.connect(self.open_discord_link)
self.website_link.triggered.connect(self.open_website_link)

self.menubar.addMenu(self.help_menu)

# Plugins Menu Controls

# TODO move this out into styles
Expand Down Expand Up @@ -81,12 +102,18 @@ def __init__(self, *args, **kwargs):
# Window Setup
self.setWindowTitle(f"Joystick Diagrams - {version.get_current_version()}")

def open_discord_link(self):
QDesktopServices.openUrl("https://discord.gg/UUyRUuX2dX")

def open_website_link(self):
QDesktopServices.openUrl("https://joystick-diagrams.com")

def load_setting_widget(self):
self.setupSectionButton.setChecked(True)

if self.window_content:
self.window_content.hide()
self.window_content = setting_page.PluginsPage()
self.window_content = plugins_page.PluginsPage()
self.horizontalLayout_2.addWidget(self.window_content)
self.window_content.show()

Expand Down
157 changes: 0 additions & 157 deletions joystick_diagrams/ui/plugin_settings.py

This file was deleted.

Loading

0 comments on commit 9ecb8f3

Please sign in to comment.