diff --git a/builder/pyinstaller_build_ubuntu_gui.py b/builder/pyinstaller_build_ubuntu_gui.py index 97bb9f25..4f8293db 100644 --- a/builder/pyinstaller_build_ubuntu_gui.py +++ b/builder/pyinstaller_build_ubuntu_gui.py @@ -40,6 +40,6 @@ # "--onedir", "--onefile", "--windowed", - str(package_folder / "dicogis.py"), + str(package_folder.joinpath("ui/main.py")), ] ) diff --git a/builder/pyinstaller_build_windows_gui.py b/builder/pyinstaller_build_windows_gui.py index 5da0b266..ec498137 100644 --- a/builder/pyinstaller_build_windows_gui.py +++ b/builder/pyinstaller_build_windows_gui.py @@ -42,6 +42,6 @@ "--onefile", "--version-file={}".format("version_info.txt"), "--windowed", - str(package_folder / "dicogis.py"), + str(package_folder.joinpath("ui/main.py")), ] ) diff --git a/dicogis/cli/main.py b/dicogis/cli/main.py index 6701f1f6..9de12ca6 100644 --- a/dicogis/cli/main.py +++ b/dicogis/cli/main.py @@ -19,7 +19,7 @@ # ########## Globals ############### # ################################## -cli_dicogis = typer.Typer() +dicogis_cli = typer.Typer() state = {"verbose": False} APP_NAME = __title__ logger = logging.getLogger(__name__) @@ -43,7 +43,7 @@ def version_callback(value: bool): raise typer.Exit() -@cli_dicogis.callback() +@dicogis_cli.callback() def main( verbose: Annotated[ bool, @@ -76,7 +76,7 @@ def main( # integrate subcommands -cli_dicogis.add_typer(cli_list, name="list") +dicogis_cli.add_typer(cli_list, name="list") # ############################################################################ @@ -84,4 +84,4 @@ def main( # ################################# if __name__ == "__main__": """standalone execution""" - cli_dicogis() + dicogis_cli() diff --git a/dicogis/ui/main.py b/dicogis/ui/main.py new file mode 100644 index 00000000..97dfddf9 --- /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 dicogis_gui(): + """Launch DicoGIS GUI.""" + # 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""" + dicogis_gui() 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/docs/development/ubuntu.md b/docs/development/ubuntu.md index 5718fb07..35ee3e96 100644 --- a/docs/development/ubuntu.md +++ b/docs/development/ubuntu.md @@ -134,7 +134,9 @@ dicogis-cli --help GUI: ```sh -python dicogis/dicogis.py +dicogis-gui +# or +python dicogis/ui/main.py ``` ## Install git hooks diff --git a/docs/development/windows.md b/docs/development/windows.md index 10322dec..a50adee2 100644 --- a/docs/development/windows.md +++ b/docs/development/windows.md @@ -70,7 +70,9 @@ dicogis-cli --help GUI: ```sh -python dicogis/dicogis.py +dicogis-gui +# or +python dicogis/ui/main.py ``` ## Install git hooks diff --git a/setup.py b/setup.py index 6d62b4c7..9ae5d215 100644 --- a/setup.py +++ b/setup.py @@ -80,7 +80,7 @@ def load_requirements(requirements_files: Path | list[Path]) -> list: ), include_package_data=True, # dependencies - python_requires=">=3.9, <4", + python_requires=">=3.10, <4", extras_require={ "dev": load_requirements(HERE / "requirements/development.txt"), "doc": load_requirements(HERE / "requirements/documentation.txt"), @@ -91,10 +91,10 @@ def load_requirements(requirements_files: Path | list[Path]) -> list: # run entry_points={ "console_scripts": [ - f"{__about__.__package_name__}-cli = dicogis.cli.main:cli_dicogis" + f"{__about__.__package_name__}-cli = dicogis.cli.main:dicogis_cli" ], "gui_scripts": [ - "dicogis = dicogis.DicoGIS:__main__", + f"{__about__.__package_name__}-gui = dicogis.ui.main:dicogis_gui", ], }, # metadata @@ -103,15 +103,16 @@ def load_requirements(requirements_files: Path | list[Path]) -> list: "Intended Audience :: End Users/Desktop", "Intended Audience :: Information Technology", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: CPython", "Development Status :: 5 - Production/Stable", "Environment :: Win32 (MS Windows)", "License :: OSI Approved :: Apache Software License 2.0", "Operating System :: OS Independent", "Operating System :: Microsoft :: Windows :: Windows 10", + "Operating System :: Microsoft :: Windows :: Windows 11", "Topic :: Scientific/Engineering :: GIS", ], )