Save file

This commit is contained in:
CPD 2025-03-05 10:27:34 +01:00
parent 8ada9f0766
commit 9a625a5af7

View File

@ -1,6 +1,6 @@
''' app/ui/main_window.py '''
from PyQt6.QtCore import Qt, QTimer
from PyQt6.QtWidgets import QMainWindow, QWidget, QHBoxLayout, QTextEdit, QLabel, QDialog, QToolButton, QStatusBar
from PyQt6.QtWidgets import QMainWindow, QWidget, QHBoxLayout, QTextEdit, QLabel, QDialog, QToolButton, QStatusBar, QFileDialog
from PyQt6.QtWidgets import QToolBox
from PyQt6.QtGui import QIcon
from .widgets.menubar import MenuBar
@ -98,9 +98,9 @@ class MainWindow(QMainWindow):
self.topbar.add_button("meas_devices", "Devices", QIcon.fromTheme(QIcon.ThemeIcon.Printer), self.vmdev_connect_from_dialog)
self.topbar.add_button("meas_start", "Start", QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStart), self.measure_start)
self.topbar.add_button("meas_stop", "Stop", QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStop), self.measure_stop)
self.topbar.add_button("meas_save", "Save", QIcon.fromTheme(QIcon.ThemeIcon.DocumentSaveAs), self.save_file)
self.topbar.add_button("meas_save", "Save", QIcon.fromTheme(QIcon.ThemeIcon.DocumentSaveAs), self.measurement_save)
self.topbar.add_separator()
self.topbar.add_button("app_exit", "Exit", QIcon.fromTheme(QIcon.ThemeIcon.ApplicationExit), self.exit_app)
self.topbar.add_button("app_exit", "Exit", QIcon.fromTheme(QIcon.ThemeIcon.ApplicationExit), self.app_exit)
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, self.topbar)
# disable the Stop and Save buttons
@ -183,7 +183,10 @@ class MainWindow(QMainWindow):
self.topbar.disable_button("meas_start")
self.topbar.disable_button("meas_devices")
self.topbar.disable_button("meas_save")
self.topbar.enable_button("meas_stop")
self.w_plot.clear_data()
script = 100
measurement_name = "guitest"
led_script = LedScript(script=script)
@ -262,21 +265,26 @@ class MainWindow(QMainWindow):
def measurement_is_running(self):
return self.proc_measure is not None
def open_file(self) -> None:
def measurement_save(self) -> None:
"""
Event handler for the "Open" button. Displays the "Open File" dialog.
Save the last measurement data to a file.
"""
print("Open")
if self.data_collector is None:
raise RuntimeError("Can not save, not data collector initialized")
csv = self.data_collector.to_csv()
# open file dialog
filename = self.data_collector.dirname + ".csv"
file_name, _ = QFileDialog.getSaveFileName(self, "Save File", filename, "CSV Files (*.csv)")
if file_name:
with open(file_name, "w") as f:
f.write(csv)
self.set_status(f"Saved data to {file_name}")
else:
self.set_status(f"Aborted saving data, no file selected")
def save_file(self) -> None:
def app_exit(self) -> None:
"""
Event handler for the "Save" button. Displays the "Save File" dialog.
"""
print("Save")
def exit_app(self) -> None:
"""
Event handler for the "Exit" button. Closes the application.
Closes the application.
"""
self.close()