From 6950d25d0c646318ee5ec4784b836c63a1f319b7 Mon Sep 17 00:00:00 2001 From: eliranwong Date: Thu, 31 Oct 2024 23:14:05 +0000 Subject: [PATCH] added `chapter:::` and compare `comparechapter:::` --- setup.py | 2 +- uniquebible/db/BiblesSqlite.py | 2 +- uniquebible/util/TextCommandParser.py | 81 ++++++++++++++++++++++++++- 3 files changed, 80 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 2d69e5d8fc..eab6a7f5c1 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ # https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/ setup( name=package, - version="0.1.43", + version="0.1.45", python_requires=">=3.8, <3.13", description=f"UniqueBible App is a cross-platform & offline bible application, integrated with high-quality resources and unique features. Developers: Eliran Wong and Oliver Tseng", long_description=long_description, diff --git a/uniquebible/db/BiblesSqlite.py b/uniquebible/db/BiblesSqlite.py index 490d4278d7..820ac43815 100644 --- a/uniquebible/db/BiblesSqlite.py +++ b/uniquebible/db/BiblesSqlite.py @@ -323,7 +323,7 @@ def getVerses(self, b=config.mainB, c=config.mainC, text=""): return " ".join(["{0}{1}".format(self.formVerseTag(b, c, verse, text), verse) for verse in verseList]) def compareVerse(self, verseList, texts=["ALL"]): - if len(verseList) == 1 and not texts == ["ALL"]: + if len(verseList) == 1 and not texts == ["ALL"] and not config.rawOutput: b, c, v, *_ = verseList[0] return self.compareVerseChapter(b, c, v, texts) else: diff --git a/uniquebible/util/TextCommandParser.py b/uniquebible/util/TextCommandParser.py index e32ad5b1f5..6ceb602477 100644 --- a/uniquebible/util/TextCommandParser.py +++ b/uniquebible/util/TextCommandParser.py @@ -91,6 +91,10 @@ def __init__(self, parent): # e.g. BIBLE:::Jn 3:16; Rm 5:8; Deu 6:4 # e.g. BIBLE:::KJV:::John 3:16 # e.g. BIBLE:::KJV:::Jn 3:16; Rm 5:8; Deu 6:4"""), + "chapter": (self.textFormattedChapter, """ + # [KEYWORD] CHAPTER + # Feature - Open bible versions of a single chapter. + # Usage - CHAPTER:::[BIBLE_VERSION(S)]:::[BIBLE_CHAPTER]"""), "main": (self.textMain, """ # [KEYWORD] MAIN # Feature - Open a bible chapter or multiples verses on main view. @@ -143,6 +147,10 @@ def __init__(self, parent): # e.g. COMPARE:::John 3:16 # e.g. COMPARE:::KJV_NET_CUV:::John 3:16 # e.g. COMPARE:::KJV_NET_CUV:::John 3:16; Rm 5:8"""), + "comparechapter": (self.textCompareChapter, """ + # [KEYWORD] COMPARECHAPTER + # Feature - Compare bible versions of a single chapter. + # Usage - COMPARECHAPTER:::[BIBLE_VERSION(S)]:::[BIBLE_CHAPTER]"""), "sidebyside": (self.textCompareSideBySide, """ # [KEYWORD] SIDEBYSIDE # Feature - Compare bible versions side by side @@ -1445,6 +1453,38 @@ def textFormattedBible(self, verse, text, source=""): content = f"{content}
{config.mainWindow.divider}
{singleVerse}" return content + def textFormattedChapter(self, command, source): + if command.count(":::") == 0: + if config.openBibleInMainViewOnly: + updateViewConfig, viewText, *_ = self.getViewConfig("main") + else: + updateViewConfig, viewText, *_ = self.getViewConfig(source) + command = "{0}:::{1}".format(viewText, command) + texts, references = self.splitCommand(command) + verseList = self.extractAllVerses(references) + if not verseList: + return self.invalidCommand() + texts = self.getConfirmedTexts(texts) + marvelBibles = self.getMarvelBibles() + if not texts: + return self.invalidCommand() + else: + self.cancelBibleParallels() + text = texts[0] + if text in marvelBibles: + fileItems = marvelBibles[text][0] + if os.path.isfile(os.path.join(*fileItems)): + content = self.textFormattedBible(verseList[0], text, source) + return ("main", content, {}) + else: + databaseInfo = marvelBibles[text] + if self.parent is not None: + self.parent.downloadHelper(databaseInfo) + return ("", "", {}) + else: + content = self.textFormattedBible(verseList[0], text, source) + return ("main", content, {}) + # cmd::: # run os command def osCommand(self, command, source): @@ -2540,10 +2580,13 @@ def distinctTranslation(self, command, source): display = " | ".join(translations) return ("study", display, {}) + def getAllFavouriteBibles(self): + return sorted(set([config.mainText, config.favouriteBible, config.favouriteBible2, config.favouriteBible3, config.favouriteBiblePrivate, config.favouriteBiblePrivate2, config.favouriteBiblePrivate3])) + # COMPARE::: def textCompare(self, command, source): if command.count(":::") == 0: - confirmedTexts = ["ALL"] + confirmedTexts = self.getAllFavouriteBibles() verseList = self.extractAllVerses(command) else: texts, references = self.splitCommand(command) @@ -2559,8 +2602,9 @@ def textCompare(self, command, source): config.mainCssBibleFontStyle = "" texts = confirmedTexts if confirmedTexts == ["ALL"]: - plainBibleList, formattedBibleList = biblesSqlite.getTwoBibleLists() - texts = set(plainBibleList + formattedBibleList) + #plainBibleList, formattedBibleList = biblesSqlite.getTwoBibleLists() + #texts = set(plainBibleList + formattedBibleList) + texts = self.getAllFavouriteBibles() for text in texts: (fontFile, fontSize, css) = Bible(text).getFontInfo() config.mainCssBibleFontStyle += css @@ -2569,6 +2613,37 @@ def textCompare(self, command, source): updateViewConfig(viewText, verseList[-1]) return ("study" if config.compareOnStudyWindow else "main", verses, {}) + # COMPARECHAPTER::: + def textCompareChapter(self, command, source): + if command.count(":::") == 0: + confirmedTexts = self.getAllFavouriteBibles() + verseList = self.extractAllVerses(command) + else: + texts, references = self.splitCommand(command) + confirmedTexts = self.getConfirmedTexts(texts) + verseList = self.extractAllVerses(references) + if not confirmedTexts or not verseList: + return self.invalidCommand() + else: + if config.runMode == "terminal" and not confirmedTexts == ["ALL"]: + config.compareParallelList = confirmedTexts + config.terminalBibleComparison = True + biblesSqlite = BiblesSqlite() + config.mainCssBibleFontStyle = "" + texts = confirmedTexts + if confirmedTexts == ["ALL"]: + #plainBibleList, formattedBibleList = biblesSqlite.getTwoBibleLists() + texts = self.getAllFavouriteBibles() + for text in texts: + (fontFile, fontSize, css) = Bible(text).getFontInfo() + config.mainCssBibleFontStyle += css + #verses = biblesSqlite.compareVerse(verseList, confirmedTexts) + b, c, v, *_ = verseList[0] + verses = biblesSqlite.compareVerseChapter(b, c, v, confirmedTexts) + updateViewConfig, viewText, *_ = self.getViewConfig(source) + updateViewConfig(viewText, verseList[0]) + return ("study" if config.compareOnStudyWindow else "main", verses, {}) + # SIDEBYSIDE::: def textCompareSideBySide(self, command, source): if command.count(":::") == 0: