Free Motion Capture for Everyone πβ¨
TypeScript
GUI updates with folder path
Aaron Cherianbfaeca69ba11
diff --git a/freemocap/parameters.yaml b/freemocap/parameters.yamldeleted file mode 100644index 718b3f3c..00000000--- a/freemocap/parameters.yaml+++ /dev/null@@ -1,30 +0,0 @@-#default parameters-----default:- rotations: {}- parameters:- exposure: -5- resWidth: 640- resHeight: 480- framerate: 25- codec: DIVX--#saved parameters------saved:- rotations:- 1: 0- 2: 0- parameters:- exposure: -6- resWidth: 640- resHeight: 480- framerate: 30- codec: H264diff --git a/freemocap/recordingconfig.py b/freemocap/recordingconfig.pyindex 2a7bf710..3fda9ed2 100644--- a/freemocap/recordingconfig.py+++ b/freemocap/recordingconfig.py@@ -5,11 +5,11 @@ Created on Thu Mar 11 11:54:12 2021@author: Rontc"""-+from pathlib import Pathfolder_setup = ['RawVideos','SyncedVideos','CalVideos','DataArrays','DLCData','OpenPoseData','MediaPipeData','imOut']-default_parameters = {'rotations':{},'parameters':{'exposure':-5,'resWidth':640,'resHeight':480,'framerate':25,'codec':'DIVX'}}+default_parameters = {'path_to_save': str(Path.cwd()),'rotations':{},'parameters':{'exposure':-5,'resWidth':640,'resHeight':480,'framerate':25,'codec':'DIVX'}}saved_parameters = default_parametersparameters_for_yaml = {'default':default_parameters,'saved':{}}diff --git a/freemocap/webcam/recordGUI.py b/freemocap/webcam/recordGUI.pyindex 112e6a4f..21d9decb 100644--- a/freemocap/webcam/recordGUI.py+++ b/freemocap/webcam/recordGUI.py@@ -5,10 +5,11 @@ Created on Wed Mar 3 12:18:46 2021@author: Rontc"""import tkinter as tk-from tkinter import Tk, Label, Button, Frame, Listbox, Entry+from tkinter import Tk, Label, Button, Frame, Listbox, Entry, filedialogfrom freemocap.webcam import checkcamsimport pickleimport datetime+from pathlib import Pathclass recordGUI:@@ -77,6 +78,7 @@ class SettingsGUI:rotation_dictionary,sessionID_in,task,+ current_path_to_save,):self.master = masterself.cam_inputs = cam_inputs@@ -84,6 +86,7 @@ class SettingsGUI:self.rotation_dictionary = rotation_dictionaryself.sessionID_in = sessionID_inself.task = task+ self.currentPath = current_path_to_save# check if any previous parameters existif self.parameter_dictionary is not None:existing_parameters = True@@ -96,6 +99,9 @@ class SettingsGUI:# create frames to organize rotation inputs, resolution inputs, and parameter inputstopFrame = Frame(self.master)topFrame.pack(side=tk.TOP)+ if self.task == 'record':+ recordingSettingsFrame = Frame(self.master)+ recordingSettingsFrame.pack()rotLabelFrame = Frame(self.master)rotLabelFrame.pack()resFrame = Frame(self.master)@@ -104,6 +110,8 @@ class SettingsGUI:parametersFrame.pack()bottomFrame = Frame(self.master).pack(side=tk.BOTTOM)++taskText = "Current Task: " + self.tasktaskLabel = Label(topFrame, text=taskText, font="bold")taskLabel.pack()@@ -151,11 +159,31 @@ class SettingsGUI:# ---SessionID entry- default is the date/timeif self.task == "record":sessionText = "Change SessionID if desired"- sessionLabel = Label(parametersFrame, text=sessionText).pack()- self.sessionIDEntry = Entry(parametersFrame)+ sessionLabel = Label(recordingSettingsFrame, text=sessionText)+ sessionLabel.pack()++ self.sessionIDEntry = Entry(recordingSettingsFrame)self.sessionIDEntry.pack()self.sessionIDEntry.insert(0, self.sessionID_in)+ pathText = 'Choose where to create your Freemocap_Data folder:'+ pathLabel = Label(recordingSettingsFrame, text=pathText)+ pathLabel.pack()++ text = 'Current file path: ' + self.currentPath+ self.currentPathText = tk.StringVar()+ self.currentPathText.set(text)+ currentPathLabel = Label(recordingSettingsFrame,textvariable = self.currentPathText)+ currentPathLabel.pack()++ self.path_changed = False #will be set to True if the user changes the path with the file dialog++ changepath_button = Button(recordingSettingsFrame,text = 'Change File Path',command = self.openFileDialog)+ changepath_button.pack(side = 'left')++ #savedefault_button = Button(recordingSettingsFrame,text = 'Save as Default Path')+ #savedefault_button.pack(side = 'left')+# ---If previous parameters were recieved, insert them into the entry boxesif existing_parameters == True:@@ -169,6 +197,13 @@ class SettingsGUI:self.sub_button = Button(bottomFrame, text="Submit", command=self.Submit)self.sub_button.pack(side=tk.BOTTOM)+ def openFileDialog(self):+ self.currentPath = filedialog.askdirectory(+ title='Open a file',+ initialdir= Path.cwd())+ self.currentPathText.set('Current file path: ' + self.currentPath)++def Submit(self):# get the final entries for all parameters# get the rotations for each camera and save them as values of a dictionary@@ -187,7 +222,7 @@ class SettingsGUI:# spit out the sessionIDif self.task == "record":self.sessionID_out = self.sessionIDEntry.get()-+ self.save_path = self.currentPathself.master.destroy()def RotationRetrieval(self, cam_inputs, rotation_dictionary):@@ -201,14 +236,19 @@ class SettingsGUI:else:rotationValues.append(0)return rotationValues++++class ProceedToRecordGUI:- def __init__(self, master, sessionID_in):+ def __init__(self, master, sessionID_in, current_path_to_save):self.master = masterself.sessionID_in = sessionID_inself.continueToRecording = ""self.sessionID_out = ""+ self.currentPath = current_path_to_savesessionText = "Proceed to recording with this sessionID?"sessionLabel = Label(master, text=sessionText)@@ -218,22 +258,45 @@ class ProceedToRecordGUI:self.sessionIDEntry.pack()self.sessionIDEntry.insert(0, self.sessionID_in)- # master.title("Proceed to Recording?")- self.proceed_button = Button(text="Proceed", command=self.destroy)++ pathText = 'Choose where to create your Freemocap_Data folder:'+ pathLabel = Label(master,text=pathText)+ pathLabel.pack()++ text = 'Current file path: ' + self.currentPath+ self.currentPathText = tk.StringVar()+ self.currentPathText.set(text)+ currentPathLabel = Label(master,textvariable = self.currentPathText)+ currentPathLabel.pack()++ changepath_button = Button(master,text = 'Change Folder Path',command = self.openFileDialog)+ changepath_button.pack(side = 'left')++ # master.title("Proceed to Recording?")+ self.proceed_button = Button(text="Proceed", command=self.proceed)self.stop_button = Button(text="Quit", command=self.stop)self.stop_button.pack(side=tk.RIGHT)self.proceed_button.pack(side=tk.RIGHT)++ def openFileDialog(self):+ self.currentPath = filedialog.askdirectory(+ title='Open a file',+ initialdir= Path.cwd())+ self.currentPathText.set('Current file path: ' + self.currentPath)++def stop(self):self.master.destroy()- def destroy(self):+ def proceed(self):self.continueToRecording = Trueself.sessionID_out = self.sessionIDEntry.get()+ self.save_path = self.currentPathself.master.destroy()-def RunGUI(sessionID_in, rotation_entry, parameter_entry):+def RunGUI(sessionID_in, rotation_entry, parameter_entry,current_path_to_save):# ---Get the camera inputs and the taskroot = tk.Tk()@@ -248,7 +311,7 @@ def RunGUI(sessionID_in, rotation_entry, parameter_entry):# ---Get all the necessary parametersroot = tk.Tk()recording_settings = SettingsGUI(- root, cam_inputs, parameter_entry, rotation_entry, sessionID_in, task+ root, cam_inputs, parameter_entry, rotation_entry, sessionID_in, task, current_path_to_save)root.mainloop()@@ -259,15 +322,17 @@ def RunGUI(sessionID_in, rotation_entry, parameter_entry):if task == "record":sessionID = recording_settings.sessionID_out+ savepath = recording_settings.save_pathelse:sessionID = None+ savepath = None- return task, cam_inputs, recording_settings.rotation_output, paramDict, sessionID+ return task, cam_inputs, recording_settings.rotation_output, paramDict, sessionID,savepath-def RunProceedtoRecordGUI(sessionID_in):+def RunProceedtoRecordGUI(sessionID_in,current_path_to_save):root = tk.Tk()- goToRecording = ProceedToRecordGUI(root, sessionID_in)+ goToRecording = ProceedToRecordGUI(root, sessionID_in,current_path_to_save)root.mainloop()- return goToRecording.continueToRecording, goToRecording.sessionID_out+ return goToRecording.continueToRecording, goToRecording.sessionID_out, goToRecording.save_pathdiff --git a/freemocap/webcamGUI.py b/freemocap/webcamGUI.pyindex 3a77041c..5e1e2061 100644--- a/freemocap/webcamGUI.py+++ b/freemocap/webcamGUI.py@@ -26,7 +26,7 @@ def initialize(session, stage, board):#load the parameters YAML and extract the saved parameters if possible, and the default otherwisehere = Path(__file__).parent- parameter_path = here/'parameters.yaml'+ parameter_path = here/'user_preferences.yaml'parameters_yaml = YAML()if parameter_path.exists():parameters = parameters_yaml.load(parameter_path)@@ -39,22 +39,26 @@ def initialize(session, stage, board):try:rotation_entry = parameters["saved"]["rotations"]parameter_entry = parameters["saved"]["parameters"]+ current_path_to_save = parameters['saved']['path_to_save']except:print("Could not load saved parameters, using default parameters")rotation_entry = parameters['default']['rotations']- parameter_entry = parameters['default']['parameters']+ parameter_entry = parameters['default']['parameters']+ current_path_to_save = parameters['default']['path_to_save']proceedToRecording = False #create this boolean, set it to false, and if the user wants to record#later in the pipeline, it will be set to true#run the GUI to get the tasks, the cams chosen, the camera settings, and the session ID- task, cam_inputs, rotDict, paramDict, session.sessionID = recordGUI.RunGUI(sessionID_in,rotation_entry,parameter_entry)+ task, cam_inputs, rotDict, paramDict, session.sessionID,savepath = recordGUI.RunGUI(sessionID_in,rotation_entry,parameter_entry,current_path_to_save)#update the saved parameters in the YAML#recordingconfig.rotation_settings['saved'] = rotDict#recordingconfig.camera_parameters['saved'] = paramDictparameters['saved']['rotations'] = rotDictparameters['saved']['parameters'] = paramDict+ if savepath is not None:+ parameters['saved']['path_to_save'] = savepathparameters_yaml.dump(parameters, parameter_path)#save recording parameters to the config yaml@@ -66,9 +70,11 @@ def initialize(session, stage, board):if task == "setup":# run setup processes, and then check if th user wants to proceed to recordingcamsetup.RunSetup(cam_inputs, rotation_input, paramDict)- proceedToRecording, session.sessionID = recordGUI.RunProceedtoRecordGUI(- sessionID_in+ proceedToRecording, session.sessionID, savepath = recordGUI.RunProceedtoRecordGUI(+ sessionID_in,current_path_to_save)+ parameters['saved']['path_to_save'] = savepath+ parameters_yaml.dump(parameters, parameter_path)elif task == "record":proceedToRecording = True@@ -78,6 +84,7 @@ def initialize(session, stage, board):session.cam_inputs = cam_inputssession.parameterDictionary = paramDictsession.rotationInputs = rotation_input+ session.basePath = Path(savepath)#create a config yaml and text file for this sessionsession.start_session(session.parameterDictionary,session.rotationInputs)