Skip to content

Commit

Permalink
Move DCS to plugin structure, fixed relative config sourcing
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexeh committed Jan 1, 2024
1 parent 077d0b9 commit 0a101f0
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 10 deletions.
5 changes: 2 additions & 3 deletions joystick_diagrams/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from PyQt5 import QtWidgets
from qt_material import apply_stylesheet

from joystick_diagrams.adaptors.dcs.dcs_world import DCSWorldParser
from joystick_diagrams.adaptors.joystick_gremlin.joystick_gremlin import JoystickGremlin
from joystick_diagrams.adaptors.star_citizen.star_citizen import StarCitizen
from joystick_diagrams.classes import export
Expand Down Expand Up @@ -63,8 +62,8 @@ def get_log_level():
setup_logging()
try:
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
# window = MainWindow()
# window.show()

# Load Plugins
plugins = initialise_plugins()
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions joystick_diagrams/plugins/dcs_world_plugin/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pathlib import Path

from dynaconf import Dynaconf, Validator

print(f"{Path(__file__).parent}")
settings = Dynaconf(
settings_files=[f"{Path(__file__).parent.joinpath('settings.json')}"],
)

settings.validators.register(
Validator("PLUGIN_NAME", required=True),
Validator("PLUGIN_ICON", required=True),
Validator("VERSION", required=True),
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

from ply import lex, yacc # type: ignore

# Required by PLY
import joystick_diagrams.adaptors.dcs.dcs_world_lex # pylint: disable=unused-import
import joystick_diagrams.adaptors.dcs.dcs_world_yacc # pylint: disable=unused-import

#################
import joystick_diagrams.adaptors.joystick_diagram_interface as jdi
from joystick_diagrams.input.device import Device_
from joystick_diagrams.input.profile_collection import ProfileCollection

# Required by PLY
from . import dcs_world_lex, dcs_world_yacc # pylint: disable=unused-import

_logger = logging.getLogger(__name__)

EASY_MODES = "_easy"
Expand Down
Binary file not shown.
50 changes: 50 additions & 0 deletions joystick_diagrams/plugins/dcs_world_plugin/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import logging
from pathlib import Path

from dynaconf import Dynaconf, Validator

from joystick_diagrams.input.profile_collection import ProfileCollection
from joystick_diagrams.plugins.dcs_world_plugin.dcs_world import DCSWorldParser
from joystick_diagrams.plugins.plugin_interface import PluginInterface

from .config import settings

_logger = logging.getLogger("__name__")


class ParserPlugin(PluginInterface):
def __init__(self):
self.path = None
self.settings = settings
self.settings.validators.register()

def process(self) -> ProfileCollection:
return self.instance.process_profiles()

def set_path(self, path: Path) -> bool:
self.path = path
try:
self.instance = DCSWorldParser(self.path)
except:
return False
return True

@property
def name(self) -> str:
return f"{self.settings.PLUGIN_NAME}"

@property
def version(self) -> str:
return f"{self.settings.VERSION}"

@property
def icon(self) -> str:
return f"{Path.joinpath(Path(__file__).parent,self.settings.PLUGIN_ICON)}"

@property
def get_path(self) -> bool:
return self.path


if __name__ == "__main__":
plugin = ParserPlugin()
5 changes: 5 additions & 0 deletions joystick_diagrams/plugins/dcs_world_plugin/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"PLUGIN_NAME": "DCS World",
"PLUGIN_ICON": "./img/dcs.ico",
"VERSION": "2.0.0"
}
3 changes: 2 additions & 1 deletion joystick_diagrams/plugins/examplePlugin/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import logging
from pathlib import Path

from config import settings
from dynaconf import Dynaconf, Validator

from joystick_diagrams.plugins.plugin_interface import PluginInterface

from .config import settings

_logger = logging.getLogger("__name__")


Expand Down
3 changes: 2 additions & 1 deletion joystick_diagrams/plugins/plugin_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dynaconf

import joystick_diagrams.exceptions as JDException
from joystick_diagrams.input.profile_collection import ProfileCollection


class PluginInterface(ABC):
Expand All @@ -19,7 +20,7 @@ def FileTypeInvalid(self, exceptionMessage: str):
return JDException.FileTypeInvalid(value=exceptionMessage)

@abstractmethod
def process(self) -> int:
def process(self) -> ProfileCollection:
"""
Runs the relevant processes to return an InputCollection
Expand Down
1 change: 0 additions & 1 deletion joystick_diagrams/ui/main_window/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from PyQt5 import QtCore, QtGui, QtWidgets

from joystick_diagrams.adaptors.dcs.dcs_world import DCSWorldParser
from joystick_diagrams.adaptors.joystick_gremlin.joystick_gremlin import JoystickGremlin
from joystick_diagrams.adaptors.star_citizen.star_citizen import StarCitizen
from joystick_diagrams.classes import export
Expand Down

0 comments on commit 0a101f0

Please sign in to comment.