gui.ui.tab_verse_logic

File:

EuljiroBible/gui/ui/tab_verse_logic.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.

Provides logic for verse display, saving, and verse shifting for the gui.ui.tab_verse.TabVerse UI.

class gui.ui.tab_verse_logic.TabVerseLogic(bible_data, tr_func, settings, current_language)[source]

Bases: object

Backend logic for displaying, exporting, and navigating Bible verses.

This class provides the non-UI operations used by the TabVerse GUI tab. It delegates complex formatting and parsing to shared logic functions while holding the dependencies required for verse retrieval, localization, and output persistence.

bible_data

Bible data loader instance used to access verse content.

Type:

BibleDataLoader

tr

Translation function used for localized UI messages.

Type:

Callable[[str], str]

settings

Application settings dictionary used for output persistence.

Type:

dict

current_language

Active UI language code (e.g., “ko”, “en”).

Type:

str

delta

Verse navigation direction used by shift_verse (+1 for next, -1 for previous). This is set externally by the UI layer.

Type:

int

__init__(bible_data, tr_func, settings, current_language)[source]

Initialize the logic handler with dependencies.

Parameters:
  • bible_data (BibleDataLoader) – Bible data loader instance containing Bible content.

  • tr_func (Callable[[str], str]) – Translation function for localized UI strings.

  • settings (dict) – Application settings dictionary used for output.

  • current_language (str) – Current UI language code (e.g., “ko”, “en”).

display_verse(ref_func, verse_input, apply_output_text)[source]

Render and return formatted verse text for the current UI reference.

This delegates to the shared verse display implementation, injecting the current dependencies (bible_data, translation function, settings, language) and a callback for applying output to the UI.

Parameters:
  • ref_func (Callable[[], tuple]) – Callback returning the current resolved reference. Expected to return a tuple like: (versions, book, chapter, verse_range, warning).

  • verse_input (QLineEdit) – Verse input widget (used by the shared display logic).

  • apply_output_text (Callable[[str], None]) – Callback that applies rendered text to the UI.

Returns:

Rendered verse output, or None if display failed.

Return type:

str | tuple | None

save_verse(formatted_verse_text)[source]

Save formatted verse text to the configured output destination.

Parameters:

formatted_verse_text (str) – Verse text to save. If empty/None, an empty string is written.

Raises:

Exception – If saving fails.

shift_verse(ref_func, verse_input_widget)[source]

Shift the current verse number by self.delta and update the input widget.

This validates that a single verse is selected (not a range), determines the maximum verse count for the chapter, computes the new verse number, and writes it back into the verse input widget.

Parameters:
  • ref_func (Callable[[], tuple]) – Callback returning the current resolved reference. Expected to return: (versions, book, chapter, verse_range, warning).

  • verse_input_widget (QLineEdit) – Verse input widget to update with the new verse number.

Returns:

New verse number if shifting succeeds; otherwise None.

Return type:

int | None

Raises:

Exception – If reference data is invalid, the book/chapter cannot be resolved, or shifting is not possible (e.g., verse range selected).