Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@ Note the inconsistency: `get_selected_book_from_dropdown()` returns an already-a

## Theming

`THEMES` is a dict of named palettes with a fixed key set (`bg`, `fg`, `text_bg`, `text_fg`, `entry_bg`, `entry_fg`, `btn_bg`, `sel_bg`, `sel_fg`). Adding a theme means adding one entry with **all** keys — `_theme_widget()` indexes them unconditionally.
`THEMES` is a dict of named palettes with a fixed key set (`bg`, `fg`, `text_bg`, `text_fg`, `entry_bg`, `entry_fg`, `btn_bg`, `sel_bg`, `sel_fg`, `red`). Adding a theme means adding one entry with **all** keys — `_theme_widget()` indexes them unconditionally.

`_theme_widget()` walks the widget tree recursively and dispatches on `winfo_class()`. Classic `tk` widgets are recolored per-class there; `ttk` widgets (Combobox, Button, Scrollbar) can't be, so they're styled through `ttk.Style()` in `apply_theme()`. `ttk.Style().theme_use("clam")` is set at import time precisely because the native macOS/Windows ttk themes ignore color overrides — don't remove it. `Toplevel` is deliberately skipped so dialogs keep native chrome.

If you add a new widget kind, it needs a branch in `_theme_widget()` (tk) or a `style.configure` call (ttk), or it will stay unthemed.

## Red letters (words of Christ)

`red_letter_kjv.json` is copied verbatim from the Bible-Verse Android app (`app/src/main/assets/`): `"bookIndex:chapter:verse"` → the verse text with the words of Christ wrapped in `<font color="#CC0000">…</font>`, 2027 entries. `bookIndex` indexes `books_file_names`. Every entry's text matches this repo's verse files exactly — keep it that way when replacing either.

`_load_red_letter()` parses it once into `(plain text, [(start, end), …])`. `update_bible_text_widget(text, book_at)` inserts the text, then `apply_red_letter()` walks the widget's lines and adds the `red` tag to matching verses. `book_at(line, chapter, verse)` says which book a line belongs to: `one_book(i)` for book/chapter/verse views, a line→book dict for search results (each result is exactly two lines), and `whole_bible()` for `Bible.txt`, which detects book boundaries by the verse numbering going backwards — not by `1:1:`, since 2 Corinthians starts at 1:2. A verse is tagged only if its text equals the entry's plain text, so a misaligned line is skipped rather than miscoloured. `apply_theme()` sets the tag colour and raises `sel` above it. A missing JSON file just means no red letters.

All three packagers install the JSON explicitly — their globs only cover `*.py` and `*.txt`.

## Settings persistence

`settings.json` holds `theme`, `font_family`, `font_size` and lives at `$XDG_CONFIG_HOME/bibleapp/settings.json` (default `~/.config/bibleapp/`), resolved by `_config_path()`. It is **not** next to the script: packaged installs mount the program directory read-only, so writes there fail silently. `_config_path()` falls back to the old in-tree location only if the config dir can't be created.
Expand Down
106 changes: 96 additions & 10 deletions bible-gui-tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def _set_dock_icon():
"btn_bg": "#a8a8a8",
"sel_bg": "#0078d7",
"sel_fg": "#ffffff",
"red": "#cc0000",
},
"Dark": {
"bg": "#2d2d2d",
Expand All @@ -59,6 +60,7 @@ def _set_dock_icon():
"btn_bg": "#3c3c3c",
"sel_bg": "#264f78",
"sel_fg": "#ffffff",
"red": "#f47067",
},
"Sepia": {
"bg": "#f0e6c8",
Expand All @@ -70,6 +72,7 @@ def _set_dock_icon():
"btn_bg": "#c8a050",
"sel_bg": "#8b6914",
"sel_fg": "#ffffff",
"red": "#b00000",
},
"High Contrast": {
"bg": "#000000",
Expand All @@ -81,6 +84,7 @@ def _set_dock_icon():
"btn_bg": "#1a1a1a",
"sel_bg": "#ffff00",
"sel_fg": "#000000",
"red": "#ff5555",
},
}

Expand Down Expand Up @@ -152,9 +156,83 @@ def clean(s):
def hasonlyspaces(string):
return not string or string.isspace()

def update_bible_text_widget(text):
def update_bible_text_widget(text, book_at=None):
bible_text_widget.delete("1.0", "end")
bible_text_widget.insert(tk.END, text)
if book_at:
apply_red_letter(book_at)

def book_index(path):
return books_file_names.index(os.path.basename(path))

# ── Red letters (words of Christ) ─────────────────────────────────────────────
# Same data as the Bible-Verse Android app: red_letter_kjv.json maps
# "bookIndex:chapter:verse" (bookIndex into books_file_names) to the verse text
# with the words of Christ wrapped in <font color="#CC0000">…</font>. Parsed once
# here into (plain text, [(start, end), …]) so tagging is just offset math.
VERSE_LINE = re.compile(r'^\s*(\d+):(\d+):\s?(.*?)\s*$')
FONT_SPAN = re.compile(r'<font[^>]*>(.*?)</font>', re.S)

def _load_red_letter():
try:
with open(_bpath("red_letter_kjv.json"), encoding="utf-8") as f:
data = json.load(f)
except (OSError, json.JSONDecodeError):
return {} # no data file — the app simply shows no red letters
parsed = {}
for ref, html in data.items():
plain, spans, pos = "", [], 0
for m in FONT_SPAN.finditer(html):
plain += html[pos:m.start()]
spans.append((len(plain), len(plain) + len(m[1])))
plain += m[1]
pos = m.end()
plain += html[pos:]
lead = len(plain) - len(plain.lstrip())
parsed[ref] = (plain.strip(), [(s - lead, e - lead) for s, e in spans])
return parsed

RED_LETTER = _load_red_letter()

def apply_red_letter(book_at):
"""Tag the words of Christ in whatever the text widget is showing.

book_at(line_number, chapter, verse) returns the book index a verse line
belongs to. A verse is only tagged when its text matches the red-letter
entry exactly, so a stray line can never get the wrong span coloured.
"""
bible_text_widget.tag_remove("red", "1.0", "end")
lines = bible_text_widget.get("1.0", "end-1c").split("\n")
for n, line in enumerate(lines, start=1):
m = VERSE_LINE.match(line)
if not m:
continue
ch, v = int(m[1]), int(m[2])
entry = RED_LETTER.get(f"{book_at(n, ch, v)}:{ch}:{v}")
if not entry or entry[0] != m[3]:
continue
col = m.start(3)
for s, e in entry[1]:
bible_text_widget.tag_add("red", f"{n}.{col + s}", f"{n}.{col + e}")

def one_book(index):
return lambda n, ch, v: index

def whole_bible():
"""book_at for Bible.txt, which runs all 66 books together.

A new book starts wherever the verse numbering goes backwards. Watching for
"1:1:" would not do: 2 Corinthians 1:1 is missing from the data, so that
book starts at 1:2.
"""
book, prev = 0, None
def book_at(n, ch, v):
nonlocal book, prev
if prev and (ch, v) < prev:
book += 1
prev = (ch, v)
return book
return book_at

def apply_font():
bible_text_widget.config(font=(_font_family.get(), _font_size.get()))
Expand Down Expand Up @@ -214,6 +292,8 @@ def apply_theme(theme_name=None, target=None):
foreground=[("active", t["sel_fg"]), ("pressed", t["sel_fg"])])

_theme_widget(target or window, t)
bible_text_widget.tag_configure("red", foreground=t["red"])
bible_text_widget.tag_raise("sel") # selection colours win over red text
apply_font()

# ── Context menu ─────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -358,7 +438,7 @@ def _block_text_edit(event):
# ── Navigation callbacks ──────────────────────────────────────────────────────
def go_home():
with open(_bpath("Bible.txt"), "r") as f:
update_bible_text_widget(f.read())
update_bible_text_widget(f.read(), whole_bible())

def get_selected_book_from_dropdown():
return _bpath(books_file_names[books_titled.index(book_selector_combobox.get())])
Expand All @@ -369,7 +449,7 @@ def get_selected_chapter_from_dropdown():
def get_selected_book(event):
filename = get_selected_book_from_dropdown()
with open(filename, "r") as f:
update_bible_text_widget(f.read())
update_bible_text_widget(f.read(), one_book(book_index(filename)))
with open(filename, "r") as f:
lines = f.readlines()
n_chapters = int(lines[-1].split(':')[0])
Expand All @@ -385,15 +465,17 @@ def get_selected_chapter(event):
)
verse_selector_combobox['values'] = [str(i + 1) for i in range(len(chapter_list))]
verse_selector_combobox.set("")
update_bible_text_widget(" ".join(chapter_list))
update_bible_text_widget(" ".join(chapter_list),
one_book(book_index(get_selected_book_from_dropdown())))

def get_selected_verse(event):
verse_text = ChapterVerse.get_verse(
get_selected_book_from_dropdown(),
get_selected_chapter_from_dropdown(),
int(verse_selector_combobox.get())
)
update_bible_text_widget(verse_text)
update_bible_text_widget(verse_text,
one_book(book_index(get_selected_book_from_dropdown())))

book_selector_combobox.bind("<<ComboboxSelected>>", get_selected_book)
chapter_selector_combobox.bind("<<ComboboxSelected>>", get_selected_chapter)
Expand All @@ -420,9 +502,10 @@ def search_button_event():
linearsearch(word)

def linearsearch(searchkey):
results = []
key_lower = searchkey.lower()
pattern = re.compile(r'\b' + re.escape(key_lower) + r'\b') if whole_word_var.get() else None
results = []
line_books = {} # widget line number -> book index, for red letters
key_lower = searchkey.lower()
pattern = re.compile(r'\b' + re.escape(key_lower) + r'\b') if whole_word_var.get() else None

for book in get_search_files():
with open(_bpath(book)) as f:
Expand All @@ -432,7 +515,10 @@ def linearsearch(searchkey):
verse_lower = verse.lower()
matched = bool(pattern.search(verse_lower)) if pattern else key_lower in verse_lower
if matched:
results.append(f"{book_title}\n{verse}")
# Each result is exactly two lines, so the verse sits on line 2k+2.
# A book's last line may lack its newline; add one so it holds.
line_books[2 * len(results) + 2] = book_index(book)
results.append(f"{book_title}\n{verse.rstrip(chr(10))}\n")

count = len(results)
if count == 0:
Expand All @@ -442,7 +528,7 @@ def linearsearch(searchkey):
)
results_label.config(text=f"No results for '{searchkey}'")
else:
update_bible_text_widget("".join(results))
update_bible_text_widget("".join(results), lambda n, ch, v: line_books.get(n))
noun = "result" if count == 1 else "results"
results_label.config(text=f"{count} {noun} for '{searchkey}'")

Expand Down
1 change: 1 addition & 0 deletions flatpak/io.github.josh_reimer.BibleApp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ modules:
- install -d /app/share/bibleapp
- install -Dm644 -t /app/share/bibleapp *.py
- install -Dm644 -t /app/share/bibleapp *.txt
- install -Dm644 -t /app/share/bibleapp red_letter_kjv.json
- install -Dm644 black-bible.png
/app/share/icons/hicolor/256x256/apps/io.github.josh_reimer.BibleApp.png
- install -Dm644 flatpak/io.github.josh_reimer.BibleApp.desktop
Expand Down
1 change: 1 addition & 0 deletions packaging/build-appimage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ install -d "$APPDIR/usr/share/bibleapp" \
install -m644 "$ROOT"/*.py "$APPDIR/usr/share/bibleapp/"
find "$ROOT" -maxdepth 1 -name '*.txt' ! -name 'bibleSearchResult.txt' \
-exec install -m644 {} "$APPDIR/usr/share/bibleapp/" \;
install -m644 "$ROOT/red_letter_kjv.json" "$APPDIR/usr/share/bibleapp/"

# Shared with the Flatpak and .deb builds; see packaging/build-deb.sh.
DESKTOP=io.github.josh_reimer.BibleApp.desktop
Expand Down
1 change: 1 addition & 0 deletions packaging/build-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ install -d "$STAGE/DEBIAN" \
install -m644 "$ROOT"/*.py "$STAGE/usr/share/bibleapp/"
find "$ROOT" -maxdepth 1 -name '*.txt' ! -name 'bibleSearchResult.txt' \
-exec install -m644 {} "$STAGE/usr/share/bibleapp/" \;
install -m644 "$ROOT/red_letter_kjv.json" "$STAGE/usr/share/bibleapp/"

cat > "$STAGE/usr/bin/bibleapp" <<'EOF'
#!/bin/sh
Expand Down
1 change: 1 addition & 0 deletions red_letter_kjv.json

Large diffs are not rendered by default.

Loading