-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAstroFileManager.py
More file actions
360 lines (303 loc) · 12.7 KB
/
Copy pathAstroFileManager.py
File metadata and controls
360 lines (303 loc) · 12.7 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#!/usr/bin/env python3
"""
AstroFileManager - XISF File Management for Astrophotography
A PyQt6-based application for cataloging, organizing, and managing XISF astrophotography files.
"""
import sys
from typing import Any
from PyQt6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QTabWidget, QMessageBox
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QAction
# Import constants
from constants import (
TEMP_TOLERANCE_DARKS, TEMP_TOLERANCE_FLATS, TEMP_TOLERANCE_BIAS,
EXPOSURE_TOLERANCE, MIN_FRAMES_RECOMMENDED, MIN_FRAMES_ACCEPTABLE,
IMPORT_BATCH_SIZE, DATE_OFFSET_HOURS, __VERSION__
)
# Import core business logic modules
from core.database import DatabaseManager
from core.calibration import CalibrationMatcher
from core.config_manager import ConfigManager
# Import UI modules
from ui.import_tab import ImportTab
from ui.settings_tab import SettingsTab
from ui.maintenance_tab import MaintenanceTab
from ui.sessions_tab import SessionsTab
from ui.analytics_tab import AnalyticsTab
from ui.view_catalog_tab import ViewCatalogTab
from ui.projects_tab import ProjectsTab
from ui.update_dialog import UpdateDialog
class XISFCatalogGUI(QMainWindow):
def __init__(self) -> None:
super().__init__()
self.db_path = 'xisf_catalog.db'
self.settings = ConfigManager('AstroFileManager', 'AstroFileManager')
# Initialize core business logic components
self.db = DatabaseManager(self.db_path)
self.calibration = CalibrationMatcher(
self.db,
include_masters=True,
temp_tolerance_darks=TEMP_TOLERANCE_DARKS,
temp_tolerance_flats=TEMP_TOLERANCE_FLATS,
temp_tolerance_bias=TEMP_TOLERANCE_BIAS,
exposure_tolerance=EXPOSURE_TOLERANCE,
min_frames_recommended=MIN_FRAMES_RECOMMENDED,
min_frames_acceptable=MIN_FRAMES_ACCEPTABLE
)
self.init_ui()
# Restore settings after all UI is created
self.restore_settings()
# Populate the View Catalog tab on startup (fixes Issue #44)
self.view_tab.refresh_catalog_view()
def init_ui(self) -> None:
"""Initialize the user interface"""
self.setWindowTitle('AstroFileManager')
self.setGeometry(100, 100, 1000, 600)
# Create menu bar
self.create_menu_bar()
# Create central widget and main layout
central_widget = QWidget()
self.setCentralWidget(central_widget)
layout = QVBoxLayout(central_widget)
# Create tab widget
tabs = QTabWidget()
layout.addWidget(tabs)
# Create tabs
self.import_tab = ImportTab(self.db_path, self.settings)
self.settings_tab = SettingsTab(self.settings)
self.maintenance_tab = MaintenanceTab(self.db_path, self.settings, self.import_tab.log_text)
self.sessions_tab = SessionsTab(self.db_path, self.db, self.calibration, self.settings)
self.view_tab = ViewCatalogTab(
db_path=self.db_path,
settings=self.settings,
status_callback=self.statusBar().showMessage,
reimport_callback=self.import_tab.start_import
)
self.analytics_tab = AnalyticsTab(self.db_path, self.settings)
self.projects_tab = ProjectsTab(self.db_path, self.settings, self.calibration)
# Set cross-tab dependencies after all tabs are created
self.import_tab.clear_db_btn = self.maintenance_tab.clear_db_btn
self.clear_db_btn = self.maintenance_tab.clear_db_btn # For backward compatibility
tabs.addTab(self.view_tab, "View Catalog")
tabs.addTab(self.projects_tab, "Projects")
tabs.addTab(self.sessions_tab, "Sessions")
tabs.addTab(self.analytics_tab, "Analytics")
tabs.addTab(self.import_tab, "Import Files")
tabs.addTab(self.maintenance_tab, "Maintenance")
tabs.addTab(self.settings_tab, "Settings")
# Connect tab change to refresh
tabs.currentChanged.connect(self.on_tab_changed)
def create_menu_bar(self) -> None:
"""Create the menu bar with Help menu."""
menubar = self.menuBar()
# Help menu
help_menu = menubar.addMenu('&Help')
# Check for Updates action
update_action = QAction('Check for &Updates...', self)
update_action.setStatusTip('Check for application updates from GitHub')
update_action.triggered.connect(self.show_update_dialog)
help_menu.addAction(update_action)
# Separator
help_menu.addSeparator()
# About action
about_action = QAction('&About', self)
about_action.setStatusTip('About AstroFileManager')
about_action.triggered.connect(self.show_about_dialog)
help_menu.addAction(about_action)
def show_update_dialog(self) -> None:
"""Show the update dialog."""
dialog = UpdateDialog(self)
dialog.exec()
def show_about_dialog(self) -> None:
"""Show the about dialog."""
QMessageBox.about(
self,
'About AstroFileManager',
f'<h3>AstroFileManager</h3>'
f'<p>Version {__VERSION__}</p>'
f'<p>A PyQt6-based application for cataloging, organizing, and managing '
f'XISF astrophotography files.</p>'
f'<p>Copyright © 2024-2026</p>'
f'<p><a href="https://github.com/johnwhobbs/AstroFileManager">'
f'GitHub Repository</a></p>'
)
def connect_signals(self) -> None:
"""Connect signals after all widgets are created"""
# Connect column resize signals to save settings
self.view_tab.catalog_tree.header().sectionResized.connect(self.save_settings)
self.sessions_tab.sessions_tree.header().sectionResized.connect(self.save_settings)
def save_settings(self) -> None:
"""Save window size and column widths"""
# Save window geometry
self.settings.setValue('geometry', self.saveGeometry())
# Save catalog tree column widths
for i in range(self.view_tab.catalog_tree.columnCount()):
self.settings.setValue(f'catalog_tree_col_{i}', self.view_tab.catalog_tree.columnWidth(i))
# Save sessions tree column widths
for i in range(self.sessions_tab.sessions_tree.columnCount()):
self.settings.setValue(f'sessions_tree_col_{i}', self.sessions_tab.sessions_tree.columnWidth(i))
# Save sessions tab splitter state
self.sessions_tab.save_splitter_state()
# Save projects tab splitter state
self.projects_tab.save_splitter_state()
# Save View Catalog tab splitter state
self.view_tab.save_splitter_state()
def restore_settings(self) -> None:
"""Restore window size and column widths"""
# Restore window geometry
geometry = self.settings.value('geometry')
if geometry:
self.restoreGeometry(geometry)
# Restore catalog tree column widths
for i in range(self.view_tab.catalog_tree.columnCount()):
width = self.settings.value(f'catalog_tree_col_{i}')
if width is not None:
self.view_tab.catalog_tree.setColumnWidth(i, int(width))
# Restore sessions tree column widths
for i in range(self.sessions_tab.sessions_tree.columnCount()):
width = self.settings.value(f'sessions_tree_col_{i}')
if width is not None:
self.sessions_tab.sessions_tree.setColumnWidth(i, int(width))
# Restore sessions tab splitter state
self.sessions_tab.restore_splitter_state()
# Restore projects tab splitter state
self.projects_tab.restore_splitter_state()
# Restore View Catalog tab splitter state
self.view_tab.restore_splitter_state()
# Connect signals after restoring settings to avoid triggering saves during restore
self.connect_signals()
def closeEvent(self, event: Any) -> None:
"""Save settings when closing"""
self.save_settings()
event.accept()
def on_tab_changed(self, index: int) -> None:
"""Handle tab change"""
if index == 0: # View Catalog tab
self.view_tab.refresh_catalog_view()
elif index == 1: # Projects tab
self.projects_tab.refresh_projects()
elif index == 2: # Sessions tab
self.sessions_tab.refresh_sessions()
elif index == 3: # Analytics tab
self.analytics_tab.refresh_analytics()
elif index == 5: # Maintenance tab
# Populate current values when maintenance tab is opened
keyword = self.maintenance_tab.keyword_combo.currentText()
self.maintenance_tab.populate_current_values(keyword)
def main() -> None:
app = QApplication(sys.argv)
# Load theme setting
settings = ConfigManager('AstroFileManager', 'AstroFileManager')
theme = settings.value('theme', 'standard')
# Apply theme
if theme == 'dark':
apply_dark_theme(app)
else:
apply_standard_theme(app)
window = XISFCatalogGUI()
window.show()
sys.exit(app.exec())
def apply_dark_theme(app: QApplication) -> None:
"""Apply dark theme to the application"""
app.setStyle('Fusion')
dark_palette = app.palette()
# Define dark theme colors
dark_palette.setColor(dark_palette.ColorRole.Window, Qt.GlobalColor.darkGray)
dark_palette.setColor(dark_palette.ColorRole.WindowText, Qt.GlobalColor.white)
dark_palette.setColor(dark_palette.ColorRole.Base, Qt.GlobalColor.black)
dark_palette.setColor(dark_palette.ColorRole.AlternateBase, Qt.GlobalColor.darkGray)
dark_palette.setColor(dark_palette.ColorRole.ToolTipBase, Qt.GlobalColor.white)
dark_palette.setColor(dark_palette.ColorRole.ToolTipText, Qt.GlobalColor.white)
dark_palette.setColor(dark_palette.ColorRole.Text, Qt.GlobalColor.white)
dark_palette.setColor(dark_palette.ColorRole.Button, Qt.GlobalColor.darkGray)
dark_palette.setColor(dark_palette.ColorRole.ButtonText, Qt.GlobalColor.white)
dark_palette.setColor(dark_palette.ColorRole.BrightText, Qt.GlobalColor.red)
dark_palette.setColor(dark_palette.ColorRole.Link, Qt.GlobalColor.blue)
dark_palette.setColor(dark_palette.ColorRole.Highlight, Qt.GlobalColor.blue)
dark_palette.setColor(dark_palette.ColorRole.HighlightedText, Qt.GlobalColor.black)
app.setPalette(dark_palette)
# Additional stylesheet for better appearance
app.setStyleSheet("""
QToolTip {
color: #ffffff;
background-color: #2a2a2a;
border: 1px solid white;
}
QPushButton {
background-color: #404040;
border: 1px solid #555555;
padding: 5px;
border-radius: 3px;
}
QPushButton:hover {
background-color: #505050;
}
QPushButton:pressed {
background-color: #303030;
}
QTreeWidget, QTableWidget {
background-color: #2a2a2a;
alternate-background-color: #353535;
}
QHeaderView::section {
background-color: #404040;
padding: 4px;
border: 1px solid #555555;
font-weight: bold;
}
QProgressBar {
border: 1px solid #555555;
border-radius: 3px;
text-align: center;
}
QProgressBar::chunk {
background-color: #3a7bd5;
}
QTextEdit {
background-color: #2a2a2a;
border: 1px solid #555555;
}
QGroupBox {
border: 1px solid #555555;
margin-top: 0.5em;
padding-top: 0.5em;
}
QGroupBox::title {
subcontrol-origin: margin;
left: 10px;
padding: 0 3px 0 3px;
}
""")
def apply_standard_theme(app: QApplication) -> None:
"""Apply standard theme to the application"""
# Use the system default style
app.setStyle('Fusion')
# Use system default palette - no custom colors
app.setPalette(app.style().standardPalette())
# Minimal stylesheet for consistency
app.setStyleSheet("""
QPushButton {
padding: 5px;
}
QProgressBar {
border: 1px solid #cccccc;
border-radius: 3px;
text-align: center;
}
QProgressBar::chunk {
background-color: #0078d4;
}
QGroupBox {
font-weight: bold;
border: 1px solid #cccccc;
margin-top: 0.5em;
padding-top: 0.5em;
}
QGroupBox::title {
subcontrol-origin: margin;
left: 10px;
padding: 0 3px 0 3px;
}
""")
if __name__ == '__main__':
main()