Skip to content

UI Dialogs

biopro_sdk.plugin.dialogs

Dialog utilities for BioPro SDK.

Provides convenient wrappers for common PyQt6 file dialogs and message boxes that work with the current theme.

ask_ok_cancel(parent=None, title='', message='')

Show OK/Cancel dialog.

Parameters:

Name Type Description Default
parent

Parent widget

None
title str

Dialog title

''
message str

Dialog message

''

Returns:

Type Description
bool

True if user clicks OK, False otherwise

Source code in src/biopro_sdk/plugin/dialogs.py
def ask_ok_cancel(parent=None, title: str = "", message: str = "") -> bool:
    """Show OK/Cancel dialog.

    Args:
        parent: Parent widget
        title: Dialog title
        message: Dialog message

    Returns:
        True if user clicks OK, False otherwise
    """
    reply = QMessageBox.question(
        parent, title, message, QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Cancel
    )
    return reply == QMessageBox.StandardButton.Ok

ask_yes_no(parent=None, title='', message='')

Show yes/no question dialog.

Parameters:

Name Type Description Default
parent

Parent widget

None
title str

Dialog title

''
message str

Dialog message

''

Returns:

Type Description
bool

True if user clicks Yes, False otherwise

Source code in src/biopro_sdk/plugin/dialogs.py
def ask_yes_no(parent=None, title: str = "", message: str = "") -> bool:
    """Show yes/no question dialog.

    Args:
        parent: Parent widget
        title: Dialog title
        message: Dialog message

    Returns:
        True if user clicks Yes, False otherwise
    """
    reply = QMessageBox.question(parent, title, message, QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
    return reply == QMessageBox.StandardButton.Yes

get_directory(parent=None, title='Select Directory', start_dir='')

Show directory selection dialog.

Parameters:

Name Type Description Default
parent

Parent widget

None
title str

Dialog title

'Select Directory'
start_dir str

Initial directory

''

Returns:

Type Description
str | None

Selected directory path or None if cancelled

Source code in src/biopro_sdk/plugin/dialogs.py
def get_directory(parent=None, title: str = "Select Directory", start_dir: str = "") -> str | None:
    """Show directory selection dialog.

    Args:
        parent: Parent widget
        title: Dialog title
        start_dir: Initial directory

    Returns:
        Selected directory path or None if cancelled
    """
    dir_path = QFileDialog.getExistingDirectory(parent, title, start_dir)
    return dir_path if dir_path else None

get_double(parent=None, title='', label='', value=0.0, min_val=-999.99, max_val=999.99, decimals=2)

Show float input dialog.

Parameters:

Name Type Description Default
parent

Parent widget

None
title str

Dialog title

''
label str

Label text

''
value float

Default value

0.0
min_val float

Minimum allowed value

-999.99
max_val float

Maximum allowed value

999.99
decimals int

Number of decimal places

2

Returns:

Type Description
float | None

User input or None if cancelled

Source code in src/biopro_sdk/plugin/dialogs.py
def get_double(
    parent=None,
    title: str = "",
    label: str = "",
    value: float = 0.0,
    min_val: float = -999.99,
    max_val: float = 999.99,
    decimals: int = 2,
) -> float | None:
    """Show float input dialog.

    Args:
        parent: Parent widget
        title: Dialog title
        label: Label text
        value: Default value
        min_val: Minimum allowed value
        max_val: Maximum allowed value
        decimals: Number of decimal places

    Returns:
        User input or None if cancelled
    """
    num, ok = QInputDialog.getDouble(parent, title, label, value, min_val, max_val, decimals)
    return num if ok else None

get_image_path(parent=None, title='Select Image', start_dir='')

Show file dialog to select an image.

Parameters:

Name Type Description Default
parent

Parent widget

None
title str

Dialog title

'Select Image'
start_dir str

Initial directory

''

Returns:

Type Description
str | None

Selected file path or None if cancelled

Source code in src/biopro_sdk/plugin/dialogs.py
def get_image_path(parent=None, title: str = "Select Image", start_dir: str = "") -> str | None:
    """Show file dialog to select an image.

    Args:
        parent: Parent widget
        title: Dialog title
        start_dir: Initial directory

    Returns:
        Selected file path or None if cancelled
    """
    file_path, _ = QFileDialog.getOpenFileName(
        parent, title, start_dir, "Images (*.png *.jpg *.jpeg *.tiff *.tif);;All Files (*)"
    )
    return file_path if file_path else None

get_image_paths(parent=None, title='Select Images', start_dir='')

Show file dialog to select multiple images.

Parameters:

Name Type Description Default
parent

Parent widget

None
title str

Dialog title

'Select Images'
start_dir str

Initial directory

''

Returns:

Type Description
list[str]

List of selected file paths

Source code in src/biopro_sdk/plugin/dialogs.py
def get_image_paths(parent=None, title: str = "Select Images", start_dir: str = "") -> list[str]:
    """Show file dialog to select multiple images.

    Args:
        parent: Parent widget
        title: Dialog title
        start_dir: Initial directory

    Returns:
        List of selected file paths
    """
    file_paths, _ = QFileDialog.getOpenFileNames(
        parent, title, start_dir, "Images (*.png *.jpg *.jpeg *.tiff *.tif);;All Files (*)"
    )
    return file_paths if file_paths else []

get_number(parent=None, title='', label='', value=0, min_val=-999999, max_val=999999)

Show integer input dialog.

Parameters:

Name Type Description Default
parent

Parent widget

None
title str

Dialog title

''
label str

Label text

''
value int

Default value

0
min_val int

Minimum allowed value

-999999
max_val int

Maximum allowed value

999999

Returns:

Type Description
int | None

User input or None if cancelled

Source code in src/biopro_sdk/plugin/dialogs.py
def get_number(
    parent=None,
    title: str = "",
    label: str = "",
    value: int = 0,
    min_val: int = -999999,
    max_val: int = 999999,
) -> int | None:
    """Show integer input dialog.

    Args:
        parent: Parent widget
        title: Dialog title
        label: Label text
        value: Default value
        min_val: Minimum allowed value
        max_val: Maximum allowed value

    Returns:
        User input or None if cancelled
    """
    num, ok = QInputDialog.getInt(parent, title, label, value, min_val, max_val)
    return num if ok else None

get_save_path(parent=None, title='Save As', start_dir='', file_filter='')

Show save file dialog.

Parameters:

Name Type Description Default
parent

Parent widget

None
title str

Dialog title

'Save As'
start_dir str

Initial directory

''
file_filter str

Qt file filter string (e.g. "CSV Files (.csv);;All Files ()")

''

Returns:

Type Description
str | None

Selected file path or None if cancelled

Source code in src/biopro_sdk/plugin/dialogs.py
def get_save_path(parent=None, title: str = "Save As", start_dir: str = "", file_filter: str = "") -> str | None:
    """Show save file dialog.

    Args:
        parent: Parent widget
        title: Dialog title
        start_dir: Initial directory
        file_filter: Qt file filter string (e.g. "CSV Files (*.csv);;All Files (*)")

    Returns:
        Selected file path or None if cancelled
    """
    if not file_filter:
        file_filter = "All Files (*)"

    file_path, _ = QFileDialog.getSaveFileName(parent, title, start_dir, file_filter)
    return file_path if file_path else None

get_text(parent=None, title='', label='', default='')

Show text input dialog.

Parameters:

Name Type Description Default
parent

Parent widget

None
title str

Dialog title

''
label str

Label text

''
default str

Default value in text field

''

Returns:

Type Description
str | None

User input or None if cancelled

Source code in src/biopro_sdk/plugin/dialogs.py
def get_text(parent=None, title: str = "", label: str = "", default: str = "") -> str | None:
    """Show text input dialog.

    Args:
        parent: Parent widget
        title: Dialog title
        label: Label text
        default: Default value in text field

    Returns:
        User input or None if cancelled
    """
    text, ok = QInputDialog.getText(parent, title, label, text=default)
    return text if ok else None

import_assets_workflow(parent, project_manager, file_paths)

Orchestrates the multi-file import workflow as requested by the user.

  1. If multiple files, asks if they should be grouped in a subdirectory.
  2. Asks once for 'Copy to Workspace' for the entire batch.
  3. Executes the batch import via ProjectManager.

Returns:

Type Description
list[str]

List of file hashes for the imported assets.

Source code in src/biopro_sdk/plugin/dialogs.py
def import_assets_workflow(parent, project_manager, file_paths: list[str]) -> list[str]:
    """Orchestrates the multi-file import workflow as requested by the user.

    1. If multiple files, asks if they should be grouped in a subdirectory.
    2. Asks once for 'Copy to Workspace' for the entire batch.
    3. Executes the batch import via ProjectManager.

    Returns:
        List of file hashes for the imported assets.
    """
    if not file_paths:
        return []

    subfolder = None
    if len(file_paths) > 1 and ask_yes_no(
        parent,
        "Group Files?",
        "Would you like to create a subdirectory in 'assets' for this collected set of files?",
    ):
        subfolder = get_text(parent, "Subdirectory Name", "Enter folder name:", default="experiment_data")
        if not subfolder or not subfolder.strip():
            subfolder = None

    copy_to_workspace = ask_yes_no(
        parent,
        "Copy to Workspace?",
        f"Copy these {len(file_paths)} files into the project assets folder?\n\n"
        "This ensures the project remains portable if moved to another computer.",
    )

    from pathlib import Path

    path_objs = [Path(p) for p in file_paths]

    return project_manager.batch_add_images(path_objs, copy_to_workspace, subfolder)

show_error(parent=None, title='Error', message='')

Show error dialog.

Parameters:

Name Type Description Default
parent

Parent widget

None
title str

Dialog title

'Error'
message str

Dialog message

''
Source code in src/biopro_sdk/plugin/dialogs.py
def show_error(parent=None, title: str = "Error", message: str = "") -> None:
    """Show error dialog.

    Args:
        parent: Parent widget
        title: Dialog title
        message: Dialog message
    """
    QMessageBox.critical(parent, title, message)

show_info(parent=None, title='Information', message='')

Show information dialog.

Parameters:

Name Type Description Default
parent

Parent widget

None
title str

Dialog title

'Information'
message str

Dialog message

''
Source code in src/biopro_sdk/plugin/dialogs.py
def show_info(parent=None, title: str = "Information", message: str = "") -> None:
    """Show information dialog.

    Args:
        parent: Parent widget
        title: Dialog title
        message: Dialog message
    """
    QMessageBox.information(parent, title, message)

show_warning(parent=None, title='Warning', message='')

Show warning dialog.

Parameters:

Name Type Description Default
parent

Parent widget

None
title str

Dialog title

'Warning'
message str

Dialog message

''
Source code in src/biopro_sdk/plugin/dialogs.py
def show_warning(parent=None, title: str = "Warning", message: str = "") -> None:
    """Show warning dialog.

    Args:
        parent: Parent widget
        title: Dialog title
        message: Dialog message
    """
    QMessageBox.warning(parent, title, message)