Skip to content

Commit

Permalink
refacto: move GUI main windows in a separate folder and change setupt…
Browse files Browse the repository at this point in the history
…ools gui_scrip
  • Loading branch information
Guts committed Mar 20, 2024
1 parent c2dbef8 commit 2b05c54
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 1 deletion.
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 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()
File renamed without changes.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2b05c54

Please sign in to comment.