-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvoyager_ui.py
More file actions
224 lines (199 loc) · 8.03 KB
/
voyager_ui.py
File metadata and controls
224 lines (199 loc) · 8.03 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
import numpy as np
from PyQt5.QtWidgets import (
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
QListWidget, QLabel, QComboBox, QPushButton, QLineEdit, QMessageBox
)
from PyQt5.QtCore import QTimer, Qt
from voyager_plot import VoyagerPlot
from Voyager_data import VOYAGER_EVENTS
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("🚀 Voyager 1 Interactive Path Viewer")
self.setMinimumSize(1000, 600)
self.dark_mode = True # Default mode
central_widget = QWidget()
self.setCentralWidget(central_widget)
layout = QHBoxLayout()
central_widget.setLayout(layout)
# === Left Plot Area ===
self.plot_widget = VoyagerPlot(self)
layout.addWidget(self.plot_widget, 2)
# === Right Panel ===
right_panel = QVBoxLayout()
# View selector
self.view_selector = QComboBox()
self.view_selector.addItems(["3D View", "2D View"])
self.view_selector.currentIndexChanged.connect(self.change_view)
# Theme toggle button
self.theme_btn = QPushButton("🌙 Dark Mode")
self.theme_btn.clicked.connect(self.toggle_theme)
# Event list
self.event_list = QListWidget()
for e in VOYAGER_EVENTS:
self.event_list.addItem(f"{e['year']} - {e['event']}")
self.event_list.itemClicked.connect(self.event_selected)
# Search
self.search_input = QLineEdit()
self.search_input.setPlaceholderText("Enter Year (e.g., 1990)")
self.search_btn = QPushButton("🔍 Search Year")
self.search_btn.clicked.connect(self.search_year)
# Details
self.details_label = QLabel("Voyager is moving...\nEvents update automatically.")
self.details_label.setWordWrap(True)
# Animation controls
self.start_btn = QPushButton("▶ Start")
self.stop_btn = QPushButton("⏸ Pause")
self.reset_btn = QPushButton("⏮ Reset")
self.start_btn.clicked.connect(self.start_animation)
self.stop_btn.clicked.connect(self.stop_animation)
self.reset_btn.clicked.connect(self.reset_animation)
# Add widgets to panel
right_panel.addWidget(QLabel("View Mode:"))
right_panel.addWidget(self.view_selector)
right_panel.addWidget(self.theme_btn)
right_panel.addWidget(QLabel("Mission Events:"))
right_panel.addWidget(self.event_list)
right_panel.addWidget(QLabel("Details:"))
right_panel.addWidget(self.details_label)
right_panel.addWidget(self.start_btn)
right_panel.addWidget(self.stop_btn)
right_panel.addWidget(self.reset_btn)
right_panel.addWidget(QLabel("Search Voyager by Year:"))
right_panel.addWidget(self.search_input)
right_panel.addWidget(self.search_btn)
right_panel.addStretch()
layout.addLayout(right_panel, 1)
# Timer
self.timer = QTimer()
self.timer.timeout.connect(self.animate_voyager)
self.timer.start(200)
# Apply initial theme
self.apply_theme()
# === Animation Controls ===
def start_animation(self): self.timer.start(200)
def stop_animation(self): self.timer.stop()
def reset_animation(self):
self.plot_widget.current_index = 0
self.plot_widget.plot_trajectory()
def animate_voyager(self):
self.plot_widget.move_forward()
x, y, z = self.plot_widget.get_current_position()
for e in VOYAGER_EVENTS:
ex, ey, ez = e["coords"]
dist = np.sqrt((x - ex) ** 2 + (y - ey) ** 2 + (z - ez) ** 2)
if dist < 1e9:
self.details_label.setText(
f"Year: {e['year']}\nEvent: {e['event']}\nPosition: ({x:.2e}, {y:.2e}, {z:.2e}) km"
)
return
self.details_label.setText(f"Voyager position:\n({x:.2e}, {y:.2e}, {z:.2e}) km")
# === Search Function ===
def search_year(self):
year_text = self.search_input.text().strip()
if not year_text.isdigit():
QMessageBox.warning(self, "Invalid Input", "Please enter a valid year (numbers only).")
return
year = int(year_text)
sorted_events = sorted(VOYAGER_EVENTS, key=lambda e: e["year"])
years = [e["year"] for e in sorted_events]
if year < years[0] or year > years[-1]:
QMessageBox.information(self, "No Data", f"No data available for year {year}.")
return
for i in range(len(sorted_events) - 1):
y0, y1 = sorted_events[i]["year"], sorted_events[i + 1]["year"]
if y0 <= year <= y1:
coords0 = np.array(sorted_events[i]["coords"])
coords1 = np.array(sorted_events[i + 1]["coords"])
t = (year - y0) / (y1 - y0)
pos = coords0 + t * (coords1 - coords0)
event_before = sorted_events[i]["event"]
event_after = sorted_events[i + 1]["event"]
break
self.plot_widget.show_event(pos)
QMessageBox.information(
self,
f"Voyager Position - {year}",
f"Approximate Position for {year}:\n"
f"X: {pos[0]:.2e} km\n"
f"Y: {pos[1]:.2e} km\n"
f"Z: {pos[2]:.2e} km\n\n"
f"Between events:\n- {y0}: {event_before}\n- {y1}: {event_after}"
)
# === Event Selection ===
def event_selected(self, item):
text = item.text()
year = int(text.split(" - ")[0])
for e in VOYAGER_EVENTS:
if e["year"] == year:
self.plot_widget.show_event(e["coords"])
self.details_label.setText(
f"Year: {e['year']}\nEvent: {e['event']}\nPosition: {e['coords']}"
)
break
# === View Change ===
def change_view(self):
mode = "3D" if self.view_selector.currentText() == "3D View" else "2D"
self.plot_widget.set_mode(mode)
# === Theme Toggle ===
def toggle_theme(self):
self.dark_mode = not self.dark_mode
self.plot_widget.set_theme(self.dark_mode)
self.apply_theme()
def apply_theme(self):
if self.dark_mode:
self.setStyleSheet("""
QMainWindow, QWidget {
background-color: #121212;
color: #ffffff;
}
QListWidget, QLineEdit, QComboBox {
background-color: #1e1e1e;
color: #ffffff;
border: 1px solid #333;
border-radius: 6px;
padding: 4px;
}
QPushButton {
background-color: #2d89ef;
color: white;
border-radius: 8px;
padding: 8px;
font-weight: bold;
}
QPushButton:hover {
background-color: #1d6edb;
}
QLabel {
color: #e0e0e0;
}
""")
self.theme_btn.setText("☀ Light Mode")
else:
self.setStyleSheet("""
QMainWindow, QWidget {
background-color: #f2f2f2;
color: #000000;
}
QListWidget, QLineEdit, QComboBox {
background-color: #ffffff;
color: #000000;
border: 1px solid #aaa;
border-radius: 6px;
padding: 4px;
}
QPushButton {
background-color: #0078d4;
color: white;
border-radius: 8px;
padding: 8px;
font-weight: bold;
}
QPushButton:hover {
background-color: #005a9e;
}
QLabel {
color: #202020;
}
""")
self.theme_btn.setText("🌙 Dark Mode")