-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
160 lines (130 loc) · 4.74 KB
/
Copy pathmain.py
File metadata and controls
160 lines (130 loc) · 4.74 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
#!/usr/bin/env python3
"""
SatelliteProcessor - Main Application Entry Point
A desktop application for processing AMSR-2 satellite data
"""
import os
import sys
import pathlib
import tkinter as tk
from tkinter import messagebox
# Add project root to path
PROJECT_ROOT = pathlib.Path(__file__).parent
sys.path.insert(0, str(PROJECT_ROOT))
# Import our modules
from gui.login_window import LoginWindow
from gui.path_selector import PathSelector
from gui.main_window import MainWindow
from core.auth_manager import AuthManager
from core.path_manager import PathManager
from utils.file_manager import FileManager
class SatelliteProcessor:
"""Main application class that handles initialization and flow"""
def __init__(self):
self.root = tk.Tk()
self.root.withdraw() # Hide root window initially
# Initialize managers
self.auth_manager = AuthManager()
self.path_manager = PathManager()
self.file_manager = FileManager()
# Application state
self.authenticated = False
self.output_path_set = False
def run(self):
"""Main application flow"""
try:
# Start the main loop first
self.root.after(100, self.initialize_app)
self.root.mainloop()
except Exception as e:
messagebox.showerror("Error", f"Application error: {str(e)}")
self.cleanup_and_exit()
def initialize_app(self):
"""Initialize app after mainloop starts"""
try:
# Step 1: Check and handle authentication
if not self.check_authentication():
self.show_login()
return
# Step 2: Check and handle output path
if not self.check_output_path():
self.show_path_selector()
return
# Step 3: Show main window
self.show_main_window()
except Exception as e:
messagebox.showerror("Error", f"Initialization error: {str(e)}")
self.cleanup_and_exit()
def check_authentication(self):
"""Check if valid credentials exist"""
if self.auth_manager.has_credentials():
# Credentials exist, validate them
try:
username, password = self.auth_manager.get_credentials()
# Here we'll validate with gportal
# For now, assume valid if credentials exist
self.authenticated = True
return True
except:
return False
return False
def check_output_path(self):
"""Check if output path is set"""
if self.path_manager.has_output_path():
output_path = self.path_manager.get_output_path()
if output_path and output_path.exists():
self.output_path_set = True
return True
return False
def show_login(self):
"""Show login window"""
def on_login_complete():
if hasattr(self, '_login_window') and self._login_window.login_successful:
self.authenticated = True
self.root.after(100, self.initialize_app)
else:
self.cleanup_and_exit()
self._login_window = LoginWindow(self.root, self.auth_manager)
self.root.wait_window(self._login_window.window)
on_login_complete()
def show_path_selector(self):
"""Show path selection window"""
def on_path_complete():
if hasattr(self, '_path_window') and self._path_window.path_selected:
self.output_path_set = True
self.root.after(100, self.initialize_app)
else:
self.cleanup_and_exit()
self._path_window = PathSelector(self.root, self.path_manager)
self.root.wait_window(self._path_window.window)
on_path_complete()
def show_main_window(self):
"""Show main application window"""
# Clean up temp directory first
self.file_manager.cleanup_temp()
# Show main window
self.root.deiconify()
main_window = MainWindow(self.root, self.auth_manager, self.path_manager)
self.root.mainloop()
def cleanup_and_exit(self):
"""Clean up and exit application"""
try:
self.file_manager.cleanup_temp()
except:
pass
self.root.quit()
sys.exit(0)
def main():
"""Main entry point"""
# Create necessary directories
config_dir = PROJECT_ROOT / "config"
temp_dir = PROJECT_ROOT / "temp"
assets_dir = PROJECT_ROOT / "assets"
config_dir.mkdir(exist_ok=True)
temp_dir.mkdir(exist_ok=True)
assets_dir.mkdir(exist_ok=True)
# Run application
app = SatelliteProcessor()
app.run()
if __name__ == "__main__":
main()