Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refacto: move GUI related code in a separate module and adapt setuptools #232

Merged
merged 7 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builder/pyinstaller_build_ubuntu_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
# "--onedir",
"--onefile",
"--windowed",
str(package_folder / "dicogis.py"),
str(package_folder.joinpath("ui/main.py")),
]
)
2 changes: 1 addition & 1 deletion builder/pyinstaller_build_windows_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
"--onefile",
"--version-file={}".format("version_info.txt"),
"--windowed",
str(package_folder / "dicogis.py"),
str(package_folder.joinpath("ui/main.py")),
]
)
8 changes: 4 additions & 4 deletions dicogis/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# ########## Globals ###############
# ##################################

cli_dicogis = typer.Typer()
dicogis_cli = typer.Typer()
state = {"verbose": False}
APP_NAME = __title__
logger = logging.getLogger(__name__)
Expand All @@ -43,7 +43,7 @@ def version_callback(value: bool):
raise typer.Exit()


@cli_dicogis.callback()
@dicogis_cli.callback()
def main(
verbose: Annotated[
bool,
Expand Down Expand Up @@ -76,12 +76,12 @@ def main(


# integrate subcommands
cli_dicogis.add_typer(cli_list, name="list")
dicogis_cli.add_typer(cli_list, name="list")


# ############################################################################
# #### Stand alone program ########
# #################################
if __name__ == "__main__":
"""standalone execution"""
cli_dicogis()
dicogis_cli()
108 changes: 108 additions & 0 deletions dicogis/ui/main.py
Original file line number Diff line number Diff line change
@@ -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()
File renamed without changes.
4 changes: 3 additions & 1 deletion docs/development/ubuntu.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ dicogis-cli --help
GUI:

```sh
python dicogis/dicogis.py
dicogis-gui
# or
python dicogis/ui/main.py
```

## Install git hooks
Expand Down
4 changes: 3 additions & 1 deletion docs/development/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ dicogis-cli --help
GUI:

```sh
python dicogis/dicogis.py
dicogis-gui
# or
python dicogis/ui/main.py
```

## Install git hooks
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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
Expand All @@ -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",
],
)