Ejemplo n.º 1
0
 def generateDict(self):
     bookNumDict = {}
     parser = BibleVerseParser(config.parserStandarisation)
     bookName = "Gen."
     bookNum = parser.bookNameToNum(bookName)
     bookNumDict[bookName] = bookNum
     for key in bookNumDict.keys():
         print('"{0}": "{1}",'.format(key, bookNumDict[key]))
Ejemplo n.º 2
0
 def updateContextMenu(self):
     text = self.getText()
     parser = BibleVerseParser(config.parserStandarisation)
     book = parser.bcvToVerseReference(self.getBook(), 1, 1)[:-4]
     del parser
     self.searchText.setText("{1} {0}".format(
         text, config.thisTranslation["context1_search"]))
     self.searchTextInBook.setText("{2} {0} > {1}".format(
         text, book, config.thisTranslation["context1_search"]))
Ejemplo n.º 3
0
 def displayVersesInBibleWindow(self):
     selectedText = self.selectedText().strip()
     if selectedText:
         parser = BibleVerseParser(config.parserStandarisation)
         verses = parser.extractAllReferences(selectedText, False)
         if verses:
             references = "; ".join(
                 [parser.bcvToVerseReference(*verse) for verse in verses])
             self.parent.parent.textCommandChanged(references, "main")
         else:
             self.displayMessage(
                 config.thisTranslation["message_noReference"])
         del parser
     else:
         self.messageNoSelection()
Ejemplo n.º 4
0
 def copyAllReferences(self):
     selectedText = self.selectedText().strip()
     if selectedText:
         parser = BibleVerseParser(config.parserStandarisation)
         verseList = parser.extractAllReferences(selectedText, False)
         if not verseList:
             self.displayMessage(
                 config.thisTranslation["message_noReference"])
         else:
             references = "; ".join([
                 parser.bcvToVerseReference(*verse) for verse in verseList
             ])
             QApplication.clipboard().setText(references)
         del parser
     else:
         self.messageNoSelection()
Ejemplo n.º 5
0
 def getBooks(self, text=config.mainText):
     bookList = self.getBookList(text)
     standardAbbreviation = BibleVerseParser(
         config.parserStandarisation).standardAbbreviation
     return " ".join([
         "{0}<button class='feature'>{1}</button></ref>".format(
             self.formBookTag(book, text), standardAbbreviation[str(book)])
         for book in bookList if str(book) in standardAbbreviation
     ])
Ejemplo n.º 6
0
 def setupVariables(self):
     self.isRefreshing = False
     bibleVerseParser = BibleVerseParser(config.parserStandarisation)
     bookNo2Abb = bibleVerseParser.standardAbbreviation
     #bookNo2Name = bibleVerseParser.standardFullBookName
     bookList = [i + 1 for i in range(66)]
     self.searchList = [
         config.thisTranslation["filter"], "{0}-{1}".format(
             bookNo2Abb["1"], bookNo2Abb["66"]), "{0}-{1}".format(
                 bookNo2Abb["1"], bookNo2Abb["39"]), "{0}-{1}".format(
                     bookNo2Abb["40"], bookNo2Abb["66"])
     ] + [bookNo2Abb[str(b)] for b in bookList]
Ejemplo n.º 7
0
 def compareAllVersions(self):
     selectedText = self.selectedText().strip()
     if selectedText:
         verses = BibleVerseParser(
             config.parserStandarisation).extractAllReferences(
                 selectedText, False)
         if verses:
             command = "COMPARE:::{0}".format(selectedText)
             self.parent.parent.textCommandChanged(command, self.name)
         else:
             self.displayMessage(
                 config.thisTranslation["message_noReference"])
     else:
         self.messageNoSelection()
Ejemplo n.º 8
0
def presentReferenceOnFullScreen(command, source):
    if ":::" in command:
        screenNo, reference, *_ = command.split(":::")
    else:
        screenNo = config.presentationScreenNo
        reference = command
    verseList = BibleVerseParser(config.parserStandarisation).extractAllReferences(reference, False)
    if command.count(":::") == 2:
            style = command.split(":::")[2]
    else:
        style = "font-size:{0}em;margin-left:{1}px;margin-right:{1}px;color:{2}".format(config.presentationFontSize, config.presentationMargin, config.presentationColorOnDarkTheme if config.theme == "dark" else config.presentationColorOnLightTheme)
    content = command if not verseList or not config.presentationParser else BiblesSqlite().readMultipleVerses(config.mainText, verseList, presentMode=True)
    content = "<div style='display:flex;'><div style='position: absolute;top: {2}%;transform: translateY(-{3}%);{1}'>{0}</div></div>".format(re.sub("\n", "<br>", content), style, config.presentationVerticalPosition, config.presentationHorizontalPosition)
    return ("popover.fullscreen".format(screenNo), content, {})
Ejemplo n.º 9
0
 def displayVersesInBottomWindow(self):
     selectedText = self.selectedText().strip()
     if selectedText:
         verses = BibleVerseParser(
             config.parserStandarisation).extractAllReferences(
                 selectedText, False)
         if verses:
             html = BiblesSqlite().readMultipleVerses(
                 self.getText(), verses)
             self.parent.parent.displayPlainTextOnBottomWindow(html)
         else:
             self.displayMessage(
                 config.thisTranslation["message_noReference"])
     else:
         self.messageNoSelection()
Ejemplo n.º 10
0
 def getHighlightedBcvList(self, highlight, reference):
     highlight = highlight.lower()
     if highlight == "" or highlight == "all":
         where = "WHERE 1=1 "
     else:
         code = self.decode(highlight)
         where = "WHERE CODE='{0}' ".format(code)
     if reference == "nt":
         where += "AND Book >= 40"
     elif reference == "ot":
         where += "AND Book < 40"
     elif not(reference == "" or reference == "all"):
         ref = BibleVerseParser(config.standardAbbreviation).extractAllReferences("{0} 1".format(reference))
         if ref:
             where += "AND Book={0}".format(ref[0][0])
     return self.getHighlightedVerses(where)
Ejemplo n.º 11
0
 def openReferenceInBibleVersion(self, bible):
     selectedText = self.selectedText().strip()
     useFastVerseParsing = config.useFastVerseParsing
     config.useFastVerseParsing = False
     verses = BibleVerseParser(
         config.parserStandarisation).extractAllReferences(
             selectedText, False)
     config.useFastVerseParsing = useFastVerseParsing
     if verses:
         command = "BIBLE:::{0}:::{1}".format(bible, selectedText)
     elif not config.openBibleInMainViewOnly and self.name == "study":
         command = "STUDY:::{0}:::{1} {2}:{3}".format(
             bible, BibleBooks.eng[str(config.studyB)][0], config.studyC,
             config.studyV)
     else:
         command = "TEXT:::{0}".format(bible)
     self.parent.parent.textCommandChanged(command, self.name)
Ejemplo n.º 12
0
 def getChapterContent(self, table, bcTuple):
     query = "SELECT * FROM {0} WHERE Book = ? AND Chapter = ?".format(
         table)
     self.cursor.execute(query, bcTuple)
     parser = BibleVerseParser(config.parserStandarisation)
     content = "<br>".join([
         '[<ref onclick="bcv({0},{1},{2})">{1}:{2}</ref>] {3}'.format(
             b, c, v, re.sub("<p>|</p>", " ", text))
         for b, c, v, text in self.cursor.fetchall()
     ])
     if not content:
         return "[not applicable]"
     else:
         if table == "dictionaries" or table == "encyclopedia":
             return "<table>{0}</table>".format(content)
         else:
             return content
Ejemplo n.º 13
0
    def __init__(self, parent, bcvTextTuple):
        super().__init__()

        self.parent = parent
        self.b, self.c, self.v, self.text = bcvTextTuple
        self.bcvChain = False
        self.biblesSqlite = BiblesSqlite()
        bibleVerseParser = BibleVerseParser(config.parserStandarisation)
        self.bookNo2Abb = bibleVerseParser.standardAbbreviation
        self.bookNo2Name = bibleVerseParser.standardFullBookName
        self.bookLabel = QLabel("")
        self.chapterLabel = QLabel("")
        self.verseLabel = QLabel("")

        # set title
        self.setWindowTitle(config.thisTranslation["menu_bible"])
        # setup interface
        self.setupUI()
Ejemplo n.º 14
0
    def resetItems(self):
        from BibleVerseParser import BibleVerseParser
        from qtpy.QtGui import QStandardItem

        # Empty the model before reset
        self.dataViewModel.clear()
        # Reset
        # Parse entered reference
        reference = self.searchEntry.text().strip()
        verses = BibleVerseParser(
            config.parserStandarisation).extractAllReferences(
                reference, False)
        if verses:
            # Search morphology database
            bcv = verses[0][0:3]
            query = "SELECT * FROM morphology WHERE Book = ? AND Chapter = ? AND Verse = ?"
            self.cursor.execute(query, bcv)
            self.results = self.cursor.fetchall()
            # Display data
            # TABLE morphology (WordID INT, ClauseID INT, Book INT, Chapter INT, Verse INT, Word TEXT, LexicalEntry TEXT, MorphologyCode TEXT, Morphology TEXT, Lexeme TEXT, Transliteration TEXT, Pronunciation TEXT, Interlinear TEXT, Translation TEXT, Gloss TEXT)
            #for wordID, clauseID, b, c, v, textWord, lexicalEntry, morphologyCode, morphology, lexeme, transliteration, pronuciation, interlinear, translation, gloss in self.results:
            for row, result in enumerate(self.results):
                for column in range(0, len(result)):
                    text = str(
                        result[column]) if column < 5 else result[column]
                    item = QStandardItem(text)
                    self.dataViewModel.setItem(row, column, item)
            self.dataViewModel.setHorizontalHeaderLabels([
                "WordID", "ClauseID", "Book", "Chapter", "Verse", "Word",
                "LexicalEntry", "MorphologyCode", "Morphology", "Lexeme",
                "Transliteration", "Pronunciation", "Interlinear",
                "Translation", "Gloss"
            ])
        else:
            self.results = []
            self.displayMessage(self.translation[2])
        self.dataView.resizeColumnsToContents()
Ejemplo n.º 15
0
    def addMenuActions(self):

        subMenu = QMenu()

        for text in self.parent.parent.textList:
            action = QAction(self)
            action.setText(text)
            action.triggered.connect(
                partial(self.openReferenceInBibleVersion, text))
            subMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subMenu.addAction(separator)

        action = QAction(self)
        action.setText(config.thisTranslation["all"])
        action.triggered.connect(self.compareAllVersions)
        subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["openReferences"])
        action.setMenu(subMenu)
        self.addAction(action)

        subMenu = QMenu()

        for text in self.parent.parent.textList:
            action = QAction(self)
            action.setText(text)
            action.triggered.connect(
                partial(self.compareReferenceWithBibleVersion, text))
            subMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subMenu.addAction(separator)

        action = QAction(self)
        action.setText(config.thisTranslation["all"])
        action.triggered.connect(self.compareAllVersions)
        subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["compareReferences"])
        action.setMenu(subMenu)
        self.addAction(action)

        subMenu = QMenu()

        for text in self.parent.parent.textList:
            action = QAction(self)
            action.setText(text)
            action.triggered.connect(
                partial(self.parallelReferenceWithBibleVersion, text))
            subMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subMenu.addAction(separator)

        action = QAction(self)
        action.setText(config.thisTranslation["all"])
        action.triggered.connect(self.compareAllVersions)
        subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["parallelReferences"])
        action.setMenu(subMenu)
        self.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        self.addAction(separator)

        subMenu = QMenu()

        searchBibleReferences = QAction(self)
        searchBibleReferences.setText(
            config.thisTranslation["openOnNewWindow"])
        searchBibleReferences.triggered.connect(self.displayVersesInNewWindow)
        subMenu.addAction(searchBibleReferences)

        searchBibleReferences = QAction(self)
        searchBibleReferences.setText(config.thisTranslation["bar1_menu"])
        searchBibleReferences.triggered.connect(
            self.displayVersesInBibleWindow)
        subMenu.addAction(searchBibleReferences)

        searchBibleReferences = QAction(self)
        searchBibleReferences.setText(config.thisTranslation["bottomWindow"])
        searchBibleReferences.triggered.connect(
            self.displayVersesInBottomWindow)
        subMenu.addAction(searchBibleReferences)

        action = QAction(self)
        action.setText(config.thisTranslation["displayVerses"])
        action.setMenu(subMenu)
        self.addAction(action)

        if self.name in ("main", "study"):

            subMenu = QMenu()

            if hasattr(config, "cli"):
                action = QAction(self)
                action.setText(config.thisTranslation["cli"])
                action.triggered.connect(self.switchToCli)
                subMenu.addAction(action)

            action = QAction(self)
            action.setText(config.thisTranslation["openOnNewWindow"])
            action.triggered.connect(self.openOnNewWindow)
            subMenu.addAction(action)

            action = QAction(self)
            action.setText(config.thisTranslation["pdfDocument"])
            action.triggered.connect(self.exportToPdf)
            subMenu.addAction(action)

            action = QAction(self)
            action.setText(config.thisTranslation["displayContent"])
            action.setMenu(subMenu)
            self.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        self.addAction(separator)

        subMenu = QMenu()

        copyText = QAction(self)
        copyText.setText(config.thisTranslation["text"])
        copyText.triggered.connect(self.copySelectedText)
        subMenu.addAction(copyText)

        copyReferences = QAction(self)
        copyReferences.setText(config.thisTranslation["bibleReferences"])
        copyReferences.triggered.connect(self.copyAllReferences)
        subMenu.addAction(copyReferences)

        copyHtml = QAction(self)
        copyHtml.setText(config.thisTranslation["htmlCode"])
        copyHtml.triggered.connect(self.copyHtmlCode)
        subMenu.addAction(copyHtml)

        action = QAction(self)
        action.setText(config.thisTranslation["context1_copy"])
        action.setMenu(subMenu)
        self.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        self.addAction(separator)

        if self.name == "main":
            subMenu = QMenu()

            # Instant highlight feature
            action = QAction(self)
            action.setText(config.thisTranslation["menu_highlight"])
            action.triggered.connect(self.instantHighlight)
            subMenu.addAction(action)

            action = QAction(self)
            action.setText(config.thisTranslation["remove"])
            action.triggered.connect(self.removeInstantHighlight)
            subMenu.addAction(action)

            action = QAction(self)
            action.setText(config.thisTranslation["instantHighlight"])
            action.setMenu(subMenu)
            self.addAction(action)

            separator = QAction(self)
            separator.setSeparator(True)
            self.addAction(separator)

        action = QAction(self)
        action.setText(config.thisTranslation["context1_search"])
        action.triggered.connect(self.searchPanel)
        self.addAction(action)

        subMenu = QMenu()

        self.searchText = QAction(self)
        self.searchText.setText("{0} [{1}]".format(
            config.thisTranslation["context1_search"], config.mainText))
        self.searchText.triggered.connect(self.searchSelectedText)
        subMenu.addAction(self.searchText)

        self.searchTextInBook = QAction(self)
        self.searchTextInBook.setText(
            config.thisTranslation["context1_current"])
        self.searchTextInBook.triggered.connect(self.searchSelectedTextInBook)
        subMenu.addAction(self.searchTextInBook)

        searchFavouriteBible = QAction(self)
        searchFavouriteBible.setText(
            config.thisTranslation["context1_favourite"])
        searchFavouriteBible.triggered.connect(
            self.searchSelectedFavouriteBible)
        subMenu.addAction(searchFavouriteBible)

        action = QAction(self)
        action.setText(config.thisTranslation["cp0"])
        action.setMenu(subMenu)
        self.addAction(action)

        subMenu = QMenu()

        bibleVerseParser = BibleVerseParser(config.parserStandarisation)
        for bookNo in range(1, 67):
            action = QAction(self)
            action.setText(bibleVerseParser.standardFullBookName[str(bookNo)])
            action.triggered.connect(
                partial(self.searchSelectedTextInBook, bookNo))
            subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["bibleBook"])
        action.setMenu(subMenu)
        self.addAction(action)

        subMenu = QMenu()

        for text in self.parent.parent.textList:
            action = QAction(self)
            action.setText(text)
            action.triggered.connect(partial(self.searchSelectedText, text))
            subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["bibleVersion"])
        action.setMenu(subMenu)
        self.addAction(action)

        # Search Strong's number bibles, if installed
        if self.parent.parent.strongBibles:
            subMenu = QMenu()
            for text in self.parent.parent.strongBibles:
                action = QAction(self)
                action.setText(text)
                action.triggered.connect(partial(self.searchStrongBible, text))
                subMenu.addAction(action)

            separator = QAction(self)
            separator.setSeparator(True)
            subMenu.addAction(separator)

            action = QAction(self)
            action.setText(config.thisTranslation["all"])
            action.triggered.connect(self.searchAllStrongBible)
            subMenu.addAction(action)

            action = QAction(self)
            action.setText(config.thisTranslation["bibleConcordance"])
            action.setMenu(subMenu)
            self.addAction(action)

        subMenu = QMenu()
        for keyword in ("SEARCHBOOKNOTE", "SEARCHCHAPTERNOTE",
                        "SEARCHVERSENOTE"):
            action = QAction(self)
            action.setText(config.thisTranslation[keyword])
            action.triggered.connect(partial(self.searchBibleNote, keyword))
            subMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subMenu.addAction(separator)

        action = QAction(self)
        action.setText(config.thisTranslation["removeNoteHighlight"])
        action.triggered.connect(self.removeNoteHighlight)
        subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["menu6_notes"])
        action.setMenu(subMenu)
        self.addAction(action)

        subMenu = QMenu()

        searchBibleCharacter = QAction(self)
        searchBibleCharacter.setText(
            config.thisTranslation["menu5_characters"])
        searchBibleCharacter.triggered.connect(self.searchCharacter)
        subMenu.addAction(searchBibleCharacter)

        searchBibleName = QAction(self)
        searchBibleName.setText(config.thisTranslation["menu5_names"])
        searchBibleName.triggered.connect(self.searchName)
        subMenu.addAction(searchBibleName)

        searchBibleLocation = QAction(self)
        searchBibleLocation.setText(config.thisTranslation["menu5_locations"])
        searchBibleLocation.triggered.connect(self.searchLocation)
        subMenu.addAction(searchBibleLocation)

        subSubMenu = QMenu()

        action = QAction(self)
        action.setText(config.thisTranslation["previous"])
        action.triggered.connect(self.searchTopic)
        subSubMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subSubMenu.addAction(separator)

        for module in self.parent.parent.topicListAbb:
            action = QAction(self)
            action.setText(module)
            action.triggered.connect(partial(self.searchResource, module))
            subSubMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["menu5_topics"])
        action.setMenu(subSubMenu)
        subMenu.addAction(action)

        subSubMenu = QMenu()

        action = QAction(self)
        action.setText(config.thisTranslation["previous"])
        action.triggered.connect(self.searchDictionary)
        subSubMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subSubMenu.addAction(separator)

        for module in self.parent.parent.dictionaryListAbb:
            action = QAction(self)
            action.setText(module)
            action.triggered.connect(partial(self.searchResource, module))
            subSubMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["context1_dict"])
        action.setMenu(subSubMenu)
        subMenu.addAction(action)

        subSubMenu = QMenu()

        action = QAction(self)
        action.setText(config.thisTranslation["previous"])
        action.triggered.connect(self.searchEncyclopedia)
        subSubMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subSubMenu.addAction(separator)

        for module in self.parent.parent.encyclopediaListAbb:
            action = QAction(self)
            action.setText(module)
            action.triggered.connect(partial(self.searchResource, module))
            subSubMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["context1_encyclopedia"])
        action.setMenu(subSubMenu)
        subMenu.addAction(action)

        subSubMenu = QMenu()

        action = QAction(self)
        action.setText(config.thisTranslation["previous"])
        action.triggered.connect(self.searchHebrewGreekLexicon)
        subSubMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subSubMenu.addAction(separator)

        for module in self.parent.parent.lexiconList:
            action = QAction(self)
            action.setText(module)
            action.triggered.connect(
                partial(self.searchHebrewGreekLexiconSelected, module))
            subSubMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["menu5_lexicon"])
        action.setMenu(subSubMenu)
        subMenu.addAction(action)

        subSubMenu = QMenu()

        action = QAction(self)
        action.setText(config.thisTranslation["previous"])
        action.triggered.connect(self.searchThirdPartyDictionary)
        subSubMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subSubMenu.addAction(separator)

        for module in self.parent.parent.thirdPartyDictionaryList:
            action = QAction(self)
            action.setText(module)
            action.triggered.connect(
                partial(self.searchThirdPartyDictionarySelected, module))
            subSubMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["menu5_3rdDict"])
        action.setMenu(subSubMenu)
        subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["bibleResources"])
        action.setMenu(subMenu)
        self.addAction(action)

        subMenu = QMenu()

        action = QAction(self)
        action.setText(config.thisTranslation["previous"])
        action.triggered.connect(self.searchPreviousBook)
        subMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subMenu.addAction(separator)

        subSubMenu = QMenu()

        for module in config.favouriteBooks:
            action = QAction(self)
            action.setText(module)
            action.triggered.connect(partial(self.searchSelectedBook, module))
            subSubMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subSubMenu.addAction(separator)

        action = QAction(self)
        action.setText(config.thisTranslation["all"])
        action.triggered.connect(self.searchFavouriteBooks)
        subSubMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["context1_favouriteBooks"])
        action.setMenu(subSubMenu)
        subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["context1_allBooks"])
        action.triggered.connect(self.searchAllBooks)
        subMenu.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        subMenu.addAction(separator)

        action = QAction(self)
        action.setText(config.thisTranslation["removeBookHighlight"])
        action.triggered.connect(self.removeBookHighlight)
        subMenu.addAction(action)

        action = QAction(self)
        action.setText(config.thisTranslation["installBooks"])
        action.setMenu(subMenu)
        self.addAction(action)

        separator = QAction(self)
        separator.setSeparator(True)
        self.addAction(separator)

        # TEXT-TO-SPEECH feature
        languages = self.parent.parent.getTtsLanguages()
        tts = QAction(self)
        tts.setText("{0} [{1}]".format(
            config.thisTranslation["context1_speak"],
            languages[config.ttsDefaultLangauge][1].capitalize()))
        tts.triggered.connect(self.textToSpeech)
        self.addAction(tts)

        if config.isTtsInstalled:
            ttsMenu = QMenu()
            languageCodes = list(languages.keys())
            items = [languages[code][1] for code in languageCodes]
            for index, item in enumerate(items):
                languageCode = languageCodes[index]
                action = QAction(self)
                action.setText(item.capitalize())
                action.triggered.connect(
                    partial(self.textToSpeechLanguage, languageCode))
                ttsMenu.addAction(action)

            tts = QAction(self)
            tts.setText(config.thisTranslation["context1_speak"])
            tts.setMenu(ttsMenu)
            self.addAction(tts)

        separator = QAction(self)
        separator.setSeparator(True)
        self.addAction(separator)

        # IBM-Watson Translation Service

        # Translate into User-defined Language
        userLanguage = config.userLanguage
        translateText = QAction(self)
        translateText.setText("{0} [{1}]".format(
            config.thisTranslation["context1_translate"], userLanguage))
        translateText.triggered.connect(self.checkUserLanguage)
        self.addAction(translateText)

        translateMenu = QMenu()
        for index, item in enumerate(Translator.toLanguageNames):
            languageCode = Translator.toLanguageCodes[index]
            action = QAction(self)
            action.setText(item)
            action.triggered.connect(
                partial(self.selectedTextToSelectedLanguage, languageCode))
            translateMenu.addAction(action)

        translate = QAction(self)
        translate.setText(config.thisTranslation["watsonTranslator"])
        translate.setMenu(translateMenu)
        self.addAction(translate)

        translateMenu = QMenu()
        for language, languageCode in Languages.googleTranslateCodes.items():
            action = QAction(self)
            action.setText(language)
            action.triggered.connect(
                partial(self.googleTranslate, languageCode))
            translateMenu.addAction(action)

        translate = QAction(self)
        translate.setText(config.thisTranslation["googleTranslate"])
        translate.setMenu(translateMenu)
        self.addAction(translate)

        # Context menu plugins
        if config.enablePlugins:

            separator = QAction(self)
            separator.setSeparator(True)
            self.addAction(separator)

            subMenu = QMenu()

            for plugin in FileUtil.fileNamesWithoutExtension(
                    os.path.join("plugins", "context"), "py"):
                if not plugin in config.excludeContextPlugins:
                    action = QAction(self)
                    if "_" in plugin:
                        feature, shortcut = plugin.split("_", 1)
                        action.setText(feature)
                        # The following line does not work
                        #action.setShortcut(QKeySequence(shortcut))
                        self.parent.parent.addContextPluginShortcut(
                            plugin, shortcut)
                    else:
                        action.setText(plugin)
                    action.triggered.connect(partial(self.runPlugin, plugin))
                    subMenu.addAction(action)

            separator = QAction(self)
            separator.setSeparator(True)
            subMenu.addAction(separator)

            action = QAction(self)
            action.setText(config.thisTranslation["enableIndividualPlugins"])
            action.triggered.connect(
                self.parent.parent.enableIndividualPluginsWindow)
            subMenu.addAction(action)

            action = QAction(self)
            action.setText(config.thisTranslation["menu_plugins"])
            action.setMenu(subMenu)
            self.addAction(action)
Ejemplo n.º 16
0
    def setupUI(self):
        mainLayout = QGridLayout()

        commandBox = QVBoxLayout()
        commandBox.setSpacing(3)

        commandBar = QWidget()
        commandLayout1 = QBoxLayout(QBoxLayout.LeftToRight)
        commandLayout1.setSpacing(5)
        self.searchLineEdit = QLineEdit()
        self.searchLineEdit.setClearButtonEnabled(True)
        self.searchLineEdit.setToolTip(
            config.thisTranslation["enter_command_here"])
        self.searchLineEdit.returnPressed.connect(self.searchLineEntered)
        self.searchLineEdit.setFixedWidth(300)
        commandLayout1.addWidget(self.searchLineEdit)

        enterButton = QPushButton(config.thisTranslation["enter"])
        enterButton.setFixedWidth(100)
        enterButton.clicked.connect(self.searchLineEntered)
        commandLayout1.addWidget(enterButton)

        commandLayout1.addStretch()
        commandBox.addLayout(commandLayout1)

        commandLayout2 = QBoxLayout(QBoxLayout.LeftToRight)
        commandLayout2.setSpacing(5)

        keys = [
            '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ':', '-', ',',
            '.', ' ', '<', 'X'
        ]
        for key in keys:
            button = QPushButton(key)
            button.setMaximumWidth(30)
            button.clicked.connect(partial(self.keyEntryAction, key))
            commandLayout2.addWidget(button)

        commandLayout2.addStretch()
        commandBox.addLayout(commandLayout2)

        if config.isTtsInstalled:
            ttsLayout = QBoxLayout(QBoxLayout.LeftToRight)
            ttsLayout.setSpacing(5)

            self.languageCombo = QComboBox()
            ttsLayout.addWidget(self.languageCombo)
            if config.espeak:
                languages = TtsLanguages().isoLang2epeakLang
            else:
                languages = TtsLanguages().isoLang2qlocaleLang
            self.languageCodes = list(languages.keys())
            for code in self.languageCodes:
                self.languageCombo.addItem(languages[code][1])
            # Check if selected tts engine has the language user specify.
            if not (config.ttsDefaultLangauge in self.languageCodes):
                config.ttsDefaultLangauge = "en"
            # Set initial item
            initialIndex = self.languageCodes.index(config.ttsDefaultLangauge)
            self.languageCombo.setCurrentIndex(initialIndex)

            # setting tts default language here is confusing; better place in menu
            #setDefaultButton = QPushButton(config.thisTranslation["setDefault"])
            #setDefaultButton.setFixedWidth(130)
            #setDefaultButton.clicked.connect(self.setTtsDefaultLanguage)
            #ttsLayout.addWidget(setDefaultButton)

            speakButton = QPushButton(config.thisTranslation["speak"])
            speakButton.setFixedWidth(100)
            speakButton.clicked.connect(self.speakCommandFieldText)
            ttsLayout.addWidget(speakButton)

            stopButton = QPushButton(config.thisTranslation["stop"])
            stopButton.setFixedWidth(100)
            stopButton.clicked.connect(
                self.parent.textCommandParser.stopTtsAudio)
            ttsLayout.addWidget(stopButton)

            ttsLayout.addStretch()

            commandBox.addLayout(ttsLayout)

        commandBar.setLayout(commandBox)
        mainLayout.addWidget(commandBar, 0, 0, Qt.AlignCenter)

        self.tabs = QTabWidget()
        self.tabs.currentChanged.connect(self.tabChanged)
        mainLayout.addWidget(self.tabs, 1, 0, Qt.AlignCenter)

        parser = BibleVerseParser(config.parserStandarisation)
        self.bookMap = parser.standardAbbreviation
        bookNums = list(self.bookMap.keys())
        bookNumGps = [
            bookNums[0:10],
            bookNums[10:20],
            bookNums[20:30],
            bookNums[30:39],
            bookNums[39:49],
            bookNums[49:59],
            bookNums[59:66],
        ]

        bible = QWidget()
        bible_layout = QVBoxLayout()
        bible_layout.setMargin(0)
        bible_layout.setSpacing(0)
        for bookNumGp in bookNumGps[0:5]:
            gp = QWidget()
            layout = self.newRowLayout()
            for bookNum in bookNumGp:
                text = self.bookMap[bookNum]
                button = QPushButton(text)
                button.clicked.connect(partial(self.bibleBookAction, bookNum))
                layout.addWidget(button)
            gp.setLayout(layout)
            bible_layout.addWidget(gp)

        for bookNumGp in bookNumGps[5:]:
            gp = QWidget()
            layout = self.newRowLayout()
            for bookNum in bookNumGp:
                text = self.bookMap[bookNum]
                button = QPushButton(text)
                button.clicked.connect(partial(self.bibleBookAction, bookNum))
                layout.addWidget(button)
            gp.setLayout(layout)
            bible_layout.addWidget(gp)

        bible_layout.addStretch()
        bible.setLayout(bible_layout)
        self.tabs.addTab(bible, config.thisTranslation["bible"])

        bibles_box = QWidget()
        box_layout = QVBoxLayout()
        box_layout.setMargin(0)
        box_layout.setSpacing(0)
        row_layout = self.newRowLayout()
        biblesSqlite = BiblesSqlite()
        bibles = biblesSqlite.getBibleList()
        count = 0
        for bible in bibles:
            button = QPushButton(bible)
            button.clicked.connect(partial(self.bibleAction, bible))
            row_layout.addWidget(button)
            count += 1
            if count > 6:
                count = 0
                box_layout.addLayout(row_layout)
                row_layout = self.newRowLayout()
        box_layout.addLayout(row_layout)
        box_layout.addStretch()
        bibles_box.setLayout(box_layout)

        self.tabs.addTab(bibles_box, config.thisTranslation["translations"])

        commentaries_box = QWidget()
        box_layout = QVBoxLayout()
        box_layout.setMargin(0)
        box_layout.setSpacing(0)
        row_layout = self.newRowLayout()
        commentaries = Commentary().getCommentaryList()
        count = 0
        for commentary in commentaries:
            button = QPushButton(commentary)
            button.clicked.connect(partial(self.commentaryAction, commentary))
            row_layout.addWidget(button)
            count += 1
            if count > 6:
                count = 0
                box_layout.addLayout(row_layout)
                row_layout = self.newRowLayout()
        box_layout.addLayout(row_layout)
        box_layout.addStretch()
        commentaries_box.setLayout(box_layout)

        self.tabs.addTab(commentaries_box,
                         config.thisTranslation["commentaries"])

        lexicons_box = QWidget()
        box_layout = QVBoxLayout()
        box_layout.setMargin(0)
        box_layout.setSpacing(0)
        row_layout = self.newRowLayout()
        lexicons = LexiconData().lexiconList
        count = 0
        for lexicon in lexicons:
            button = QPushButton(lexicon)
            button.clicked.connect(partial(self.lexiconAction, lexicon))
            row_layout.addWidget(button)
            count += 1
            if count > 6:
                count = 0
                box_layout.addLayout(row_layout)
                row_layout = self.newRowLayout()
        box_layout.addLayout(row_layout)
        box_layout.addStretch()
        lexicons_box.setLayout(box_layout)

        self.tabs.addTab(lexicons_box, config.thisTranslation["lexicons"])

        dictionaries_box = QWidget()
        box_layout = QVBoxLayout()
        box_layout.setMargin(0)
        box_layout.setSpacing(0)
        row_layout = self.newRowLayout()
        dictionaries = IndexesSqlite().dictionaryList
        count = 0
        for dictionary in dictionaries:
            button = QPushButton(dictionary[0])
            button.setToolTip(dictionary[1])
            button.clicked.connect(
                partial(self.dictionaryAction, dictionary[0]))
            row_layout.addWidget(button)
            count += 1
            if count > 6:
                count = 0
                box_layout.addLayout(row_layout)
                row_layout = self.newRowLayout()
        box_layout.addLayout(row_layout)
        box_layout.addStretch()
        dictionaries_box.setLayout(box_layout)

        self.tabs.addTab(dictionaries_box,
                         config.thisTranslation["dictionaries"])
        self.tabs.setCurrentIndex(config.miniControlInitialTab)
        self.setLayout(mainLayout)
Ejemplo n.º 17
0
 def setUp(self):
     config.standardAbbreviation = 'ENG'
     self.parser = BibleVerseParser(config.standardAbbreviation)
Ejemplo n.º 18
0
 def getSearchedVerseList(self, searchString):
     searchString = "%{0}%".format(searchString)
     query = "SELECT DISTINCT Book, Chapter, Verse FROM VerseNote WHERE Note LIKE ? ORDER BY Book, Chapter, Verse"
     self.cursor.execute(query, (searchString,))
     return ["<ref onclick='document.title=\"_openversenote:::{0}.{1}.{2}\"'>{3}</ref>".format(book, chapter, verse, BibleVerseParser(config.parserStandarisation).bcvToVerseReference(book, chapter, verse)) for book, chapter, verse in self.cursor.fetchall()]
Ejemplo n.º 19
0
 def getSearchedChapterList(self, searchString):
     searchString = "%{0}%".format(searchString)
     query = "SELECT DISTINCT Book, Chapter FROM ChapterNote WHERE Note LIKE ? ORDER BY Book, Chapter"
     self.cursor.execute(query, (searchString,))
     parser = BibleVerseParser(config.parserStandarisation)
     return ["<ref onclick='document.title=\"_openchapternote:::{0}.{1}\"'>{2}</ref>".format(book, chapter, parser.bcvToVerseReference(book, chapter, 1)[:-2]) for book, chapter in self.cursor.fetchall()]
Ejemplo n.º 20
0
 def getSearchedBookList(self, searchString):
     searchString = "%{0}%".format(searchString)
     query = "SELECT DISTINCT Book FROM BookNote WHERE Note LIKE ? ORDER BY Book"
     self.cursor.execute(query, (searchString,))
     standardAbbreviation = BibleVerseParser(config.parserStandarisation).standardAbbreviation
     return ["<ref onclick='document.title=\"_openbooknote:::{0}\"'>{1}</ref>".format(book[0], standardAbbreviation[str(book[0])]) for book in self.cursor.fetchall()]
Ejemplo n.º 21
0
 def bcvToVerseReference(self, b, c, v):
     return BibleVerseParser(
         config.parserStandarisation).bcvToVerseReference(b, c, v)
Ejemplo n.º 22
0
class BibleVerseParserTestCase(unittest.TestCase):
    def setUp(self):
        config.standardAbbreviation = 'ENG'
        self.parser = BibleVerseParser(config.standardAbbreviation)

    def test_gen_parseText(self):
        input = "Genesis 1:1-3:1"
        expected = '<ref onclick="bcv(1,1,1,3,1)">Genesis 1:1-3:1</ref>'
        res = self.parser.parseText(input)
        self.assertEqual(expected, res)

    def test_prov_parseText(self):
        input = "Prov 1:1"
        expected = '<ref onclick="bcv(20,1,1)">Prov 1:1</ref>'
        res = self.parser.parseText(input)
        self.assertEqual(expected, res)

    def test_prov_extractAllReferences(self):
        input = "Prov 1:1"
        expected = [(20, 1, 1)]
        res = self.parser.extractAllReferences(input)
        self.assertEqual(expected, res)

    def test_matt_extractAllReferences(self):
        input = "Matt 28:18-20"
        expected = [(40, 28, 18, 28, 20)]
        res = self.parser.extractAllReferences(input)
        self.assertEqual(expected, res)

    def test_1cor_extractAllReferences(self):
        input = "1 Cor 13"
        expected = [(46, 13, 1)]
        res = self.parser.extractAllReferences(input)
        self.assertEqual(expected, res)

    def test_rev_extractAllReferences(self):
        input = "rev 1-10"
        expected = [(66, 1, 1, 10, 1)]
        res = self.parser.extractAllReferences(input)
        self.assertEqual(expected, res)

    def test_gen_verseReferenceToBCV(self):
        input = "gen"
        expected = (1, 1, 1)
        res = self.parser.verseReferenceToBCV(input)
        self.assertEqual(expected, res)

    def test_num_verseReferenceToBCV(self):
        input = "Num. 10"
        expected = (4, 10, 1)
        res = self.parser.verseReferenceToBCV(input)
        self.assertEqual(expected, res)

    def test_job_verseReferenceToBCV(self):
        input = "Job 2-10"
        expected = (18, 2, 1, 10, 1)
        res = self.parser.verseReferenceToBCV(input)
        self.assertEqual(expected, res)

    def test_psa_verseReferenceToBCV(self):
        input = "Psalms 23:1-10"
        expected = (19, 23, 1, 23, 10)
        res = self.parser.verseReferenceToBCV(input)
        self.assertEqual(expected, res)

    def test_pro_verseReferenceToBCV(self):
        input = "Prov. 2:1-10:6"
        expected = (20, 2, 1, 10, 6)
        res = self.parser.verseReferenceToBCV(input)
        self.assertEqual(expected, res)

    def test_1sam_verseReferenceToBCV(self):
        input = "1Sam. 4:5-   10:6"
        expected = (9, 4, 5, 10, 6)
        res = self.parser.verseReferenceToBCV(input)
        self.assertEqual(expected, res)

    def test_2kings_verseReferenceToBCV(self):
        input = "II Ki. 4:5 - 10:6"
        expected = (12, 4, 5, 10, 6)
        res = self.parser.verseReferenceToBCV(input)
        self.assertEqual(expected, res)

    def test_1sam_verseReferenceToBCV(self):
        input = "1 S.  4:5 - 10:9999"
        expected = (9, 4, 5, 10, 9999)
        res = self.parser.verseReferenceToBCV(input)
        self.assertEqual(expected, res)

    def test_mark_verseReferenceToBCV(self):
        input = "mar  3:2"
        expected = (41, 3, 2)
        res = self.parser.verseReferenceToBCV(input)
        self.assertEqual(expected, res)

    def test_2tim_verseReferenceToBCV(self):
        input = " 2 Timothy  5 "
        expected = (55, 5, 1)
        res = self.parser.verseReferenceToBCV(input)
        self.assertEqual(expected, res)

    def test_adddaniel_verseReferenceToBCV(self):
        input = "Additions to Daniel 10"
        expected = (71, 10, 1)
        res = self.parser.verseReferenceToBCV(input)
        self.assertEqual(expected, res)