-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
116 lines (95 loc) · 3.56 KB
/
main.py
File metadata and controls
116 lines (95 loc) · 3.56 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# main.py
import tkinter as tk
import platform
import sys
import os
from pathlib import Path
from ui_controller import UIController
from logger_config import logger, setup_logger
# Version metadata
__version__ = '1.0.0'
__description__ = 'Linux Command Builder - GUI for generating Linux shell commands'
__author__ = 'Crenta'
def check_minimum_python():
"""Ensure minimum Python version"""
if sys.version_info < (3, 8):
import tkinter.messagebox as messagebox
messagebox.showerror(
"Python Version Error",
f"This app requires Python 3.8+\nYou have {sys.version}"
)
sys.exit(1)
def get_resource_path(relative_path):
"""Get absolute path to bundled resource"""
try:
base_path = Path(sys._MEIPASS)
except AttributeError:
base_path = Path(__file__).parent
return base_path / relative_path
def get_data_dir():
"""Get persistent user data directory"""
if getattr(sys, 'frozen', False):
if sys.platform == 'win32':
data_dir = Path.home() / 'AppData' / 'Local' / 'LinuxCommander'
elif sys.platform == 'darwin':
data_dir = Path.home() / 'Library' / 'Application Support' / 'LinuxCommander'
else:
data_dir = Path.home() / '.local' / 'share' / 'LinuxCommander'
else:
data_dir = Path(__file__).parent
data_dir.mkdir(parents=True, exist_ok=True)
return data_dir
def main():
# Check Python version first
check_minimum_python()
# Setup logging with file output
data_dir = get_data_dir()
log_file = data_dir / 'app.log'
# Check for debug mode
debug_mode = os.getenv('DEBUG', '').lower() in ('1', 'true', 'yes')
# Reinitialize logger with file output
import logging
setup_logger(
name="LinuxCommander",
log_file=str(log_file),
level=logging.DEBUG if debug_mode else logging.INFO
)
logger.info(f"Starting Linux Command Builder v{__version__}")
logger.info(f"Python version: {sys.version}")
logger.info(f"Platform: {platform.system()}")
logger.info(f"Data directory: {data_dir}")
if debug_mode:
logger.debug("DEBUG MODE ENABLED")
logger.debug(f"Log file: {log_file}")
# Windows taskbar icon fix
if platform.system() == "Windows":
try:
import ctypes
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(
"lcommander.app.1.0"
)
except Exception as e:
logger.warning(f"Could not set Windows taskbar icon: {e}")
# Setup paths
bundled_commands = get_resource_path("commands")
user_commands = data_dir / "commands"
logo_path = get_resource_path("LOGO.png")
logger.debug(f"Bundled commands: {bundled_commands}")
logger.debug(f"User commands: {user_commands}")
logger.debug(f"Logo path: {logo_path}")
# Launch app
try:
root = tk.Tk()
if debug_mode:
# Show widget boundaries in debug mode
root.config(highlightthickness=2, highlightcolor="red")
app = UIController(root, user_commands, bundled_commands, logo_path)
logger.info("Application initialized successfully")
root.mainloop()
except Exception as e:
logger.exception("Fatal error during application startup")
raise
finally:
logger.info("Application shutdown")
if __name__ == "__main__":
main()