-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapplication.py
62 lines (47 loc) · 1.54 KB
/
application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""Application here uses PySimpleGUI."""
from __future__ import annotations
import logging
import sys
from typing import Any
from cli2gui import models
from cli2gui.application.application2args import argFormat
from cli2gui.gui import helpers
from cli2gui.gui.dearpygui_wrapper import DearPyGuiWrapper
from cli2gui.gui.pysimplegui_wrapper import PySimpleGUIWrapper
def run(buildSpec: models.FullBuildSpec) -> Any:
"""Establish the main entry point.
Args:
----
buildSpec (types.FullBuildSpec): args that customise the application such as the theme
or the function to run
"""
# Set the theme
theme = helpers.get_base24_theme(buildSpec.theme, buildSpec.darkTheme)
buildSpec.gui = buildSpec.gui.replace("pysimplegui", "psg").replace("freesimplegui", "fsg")
if buildSpec.gui in [
"psg",
"psgqt",
"psgweb",
"fsg",
# "fsgqt", # cannot test on windows
# "fsgweb", # bug in remi prevents this from working
]:
gui_wrapper = PySimpleGUIWrapper
else:
gui_wrapper = DearPyGuiWrapper
if gui_wrapper is PySimpleGUIWrapper:
gui = gui_wrapper(theme, buildSpec.gui)
elif gui_wrapper is DearPyGuiWrapper:
gui = gui_wrapper(theme)
def quit_callback() -> None:
sys.exit(0)
def run_callback(values: dict[str, Any]) -> None:
args = argFormat(values, buildSpec.parser)
if not buildSpec.run_function:
return args
buildSpec.run_function(args)
return None
try:
gui.main(buildSpec=buildSpec, quit_callback=quit_callback, run_callback=run_callback)
except KeyboardInterrupt:
logging.error("Application Exited Early!") # noqa: TRY400