From 2b05c54d8cad5b2baa37b960a445f23e5f15d48b Mon Sep 17 00:00:00 2001 From: "Julien M." Date: Wed, 20 Mar 2024 17:23:04 +0100 Subject: [PATCH] refacto: move GUI main windows in a separate folder and change setuptools gui_scrip --- dicogis/ui/main.py | 108 +++++++++++++++++++++ dicogis/{dicogis.py => ui/main_windows.py} | 0 setup.py | 2 +- 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 dicogis/ui/main.py rename dicogis/{dicogis.py => ui/main_windows.py} (100%) diff --git a/dicogis/ui/main.py b/dicogis/ui/main.py new file mode 100644 index 00000000..956bd34b --- /dev/null +++ b/dicogis/ui/main.py @@ -0,0 +1,108 @@ +#! python3 # noqa: E265 + + +""" + DicoGIS + Automatize the creation of a dictionnary of geographic data + contained in a folders structures. + It produces an Excel output file (.xlsx) + + Julien Moura (@geojulien) +""" + +# ############################################################################## +# ########## Libraries ############# +# ################################## + +# standard library +import logging +import sys +from logging.handlers import RotatingFileHandler +from os import getenv +from sys import platform as opersys + +# GUI +from tkinter import TkVersion + +# Project +from dicogis.ui.main_windows import DicoGIS + +# ############################################################################## +# ############ Globals ############ +# ################################# + + +logger = logging.getLogger("DicoGIS") + +# ############################################################################## +# ############ Functions ########### +# ################################## + + +def main_gui_launcher(): + # LOG + + logging.captureWarnings(True) + logger.setLevel(logging.DEBUG) # all errors will be get + log_form = logging.Formatter( + "%(asctime)s || %(levelname)s " + "|| %(module)s - %(lineno)d ||" + " %(funcName)s || %(message)s" + ) + logfile = RotatingFileHandler("LOG_DicoGIS.log", "a", 5000000, 1) + logfile.setLevel(logging.DEBUG) + logfile.setFormatter(log_form) + logger.addHandler(logfile) + + # 3rd party + # condition import + if opersys == "linux": + import distro + + # check Tk version + logger.info(f"{TkVersion=}") + if TkVersion < 8.6: + logger.critical("DicoGIS requires Tkversion >= 8.6.") + sys.exit(1) + + # determine theme depending on operating system and distro + theme = "arc" + if theme_from_env := getenv("DICOGIS_UI_THEME"): + theme = theme_from_env + elif opersys == "darwin": + theme = "breeze" + elif opersys == "linux": + theme = "radiance" + if distro.name().lower() == "ubuntu": + theme = "yaru" + elif opersys == "win32": + theme = "breeze" + else: + logger.warning( + f"Your platform/operating system is not recognized: {opersys}. " + "It may lead to some strange behavior or buggy events." + ) + + logger.info(f"Used theme: {theme}") + + # launch the main UI + try: + app = DicoGIS(theme=theme) + app.set_theme(theme_name=theme) + except Exception as err: + logger.critical( + "Launching DicoGIS UI failed. Did you install the system " + f"requirements? Trace: {err}" + ) + raise (err) + + app.mainloop() + + +# ############################################################################ +# #### Stand alone program ######## +# ################################# + +if __name__ == "__main__": + """standalone execution""" + main_gui_launcher() diff --git a/dicogis/dicogis.py b/dicogis/ui/main_windows.py similarity index 100% rename from dicogis/dicogis.py rename to dicogis/ui/main_windows.py diff --git a/setup.py b/setup.py index 6d62b4c7..6cfa84ef 100644 --- a/setup.py +++ b/setup.py @@ -94,7 +94,7 @@ def load_requirements(requirements_files: Path | list[Path]) -> list: f"{__about__.__package_name__}-cli = dicogis.cli.main:cli_dicogis" ], "gui_scripts": [ - "dicogis = dicogis.DicoGIS:__main__", + f"{__about__.__package_name__}-gui = dicogis.ui.main:main_gui_launcher", ], }, # metadata