def on_end_separator_line_edit_finished(self):
     if self.end_separator_line_edit.isModified():
         text = self.end_separator_line_edit.text()
         if text == get_reference_separator('sep_e_default') or not text.replace('|', ''):
             self.end_separator_check_box.setChecked(False)
             self.end_separator_line_edit.setText(get_reference_separator('sep_e_default'))
             self.end_separator_line_edit.setPalette(self.get_grey_text_palette(True))
Exemple #2
0
 def onAdvancedSearchButton(self):
     """
     Does an advanced search and saves the search results.
     """
     log.debug('Advanced Search Button clicked')
     self.advancedSearchButton.setEnabled(False)
     self.application.process_events()
     bible = self.advancedVersionComboBox.currentText()
     second_bible = self.advancedSecondComboBox.currentText()
     book = self.advancedBookComboBox.currentText()
     book_ref_id = self.advancedBookComboBox.itemData(int(self.advancedBookComboBox.currentIndex()))
     chapter_from = self.advancedFromChapter.currentText()
     chapter_to = self.advancedToChapter.currentText()
     verse_from = self.advancedFromVerse.currentText()
     verse_to = self.advancedToVerse.currentText()
     verse_separator = get_reference_separator('sep_v_display')
     range_separator = get_reference_separator('sep_r_display')
     verse_range = chapter_from + verse_separator + verse_from + range_separator + chapter_to + \
         verse_separator + verse_to
     versetext = '%s %s' % (book, verse_range)
     self.application.set_busy_cursor()
     self.search_results = self.plugin.manager.get_verses(bible, versetext, book_ref_id)
     if second_bible:
         self.second_search_results = self.plugin.manager.get_verses(second_bible, versetext, book_ref_id)
     if not self.advancedLockButton.isChecked():
         self.list_view.clear()
     if self.list_view.count() != 0:
         self.__check_second_bible(bible, second_bible)
     elif self.search_results:
         self.displayResults(bible, second_bible)
     self.advancedSearchButton.setEnabled(True)
     self.check_search_result()
     self.application.set_normal_cursor()
Exemple #3
0
 def format_verses(self):
     verse_sep = get_reference_separator('sep_v_display')
     range_sep = get_reference_separator('sep_r_display')
     list_sep = get_reference_separator('sep_l_display')
     result = ''
     for index, verse in enumerate(self.verse_list):
         if index == 0:
             result = '%s %s%s%s' % (verse['book'], verse['chapter'], verse_sep, verse['start'])
             if verse['start'] != verse['end']:
                 result = '%s%s%s' % (result, range_sep, verse['end'])
             continue
         prev = index - 1
         if self.verse_list[prev]['version'] != verse['version']:
             result = '%s (%s)' % (result, self.verse_list[prev]['version'])
         result += '%s ' % list_sep
         if self.verse_list[prev]['book'] != verse['book']:
             result = '%s%s %s%s' % (result, verse['book'], verse['chapter'], verse_sep)
         elif self.verse_list[prev]['chapter'] != verse['chapter']:
             result = '%s%s%s' % (result, verse['chapter'], verse_sep)
         result += str(verse['start'])
         if verse['start'] != verse['end']:
             result = '%s%s%s' % (result, range_sep, verse['end'])
     if len(self.version_list) > 1:
         result = '%s (%s)' % (result, verse['version'])
     return result
Exemple #4
0
def test_get_reference_separator(mocked_update_reference_separators):
    """
    Test the get_reference_separator method
    """
    # GIVEN: A list of expected separators and the lib module's constant is empty
    lib.REFERENCE_SEPARATORS = None
    separators = {
        'sep_r': '\\s*(?:e)\\s*',
        'sep_e_default': 'end',
        'sep_v_display': 'w',
        'sep_l_display': 'r',
        'sep_v_default': ':|v|V|verse|verses',
        'sep_l': '\\s*(?:r)\\s*',
        'sep_l_default': ',|and',
        'sep_e': '\\s*(?:t)\\s*',
        'sep_v': '\\s*(?:w)\\s*',
        'sep_r_display': 'e',
        'sep_r_default': '-|to'
    }

    def _update_side_effect():
        """
        Update the references after mocking out the method
        """
        lib.REFERENCE_SEPARATORS = separators

    mocked_update_reference_separators.side_effect = _update_side_effect

    # WHEN: Calling get_reference_separator
    for key, value in separators.items():
        lib.get_reference_separator(key)

        # THEN: get_reference_separator should return the correct separator
        assert separators[key] == value
    mocked_update_reference_separators.assert_called_once_with()
Exemple #5
0
    def formatTitle(self, start_bitem, old_bitem):
        """
        This method is called, when we have to change the title, because
        we are at the end of a verse range. E. g. if we want to add
        Genesis 1:1-6 as well as Daniel 2:14.

        ``start_item``
            The first item of a range.

        ``old_item``
            The last item of a range.
        """
        verse_separator = get_reference_separator('sep_v_display')
        range_separator = get_reference_separator('sep_r_display')
        old_chapter = self._decode_qt_object(old_bitem, 'chapter')
        old_verse = self._decode_qt_object(old_bitem, 'verse')
        start_book = self._decode_qt_object(start_bitem, 'book')
        start_chapter = self._decode_qt_object(start_bitem, 'chapter')
        start_verse = self._decode_qt_object(start_bitem, 'verse')
        start_bible = self._decode_qt_object(start_bitem, 'bible')
        start_second_bible = self._decode_qt_object(start_bitem, 'second_bible')
        if start_second_bible:
            bibles = '%s, %s' % (start_bible, start_second_bible)
        else:
            bibles = start_bible
        if start_chapter == old_chapter:
            if start_verse == old_verse:
                verse_range = start_chapter + verse_separator + start_verse
            else:
                verse_range = start_chapter + verse_separator + start_verse + range_separator + old_verse
        else:
            verse_range = start_chapter + verse_separator + start_verse + \
                range_separator + old_chapter + verse_separator + old_verse
        return '%s %s (%s)' % (start_book, verse_range, bibles)
Exemple #6
0
 def on_end_separator_line_edit_finished(self):
     if self.end_separator_line_edit.isModified():
         text = self.end_separator_line_edit.text()
         if text == get_reference_separator('sep_e_default') or not text.replace('|', ''):
             self.end_separator_check_box.setChecked(False)
             self.end_separator_line_edit.setText(get_reference_separator('sep_e_default'))
             self.end_separator_line_edit.setPalette(self.getGreyTextPalette(True))
Exemple #7
0
 def onEndSeparatorLineEditFinished(self):
     if self.endSeparatorLineEdit.isModified():
         text = self.endSeparatorLineEdit.text()
         if text == get_reference_separator(u'sep_e_default') or not text.replace(u'|', u''):
             self.endSeparatorCheckBox.setChecked(False)
             self.endSeparatorLineEdit.setText(get_reference_separator(u'sep_e_default'))
             self.endSeparatorLineEdit.setPalette(self.getGreyTextPalette(True))
 def format_verses(self):
     verse_sep = get_reference_separator('sep_v_display')
     range_sep = get_reference_separator('sep_r_display')
     list_sep = get_reference_separator('sep_l_display')
     result = ''
     for index, verse in enumerate(self.verse_list):
         if index == 0:
             result = '{book} {chapter}{sep}{verse}'.format(book=verse['book'],
                                                            chapter=verse['chapter'],
                                                            sep=verse_sep,
                                                            verse=verse['start'])
             if verse['start'] != verse['end']:
                 result = '{result}{sep}{end}'.format(result=result, sep=range_sep, end=verse['end'])
             continue
         prev = index - 1
         if self.verse_list[prev]['version'] != verse['version']:
             result = '{result} ({version})'.format(result=result, version=self.verse_list[prev]['version'])
         result += '{sep} '.format(sep=list_sep)
         if self.verse_list[prev]['book'] != verse['book']:
             result = '{result}{book} {chapter}{sep}'.format(result=result,
                                                             book=verse['book'],
                                                             chapter=verse['chapter'],
                                                             sep=verse_sep)
         elif self.verse_list[prev]['chapter'] != verse['chapter']:
             result = '{result}{chapter}{sep}'.format(result=result, chapter=verse['chapter'], sep=verse_sep)
         result += str(verse['start'])
         if verse['start'] != verse['end']:
             result = '{result}{sep}{end}'.format(result=result, sep=range_sep, end=verse['end'])
     if len(self.version_list) > 1:
         result = '{result} ({version})'.format(result=result, version=verse['version'])
     return result
Exemple #9
0
    def get_verses(self, bible, verse_text, book_ref_id=False, show_error=True):
        """
        Parses a scripture reference, fetches the verses from the Bible
        specified, and returns a list of ``Verse`` objects.

        :param bible: Unicode. The Bible to use.
        :param verse_text:
             Unicode. The scripture reference. Valid scripture references are:

                - Genesis 1
                - Genesis 1-2
                - Genesis 1:1
                - Genesis 1:1-10
                - Genesis 1:1-10,15-20
                - Genesis 1:1-2:10
                - Genesis 1:1-10,2:1-10

        :param book_ref_id:  Unicode. The book reference id from the book in verse_text.
            For second bible this is necessary.
        :param show_error:
        """
        log.debug('BibleManager.get_verses("%s", "%s")', bible, verse_text)
        if not bible:
            if show_error:
                self.main_window.information_message(
                    translate('BiblesPlugin.BibleManager', 'No Bibles Available'),
                    translate('BiblesPlugin.BibleManager', 'There are no Bibles currently installed. Please use the '
                              'Import Wizard to install one or more Bibles.')
                )
            return None
        language_selection = self.get_language_selection(bible)
        ref_list = parse_reference(verse_text, self.db_cache[bible], language_selection, book_ref_id)
        if ref_list:
            return self.db_cache[bible].get_verses(ref_list, show_error)
        else:
            if show_error:
                reference_separators = {
                    'verse': get_reference_separator('sep_v_display'),
                    'range': get_reference_separator('sep_r_display'),
                    'list': get_reference_separator('sep_l_display')}
                self.main_window.information_message(
                    translate('BiblesPlugin.BibleManager', 'Scripture Reference Error'),
                    translate('BiblesPlugin.BibleManager', 'Your scripture reference is either not supported by '
                              'OpenLP or is invalid. Please make sure your reference '
                              'conforms to one of the following patterns or consult the manual:\n\n'
                              'Book Chapter\n'
                              'Book Chapter%(range)sChapter\n'
                              'Book Chapter%(verse)sVerse%(range)sVerse\n'
                              'Book Chapter%(verse)sVerse%(range)sVerse%(list)sVerse'
                              '%(range)sVerse\n'
                              'Book Chapter%(verse)sVerse%(range)sVerse%(list)sChapter'
                              '%(verse)sVerse%(range)sVerse\n'
                              'Book Chapter%(verse)sVerse%(range)sChapter%(verse)sVerse',
                              'Please pay attention to the appended "s" of the wildcards '
                              'and refrain from translating the words inside the names in the brackets.')
                    % reference_separators
                )
            return None
Exemple #10
0
 def load(self):
     settings = Settings()
     settings.beginGroup(self.settings_section)
     self.is_verse_number_visible = settings.value('is verse number visible')
     self.show_new_chapters = settings.value('display new chapter')
     self.display_style = settings.value('display brackets')
     self.layout_style = settings.value('verse layout style')
     self.bible_theme = settings.value('bible theme')
     self.second_bibles = settings.value('second bibles')
     self.is_verse_number_visible_check_box.setChecked(self.is_verse_number_visible)
     self.check_is_verse_number_visible()
     self.new_chapters_check_box.setChecked(self.show_new_chapters)
     self.display_style_combo_box.setCurrentIndex(self.display_style)
     self.layout_style_combo_box.setCurrentIndex(self.layout_style)
     self.bible_second_check_box.setChecked(self.second_bibles)
     verse_separator = settings.value('verse separator')
     if (verse_separator.strip('|') == '') or (verse_separator == get_reference_separator('sep_v_default')):
         self.verse_separator_line_edit.setText(get_reference_separator('sep_v_default'))
         self.verse_separator_line_edit.setPalette(self.get_grey_text_palette(True))
         self.verse_separator_check_box.setChecked(False)
     else:
         self.verse_separator_line_edit.setText(verse_separator)
         self.verse_separator_line_edit.setPalette(self.get_grey_text_palette(False))
         self.verse_separator_check_box.setChecked(True)
     range_separator = settings.value('range separator')
     if (range_separator.strip('|') == '') or (range_separator == get_reference_separator('sep_r_default')):
         self.range_separator_line_edit.setText(get_reference_separator('sep_r_default'))
         self.range_separator_line_edit.setPalette(self.get_grey_text_palette(True))
         self.range_separator_check_box.setChecked(False)
     else:
         self.range_separator_line_edit.setText(range_separator)
         self.range_separator_line_edit.setPalette(self.get_grey_text_palette(False))
         self.range_separator_check_box.setChecked(True)
     list_separator = settings.value('list separator')
     if (list_separator.strip('|') == '') or (list_separator == get_reference_separator('sep_l_default')):
         self.list_separator_line_edit.setText(get_reference_separator('sep_l_default'))
         self.list_separator_line_edit.setPalette(self.get_grey_text_palette(True))
         self.list_separator_check_box.setChecked(False)
     else:
         self.list_separator_line_edit.setText(list_separator)
         self.list_separator_line_edit.setPalette(self.get_grey_text_palette(False))
         self.list_separator_check_box.setChecked(True)
     end_separator = settings.value('end separator')
     if (end_separator.strip('|') == '') or (end_separator == get_reference_separator('sep_e_default')):
         self.end_separator_line_edit.setText(get_reference_separator('sep_e_default'))
         self.end_separator_line_edit.setPalette(self.get_grey_text_palette(True))
         self.end_separator_check_box.setChecked(False)
     else:
         self.end_separator_line_edit.setText(end_separator)
         self.end_separator_line_edit.setPalette(self.get_grey_text_palette(False))
         self.end_separator_check_box.setChecked(True)
     self.language_selection = settings.value('book name language')
     self.language_selection_combo_box.setCurrentIndex(self.language_selection)
     self.reset_to_combined_quick_search = settings.value('reset to combined quick search')
     self.reset_to_combined_quick_search_check_box.setChecked(self.reset_to_combined_quick_search)
     self.hide_combined_quick_error = settings.value('hide combined quick error')
     self.hide_combined_quick_error_check_box.setChecked(self.hide_combined_quick_error)
     self.bible_search_while_typing = settings.value('is search while typing enabled')
     self.bible_search_while_typing_check_box.setChecked(self.bible_search_while_typing)
     settings.endGroup()
Exemple #11
0
    def test_get_reference_separator(self, mocked_update_reference_separators):
        """
        Test the get_reference_separator method
        """
        # GIVEN: A list of expected separators and the lib module's constant is empty
        lib.REFERENCE_SEPARATORS = None
        separators = {'sep_r': '\\s*(?:e)\\s*', 'sep_e_default': 'end', 'sep_v_display': 'w', 'sep_l_display': 'r',
                      'sep_v_default': ':|v|V|verse|verses', 'sep_l': '\\s*(?:r)\\s*', 'sep_l_default': ',|and',
                      'sep_e': '\\s*(?:t)\\s*', 'sep_v': '\\s*(?:w)\\s*', 'sep_r_display': 'e', 'sep_r_default': '-|to'}

        def _update_side_effect():
            """
            Update the references after mocking out the method
            """
            lib.REFERENCE_SEPARATORS = separators

        mocked_update_reference_separators.side_effect = _update_side_effect

        # WHEN: Calling get_reference_separator
        for key, value in separators.items():
            _ = lib.get_reference_separator(key)

            # THEN: get_reference_separator should return the correct separator
            self.assertEqual(separators[key], value)
        mocked_update_reference_separators.assert_called_once_with()
Exemple #12
0
    def formatVerse(self, old_chapter, chapter, verse):
        """
        Formats and returns the text, each verse starts with, for the given
        chapter and verse. The text is either surrounded by round, square,
        curly brackets or no brackets at all. For example::

            u'{su}1:1{/su}'

        ``old_chapter``
            The previous verse's chapter number (int).

        ``chapter``
            The chapter number (int).

        ``verse``
            The verse number (int).
        """
        verse_separator = get_reference_separator('sep_v_display')
        if not self.settings.show_new_chapters or old_chapter != chapter:
            verse_text = str(chapter) + verse_separator + str(verse)
        else:
            verse_text = str(verse)
        if self.settings.display_style == DisplayStyle.Round:
            return '{su}(%s){/su}' % verse_text
        if self.settings.display_style == DisplayStyle.Curly:
            return '{su}{%s}{/su}' % verse_text
        if self.settings.display_style == DisplayStyle.Square:
            return '{su}[%s]{/su}' % verse_text
        return '{su}%s{/su}' % verse_text
Exemple #13
0
 def on_end_separator_check_box_clicked(self, checked):
     if checked:
         self.end_separator_line_edit.setFocus()
     else:
         self.end_separator_line_edit.setText(
             get_reference_separator('sep_e_default'))
     self.end_separator_line_edit.setPalette(
         self.get_grey_text_palette(not checked))
Exemple #14
0
 def buildDisplayResults(self, bible, second_bible, search_results):
     """
     Displays the search results in the media manager. All data needed for
     further action is saved for/in each row.
     """
     verse_separator = get_reference_separator('sep_v_display')
     version = self.plugin.manager.get_meta_data(bible, 'name').value
     copyright = self.plugin.manager.get_meta_data(bible, 'copyright').value
     permissions = self.plugin.manager.get_meta_data(bible, 'permissions').value
     second_version = ''
     second_copyright = ''
     second_permissions = ''
     if second_bible:
         second_version = self.plugin.manager.get_meta_data(second_bible, 'name').value
         second_copyright = self.plugin.manager.get_meta_data(second_bible, 'copyright').value
         second_permissions = self.plugin.manager.get_meta_data(second_bible, 'permissions').value
     items = []
     language_selection = self.plugin.manager.get_language_selection(bible)
     for count, verse in enumerate(search_results):
         book = None
         if language_selection == LanguageSelection.Bible:
             book = verse.book.name
         elif language_selection == LanguageSelection.Application:
             book_names = BibleStrings().BookNames
             data = BiblesResourcesDB.get_book_by_id(verse.book.book_reference_id)
             book = str(book_names[data['abbreviation']])
         elif language_selection == LanguageSelection.English:
             data = BiblesResourcesDB.get_book_by_id(verse.book.book_reference_id)
             book = data['name']
         data = {
             'book': book,
             'chapter': verse.chapter,
             'verse': verse.verse,
             'bible': bible,
             'version': version,
             'copyright': copyright,
             'permissions': permissions,
             'text': verse.text,
             'second_bible': second_bible,
             'second_version': second_version,
             'second_copyright': second_copyright,
             'second_permissions': second_permissions,
             'second_text': ''
         }
         if second_bible:
             try:
                 data['second_text'] = self.second_search_results[count].text
             except IndexError:
                 log.exception('The second_search_results does not have as many verses as the search_results.')
                 break
             bible_text = '%s %d%s%d (%s, %s)' % (book, verse.chapter, verse_separator, verse.verse, version,
                 second_version)
         else:
             bible_text = '%s %d%s%d (%s)' % (book, verse.chapter, verse_separator, verse.verse, version)
         bible_verse = QtGui.QListWidgetItem(bible_text)
         bible_verse.setData(QtCore.Qt.UserRole, data)
         items.append(bible_verse)
     return items
Exemple #15
0
 def load(self):
     settings = Settings()
     settings.beginGroup(self.settings_section)
     self.is_verse_number_visible = settings.value('is verse number visible')
     self.show_new_chapters = settings.value('display new chapter')
     self.display_style = settings.value('display brackets')
     self.layout_style = settings.value('verse layout style')
     self.bible_theme = settings.value('bible theme')
     self.second_bibles = settings.value('second bibles')
     self.is_verse_number_visible_check_box.setChecked(self.is_verse_number_visible)
     self.check_is_verse_number_visible()
     self.new_chapters_check_box.setChecked(self.show_new_chapters)
     self.display_style_combo_box.setCurrentIndex(self.display_style)
     self.layout_style_combo_box.setCurrentIndex(self.layout_style)
     self.bible_second_check_box.setChecked(self.second_bibles)
     verse_separator = settings.value('verse separator')
     if (verse_separator.strip('|') == '') or (verse_separator == get_reference_separator('sep_v_default')):
         self.verse_separator_line_edit.setText(get_reference_separator('sep_v_default'))
         self.verse_separator_line_edit.setPalette(self.get_grey_text_palette(True))
         self.verse_separator_check_box.setChecked(False)
     else:
         self.verse_separator_line_edit.setText(verse_separator)
         self.verse_separator_line_edit.setPalette(self.get_grey_text_palette(False))
         self.verse_separator_check_box.setChecked(True)
     range_separator = settings.value('range separator')
     if (range_separator.strip('|') == '') or (range_separator == get_reference_separator('sep_r_default')):
         self.range_separator_line_edit.setText(get_reference_separator('sep_r_default'))
         self.range_separator_line_edit.setPalette(self.get_grey_text_palette(True))
         self.range_separator_check_box.setChecked(False)
     else:
         self.range_separator_line_edit.setText(range_separator)
         self.range_separator_line_edit.setPalette(self.get_grey_text_palette(False))
         self.range_separator_check_box.setChecked(True)
     list_separator = settings.value('list separator')
     if (list_separator.strip('|') == '') or (list_separator == get_reference_separator('sep_l_default')):
         self.list_separator_line_edit.setText(get_reference_separator('sep_l_default'))
         self.list_separator_line_edit.setPalette(self.get_grey_text_palette(True))
         self.list_separator_check_box.setChecked(False)
     else:
         self.list_separator_line_edit.setText(list_separator)
         self.list_separator_line_edit.setPalette(self.get_grey_text_palette(False))
         self.list_separator_check_box.setChecked(True)
     end_separator = settings.value('end separator')
     if (end_separator.strip('|') == '') or (end_separator == get_reference_separator('sep_e_default')):
         self.end_separator_line_edit.setText(get_reference_separator('sep_e_default'))
         self.end_separator_line_edit.setPalette(self.get_grey_text_palette(True))
         self.end_separator_check_box.setChecked(False)
     else:
         self.end_separator_line_edit.setText(end_separator)
         self.end_separator_line_edit.setPalette(self.get_grey_text_palette(False))
         self.end_separator_check_box.setChecked(True)
     self.language_selection = settings.value('book name language')
     self.language_selection_combo_box.setCurrentIndex(self.language_selection)
     settings.endGroup()
Exemple #16
0
 def load(self):
     settings = Settings()
     settings.beginGroup(self.settings_section)
     self.show_new_chapters = settings.value('display new chapter')
     self.display_style = settings.value('display brackets')
     self.layout_style = settings.value('verse layout style')
     self.bible_theme = settings.value('bible theme')
     self.second_bibles = settings.value('second bibles')
     self.new_chapters_check_box.setChecked(self.show_new_chapters)
     self.display_style_combo_box.setCurrentIndex(self.display_style)
     self.layout_style_combo_box.setCurrentIndex(self.layout_style)
     self.bible_second_check_box.setChecked(self.second_bibles)
     verse_separator = settings.value('verse separator')
     if (verse_separator.strip('|') == '') or (verse_separator == get_reference_separator('sep_v_default')):
         self.verse_separator_line_edit.setText(get_reference_separator('sep_v_default'))
         self.verse_separator_line_edit.setPalette(self.getGreyTextPalette(True))
         self.verse_separator_check_box.setChecked(False)
     else:
         self.verse_separator_line_edit.setText(verse_separator)
         self.verse_separator_line_edit.setPalette(self.getGreyTextPalette(False))
         self.verse_separator_check_box.setChecked(True)
     range_separator = settings.value('range separator')
     if (range_separator.strip('|') == '') or (range_separator == get_reference_separator('sep_r_default')):
         self.range_separator_line_edit.setText(get_reference_separator('sep_r_default'))
         self.range_separator_line_edit.setPalette(self.getGreyTextPalette(True))
         self.range_separator_check_box.setChecked(False)
     else:
         self.range_separator_line_edit.setText(range_separator)
         self.range_separator_line_edit.setPalette(self.getGreyTextPalette(False))
         self.range_separator_check_box.setChecked(True)
     list_separator = settings.value('list separator')
     if (list_separator.strip('|') == '') or (list_separator == get_reference_separator('sep_l_default')):
         self.list_separator_line_edit.setText(get_reference_separator('sep_l_default'))
         self.list_separator_line_edit.setPalette(self.getGreyTextPalette(True))
         self.list_separator_check_box.setChecked(False)
     else:
         self.list_separator_line_edit.setText(list_separator)
         self.list_separator_line_edit.setPalette(self.getGreyTextPalette(False))
         self.list_separator_check_box.setChecked(True)
     end_separator = settings.value('end separator')
     if (end_separator.strip('|') == '') or (end_separator == get_reference_separator('sep_e_default')):
         self.end_separator_line_edit.setText(get_reference_separator('sep_e_default'))
         self.end_separator_line_edit.setPalette(self.getGreyTextPalette(True))
         self.end_separator_check_box.setChecked(False)
     else:
         self.end_separator_line_edit.setText(end_separator)
         self.end_separator_line_edit.setPalette(self.getGreyTextPalette(False))
         self.end_separator_check_box.setChecked(True)
     self.language_selection = settings.value('book name language')
     self.language_selection_combo_box.setCurrentIndex(self.language_selection)
     settings.endGroup()
Exemple #17
0
 def load(self):
     settings = Settings()
     settings.beginGroup(self.settingsSection)
     self.show_new_chapters = settings.value(u'display new chapter')
     self.display_style = settings.value(u'display brackets')
     self.layout_style = settings.value(u'verse layout style')
     self.bible_theme = settings.value(u'bible theme')
     self.second_bibles = settings.value(u'second bibles')
     self.newChaptersCheckBox.setChecked(self.show_new_chapters)
     self.displayStyleComboBox.setCurrentIndex(self.display_style)
     self.layoutStyleComboBox.setCurrentIndex(self.layout_style)
     self.bibleSecondCheckBox.setChecked(self.second_bibles)
     verse_separator = settings.value(u'verse separator')
     if (verse_separator.strip(u'|') == u'') or (verse_separator == get_reference_separator(u'sep_v_default')):
         self.verseSeparatorLineEdit.setText(get_reference_separator(u'sep_v_default'))
         self.verseSeparatorLineEdit.setPalette(self.getGreyTextPalette(True))
         self.verseSeparatorCheckBox.setChecked(False)
     else:
         self.verseSeparatorLineEdit.setText(verse_separator)
         self.verseSeparatorLineEdit.setPalette(self.getGreyTextPalette(False))
         self.verseSeparatorCheckBox.setChecked(True)
     range_separator = settings.value(u'range separator')
     if (range_separator.strip(u'|') == u'') or (range_separator == get_reference_separator(u'sep_r_default')):
         self.rangeSeparatorLineEdit.setText(get_reference_separator(u'sep_r_default'))
         self.rangeSeparatorLineEdit.setPalette(self.getGreyTextPalette(True))
         self.rangeSeparatorCheckBox.setChecked(False)
     else:
         self.rangeSeparatorLineEdit.setText(range_separator)
         self.rangeSeparatorLineEdit.setPalette(self.getGreyTextPalette(False))
         self.rangeSeparatorCheckBox.setChecked(True)
     list_separator = settings.value(u'list separator')
     if (list_separator.strip(u'|') == u'') or (list_separator == get_reference_separator(u'sep_l_default')):
         self.listSeparatorLineEdit.setText(get_reference_separator(u'sep_l_default'))
         self.listSeparatorLineEdit.setPalette(self.getGreyTextPalette(True))
         self.listSeparatorCheckBox.setChecked(False)
     else:
         self.listSeparatorLineEdit.setText(list_separator)
         self.listSeparatorLineEdit.setPalette(self.getGreyTextPalette(False))
         self.listSeparatorCheckBox.setChecked(True)
     end_separator = settings.value(u'end separator')
     if (end_separator.strip(u'|') == u'') or (end_separator == get_reference_separator(u'sep_e_default')):
         self.endSeparatorLineEdit.setText(get_reference_separator(u'sep_e_default'))
         self.endSeparatorLineEdit.setPalette(self.getGreyTextPalette(True))
         self.endSeparatorCheckBox.setChecked(False)
     else:
         self.endSeparatorLineEdit.setText(end_separator)
         self.endSeparatorLineEdit.setPalette(self.getGreyTextPalette(False))
         self.endSeparatorCheckBox.setChecked(True)
     self.language_selection = settings.value(u'book name language')
     self.languageSelectionComboBox.setCurrentIndex(self.language_selection)
     settings.endGroup()
Exemple #18
0
 def format_verses(self):
     verse_sep = get_reference_separator('sep_v_display')
     range_sep = get_reference_separator('sep_r_display')
     list_sep = get_reference_separator('sep_l_display')
     result = ''
     for index, verse in enumerate(self.verse_list):
         if index == 0:
             result = '{book} {chapter}{sep}{verse}'.format(
                 book=verse['book'],
                 chapter=verse['chapter'],
                 sep=verse_sep,
                 verse=verse['start'])
             if verse['start'] != verse['end']:
                 result = '{result}{sep}{end}'.format(result=result,
                                                      sep=range_sep,
                                                      end=verse['end'])
             continue
         prev = index - 1
         if self.verse_list[prev]['version'] != verse['version']:
             result = '{result} ({version})'.format(
                 result=result, version=self.verse_list[prev]['version'])
         result += '{sep} '.format(sep=list_sep)
         if self.verse_list[prev]['book'] != verse['book']:
             result = '{result}{book} {chapter}{sep}'.format(
                 result=result,
                 book=verse['book'],
                 chapter=verse['chapter'],
                 sep=verse_sep)
         elif self.verse_list[prev]['chapter'] != verse['chapter']:
             result = '{result}{chapter}{sep}'.format(
                 result=result, chapter=verse['chapter'], sep=verse_sep)
         result += str(verse['start'])
         if verse['start'] != verse['end']:
             result = '{result}{sep}{end}'.format(result=result,
                                                  sep=range_sep,
                                                  end=verse['end'])
     if len(self.version_list) > 1:
         result = '{result} ({version})'.format(result=result,
                                                version=verse['version'])
     return result
Exemple #19
0
    def get_reference_separator_test(self):
        """
        Test the get_reference_separator method
        """
        # GIVEN: A list of expected separators
        separators = {'sep_r': '\\s*(?:e)\\s*', 'sep_e_default': 'end', 'sep_v_display': 'w', 'sep_l_display': 'r',
                      'sep_v_default': ':|v|V|verse|verses', 'sep_l': '\\s*(?:r)\\s*', 'sep_l_default': ',|and',
                      'sep_e': '\\s*(?:t)\\s*', 'sep_v': '\\s*(?:w)\\s*', 'sep_r_display': 'e', 'sep_r_default': '-|to'}

        def side_effect():
            lib.REFERENCE_SEPARATORS = separators

        with patch('openlp.plugins.bibles.lib.update_reference_separators',
                   **{'side_effect': side_effect}) as mocked_update_reference_separators:

            # WHEN: Calling get_reference_separator
            for key, value in separators.items():
                ret = lib.get_reference_separator(key)

                # THEN: get_reference_separator should return the correct separator
                self.assertEqual(separators[key], value)
            mocked_update_reference_separators.assert_called_once_with()
Exemple #20
0
def get_reference_separators():
    return {'verse': get_reference_separator('sep_v_display'),
            'range': get_reference_separator('sep_r_display'),
            'list': get_reference_separator('sep_l_display')}
Exemple #21
0
 def on_end_separator_check_box_clicked(self, checked):
     if checked:
         self.end_separator_line_edit.setFocus()
     else:
         self.end_separator_line_edit.setText(get_reference_separator('sep_e_default'))
     self.end_separator_line_edit.setPalette(self.getGreyTextPalette(not checked))
Exemple #22
0
def get_reference_separators():
    return {'verse': get_reference_separator('sep_v_display'),
            'range': get_reference_separator('sep_r_display'),
            'list': get_reference_separator('sep_l_display')}
Exemple #23
0
    def get_verses(self,
                   bible,
                   verse_text,
                   book_ref_id=False,
                   show_error=True):
        """
        Parses a scripture reference, fetches the verses from the Bible
        specified, and returns a list of ``Verse`` objects.

        :param bible: Unicode. The Bible to use.
        :param verse_text:
             Unicode. The scripture reference. Valid scripture references are:

                - Genesis 1
                - Genesis 1-2
                - Genesis 1:1
                - Genesis 1:1-10
                - Genesis 1:1-10,15-20
                - Genesis 1:1-2:10
                - Genesis 1:1-10,2:1-10

        :param book_ref_id:  Unicode. The book reference id from the book in verse_text.
            For second bible this is necessary.
        :param show_error:
        """
        log.debug('BibleManager.get_verses("%s", "%s")', bible, verse_text)
        if not bible:
            if show_error:
                self.main_window.information_message(
                    translate('BiblesPlugin.BibleManager',
                              'No Bibles Available'),
                    translate(
                        'BiblesPlugin.BibleManager',
                        'There are no Bibles currently installed. Please use the '
                        'Import Wizard to install one or more Bibles.'))
            return None
        language_selection = self.get_language_selection(bible)
        ref_list = parse_reference(verse_text, self.db_cache[bible],
                                   language_selection, book_ref_id)
        if ref_list:
            return self.db_cache[bible].get_verses(ref_list, show_error)
        else:
            if show_error:
                reference_separators = {
                    'verse': get_reference_separator('sep_v_display'),
                    'range': get_reference_separator('sep_r_display'),
                    'list': get_reference_separator('sep_l_display')
                }
                self.main_window.information_message(
                    translate('BiblesPlugin.BibleManager',
                              'Scripture Reference Error'),
                    translate(
                        'BiblesPlugin.BibleManager',
                        'Your scripture reference is either not supported by '
                        'OpenLP or is invalid. Please make sure your reference '
                        'conforms to one of the following patterns or consult the manual:\n\n'
                        'Book Chapter\n'
                        'Book Chapter%(range)sChapter\n'
                        'Book Chapter%(verse)sVerse%(range)sVerse\n'
                        'Book Chapter%(verse)sVerse%(range)sVerse%(list)sVerse'
                        '%(range)sVerse\n'
                        'Book Chapter%(verse)sVerse%(range)sVerse%(list)sChapter'
                        '%(verse)sVerse%(range)sVerse\n'
                        'Book Chapter%(verse)sVerse%(range)sChapter%(verse)sVerse',
                        'Please pay attention to the appended "s" of the wildcards '
                        'and refrain from translating the words inside the names in the brackets.'
                    ) % reference_separators)
            return None
Exemple #24
0
 def onEndSeparatorCheckBoxClicked(self, checked):
     if checked:
         self.endSeparatorLineEdit.setFocus()
     else:
         self.endSeparatorLineEdit.setText(get_reference_separator(u'sep_e_default'))
     self.endSeparatorLineEdit.setPalette(self.getGreyTextPalette(not checked))
Exemple #25
0
 def on_list_separator_check_box_clicked(self, checked):
     if checked:
         self.list_separator_line_edit.setFocus()
     else:
         self.list_separator_line_edit.setText(get_reference_separator('sep_l_default'))
     self.list_separator_line_edit.setPalette(self.get_grey_text_palette(not checked))