From 64c9a96491c57812962c58d8edf66f2cf0f225b4 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Sun, 28 Mar 2021 23:01:58 +0200 Subject: [PATCH] Split main.py to separate packages and classes --- .gitignore | 3 ++- app/LauncherApplication.py | 18 ++++++++++++++++++ app/Version.py | 7 +++++++ app/__init__.py | 0 app/{main.py => webview_api/WebviewApi.py} | 11 +---------- app/webview_api/__init__.py | 1 + 6 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 app/LauncherApplication.py create mode 100644 app/Version.py create mode 100644 app/__init__.py rename app/{main.py => webview_api/WebviewApi.py} (56%) create mode 100644 app/webview_api/__init__.py diff --git a/.gitignore b/.gitignore index 71e2f83..64f49ea 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ __pycache__ *.py[cod] -venv/ +/venv/ +/tmp/ diff --git a/app/LauncherApplication.py b/app/LauncherApplication.py new file mode 100644 index 0000000..182f5aa --- /dev/null +++ b/app/LauncherApplication.py @@ -0,0 +1,18 @@ +import webview + +from app.Version import Version +from app.webview_api import WebviewApi + + +class LauncherApplication: + def __init__(self, app_root): + self.webviewApi = WebviewApi() + self.window = webview.create_window(Version.get_full_name(), app_root + '/assets/index.html', js_api=self.webviewApi, min_size=(600,400)) + + def start(self): + webview.start(debug=True) + + +if __name__ == '__main__': + app = LauncherApplication('..') + app.start() diff --git a/app/Version.py b/app/Version.py new file mode 100644 index 0000000..2f5900d --- /dev/null +++ b/app/Version.py @@ -0,0 +1,7 @@ +class Version(): + app_name = 'Stardew Mod Launcher' + app_version = '0.0.1' + + @classmethod + def get_full_name(cls): + return '{} v{}'.format(cls.app_name, cls.app_version) diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/main.py b/app/webview_api/WebviewApi.py similarity index 56% rename from app/main.py rename to app/webview_api/WebviewApi.py index d7e29fa..7102434 100644 --- a/app/main.py +++ b/app/webview_api/WebviewApi.py @@ -1,10 +1,7 @@ -#!/usr/bin/env python3 - import os -import webview -class Api(): +class WebviewApi(): def hello(self): print('Received hello()!') print('Returning "meow"!') @@ -14,9 +11,3 @@ class Api(): sdv_root_dir = "/data/Games/SteamLibrary/steamapps/common/Stardew Valley" mod_list = os.listdir(sdv_root_dir + "/Mods") return mod_list - - -if __name__ == '__main__': - api = Api() - webview.create_window('Stardew Mod Launcher v0.0.1', '../assets/index.html', js_api=api, min_size=(600,400)) - webview.start(debug=True) diff --git a/app/webview_api/__init__.py b/app/webview_api/__init__.py new file mode 100644 index 0000000..3a00e76 --- /dev/null +++ b/app/webview_api/__init__.py @@ -0,0 +1 @@ +from .WebviewApi import WebviewApi