controller.ui.emergency_caption_dialog

File:

EuljiroWorship/controller/ui/emergency_caption_dialog.py

Author:

Benjamin Jaedon Choi - https://github.com/saintbenjamin

Affiliated Church:

The Eulji-ro Presbyterian Church [대한예수교장로회(통합) 을지로교회]

Address:

The Eulji-ro Presbyterian Church, 24-10, Eulji-ro 20-gil, Jung-gu, Seoul 04549, South Korea

Telephone:

+82-2-2266-3070

E-mail:

euljirochurch [at] G.M.A.I.L. (replace [at] with @ and G.M.A.I.L as you understood.)

License:

MIT License with Attribution Requirement (see LICENSE file for details); Copyright (c) 2025 The Eulji-ro Presbyterian Church.

Emergency caption input dialog (PySide6).

This module defines a dialog used by the slide controller to generate emergency slides on demand. It supports the following workflows:

  1. Bible reference lookup
  2. Keyword search
    • User enters a keyword query and chooses a search mode:
      • AND mode: all tokens must appear

      • Compact mode: whitespace-insensitive substring match

    • Results are shown in a table; double-clicking a result selects it.

If the first input is not recognized as a Bible reference, the dialog can also build non-Bible emergency slides using a selected slide style (e.g., “lyrics”, “hymn”, “respo”, “image”, “video”) and optional preset numbers or referenced media files.

The dialog returns a list of slide dictionaries via controller.ui.emergency_caption_dialog.EmergencyCaptionDialog.get_final_slides(), ready to be written to the slide output file and broadcast by the controller.

class controller.ui.emergency_caption_dialog.EmergencyCaptionDialog(*args, **kwargs)[source]

Bases: QDialog

PySide6 dialog for building emergency slide payloads (Bible verses or custom messages).

Supported features:

  • Bible reference input (e.g., “요 3:16”)
  • Keyword search against the selected Bible version
    • AND mode: all tokens must appear in a verse.

    • Compact mode: whitespace-insensitive substring match.

    • Double-clicking a result fills inputs and finalizes slides.

  • Non-Bible emergency slide generation
    • User chooses a slide style from core.config.style_map.STYLE_ALIASES.

    • For preset-based styles (e.g., “respo” / “hymn”), numeric inputs can load presets.

    • For media styles (e.g., “image” / “video”), a referenced asset can be selected, copied into the overlay asset directory, and previewed inside the dialog.

    • Otherwise, a manual slide is created from caption/headline inputs.

Generated slides are stored in self.finalized_slides and can be retrieved via get_final_slides().

finalized_slides

Slide dictionaries generated by the most recent preview or confirmation.

Type:

list[dict]

previewed_once

Whether the Bible-reference preview has been shown at least once.

Type:

bool

versions

Available Bible versions discovered from core.config.paths.BIBLE_DATA_DIR.

Type:

list[str]

__init__(parent=None)[source]

Initialize the emergency caption dialog UI and internal state.

This constructs all widgets used for:

  • Bible reference input and preview

  • Keyword-based Bible search and result selection

  • Manual emergency message and style-based slide generation

  • Conditional media selection and preview for image/video manual slides

Parameters:

parent (QDialog | None) – Optional parent widget for the dialog.

Returns:

None

_current_manual_style_code()[source]

Return the internal style code for the current manual-style selection.

Parameters:

None

Returns:

Internal style code such as lyrics, image, or video.

Return type:

str

update_manual_media_ui(_style_display)[source]

Update the manual input area when the selected style changes.

This method toggles the visibility and wording of the manual-input widgets so that image and video styles can reuse the existing manual entry area. It also shows or hides the appropriate preview widgets and reloads previews when a stored media path is already present.

Parameters:

_style_display (str) – Current display text emitted by the style dropdown.

Returns:

None

on_manual_media_path_changed(text)[source]

Refresh media preview when the path input changes.

This method only reacts when the currently selected manual style is image or video. The single-line manual input is interpreted as a media path and the corresponding preview area is refreshed.

Parameters:

text (str) – Current contents of the single-line manual input.

Returns:

None

select_media_file()[source]

Open a file picker for the currently selected media style.

The selected file is copied into ./html/img and the relative path is stored in the single-line manual input field.

Parameters:

None

Returns:

None

copy_media_to_img_folder(source_path)[source]

Copy the selected media file into ./html/img.

If the target directory does not exist, it is created. If a file with the same name already exists there, the existing file is reused and no second copy is made.

Parameters:

source_path (str) – Absolute path to the source media file.

Returns:

Relative media path for overlay usage, e.g. img/example.png.

Return type:

str

_resolve_preview_path(raw_path)[source]

Resolve either an absolute path or an overlay-relative img/... path.

The resolution order is:

  1. Existing absolute path

  2. Overlay-relative path under ./html/

  3. Existing local relative path from the current working directory

Parameters:

raw_path (str) – Raw path text entered by the user.

Returns:

Absolute path if the file exists; otherwise an empty string.

Return type:

str

_load_image_preview(path_or_rel)[source]

Load an image preview from either an absolute or relative path.

The resolved image is scaled to fit inside the fixed preview box and the resolved absolute path is mirrored into the media status tooltip for operator visibility.

Parameters:

path_or_rel (str) – Absolute source path or stored relative overlay path.

Returns:

None

_load_video_preview(path_or_rel)[source]

Load a video preview from either an absolute or relative path.

The resolved media source is loaded into self.player and the video preview widgets are shown. If the path cannot be resolved, the preview is stopped and a failure message is displayed instead.

Parameters:

path_or_rel (str) – Absolute source path or stored relative overlay path.

Returns:

None

play_preview()[source]

Start playing the current video preview.

Parameters:

None

Returns:

None

pause_preview()[source]

Pause the current video preview.

Parameters:

None

Returns:

None

stop_preview()[source]

Stop the current video preview.

Parameters:

None

Returns:

None

get_inputs()[source]

Retrieve the current user inputs from the dialog.

Returns:

A tuple containing:

  • The Bible reference or caption text from the first input field.

  • The emergency message or verse text from the message editor.

Return type:

tuple[str, str]

handle_verse_enter()[source]

Handle Enter key events in the Bible reference input field.

On the first Enter press, this generates and displays a preview of the resolved Bible verse or caption. On subsequent Enter presses, the dialog is accepted.

Returns:

None

Handle Enter key events in the keyword search input field.

If the keyword input is non-empty, this triggers a keyword-based Bible search using the current search mode.

Returns:

None

on_confirm_clicked()[source]

Finalize emergency slide generation and close the dialog.

If the primary input is recognized as a Bible reference, a preview is generated if not already shown. Otherwise, non-Bible emergency slides are built directly. For media styles, validation failures keep the dialog open so the operator can choose a file or correct the referenced path.

Parameters:

None

Returns:

None

show_preview()[source]

Generate and display a preview of the emergency slides.

This resolves the current inputs into slide data using controller.utils.emergency_slide_factory.EmergencySlideFactory and renders a text preview in the UI. Generated slides are stored internally for later retrieval.

Returns:

None

Execute a keyword-based Bible search.

This searches the selected Bible version using the chosen search mode and populates the result table with matches.

Returns:

None

on_result_selected(index)[source]

Handle selection of a Bible verse from the keyword search results.

The selected verse reference and text are applied to the input fields, emergency slides are generated, and the dialog is accepted.

Parameters:

index (QModelIndex) – Model index corresponding to the selected table row.

Returns:

None

build_non_bible_slides()[source]

Build emergency slides from manual inputs and selected style.

Depending on the chosen style and caption input, this may:

  • Load a preset responsive reading or hymn slide.

  • Create a manual emergency slide with custom caption and text.

  • Create an image/video slide using a selected media file path.

For media styles, the single-line input stores the referenced asset path while the multiline editor stores optional caption/description text.

Parameters:

None

Returns:

True if the build step completed and the dialog may close. False if validation failed and the dialog should remain open.

Return type:

bool

get_final_slides()[source]

Return the list of finalized slides generated from the last preview.

This method provides access to the slide data created during the most recent call to show_preview() or build_non_bible_slides(). These slides reflect the selected Bible version and parsed reference or manual input.

Returns:

A list of slide dictionaries generated by the most recent preview, selection, or manual build operation.

Return type:

list[dict]