-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
75 lines (61 loc) · 2.38 KB
/
main.py
File metadata and controls
75 lines (61 loc) · 2.38 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
import logging
import os
import sys
APP_NAME = "Open Razer macOS Control"
LOG_FILE_BASENAME = "open_razer_macos_control_app.log"
if getattr(sys, 'frozen', False):
frameworks_dir = os.path.join(os.path.dirname(sys.executable), '..', 'Frameworks')
os.environ['DYLD_LIBRARY_PATH'] = frameworks_dir
try:
log_dir = os.path.expanduser("~/Library/Logs")
if not os.path.exists(log_dir):
os.makedirs(log_dir, exist_ok=True)
log_file = os.path.join(log_dir, LOG_FILE_BASENAME)
log_exists = os.path.exists(log_file)
except OSError:
log_dir = os.path.expanduser("~")
log_file = os.path.join(log_dir, LOG_FILE_BASENAME)
log_exists = os.path.exists(log_file)
log_mode = 'a' if log_exists else 'w'
logging.basicConfig(
filename=log_file,
filemode=log_mode,
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - [%(filename)s:%(lineno)d] - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
logging.info("="*20 + f" {APP_NAME} Started " + "="*20)
logging.info(f"Python: {sys.version}")
logging.info(f"Platform: {sys.platform}")
logging.info(f"Executable path: {sys.executable}")
logging.info(f"Arguments: {sys.argv}")
logging.info(f"Log path: {log_file}")
try:
logging.info("Importing UI modules...")
from PyQt5.QtWidgets import QApplication
from razer_ui import MainWindow
logging.info("Imports completed successfully.")
def main():
logging.info("Creating QApplication...")
app = QApplication(sys.argv)
logging.info("QApplication created.")
logging.info("Creating MainWindow from razer_ui...")
window = MainWindow()
logging.info("MainWindow created.")
window.show()
logging.info("Application window displayed.")
logging.info("Starting QApplication event loop...")
exit_code = app.exec_()
logging.info(f"Application exited with code: {exit_code}")
sys.exit(exit_code)
if __name__ == "__main__":
main()
except ImportError as import_err:
logging.critical(f"Critical import error: {import_err}. Application cannot start.", exc_info=True)
sys.exit(f"Import error: {import_err}")
except Exception as general_err:
logging.critical(f"Unexpected critical error: {general_err}", exc_info=True)
sys.exit(f"Critical error: {general_err}")
finally:
logging.info("="*20 + f" {APP_NAME} Terminated " + "="*20 + "\n")