BonPrinter v1.2.0
Thermal Printer tool
Loading...
Searching...
No Matches
app.py
Go to the documentation of this file.
1"""!
2********************************************************************************
3@file app.py
4@brief Application entry file
5********************************************************************************
6"""
7
8# autopep8: off
9import sys
10import os
11import time
12import logging
13
14sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
15from Source.version import __title__, __version__ # pylint: disable=wrong-import-position
16from Source.Util.app_data import I_LOG_LEVEL_DEFAULT, read_verbosity_settings, get_computer_name, ICON_APP # pylint: disable=wrong-import-position
17from Source.Util.app_err_handler import UncaughtHook # pylint: disable=wrong-import-position
18from Source.Util.app_log import LogConfig # pylint: disable=wrong-import-position
19from Source.Util.gui_toolkit import APPLICATION, SHARED_MEMORY, check_app_already_open, run_app, config_window, config_app # pylint: disable=wrong-import-position
20
21from Source.Controller.main_window import MainWindow # pylint: disable=wrong-import-position
22from Source.Controller.splash_screen import create_splash_screen, F_MIN_SPLASH_SCREEN_TIME # pylint: disable=wrong-import-position
23# autopep8: on
24
25log = logging.getLogger(__title__)
26
27
28def start_application(b_start_app: bool = True, test_mode: bool = False) -> tuple[APPLICATION | None, MainWindow]:
29 """!
30 @brief Start application
31 @param b_start_app : [True] start application; [False] only app initialization for pytest
32 @param test_mode : status if application run in test mode
33 @return windows and application object
34 """
35 log_config = LogConfig(I_LOG_LEVEL_DEFAULT)
36 log_config.update_log_level(read_verbosity_settings())
37 log.debug("Starting application")
38 log.debug("Running from %s", os.getcwd())
39 if test_mode:
40 log.warning("Test mode is active")
41
42 # Application
43 if b_start_app:
44 app = APPLICATION
45 else:
46 app = None
47 if app is not None:
48 my_app = app(sys.argv)
49 config_app(my_app, icon=ICON_APP) # set icon direct
50 else:
51 my_app = None
52
53 # Set custom application id to show correct icon instead of Python in the task bar
54 try:
55 from ctypes import windll # only exists on windows. # pylint: disable=import-outside-toplevel
56 app_id = __title__ + "." + __version__
57 log.debug("Setting explicit app user model id: %s", app_id)
58 windll.shell32.SetCurrentProcessExplicitAppUserModelID(app_id)
59 except ImportError:
60 pass
61
62 splash = create_splash_screen()
63
64 f_start_time = time.time()
65 config_window(splash, show=True, thread=True)
66
67 if b_start_app and (my_app is not None):
68 config_app(my_app, process_events=True)
69
70 authenticated = True
71
72 # Exception Handler
73 qt_exception_hook = UncaughtHook()
74 window = MainWindow(qt_exception_hook, log_config, test_mode=test_mode, authenticated=authenticated)
75
76 config_window(window, icon=ICON_APP) # set icon again if not set before
77 qt_exception_hook.set_main_window_controller(window)
78
79 f_inti_time = time.time() - f_start_time
80 if f_inti_time < F_MIN_SPLASH_SCREEN_TIME:
81 time.sleep(F_MIN_SPLASH_SCREEN_TIME - f_inti_time)
82
83 config_window(splash, show=False, thread=True)
84
85 return my_app, window
86
87
88if __name__ == "__main__":
89 shared_memory = SHARED_MEMORY(__title__) # need to use as global variable
90 if check_app_already_open(shared_memory):
91 sys.exit("Another instance is already running")
92 o_app, o_window = start_application()
93 run_app(o_window, o_app, close_event=True)
The view-controller for main window.
Log configuration.
Definition app_log.py:24
tuple[APPLICATION|None, MainWindow] start_application(bool b_start_app=True, bool test_mode=False)
Start application.
Definition app.py:28