gui.ui.widget_overlay

File:

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

Defines an overlay widget for displaying Bible verses in EuljiroBible.

class gui.ui.widget_overlay.WidgetOverlay(*args, **kwargs)[source]

Bases: QWidget

Overlay widget that displays verse output text in a dedicated window.

This widget watches (and optionally polls) the configured verse output file (e.g., verse_output.txt) and renders its contents as an on-screen overlay. It supports two display modes:

  • “fullscreen”: frameless, translucent background window intended for projection/overlay use

  • non-fullscreen/windowed: standard resizable window for testing or local preview

The widget applies user-configured font/color/background settings and includes a simple auto-shrinking mechanism to fit long text within the available area.

mode

Display mode (“fullscreen” or windowed variant used by caller).

Type:

str

base_font_size

Base font size used as the starting point for auto-fit.

Type:

int

last_text

Last rendered text content used to detect changes.

Type:

str

poll_timer

Polling timer used when polling is enabled.

Type:

QTimer | None

verse_path

Path to the verse output file being watched/polled.

Type:

str

watcher

File watcher for verse_path change notifications.

Type:

QFileSystemWatcher

label

Central label used to display the verse text.

Type:

QLabel

bg_style

CSS fragment for background color (rgba) used in the label stylesheet.

Type:

str

text_color

Current text color in hex (e.g., “#000000”).

Type:

str

__init__(font_family, font_size, text_color, bg_color, alpha, mode, geometry, parent=None)[source]

Initialize the overlay widget and start file watching/polling.

Parameters:
  • font_family (str) – Font family used for displayed text.

  • font_size (int) – Base font size used as the starting point for auto-fit.

  • text_color (str) – Text color in hex (e.g., “#000000”).

  • bg_color (str) – Background color in hex (e.g., “#FFFFFF”).

  • alpha (float) – Background alpha value used for rgba composition.

  • mode (str) – Display mode (“fullscreen” or windowed variant used by caller).

  • geometry (QRect) – Initial window geometry.

  • parent (QWidget | None) – Optional parent widget.

apply_settings()[source]

Apply updated display settings from persisted configuration.

This reloads font family/size/weight and overlay color/background settings from ConfigManager, applies them to the label, updates the stylesheet, and re-runs auto-fit against the currently displayed text.

apply_stylesheet()[source]

Apply the current text and background style to the label.

This composes the label stylesheet from:

  • text color

  • background rgba style

  • padding / border rules depending on fullscreen vs windowed mode

adjust_font_size(text)[source]

Auto-adjust the label font size to fit the given text within the widget.

This reduces the font size in steps until the rendered bounding rectangle fits within a fraction of the available widget width/height.

Parameters:

text (str) – Text content to fit.

display_text(text)[source]

Display text in the overlay and apply auto-fit sizing.

Parameters:

text (str) – Text to display.

read_verse_file()[source]

Read and return the current verse output file contents.

Returns:

Stripped file content if read succeeds; otherwise None.

Return type:

str | None

reload_text()[source]

Reload the verse file content and update the overlay display.

If the verse file is empty, the overlay closes itself (treated as an intentional “clear overlay” signal). Otherwise, the new text is rendered and cached.

poll_file()[source]

Polling loop callback to detect file changes.

When polling is enabled, this periodically reads the verse file and triggers a reload if the contents differ from the last rendered text.

on_file_changed(path)[source]

Handle file change notifications from QFileSystemWatcher.

This re-adds the path to the watcher (to handle certain platform behaviors where the watch can be dropped on write/replace) and reloads the verse content.

Parameters:

path (str) – Changed file path.

resizeEvent(event)[source]

Handle widget resize events and re-run auto-fit for the currently displayed text.

Parameters:

event (QResizeEvent) – Resize event.

keyPressEvent(event)[source]

Handle key press events for overlay control.

Pressing ESC closes the overlay window. Other keys are passed to the base class.

Parameters:

event (QKeyEvent) – Key event.

closeEvent(event)[source]

Handle widget close events and stop active polling/watching resources.

Parameters:

event (QCloseEvent) – Close event.