-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
145 lines (117 loc) · 4.73 KB
/
Copy pathapp.py
File metadata and controls
145 lines (117 loc) · 4.73 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""Script Manager Application - Main entry point."""
import os
import sys
import platform
from PyQt6.QtWidgets import QApplication
from PyQt6.QtCore import Qt
# Import platform utilities
from core.platform_utils import (
is_bundled, get_bundle_dir, get_app_data_dir,
ensure_data_dir, copy_default_config
)
# Import services and models
from models.script_model import ScriptModel
from models.repository import Repository
from core.config_service import ConfigService
from core.path_detection_service import PathDetectionService
from core.deployment_service import DeploymentService
from core.import_export_service import ImportExportService
from services.python_service import PythonService
from services.wps_service import WpsService
from services.js_service import JsService
from services.dependency_service import DependencyService
from ui.main_window import MainWindow
from ui.system_tray import SystemTray
from ui.theme import APP_STYLESHEET
def main():
"""Main application entry point.
This function:
1. Initializes QApplication
2. Sets up application paths (handles PyInstaller bundle and cross-platform)
3. Initializes all services
4. Shows MainWindow
5. Runs the application main loop
"""
# Create QApplication
app = QApplication(sys.argv)
app.setApplicationName("ScriptNexus")
app.setOrganizationName("ScriptNexus")
app.setStyleSheet(APP_STYLESHEET)
# Determine base and data directories
# - base_dir: Read-only resources (templates, icons)
# - data_dir: Writable user data (config, database)
if is_bundled():
# PyInstaller bundled mode
base_dir = get_bundle_dir()
data_dir = get_app_data_dir()
# Ensure data directory exists
ensure_data_dir()
# Copy default config if not exists
copy_default_config()
# In bundled mode, scripts go in data_dir
scripts_dir = os.path.join(data_dir, 'scripts')
else:
# Development mode
base_dir = os.path.dirname(os.path.abspath(__file__))
data_dir = os.path.join(base_dir, 'data')
# In development mode, scripts are in project root
scripts_dir = os.path.join(base_dir, 'scripts')
whl_pool_dir = os.path.join(data_dir, 'whl_pool')
templates_dir = os.path.join(base_dir, 'templates')
# Ensure writable directories exist
for directory in [scripts_dir, whl_pool_dir]:
if not os.path.exists(directory):
os.makedirs(directory, exist_ok=True)
# Database and config paths (in writable data_dir)
db_path = os.path.join(data_dir, 'scripts.db')
config_path = os.path.join(data_dir, 'config.json')
# Initialize Repository and ScriptModel
repository = Repository(db_path)
script_model = ScriptModel(db_path)
script_model.create_tables()
# Initialize ConfigService
config_service = ConfigService(config_path)
config_service.load()
# Initialize PathDetectionService
path_detection_service = PathDetectionService()
# Initialize PythonService
python_service = PythonService(db_path)
python_service.set_scripts_dir(scripts_dir)
# Initialize WpsService
wps_service = WpsService(db_path)
wps_service.set_paths(
templates_dir=templates_dir,
word_startup=config_service.get('paths.wps_word_startup'),
excel_startup=config_service.get('paths.wps_excel_startup')
)
# Initialize JsService
js_service = JsService(db_path)
chrome_bookmarks_path = config_service.get('paths.chrome_bookmarks')
if chrome_bookmarks_path:
js_service.set_chrome_path(chrome_bookmarks_path)
# Initialize DependencyService
dependency_service = DependencyService(whl_pool_dir)
dependency_service.set_python_service(python_service)
# Initialize DeploymentService with user-configured template directories
word_template_dir = config_service.get('paths.wps_word_startup')
excel_template_dir = config_service.get('paths.wps_excel_startup')
deployment_service = DeploymentService(wps_service, js_service, word_template_dir, excel_template_dir)
# Initialize ImportExportService
import_export_service = ImportExportService(
scripts_dir=scripts_dir,
config_path=config_path,
db_path=db_path,
templates_dir=templates_dir
)
# Show main window
main_window = MainWindow()
main_window.set_services(path_detection_service, config_service, deployment_service)
main_window.import_export_service = import_export_service
main_window.set_paths(scripts_dir, whl_pool_dir, templates_dir, db_path)
main_window.show()
# Keep reference to prevent garbage collection
app.main_window = main_window
# Run the application main loop
sys.exit(app.exec())
if __name__ == '__main__':
main()