Repository: eliranwong/UniqueBible (language: python)

Issue:
Ver 25.77; Import theWord OT Bibles, etc



Discussion / hints:

Fix patch:
diff --git a/UniqueBibleAppVersion.txt b/UniqueBibleAppVersion.txt
index 84b6f7bd10..24663eb6d1 100644
--- a/UniqueBibleAppVersion.txt
+++ b/UniqueBibleAppVersion.txt
@@ -1,1 +1,1 @@
-25.76
+25.77
diff --git a/db/BiblesSqlite.py b/db/BiblesSqlite.py
index d7ce901282..8493484034 100644
--- a/db/BiblesSqlite.py
+++ b/db/BiblesSqlite.py
@@ -1,6 +1,7 @@
 """
 Reading data from bibles.sqlite
 """
+import glob
 import os, sqlite3, config, re, logging
 
 from util.BibleVerseParser import BibleVerseParser
@@ -1083,8 +1084,9 @@ def insertReadBibleLink(text, b):
                 for index, dir in enumerate(directories):
                     if index > 2:
                         index = 2
-                    directory = "audio/bibles/{0}/{1}/{2}".format(text, dir, "{:02d}".format(b))
-                    if os.path.exists(directory):
+                    directory = "audio/bibles/{0}/{1}/{2}*".format(text, dir, "{:02d}".format(b))
+                    directories = [d for d in glob.glob(directory) if os.path.isdir(d)]
+                    if len(directories) > 0:
                         icon = '&#{0}'.format(128264 + index)
                         data += """ <ref onclick="document.title='READBIBLE:::@{0}'" title="{0}" style="font-size: .8em">{1}</ref>""".format(dir, icon)
         return data
diff --git a/gui/AlephMainWindow.py b/gui/AlephMainWindow.py
index b7055de465..8c3e3956c6 100644
--- a/gui/AlephMainWindow.py
+++ b/gui/AlephMainWindow.py
@@ -158,7 +158,7 @@ def create_menu(self):
         masterControlMenu.addAction(QAction(config.thisTranslation["mediaPlayer"], self, shortcut=sc.openControlPanelTab6,
                                             triggered=lambda: self.openControlPanelTab(6)))
 
-        navigation_menu.addAction(QAction(config.thisTranslation["menu1_miniControl"], self, shortcut=sc.manageMiniControl, triggered=self.manageMiniControl))
+        navigation_menu.addAction(QAction(config.thisTranslation["menu1_miniControl"], self, shortcut=sc.manageMiniControl, triggered=lambda : self.openMiniControlTab(1)))
         navigation_menu.addSeparator()
         navigation_menu.addAction(
             QAction(config.thisTranslation["menu_first_chapter"], self, shortcut=sc.gotoFirstChapter, triggered=self.gotoFirstChapter))
diff --git a/gui/MainWindow.py b/gui/MainWindow.py
index 670ba9974c..cafa2cb90e 100644
--- a/gui/MainWindow.py
+++ b/gui/MainWindow.py
@@ -255,7 +255,7 @@ def focusCommandLineField(self):
 
     def openMiniControlTab(self, index):
         config.miniControlInitialTab = index
-        self.manageMiniControl()
+        self.manageMiniControl(index)
 
     def openControlPanelTab(self, index=None, b=None, c=None, v=None, text=None):
         if index is None:
@@ -331,7 +331,7 @@ def manageControlPanel(self, show=True, index=None, b=None, c=None, v=None, text
         else:
             self.textCommandParser.databaseNotInstalled("bible")
 
-    def manageMiniControl(self):
+    def manageMiniControl(self, selectedTab = 0):
         if config.miniControl:
             textCommandText = self.textCommandLineEdit.text()
             if textCommandText:
@@ -339,7 +339,7 @@ def manageMiniControl(self):
             self.miniControl.tabs.setCurrentIndex(config.miniControlInitialTab)
             self.bringToForeground(self.miniControl)
         else:
-            self.miniControl = MiniControl(self)
+            self.miniControl = MiniControl(self, selectedTab)
             self.miniControl.setMinimumHeight(config.minicontrolWindowHeight)
             self.miniControl.setMinimumWidth(config.minicontrolWindowWidth)
             self.miniControl.show()
@@ -1479,7 +1479,8 @@ def importModules(self):
                   "e-Sword Dictionaries [Apple] (*.dcti);;e-Sword Lexicons [Apple] (*.lexi);;e-Sword Books [Apple] (*.refi);;"
                   "MyBible Bibles (*.SQLite3);;MyBible Commentaries (*.commentaries.SQLite3);;MyBible Dictionaries (*.dictionary.SQLite3);;"
                   "XML [Beblia/OSIS/Zefania] (*.xml);;"
-                  "theWord (*.nt);;"
+                  "theWord Complete Bibles (*.ont);;"
+                  "theWord NT Bibles (*.nt);;"
                   "Word Documents (*.docx);;"
                   "PDF Documents (*.pdf)"), "", options)
         if fileName:
@@ -1512,6 +1513,8 @@ def importModules(self):
                 self.importXMLBible(fileName)
             elif fileName.endswith(".nt"):
                 self.importTheWordBible(fileName)
+            elif fileName.endswith(".ont"):
+                self.importTheWordBible(fileName)
 
     def customMarvelData(self):
         options = QFileDialog.DontResolveSymlinks | QFileDialog.ShowDirsOnly
@@ -1682,7 +1685,11 @@ def openVlcPlayer(self, filename=""):
                 from gui.VlcPlayer import VlcPlayer
                 if self.vlcPlayer is not None:
                     self.vlcPlayer.stop()
-                self.vlcPlayer = VlcPlayer(self, filename)
+                    self.vlcPlayer.clearPlaylist()
+                    self.vlcPlayer.resetTimer()
+                    self.vlcPlayer.update()
+                else:
+                    self.vlcPlayer = VlcPlayer(self, filename)
                 self.vlcPlayer.loadAndPlayFile(filename)
                 self.vlcPlayer.show()
             except:
@@ -3205,7 +3212,6 @@ def setBibleAbbreviations(self):
     def setDefaultFont(self):
         ok, font = QFontDialog.getFont(QFont(config.font, config.fontSize), self)
         if ok:
-            # print(font.key())
             config.font, fontSize, *_ = font.key().split(",")
             config.fontSize = int(fontSize)
             self.defaultFontButton.setText("{0} {1}".format(config.font, config.fontSize))
@@ -3215,7 +3221,6 @@ def setDefaultFont(self):
     def setChineseFont(self):
         ok, font = QFontDialog.getFont(QFont(config.fontChinese, config.fontSize), self)
         if ok:
-            # print(font.key())
             config.fontChinese, *_ = font.key().split(",")
             self.reloadCurrentRecord(True)
 
@@ -3487,42 +3492,56 @@ def versionButtonClicked(self):
     def playBibleMP3Playlist(self, playlist):
         if playlist and config.isVlcInstalled:
             from gui.VlcPlayer import VlcPlayer
-            if self.vlcPlayer is None:
-                self.vlcPlayer = VlcPlayer(self)
-            else:
+            if self.vlcPlayer is not None:
                 self.vlcPlayer.stop()
-            self.vlcPlayer.clearPlaylist()
+                self.vlcPlayer.clearPlaylist()
+                self.vlcPlayer.resetTimer()
+                self.vlcPlayer.update()
+            else:
+                self.vlcPlayer = VlcPlayer(self)
             for listItem in playlist:
                 (text, book, chapter, folder) = listItem
-                directory = self.getBibleMP3Directory(text, book, chapter, folder)
+                directory = self.getBibleMP3Directory(text, book, folder)
                 if directory:
-                    filesearch = "{0}/{1}*{2}.mp3".format(directory, "{:02d}".format(book), "{:03d}".format(chapter))
+                    filesearch = "{0}*/{1}*{2}.mp3".format(directory, "{:02d}".format(book), "{:03d}".format(chapter))
                     files = glob.glob(filesearch)
                     if not files:
-                        filesearch = "{0}/{1}*{2}.mp3".format(directory, "{:02d}".format(book),
+                        filesearch = "{0}*/{1}*{2}.mp3".format(directory, "{:02d}".format(book),
                                                               "{:02d}".format(chapter))
                         files = glob.glob(filesearch)
-                    if not files:
-                        filesearch = "{0}/{1}*{2}.mp3".format(directory, "{:02d}".format(book),
-                                                              "{:01d}".format(chapter))
-                        files = glob.glob(filesearch)
+                        if not files:
+                            filesearch = "{0}*/{1}*{2}.mp3".format(directory, "{:02d}".format(book),
+                                                                  "{:01d}".format(chapter))
+                            files = glob.glob(filesearch)
                     if files:
                         file = files[0]
                         self.vlcPlayer.addToPlaylist(file)
             self.vlcPlayer.show()
             self.vlcPlayer.playNextInPlaylist()
 
-    def playBibleMP3File(self, text, book, chapter, folder="default"):
+    def playBibleMP3File(self, text, book, chapter, folder=config.defaultMP3BibleFolder):
         playlist = []
         playlist.append((text, book, chapter, folder))
         self.playBibleMP3Playlist(playlist)
 
-    def getBibleMP3Directory(self, text, book, chapter, folder):
-        directory = "audio/bibles/{0}/{1}/{2}".format(text, folder, "{:02d}".format(book))
-        if os.path.exists(directory):
-            return directory
-        else:
-            return None
+    def getBibleMP3Directory(self, text, book, folder):
+        directory = "audio/bibles/{0}/{1}/{2}*".format(text, folder, "{:02d}".format(book))
+        directories = [d for d in glob.glob(directory) if os.path.isdir(d)]
+        if directories:
+            if os.path.exists(directories[0]):
+                return directories[0]
+        else:
+            directory = "audio/bibles/{0}".format(text)
+            directories = [d for d in os.listdir(directory) if
+                           os.path.isdir(os.path.join(directory, d)) and not d == ".git"]
+            if directories:
+                directory = "audio/bibles/{0}/{1}/{2}*".format(text, directories[0], "{:02d}".format(book))
+                directories = [d for d in glob.glob(directory) if os.path.isdir(d)]
+                if directories:
+                    if os.path.exists(directories[0]):
+                        return directories[0]
+        return None
+
 
     def testing(self):
         #pass
diff --git a/gui/MiniControl.py b/gui/MiniControl.py
index a23420621e..10b0045bb1 100644
--- a/gui/MiniControl.py
+++ b/gui/MiniControl.py
@@ -19,7 +19,7 @@
 
 class MiniControl(QWidget):
 
-    def __init__(self, parent):
+    def __init__(self, parent, selectedTab = 0):
         super().__init__()
         self.setWindowTitle(config.thisTranslation["remote_control"])
         self.parent = parent
@@ -33,6 +33,7 @@ def __init__(self, parent):
         self.bibleButtons = {}
         # setup interface
         self.setupUI()
+        self.tabs.setCurrentIndex(selectedTab)
 
     # window appearance
     def resizeWindow(self, widthFactor, heightFactor):
diff --git a/gui/VlcPlayer.py b/gui/VlcPlayer.py
index ced6bd236e..c4fdda6e2d 100644
--- a/gui/VlcPlayer.py
+++ b/gui/VlcPlayer.py
@@ -22,7 +22,6 @@ class VlcPlayer(QWidget):
 
     def __init__(self, parent, filename=None):
         super().__init__()
-        self.debug = True
         self.playlist = []
         os.environ["VLC_VERBOSE"] = str("-1")  # turn off low level VLC logging
         self.setWindowTitle(config.thisTranslation["mediaPlayer"])
@@ -38,6 +37,7 @@ def __init__(self, parent, filename=None):
         self.resetTimer()
         if filename:
             self.loadAndPlayFile(filename)
+        self.update()
 
     def create_ui(self):
         self.videoframe = QtWidgets.QFrame()
@@ -99,8 +99,6 @@ def create_ui(self):
         self.setLayout(self.vboxlayout)
 
     def play_pause(self):
-        if self.debug:
-            print("Play/Pause")
         if self.mediaplayer.is_playing():
             self.stopbutton.setEnabled(False)
             self.mediaplayer.pause()
@@ -133,8 +131,6 @@ def open_file(self):
 
     def clearPlaylist(self):
         self.playlist = []
-        if self.debug:
-            print("Clear playlist")
 
     def loadAndPlayFile(self, filename):
         self.playlist = []
@@ -144,8 +140,6 @@ def loadAndPlayFile(self, filename):
     def addToPlaylist(self, filename):
         if not os.path.exists(filename):
             return
-        if self.debug:
-            print("Add to playlist {0}".format(filename))
         self.playlist.insert(0, filename)
         self.updateNextButton()
 
@@ -166,8 +160,6 @@ def playNextInPlaylist(self):
             self.media.parse()
             self.mediaplayer.play()
             self.setWindowTitle(self.media.get_meta(0))
-            if self.debug:
-                print("Playing {0}".format(filename))
 
             # The media player has to be 'connected' to the QFrame (otherwise the
             # video would be displayed in it's own window). This is platform
@@ -249,9 +241,7 @@ def closeEvent(self, event):
             self.mediaplayer.stop()
             self.timer.stop()
             self.stop()
-            self.parent.vlcPlayer = None
-            if self.debug:
-                print("Close VLC")
+        self.parent.vlcPlayer = None
 
 
 ## Standalone development code
diff --git a/patches.txt b/patches.txt
index 419b74a5fe..af88eb2892 100644
--- a/patches.txt
+++ b/patches.txt
@@ -906,12 +906,18 @@
 (25.75, "file", "util/Translator.py")
 (25.76, "file", "gui/MainWindow.py")
 (25.76, "file", "gui/VlcPlayer.py")
-(25.76, "file", "latest_changes.txt")
-(25.76, "file", "patches.txt")
 (25.76, "file", "plugins/startup/tagLexicalEntry.py")
 (25.76, "file", "util/BibleBooks.py")
 (25.76, "file", "util/TextCommandParser.py")
 (25.76, "file", "util/ThirdParty.py")
-(25.76, "file", "UniqueBibleAppVersion.txt")
-(25.76, "file", "latest_changes.txt")
-(25.76, "file", "patches.txt")
+(25.77, "file", "db/BiblesSqlite.py")
+(25.77, "file", "gui/AlephMainWindow.py")
+(25.77, "file", "gui/MainWindow.py")
+(25.77, "file", "gui/MiniControl.py")
+(25.77, "file", "gui/VlcPlayer.py")
+(25.77, "file", "util/ConfigUtil.py")
+(25.77, "file", "util/TextCommandParser.py")
+(25.77, "file", "util/ThirdParty.py")
+(25.77, "file", "UniqueBibleAppVersion.txt")
+(25.77, "file", "latest_changes.txt")
+(25.77, "file", "patches.txt")
diff --git a/util/ConfigUtil.py b/util/ConfigUtil.py
index b78bcd042a..052298231b 100644
--- a/util/ConfigUtil.py
+++ b/util/ConfigUtil.py
@@ -997,6 +997,11 @@ def setup():
         # Display output of CMD command"""
         if not hasattr(config, "displayCmdOutput"):
             config.displayCmdOutput = False
+        config.help["defaultMP3BibleFolder"] = """
+        # Default MP3 Bible folder
+        """
+        if not hasattr(config, "defaultMP3BibleFolder"):
+            config.defaultMP3BibleFolder = "default"
 
         # Additional conditional configurations
         if config.enableMenuUnderline:
@@ -1242,6 +1247,7 @@ def save():
             ("bibleCollections", config.bibleCollections),
             ("parseTextConvertNotesToBook", config.parseTextConvertNotesToBook),
             ("displayCmdOutput", config.displayCmdOutput),
+            ("defaultMP3BibleFolder", config.defaultMP3BibleFolder),
         )
         with open("config.py", "w", encoding="utf-8") as fileObj:
             for name, value in configs:
diff --git a/util/TextCommandParser.py b/util/TextCommandParser.py
index 94164f77a9..f00a0a57f2 100644
--- a/util/TextCommandParser.py
+++ b/util/TextCommandParser.py
@@ -1246,7 +1246,7 @@ def readBible(self, command, source):
             text = config.mainText
             book = config.mainB
             chapter = config.mainC
-            folder = "default"
+            folder = config.defaultMP3BibleFolder
             playlist = []
             if command:
                 count = command.count(":::")
@@ -2781,7 +2781,6 @@ def highlightVerse(self, command, source):
         code, reference = self.splitCommand(command)
         verseList = self.extractAllVerses(reference)
         for b, c, v in verseList:
-            #print("{0}:{1}:{2}:{3}".format(b, c, v, code))
             if code == "delete":
                 hl.removeHighlight(b, c, v)
             else:
diff --git a/util/ThirdParty.py b/util/ThirdParty.py
index a15b7d4130..b0bcbdd5b7 100644
--- a/util/ThirdParty.py
+++ b/util/ThirdParty.py
@@ -1263,7 +1263,8 @@ def importTheWordBible(self, filename):
         self.logger.info("Import successful")
 
     def stripTheWordTags(self, line):
-        line = re.sub(r"<W(G\d*)>", " \\1 ", line)
+        line = re.sub(r"<W([HG]\d*)>", " \\1 ", line)
+        line = re.sub(r"<.*?>", "", line)
         return line
 
     def storiesToTitles(self, stories):
@@ -2035,6 +2036,11 @@ def getMyBibleDictionaryData(self, entry):
     # text = " {\f1\'c2\'df\'e2\'eb\'ef\'f2\sub 1}  {\cf11\super  Biblos G976 NNSF}  {\cf2 Libro}  {\f1\u8594?}  {\cf16 de}  {\f1\u8594?}  {\cf16 la}  {\f1\'e3\'e5\'ed\'dd\'f3\'e5\'f9\'f2\sub 2}  {\cf11\super  geneseôs G1078 NGSF}  {\cf2 genealogía}  {\f1\u8594?}  {\cf16 de}  \'8b  {\f1\u7992?\'e7\'f3\'ef\u8166?{\sub 3} \'d8\'f1\'e9\'f3\'f4\'ef\u8166?\sub 4} \'9b  {\cf11\super  Iêsou Christou G2424 G5547 NGSM NGSM}  {\cf2 Jesucristo,}  {\f1\'f5\u7985?\'ef\u8166?\sub 5}  {\cf11\super  huiou G5207 NGSM}  {\cf2 hijo}  {\f1\u8594?}  {\cf16 de}  {\f1\'c4\'e1\'e2\'df\'e4\sub 6}  {\cf11\super  Dabid G1138 XP}  {\cf2 David,}  {\f1\'f5\u7985?\'ef\u8166?\sub 7}  {\cf11\super  huiou G5207 NGSM}  {\cf2 hijo}  {\f1\u8594?}  {\cf16 de}  {\f1\u7944?\'e2\'f1\'e1\'dc\'ec\sub 8}  {\cf11\super  Abraam G11 XP}  {\cf2 Abraham.}"
     # out = Converter().convertFromRichTextFormat(text, True)
     # print(out)
-    file = "/Users/otseng/Downloads/ant.nt"
-    Converter().importTheWordBible(file)
 
+    # file = "/Users/otseng/Downloads/ant.nt"
+    # Converter().importTheWordBible(file)
+
+    # line = "In <FI>the<Fi> beginning<WH7225><WTHR><WTHNcfsa> God<WH430><WTHNcmpa> created<WH1254><WTHVqp3ms> <WH853><WTHTo> the heavens<WH8064><WTHTd><WTHNcmpa> and<WH853><WTHC><WTHTo> the earth.<WH776><WTHTd><WTHNcbsa>"
+    line = """And God<WH430><WTHNcmpa> said,<WH559><WTHC><WTHVqw3ms> "Let there be<WH1961><WTHVqj3ms> light."<WH216><WTHNcbsa> And there was<WH1961><WTHC><WTHVqw3ms> light.<WH216><WTHNcbsa>"""
+    out = Converter().stripTheWordTags(line)
+    print(out)


Test patch:
diff --git a/latest_changes.txt b/latest_changes.txt
index 50cb79eaa2..7b121305a0 100644
--- a/latest_changes.txt
+++ b/latest_changes.txt
@@ -1,3 +1,11 @@
+Major changes in version 25.77:
+* Import theWord OT Bibles
+* Fix reading Bibles without a default folder
+* Allow Bible mp3 folders to have the book name in it
+* Remove VLC debugging
+* Open by default Bible tab in minicontrol for Aleph menu
+* Add defaultMP3BibleFolder config
+
 Major changes in version 25.76:
 * Import theWord NT Bibles
 * Fix display of Strongs if at end of line