spacr.gui_utils¶
Module Contents¶
- spacr.gui_utils.initialize_cuda()[source]¶
Initializes CUDA in the main process by performing a simple GPU operation.
- spacr.gui_utils.parse_list(value)[source]¶
Parses a string representation of a list and returns the parsed list.
- Parameters:
value (str) – The string representation of the list.
- Returns:
The parsed list, which can contain integers, floats, or strings.
- Return type:
list
- Raises:
ValueError – If the input value is not a valid list format or contains mixed types or unsupported types.
- spacr.gui_utils.create_input_field(frame, label_text, row, var_type='entry', options=None, default_value=None)[source]¶
Create an input field in the specified frame.
- Parameters:
frame (tk.Frame) – The frame in which the input field will be created.
label_text (str) – The text to be displayed as the label for the input field.
row (int) – The row in which the input field will be placed.
var_type (str, optional) – The type of input field to create. Defaults to ‘entry’.
options (list, optional) – The list of options for a combo box input field. Defaults to None.
default_value (str, optional) – The default value for the input field. Defaults to None.
- Returns:
A tuple containing the label, input widget, variable, and custom frame.
- Return type:
tuple
- Raises:
Exception – If an error occurs while creating the input field.
- class spacr.gui_utils.WriteToQueue(q)[source]¶
Bases:
io.TextIOBase
A custom file-like class that writes any output to a given queue. This can be used to redirect stdout and stderr.
- spacr.gui_utils.spacrFigShow(fig_queue=None)[source]¶
Replacement for plt.show() that queues figures instead of displaying them.
- spacr.gui_utils.function_gui_wrapper(function=None, settings={}, q=None, fig_queue=None, imports=1)[source]¶
Wraps the run_multiple_simulations function to integrate with GUI processes.
Parameters: - settings: dict, The settings for the run_multiple_simulations function. - q: multiprocessing.Queue, Queue for logging messages to the GUI. - fig_queue: multiprocessing.Queue, Queue for sending figures to the GUI.
- spacr.gui_utils.hide_all_settings(vars_dict, categories)[source]¶
Function to initially hide all settings in the GUI.
Parameters: - categories: dict, The categories of settings with their corresponding settings. - vars_dict: dict, The dictionary containing the settings and their corresponding widgets.
- spacr.gui_utils.download_dataset(q, repo_id, subfolder, local_dir=None, retries=5, delay=5)[source]¶
Downloads a dataset or settings files from Hugging Face and returns the local path.
- Parameters:
repo_id (str) – The repository ID (e.g., ‘einarolafsson/toxo_mito’ or ‘einarolafsson/spacr_settings’).
subfolder (str) – The subfolder path within the repository (e.g., ‘plate1’ or the settings subfolder).
local_dir (str) – The local directory where the files will be saved. Defaults to the user’s home directory.
retries (int) – Number of retry attempts in case of failure.
delay (int) – Delay in seconds between retries.
- Returns:
The local path to the downloaded files.
- Return type:
str
- spacr.gui_utils.display_gif_in_plot_frame(gif_path, parent_frame)[source]¶
Display and zoom a GIF to fill the entire parent_frame, maintaining aspect ratio, with lazy resizing and caching.
- spacr.gui_utils.display_media_in_plot_frame(media_path, parent_frame)[source]¶
Display an MP4, AVI, or GIF and play it on repeat in the parent_frame, fully filling the frame while maintaining aspect ratio.