website.p4 module

website.p4.cleanup()[source]

Clean up resources and stop all active threads.

Actions: - Set stop_event. - Clear Tkinter queue. - Destroy Tkinter window if active. - Reset global variables and clear stimulus lists.

website.p4.command_listener(conn)[source]

Listen for commands from parent program.

Loops until “exit” command is received. Dispatches valid commands to handle_command.

website.p4.handle_command(command, conn)[source]

Handle commands received from parent program via Pipe.

Supported commands:
  • “load_video_stimuli” : Load configuration.

  • “save_video_config” : Save configuration received via Pipe.

  • “start_video_stimuli”: Start presenting stimuli.

  • “stop_stimuli” : Stop presentation and cleanup.

website.p4.initialize_tkinter()[source]

Initialize a fullscreen Tkinter window for video display.

Returns:

(root, label)

root -> Tkinter root window label -> Tkinter Label widget to display video frames

Return type:

tuple

website.p4.load_stimuli()[source]

Load and read a JSON file containing stimuli configuration.

Loads the configuration from:

data/video_stimuli_data_sequence.json

Updates the global config dictionary with: - fileSequence: comma-separated filenames - fileDuration: comma-separated durations - initialDelay: delay before the first stimulus

website.p4.main(conn)[source]

Main entry point for the program.

Starts the command listener thread and waits for external commands. Exits gracefully on KeyboardInterrupt or “exit” command.

website.p4.play_video(video_path, stimuli_timestamps, stimuli_file)[source]

Play a video file (with audio) inside the Tkinter window using VLC.

Parameters:
  • video_path (str) – Path to the video file (.mp4 expected).

  • stimuli_timestamps (list) – List to append presentation timestamps.

  • stimuli_file (list) – List to append filenames of presented stimuli.

Returns:

True if playback succeeded, False otherwise.

Return type:

bool

website.p4.save_config(json_data)[source]

Save JSON configuration received from parent program.

Parameters:

json_data (str) – JSON string containing configuration.

Writes the data to:

data/video_stimuli_data_sequence.json

website.p4.start_stimuli()[source]

Start presenting video stimuli according to the loaded configuration.

website.p4.update_ui(task_type, data=None)[source]

Update the Tkinter UI depending on the task type.

Parameters:
  • task_type (str) – Type of update. Supported values: - “update_label” -> Display countdown numbers. - “black_screen” -> Replace content with a black screen. - “close_window” -> Destroy Tkinter window and save results.

  • data (Any) – Extra data required by task_type.