Free Motion Capture for Everyone πβ¨
TypeScript
Save gui state (#421)
philipqueen6c07aff3a1ff
diff --git a/freemocap/core_processes/capture_volume_calibration/charuco_stuff/default_charuco_square_size.py b/freemocap/core_processes/capture_volume_calibration/charuco_stuff/default_charuco_square_size.pydeleted file mode 100644index 021eb9d7..00000000--- a/freemocap/core_processes/capture_volume_calibration/charuco_stuff/default_charuco_square_size.py+++ /dev/null@@ -1 +0,0 @@-default_charuco_square_size_mm = 39diff --git a/freemocap/gui/qt/actions_and_menus/actions.py b/freemocap/gui/qt/actions_and_menus/actions.pyindex 755d5ea4..dbdb5ded 100644--- a/freemocap/gui/qt/actions_and_menus/actions.py+++ b/freemocap/gui/qt/actions_and_menus/actions.py@@ -5,6 +5,7 @@ CREATE_NEW_RECORDING_ACTION_NAME = "New Recording"LOAD_MOST_RECENT_RECORDING_ACTION_NAME = "Load Most Recent Recording"LOAD_RECORDING_ACTION_NAME = "Load Recording"IMPORT_VIDEOS_ACTION_NAME = "Import Videos"+RESET_TO_DEFAULTS_ACTION_NAME = "Reset to Default GUI Settings"KILL_THREADS_AND_PROCESSES_ACTION_NAME = "Kill Threads and Processes"REBOOT_GUI_ACTION_NAME = "Reboot GUI"EXIT_ACTION_NAME = "Exit"@@ -38,6 +39,9 @@ class Actions:self.import_videos_action.setShortcut("Ctrl+I")self.import_videos_action.triggered.connect(freemocap_main_window.open_import_videos_dialog)+ self.reset_to_defaults_action = QAction(RESET_TO_DEFAULTS_ACTION_NAME, parent=freemocap_main_window)+ self.reset_to_defaults_action.triggered.connect(freemocap_main_window.reset_to_default_gui_settings)+self.reboot_gui_action = QAction(REBOOT_GUI_ACTION_NAME, parent=freemocap_main_window)self.reboot_gui_action.setShortcut("Ctrl+R")self.reboot_gui_action.triggered.connect(freemocap_main_window.reboot_gui)diff --git a/freemocap/gui/qt/actions_and_menus/menu_bar.py b/freemocap/gui/qt/actions_and_menus/menu_bar.pyindex 864e68c6..58b34e80 100644--- a/freemocap/gui/qt/actions_and_menus/menu_bar.py+++ b/freemocap/gui/qt/actions_and_menus/menu_bar.py@@ -21,6 +21,7 @@ class MenuBar(QMenuBar):file_menu.addAction(actions.load_most_recent_recording_action)file_menu.addAction(actions.load_existing_recording_action)file_menu.addAction(actions.import_videos_action)+ file_menu.addAction(actions.reset_to_defaults_action)file_menu.addAction(actions.kill_running_threads_and_processes_action)file_menu.addAction(actions.reboot_gui_action)file_menu.addAction(actions.exit_action)diff --git a/freemocap/gui/qt/main_window/freemocap_main_window.py b/freemocap/gui/qt/main_window/freemocap_main_window.pyindex e942b2b5..5aa3c5d3 100644--- a/freemocap/gui/qt/main_window/freemocap_main_window.py+++ b/freemocap/gui/qt/main_window/freemocap_main_window.py@@ -57,11 +57,21 @@ from freemocap.gui.qt.widgets.home_widget import ()from freemocap.gui.qt.widgets.import_videos_window import ImportVideosWizardfrom freemocap.gui.qt.widgets.log_view_widget import LogViewWidget+from freemocap.gui.qt.utilities.save_and_load_gui_state import (+ GuiState,+ load_gui_state,+)# reboot GUI method based on this - https://stackoverflow.com/a/56563926/14662833from freemocap.system.open_file import open_filefrom freemocap.system.paths_and_filenames.file_and_folder_names import (PATH_TO_FREEMOCAP_LOGO_SVG,)+from freemocap.system.paths_and_filenames.path_getters import (+ get_blender_file_path,+ get_recording_session_folder_path,+ get_gui_state_json_path+)+from freemocap.system.paths_and_filenames.path_getters import get_recording_session_folder_path, \get_css_stylesheet_path, get_scss_stylesheet_path, get_most_recent_recording_path, get_blender_file_path, \get_freemocap_data_folder_path@@ -100,6 +110,13 @@ class MainWindow(QMainWindow):self._freemocap_data_folder_path = freemocap_data_folder_pathself._pipedream_pings = pipedream_pings+ try:+ self._gui_state = load_gui_state(get_gui_state_json_path())+ logger.info("Successfully loaded previous settings")+ except:+ logger.info("Failed to find previous GUI settings, using default settings")+ self._gui_state = GuiState()+self._kill_thread_event = multiprocessing.Event()self._active_recording_info_widget = ActiveRecordingInfoWidget(parent=self)@@ -229,7 +246,7 @@ class MainWindow(QMainWindow):def _create_central_tab_widget(self):- self._home_widget = HomeWidget(actions=self._actions, parent=self)+ self._home_widget = HomeWidget(actions=self._actions, gui_state=self._gui_state, parent=self)self._skellycam_widget = SkellyCamWidget(self._create_new_synchronized_videos_folder,@@ -241,6 +258,8 @@ class MainWindow(QMainWindow):self._controller_group_box = CameraControllerGroupBox(skellycam_widget=self._skellycam_widget,+ gui_state=self._gui_state,+ parent=self)self._skelly_viewer_widget = SkellyViewer()@@ -295,6 +314,7 @@ class MainWindow(QMainWindow):self._process_motion_capture_data_panel = ProcessMotionCaptureDataPanel(recording_processing_parameters=PostProcessingParameterModel(),get_active_recording_info=self._active_recording_info_widget.get_active_recording_info,+ gui_state=self._gui_state,kill_thread_event=self._kill_thread_event,)self._process_motion_capture_data_panel.processing_finished_signal.connect(@@ -441,6 +461,16 @@ class MainWindow(QMainWindow):self._active_recording_info_widget.set_active_recording(recording_folder_path=user_selected_directory)self._central_tab_widget.setCurrentIndex(2)+ def reset_to_default_gui_settings(self):+ self._gui_state = GuiState()++ self._home_widget._send_pings_checkbox.setChecked(self._gui_state.send_user_pings)+ self._controller_group_box._auto_process_videos_checkbox.setChecked(self._gui_state.auto_process_videos_on_save)+ self._controller_group_box._generate_jupyter_notebook_checkbox.setChecked(self._gui_state.generate_jupyter_notebook)+ self._controller_group_box._auto_open_in_blender_checkbox.setChecked(self._gui_state.auto_open_in_blender)+ self._controller_group_box._charuco_square_size_line_edit.setText(str(self._gui_state.charuco_square_size))+ self._process_motion_capture_data_panel._calibration_control_panel._charuco_square_size_line_edit.setText(str(self._gui_state.charuco_square_size))+def open_import_videos_dialog(self):# from this tutorial - https://www.youtube.com/watch?v=gg5TepTc2Jg&t=649slogger.info("Opening `Import Videos` dialog... ")diff --git a/freemocap/gui/qt/utilities/save_and_load_gui_state.py b/freemocap/gui/qt/utilities/save_and_load_gui_state.pynew file mode 100644index 00000000..7a6723ed--- /dev/null+++ b/freemocap/gui/qt/utilities/save_and_load_gui_state.py@@ -0,0 +1,21 @@+import json+from pydantic import BaseModel+++class GuiState(BaseModel):+ send_user_pings: bool = True+ auto_process_videos_on_save: bool = True+ generate_jupyter_notebook: bool = True+ auto_open_in_blender: bool = True+ charuco_square_size: float = 39+++def save_gui_state(gui_state: GuiState, file_pathstring: str = None):+ with open(file_pathstring, "w") as file:+ json.dump(gui_state.dict(), file, indent=4)+++def load_gui_state(file_pathstring: str = None) -> GuiState:+ with open(file_pathstring, "r") as file:+ gui_state = GuiState(**json.load(file))+ return gui_statediff --git a/freemocap/gui/qt/widgets/camera_controller_group_box.py b/freemocap/gui/qt/widgets/camera_controller_group_box.pyindex 97800c26..83045451 100644--- a/freemocap/gui/qt/widgets/camera_controller_group_box.py+++ b/freemocap/gui/qt/widgets/camera_controller_group_box.py@@ -15,12 +15,10 @@ from PyQt6.QtWidgets import ()from skellycam import SkellyCamControllerWidget, SkellyCamWidget-from freemocap.core_processes.capture_volume_calibration.charuco_stuff.default_charuco_square_size import (- default_charuco_square_size_mm,-)+from freemocap.gui.qt.utilities.save_and_load_gui_state import GuiState, save_gui_statefrom freemocap.system.paths_and_filenames.file_and_folder_names import SPARKLES_EMOJI_STRING, SKULL_EMOJI_STRINGfrom freemocap.system.paths_and_filenames.path_getters import create_new_recording_folder_path, \- create_new_default_recording_name+ create_new_default_recording_name, get_gui_state_json_pathCALIBRATION_RECORDING_BUTTON_TEXT = "\U0001F534 \U0001F4D0 Start Calibration Recording"MOCAP_RECORDING_BUTTON_TEXT = f"{SKULL_EMOJI_STRING} {SPARKLES_EMOJI_STRING} Start Motion Capture Recording"@@ -32,7 +30,7 @@ logger = logging.getLogger(__name__)class CameraControllerGroupBox(QGroupBox):- def __init__(self, skellycam_widget: SkellyCamWidget, parent=None):+ def __init__(self, skellycam_widget: SkellyCamWidget, gui_state: GuiState, parent=None):super().__init__(parent=parent)self.setStyleSheet("font-size: 12px;")self._skellycam_widget = skellycam_widget@@ -42,19 +40,29 @@ class CameraControllerGroupBox(QGroupBox):)self._skellycam_controller.check_recording_type = self.check_recording_type,+ self.gui_state = gui_state+self._layout = QHBoxLayout()self._layout.setAlignment(Qt.AlignmentFlag.AlignLeft)+self.setLayout(self._layout)self._layout.addLayout(self._make_record_button_layout())self._layout.addLayout(self._make_options_layout())+self._calibration_videos_radio_button.toggled.connect(self._set_record_button_text)self._mocap_videos_radio_button.toggled.connect(self._set_record_button_text)self._skellycam_widget.cameras_connected_signal.connect(lambda: self._start_recording_button.setEnabled(True))self._stop_recording_button.clicked.connect(self._set_record_button_text)+ self._auto_process_videos_checkbox.toggled.connect(self._on_auto_process_videos_checkbox_changed)+ self._generate_jupyter_notebook_checkbox.toggled.connect(self._on_generate_jupyter_notebook_checkbox_changed)+ self._auto_open_in_blender_checkbox.toggled.connect(self._on_auto_open_in_blender_checkbox_changed)+ self._charuco_square_size_line_edit.textChanged.connect(self._on_charuco_square_size_line_edit_changed)++@propertydef mocap_videos_radio_button_checked(self) -> bool:return self._mocap_videos_radio_button.isChecked()@@ -98,15 +106,15 @@ class CameraControllerGroupBox(QGroupBox):self._mocap_videos_radio_button.setChecked(True)hbox.addWidget(QLabel(" - "))self._auto_process_videos_checkbox = QCheckBox("Auto Process Videos on Save")- self._auto_process_videos_checkbox.setChecked(True)+ self._auto_process_videos_checkbox.setChecked(self.gui_state.auto_process_videos_on_save)hbox.addWidget(self._auto_process_videos_checkbox)self._generate_jupyter_notebook_checkbox = QCheckBox('Generate Jupyter Notebook')- self._generate_jupyter_notebook_checkbox.setChecked(True)+ self._generate_jupyter_notebook_checkbox.setChecked(self.gui_state.generate_jupyter_notebook)hbox.addWidget(self._generate_jupyter_notebook_checkbox)self._auto_open_in_blender_checkbox = QCheckBox("Auto Open in Blender")- self._auto_open_in_blender_checkbox.setChecked(True)+ self._auto_open_in_blender_checkbox.setChecked(self.gui_state.auto_open_in_blender)hbox.addWidget(self._auto_open_in_blender_checkbox)return hbox@@ -121,7 +129,7 @@ class CameraControllerGroupBox(QGroupBox):hbox.addWidget(QLabel("Charuco square size (mm)", parent=self))self._charuco_square_size_line_edit = QLineEdit(parent=self)self._charuco_square_size_line_edit.setFixedWidth(100)- self._charuco_square_size_line_edit.setText(str(default_charuco_square_size_mm))+ self._charuco_square_size_line_edit.setText(str(self.gui_state.charuco_square_size))self._charuco_square_size_line_edit.setToolTip("The length of one of the edges of the black squares in the calibration board in mm")@@ -225,3 +233,30 @@ class CameraControllerGroupBox(QGroupBox):self.setProperty("calibration_videos_radio_button_checked", False)self._start_recording_button.setText(MOCAP_RECORDING_BUTTON_TEXT)self.style().polish(self)++ def _on_auto_process_videos_checkbox_changed(self):+ self.gui_state.auto_process_videos_on_save = self._auto_process_videos_checkbox.isChecked()+ save_gui_state(+ gui_state=self.gui_state,+ file_pathstring=get_gui_state_json_path())++ def _on_generate_jupyter_notebook_checkbox_changed(self):+ self.gui_state.generate_jupyter_notebook = self._generate_jupyter_notebook_checkbox.isChecked()+ save_gui_state(+ gui_state=self.gui_state,+ file_pathstring=get_gui_state_json_path()+ )++ def _on_auto_open_in_blender_checkbox_changed(self):+ self.gui_state.auto_open_in_blender = self._auto_open_in_blender_checkbox.isChecked()+ save_gui_state(+ gui_state=self.gui_state,+ file_pathstring=get_gui_state_json_path()+ )++ def _on_charuco_square_size_line_edit_changed(self):+ self.gui_state.charuco_square_size = float(self._charuco_square_size_line_edit.text())+ save_gui_state(+ gui_state=self.gui_state,+ file_pathstring=get_gui_state_json_path()+ )diff --git a/freemocap/gui/qt/widgets/control_panel/calibration_control_panel.py b/freemocap/gui/qt/widgets/control_panel/calibration_control_panel.pyindex 40c06b33..91bf2253 100644--- a/freemocap/gui/qt/widgets/control_panel/calibration_control_panel.py+++ b/freemocap/gui/qt/widgets/control_panel/calibration_control_panel.py@@ -17,21 +17,30 @@ from PyQt6.QtWidgets import (QHBoxLayout,QLayout, )-from freemocap.core_processes.capture_volume_calibration.charuco_stuff.default_charuco_square_size import (- default_charuco_square_size_mm,-)+from freemocap.gui.qt.utilities.save_and_load_gui_state import GuiState, save_gui_statefrom freemocap.gui.qt.workers.anipose_calibration_thread_worker import (AniposeCalibrationThreadWorker,)-from freemocap.system.paths_and_filenames.path_getters import get_last_successful_calibration_toml_path++from freemocap.system.paths_and_filenames.path_getters import get_gui_state_json_path, get_last_successful_calibration_toml_pathlogger = logging.getLogger(__name__)class CalibrationControlPanel(QWidget):- def __init__(self, get_active_recording_info: Callable, kill_thread_event: threading.Event, parent=None):+ def __init__(self,+ get_active_recording_info: Callable,+ kill_thread_event: threading.Event,+ gui_state: GuiState,+ parent=None):+super().__init__(parent=parent)+ self.gui_state = gui_state+ self._has_a_toml_path = False+ self._calibration_toml_path = Noneself._get_active_recording_info = get_active_recording_info+ self._kill_thread_event = kill_thread_event+self.parent = parentself._layout = QVBoxLayout()@@ -244,13 +253,22 @@ class CalibrationControlPanel(QWidget):self._charuco_square_size_label = QLabel("Charuco square size (mm)")self._charuco_square_size_label.setStyleSheet("QLabel { font-size: 12px; }")- self._charuco_square_size_line_edit.setText(str(default_charuco_square_size_mm))+ self._charuco_square_size_line_edit.setText(str(self.gui_state.charuco_square_size))self._charuco_square_size_line_edit.setToolTip("The length of one of the edges of the black squares in the calibration board in mm")+ self._charuco_square_size_line_edit.textChanged.connect(self._on_charuco_square_size_line_edit_changed)charuco_square_size_form_layout.addRow(self._charuco_square_size_label, self._charuco_square_size_line_edit)charuco_square_size_form_layout.setAlignment(Qt.AlignmentFlag.AlignRight)return charuco_square_size_form_layout++ def _on_charuco_square_size_line_edit_changed(self):+ self.gui_state.charuco_square_size = float(self._charuco_square_size_line_edit.text())+ save_gui_state(+ gui_state=self.gui_state,+ file_pathstring=get_gui_state_json_path()+ )+def calibrate_from_active_recording(self, charuco_square_size_mm: float = None):diff --git a/freemocap/gui/qt/widgets/control_panel/process_mocap_data_panel/process_motion_capture_data_panel.py b/freemocap/gui/qt/widgets/control_panel/process_mocap_data_panel/process_motion_capture_data_panel.pyindex a73be881..0399a8b4 100644--- a/freemocap/gui/qt/widgets/control_panel/process_mocap_data_panel/process_motion_capture_data_panel.py+++ b/freemocap/gui/qt/widgets/control_panel/process_mocap_data_panel/process_motion_capture_data_panel.py@@ -7,6 +7,7 @@ from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qtfrom PyQt6.QtGui import QFontfrom PyQt6.QtWidgets import QPushButton, QVBoxLayout, QWidget, QGroupBoxfrom pyqtgraph.parametertree import Parameter, ParameterTree+from freemocap.gui.qt.utilities.save_and_load_gui_state import GuiStatefrom freemocap.gui.qt.widgets.control_panel.calibration_control_panel import CalibrationControlPanelfrom freemocap.gui.qt.widgets.control_panel.process_mocap_data_panel.parameter_groups.create_parameter_groups import (@@ -36,6 +37,7 @@ class ProcessMotionCaptureDataPanel(QWidget):recording_processing_parameters: PostProcessingParameterModel,get_active_recording_info: Callable,kill_thread_event: threading.Event,+ gui_state: GuiState,parent=None,):super().__init__(parent=parent)@@ -57,6 +59,7 @@ class ProcessMotionCaptureDataPanel(QWidget):self._calibration_control_panel = CalibrationControlPanel(get_active_recording_info=self._get_active_recording_info,kill_thread_event=self._kill_thread_event,+ gui_state=gui_state,parent=self,)vbox.addWidget(self._calibration_control_panel)diff --git a/freemocap/gui/qt/widgets/home_widget.py b/freemocap/gui/qt/widgets/home_widget.pyindex c95a033b..2918e32b 100644--- a/freemocap/gui/qt/widgets/home_widget.py+++ b/freemocap/gui/qt/widgets/home_widget.py@@ -18,7 +18,15 @@ from freemocap.gui.qt.actions_and_menus.actions import (IMPORT_VIDEOS_ACTION_NAME,Actions,)+from freemocap.gui.qt.utilities.save_and_load_gui_state import (+ GuiState,+ save_gui_state+)+from freemocap.system.paths_and_filenames.file_and_folder_names import PATH_TO_FREEMOCAP_LOGO_SVG+from freemocap.system.paths_and_filenames.path_getters import (+ get_gui_state_json_path+)logger = logging.getLogger(__name__)@@ -31,9 +39,11 @@ class WelcomeScreenButton(QPushButton):class HomeWidget(QWidget):- def __init__(self, actions: Actions, parent: QWidget = None):+ def __init__(self, actions: Actions, gui_state: GuiState, parent: QWidget = None):super().__init__(parent=parent)+ self.gui_state = gui_state+self._layout = QVBoxLayout()self.setLayout(self._layout)@@ -108,14 +118,22 @@ class HomeWidget(QWidget):self._layout.addLayout(hbox)hbox.addStretch(1)self._send_pings_checkbox = QCheckBox("Send anonymous usage information")- self._send_pings_checkbox.setChecked(True)+ self._send_pings_checkbox.setChecked(self.gui_state.send_user_pings)+ self._send_pings_checkbox.stateChanged.connect(self._on_send_pings_checkbox_changed)hbox.addWidget(self._send_pings_checkbox)+hbox.addStretch(1)@propertydef consent_to_send_usage_information(self):return self._send_pings_checkbox.isChecked()+ def _on_send_pings_checkbox_changed(self):+ self.gui_state.send_user_pings = self._send_pings_checkbox.isChecked()+ save_gui_state(+ gui_state=self.gui_state,+ file_pathstring=get_gui_state_json_path())+def _welcome_to_freemocap_title(self):logger.info("Creating `welcome to freemocap` layout")diff --git a/freemocap/system/paths_and_filenames/file_and_folder_names.py b/freemocap/system/paths_and_filenames/file_and_folder_names.pyindex c6fa6dbb..43c8bf8e 100644--- a/freemocap/system/paths_and_filenames/file_and_folder_names.py+++ b/freemocap/system/paths_and_filenames/file_and_folder_names.py@@ -20,6 +20,7 @@ CENTER_OF_MASS_FOLDER_NAME = "center_of_mass"# file namesMOST_RECENT_RECORDING_TOML_FILENAME = "most_recent_recording.toml"LAST_SUCCESSFUL_CALIBRATION_TOML_FILENAME = "last_successful_calibration.toml"+GUI_STATE_JSON_FILENAME = "gui_state.json"MEDIAPIPE_2D_NPY_FILE_NAME = "mediapipe2dData_numCams_numFrames_numTrackedPoints_pixelXY.npy"MEDIAPIPE_BODY_WORLD_FILE_NAME = "mediapipeBodyWorld_numCams_numFrames_numTrackedPoints_XYZ.npy"diff --git a/freemocap/system/paths_and_filenames/path_getters.py b/freemocap/system/paths_and_filenames/path_getters.pyindex 0288965e..5fcbe2e8 100644--- a/freemocap/system/paths_and_filenames/path_getters.py+++ b/freemocap/system/paths_and_filenames/path_getters.py@@ -1,4 +1,3 @@-import loggingimport timefrom datetime import datetimefrom pathlib import Path@@ -11,7 +10,8 @@ from freemocap.system.paths_and_filenames.file_and_folder_names import LOGS_INFORECORDING_SESSIONS_FOLDER_NAME, MOST_RECENT_RECORDING_TOML_FILENAME, LAST_SUCCESSFUL_CALIBRATION_TOML_FILENAME, \OUTPUT_DATA_FOLDER_NAME, SYNCHRONIZED_VIDEOS_FOLDER_NAME, RAW_DATA_FOLDER_NAME, RAW_MEDIAPIPE_3D_NPY_FILE_NAME, \CENTER_OF_MASS_FOLDER_NAME, TOTAL_BODY_CENTER_OF_MASS_NPY_FILE_NAME, MEDIAPIPE_2D_NPY_FILE_NAME, \- MEDIAPIPE_REPROJECTION_ERROR_NPY_FILE_NAME, SEGMENT_CENTER_OF_MASS_NPY_FILE_NAME, MEDIAPIPE_3D_NPY_FILE_NAME+ MEDIAPIPE_REPROJECTION_ERROR_NPY_FILE_NAME, SEGMENT_CENTER_OF_MASS_NPY_FILE_NAME, MEDIAPIPE_3D_NPY_FILE_NAME, \+ GUI_STATE_JSON_FILENAMEdef os_independent_home_dir():@@ -140,6 +140,9 @@ def get_scss_stylesheet_path():def get_most_recent_recording_toml_path():return str(Path(get_logs_info_and_settings_folder_path()) / MOST_RECENT_RECORDING_TOML_FILENAME)+def get_gui_state_json_path():+ return str(Path(get_logs_info_and_settings_folder_path()) / GUI_STATE_JSON_FILENAME)+def get_most_recent_recording_path(subfolder_str: str = None):if not Path(get_most_recent_recording_toml_path()).exists():