From 742c1c3bfa4a99d31a07bc47365d102d37be2180 Mon Sep 17 00:00:00 2001 From: raphael60650 Date: Tue, 27 Jul 2021 21:03:30 +0200 Subject: [PATCH] moved NoGui to Game.py, moved restart from Gui.py to definition.py --- source/Game.py | 33 +++++++++++++++++++++++++++++++-- source/Gui.py | 31 ------------------------------- source/Option.py | 4 +++- source/Track.py | 1 - source/definition.py | 11 +++++++++++ 5 files changed, 45 insertions(+), 35 deletions(-) diff --git a/source/Game.py b/source/Game.py index 1eee1f8..fb88120 100644 --- a/source/Game.py +++ b/source/Game.py @@ -3,11 +3,9 @@ from PIL import Image import shutil import glob import json -import os from .CT_Config import CT_Config from .definition import * -from .Gui import NoGui from . import wszst @@ -41,6 +39,37 @@ class CantConvertTrack(Exception): super().__init__("Can't convert track, check if download are enabled.") +class NoGui: + """ + 'fake' gui if no gui are used for compatibility. + """ + class NoButton: + def grid(self, *args, **kwargs): pass + def config(self, *args, **kwargs): pass + + class NoVariable: + def __init__(self, value=None): + self.value = None + + def set(self, value): + self.value = value + + def get(self): + return self.value + + def progress(*args, **kwargs): print(args, kwargs) + def translate(*args, **kwargs): return "" + def log_error(*args, **kwargs): print(args, kwargs) + + is_dev_version = False + button_install_mod = NoButton() + stringvar_game_format = NoVariable() + boolvar_disable_download = NoVariable() + intvar_process_track = NoVariable() + boolvar_dont_check_track_sha1 = NoVariable() + boolvar_del_track_after_conv = NoVariable() + + class Game: def __init__(self, path: str = "", region_ID: str = "P", game_ID: str = "RMCP01", gui=None): """ diff --git a/source/Gui.py b/source/Gui.py index 296949a..9a6afa0 100644 --- a/source/Gui.py +++ b/source/Gui.py @@ -1,7 +1,6 @@ from distutils.version import StrictVersion from tkinter import filedialog, ttk, messagebox from tkinter import * -import subprocess import traceback import requests import zipfile @@ -16,36 +15,6 @@ with open("./translation.json", encoding="utf-8") as f: translation_dict = json.load(f) -def restart(): - """ - restart the application - """ - subprocess.Popen([sys.executable] + sys.argv, creationflags=subprocess.CREATE_NO_WINDOW, cwd=os.getcwd()) - exit() - - -class NoGui: - """ - 'fake' gui if no gui are used for compatibility. - """ - class NoButton: - def grid(self, *args, **kwargs): pass - def config(self, *args, **kwargs): pass - - def progress(*args, **kwargs): print(args, kwargs) - def translate(*args, **kwargs): return "" - def log_error(*args, **kwargs): print(args, kwargs) - def restart(self): restart() - - is_dev_version = False - button_install_mod = NoButton() - stringvar_game_format = StringVar() - boolvar_disable_download = BooleanVar() - intvar_process_track = IntVar() - boolvar_dont_check_track_sha1 = BooleanVar() - boolvar_del_track_after_conv = BooleanVar() - - class Gui: def __init__(self): """ diff --git a/source/Option.py b/source/Option.py index eb5abf8..a7f1172 100644 --- a/source/Option.py +++ b/source/Option.py @@ -1,6 +1,8 @@ import json import os +from .definition import restart + class Option: def __init__(self): @@ -28,7 +30,7 @@ class Option: else: setattr(self, option, value.get()) self.save_to_file() - if need_restart: gui.restart() + if need_restart: restart() def load_from_file(self, option_file: str = "./option.json") -> None: """ diff --git a/source/Track.py b/source/Track.py index 27ee7e3..5b7509f 100644 --- a/source/Track.py +++ b/source/Track.py @@ -1,5 +1,4 @@ import requests -import os from .definition import * from . import wszst diff --git a/source/definition.py b/source/definition.py index 592b524..3c25bf3 100644 --- a/source/definition.py +++ b/source/definition.py @@ -1,4 +1,7 @@ from threading import Thread +import subprocess +import sys +import os GITHUB_REPOSITORY = "Faraphel/MKWF-Install" GITHUB_MASTER_BRANCH = f"https://raw.githubusercontent.com/{GITHUB_REPOSITORY}/master/" @@ -94,6 +97,14 @@ region_id_to_name = { } +def restart(): + """ + restart the application + """ + subprocess.Popen([sys.executable] + sys.argv, creationflags=subprocess.CREATE_NO_WINDOW, cwd=os.getcwd()) + exit() + + def in_thread(func): """ instead of calling a function, this will start it in a thread