core.generator.ui.contents.hymn_content

File:

EuljiroWorship/core/generator/ui/contents/hymn_content.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.

UI content widget for editing “hymn” style slides.

This module defines core.generator.ui.contents.hymn_content.HymnContent, a QWidget that provides an interface for editing “hymn”-based slides. It supports selecting a hymn by number, loading its title and lyrics from local JSON files, editing the content, and saving updates back to the hymn database.

Hymn data is stored as JSON files under a predefined directory (e.g., data/hymns/), and this widget serves as a lightweight editor and viewer for that dataset within the slide generator.

class core.generator.ui.contents.hymn_content.HymnContent(*args, **kwargs)[source]

Bases: QWidget

Content editor widget for “hymn” style slides.

This widget provides a small editor for hymn-based slides, including:

  • Selecting a hymn by number

  • Loading hymn JSON data from the local hymn database

  • Viewing/editing the hymn title and lyrics

  • Saving edits back to the JSON database

  • Producing slide payloads for the generator/controller export flow

The widget is designed to integrate with the generator window via core.generator.utils.slide_input_submitter.SlideInputSubmitter, so edits can be reflected in the current slide state automatically.

Parameters:
  • caption (str)

  • headline (str)

caption

Initial caption value passed at construction time. Often contains the hymn title or a string like “새찬송가 88장”.

Type:

str

headline

Initial lyrics text passed at construction time.

Type:

str

hymn_data

In-memory representation of the currently loaded hymn JSON file. This is updated when a hymn is loaded and then reused on save.

Type:

dict

generator_window

Reference to the generator window that receives live slide updates and manages auto-save/session logic.

number_input

Input field for the hymn number. Pressing Enter triggers loading.

Type:

QLineEdit

title_edit

Editor for the hymn title (used as the slide caption).

Type:

QLineEdit

headline_edit

Editor for the hymn lyrics (used as the slide headline). Font is set via get_font_from_settings().

Type:

QTextEdit

load_button

Button that triggers hymn loading for the number in number_input.

Type:

QPushButton

save_button

Button that writes the current hymn_data back to disk.

Type:

QPushButton

submitter

Auto-submit helper that observes inputs and provides updated slide payloads via build_hymn_slide(). Created after a hymn is loaded.

Type:

SlideInputSubmitter

__init__(parent, generator_window, caption='', headline='')[source]

Initialize the hymn content editor.

Parameters:
  • parent (QWidget) – Parent widget container.

  • generator_window – Reference to the generator window, used for submitting slide data and enabling auto-save behavior.

  • caption (str) – Initial title or caption value, often containing the hymn title.

  • headline (str) – Initial lyrics text.

Returns:

None

build_ui()[source]

Construct the UI layout and bind widget actions.

This method initializes all input fields and buttons, sets up layout structure, and attempts to automatically extract the hymn number from the initial caption if present.

Parameters:

None

Returns:

None

load_hymn_by_number()[source]

Load hymn data from the local JSON database using the selected number.

The method validates the hymn number, checks that it falls within the available range, and attempts to load the corresponding JSON file. On success, the title and lyrics fields are populated.

Parameters:

None

Returns:

None

Raises:
  • OSError – If the hymn directory cannot be accessed.

  • json.JSONDecodeError – If the hymn JSON file exists but contains invalid data.

build_hymn_slide()[source]

Conditionally generate hymn slide data.

If both the title and lyrics fields are empty, no slide data is generated. Otherwise, the current input values are returned as a slide data dictionary.

Parameters:

None

Returns:

Slide data dictionary if at least one field is non-empty; otherwise, None.

Return type:

dict | None

get_hymn_number_range()[source]

Determine the valid range of hymn numbers from the local database.

This method scans the hymn JSON directory and extracts the minimum and maximum hymn numbers available.

Parameters:

None

Returns:

A tuple containing the minimum and maximum hymn numbers. Returns (0, 0) if no valid hymn files are found.

Return type:

tuple[int, int]

get_slide_data()[source]

Generate the slide data dictionary for a hymn slide.

Parameters:

None

Returns:

Dictionary representing the hymn slide, including:

  • style

  • caption (hymn title)

  • headline (lyrics)

Return type:

dict

save_hymn_json()[source]

Save the current hymn data back to its JSON file.

This method updates the title and lyrics fields in the corresponding hymn JSON file. If the hymn number is missing or invalid, the save operation is aborted and the user is warned.

Parameters:

None

Returns:

None

Raises:

OSError – If the hymn file cannot be written.