Пример #1
0
    def get_book_ref_id_by_localised_name(self, book,
        language_selection):
        """
        Return the id of a named book.

        ``book``
            The name of the book, according to the selected language.

        ``language_selection``
            The language selection the user has chosen in the settings
            section of the Bible.
        """
        log.debug(u'get_book_ref_id_by_localised_name("%s", "%s")',
            book, language_selection)
        from openlp.plugins.bibles.lib import LanguageSelection, \
            BibleStrings
        book_names = BibleStrings().BookNames
        # escape reserved characters
        book_escaped = book
        for character in RESERVED_CHARACTERS:
            book_escaped = book_escaped.replace(
                character, u'\\' + character)
        regex_book = re.compile(u'\s*%s\s*' % u'\s*'.join(
            book_escaped.split()), re.UNICODE | re.IGNORECASE)
        if language_selection == LanguageSelection.Bible:
            db_book = self.get_book(book)
            if db_book:
                return db_book.book_reference_id
        elif language_selection == LanguageSelection.Application:
            books = filter(lambda key:
                regex_book.match(unicode(book_names[key])), book_names.keys())
            books = filter(None, map(BiblesResourcesDB.get_book, books))
            for value in books:
                if self.get_book_by_book_ref_id(value[u'id']):
                    return value[u'id']
        elif language_selection == LanguageSelection.English:
            books = BiblesResourcesDB.get_books_like(book)
            if books:
                book_list = filter(
                    lambda value: regex_book.match(value[u'name']), books)
                if not book_list:
                    book_list = books
                for value in book_list:
                    if self.get_book_by_book_ref_id(value[u'id']):
                        return value[u'id']
        return False
Пример #2
0
 def __init__(self, parent = None):
     """
     Constructor
     """
     QDialog.__init__(self, parent)
     self.setupUi(self)
     self.customSignals()
     self.book_names = BibleStrings().BookNames
     self.book_id = False
Пример #3
0
 def __init__(self, parent = None):
     """
     Constructor
     """
     super(BookNameForm, self).__init__(parent)
     self.setupUi(self)
     self.custom_signals()
     self.book_names = BibleStrings().BookNames
     self.book_id = False
Пример #4
0
 def __init__(self, parent=None):
     """
     Constructor
     """
     super(BookNameForm, self).__init__(parent, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
     self.setupUi(self)
     self.custom_signals()
     self.book_names = BibleStrings().BookNames
     self.book_id = False
Пример #5
0
    def get_book_ref_id_by_localised_name(self, book, language_selection):
        """
        Return the id of a named book.

        :param book: The name of the book, according to the selected language.
        :param language_selection:  The language selection the user has chosen in the settings section of the Bible.
        """
        log.debug('get_book_ref_id_by_localised_name("{book}", "{lang}")'.format(book=book, lang=language_selection))
        from openlp.plugins.bibles.lib import LanguageSelection, BibleStrings
        book_names = BibleStrings().BookNames
        # escape reserved characters
        book_escaped = book
        for character in RESERVED_CHARACTERS:
            book_escaped = book_escaped.replace(character, '\\' + character)
        # TODO: Verify regex patters before using format()
        regex_book = re.compile('\s*%s\s*' % '\s*'.join(
            book_escaped.split()), re.UNICODE | re.IGNORECASE)
        if language_selection == LanguageSelection.Bible:
            db_book = self.get_book(book)
            if db_book:
                return db_book.book_reference_id
        elif language_selection == LanguageSelection.Application:
            books = [key for key in list(book_names.keys()) if regex_book.match(str(book_names[key]))]
            books = [_f for _f in map(BiblesResourcesDB.get_book, books) if _f]
            for value in books:
                if self.get_book_by_book_ref_id(value['id']):
                    return value['id']
        elif language_selection == LanguageSelection.English:
            books = BiblesResourcesDB.get_books_like(book)
            if books:
                book_list = [value for value in books if regex_book.match(value['name'])]
                if not book_list:
                    book_list = books
                for value in book_list:
                    if self.get_book_by_book_ref_id(value['id']):
                        return value['id']
        return False
Пример #6
0
class BookNameForm(QDialog, Ui_BookNameDialog):
    """
    Class to manage a dialog which help the user to refer a book name a
    to a english book name
    """
    log.info(u'BookNameForm loaded')

    def __init__(self, parent = None):
        """
        Constructor
        """
        QDialog.__init__(self, parent)
        self.setupUi(self)
        self.customSignals()
        self.book_names = BibleStrings().BookNames
        self.book_id = False

    def customSignals(self):
        """
        Set up the signals used in the booknameform.
        """
        QtCore.QObject.connect(self.oldTestamentCheckBox, QtCore.SIGNAL(u'stateChanged(int)'),
            self.onCheckBoxIndexChanged)
        QtCore.QObject.connect(self.newTestamentCheckBox, QtCore.SIGNAL(u'stateChanged(int)'),
            self.onCheckBoxIndexChanged)
        QtCore.QObject.connect(self.apocryphaCheckBox, QtCore.SIGNAL(u'stateChanged(int)'),
            self.onCheckBoxIndexChanged)

    def onCheckBoxIndexChanged(self, index):
        """
        Reload Combobox if CheckBox state has changed
        """
        self.reloadComboBox()

    def reloadComboBox(self):
        """
        Reload the Combobox items
        """
        self.correspondingComboBox.clear()
        items = BiblesResourcesDB.get_books()
        for item in items:
            addBook = True
            for book in self.books:
                if book.book_reference_id == item[u'id']:
                    addBook = False
                    break
            if self.oldTestamentCheckBox.checkState() == QtCore.Qt.Unchecked and item[u'testament_id'] == 1:
                addBook = False
            elif self.newTestamentCheckBox.checkState() == QtCore.Qt.Unchecked and item[u'testament_id'] == 2:
                addBook = False
            elif self.apocryphaCheckBox.checkState() == QtCore.Qt.Unchecked and item[u'testament_id'] == 3:
                addBook = False
            if addBook:
                self.correspondingComboBox.addItem(self.book_names[item[u'abbreviation']])

    def exec_(self, name, books, maxbooks):
        self.books = books
        log.debug(maxbooks)
        if maxbooks <= 27:
            self.oldTestamentCheckBox.setCheckState(QtCore.Qt.Unchecked)
            self.apocryphaCheckBox.setCheckState(QtCore.Qt.Unchecked)
        elif maxbooks <= 66:
            self.apocryphaCheckBox.setCheckState(QtCore.Qt.Unchecked)
        self.reloadComboBox()
        self.currentBookLabel.setText(unicode(name))
        self.correspondingComboBox.setFocus()
        return QDialog.exec_(self)

    def accept(self):
        if self.correspondingComboBox.currentText() == u'':
            critical_error_message_box(message=translate('BiblesPlugin.BookNameForm', 'You need to select a book.'))
            self.correspondingComboBox.setFocus()
            return False
        else:
            cor_book = self.correspondingComboBox.currentText()
            for character in u'\\.^$*+?{}[]()':
                cor_book = cor_book.replace(character, u'\\' + character)
            books = filter(lambda key:
                re.match(cor_book, unicode(self.book_names[key]), re.UNICODE), self.book_names.keys())
            books = filter(None, map(BiblesResourcesDB.get_book, books))
            if books:
                self.book_id = books[0][u'id']
            return QDialog.accept(self)
Пример #7
0
class BookNameForm(QDialog, Ui_BookNameDialog):
    """
    Class to manage a dialog which help the user to refer a book name a
    to a english book name
    """
    log.info('BookNameForm loaded')

    def __init__(self, parent = None):
        """
        Constructor
        """
        super(BookNameForm, self).__init__(parent)
        self.setupUi(self)
        self.custom_signals()
        self.book_names = BibleStrings().BookNames
        self.book_id = False

    def custom_signals(self):
        """
        Set up the signals used in the booknameform.
        """
        self.old_testament_check_box.stateChanged.connect(self.onCheckBoxIndexChanged)
        self.new_testament_check_box.stateChanged.connect(self.onCheckBoxIndexChanged)
        self.apocrypha_check_box.stateChanged.connect(self.onCheckBoxIndexChanged)

    def onCheckBoxIndexChanged(self, index):
        """
        Reload Combobox if CheckBox state has changed
        """
        self.reload_combo_box()

    def reload_combo_box(self):
        """
        Reload the Combobox items
        """
        self.corresponding_combo_box.clear()
        items = BiblesResourcesDB.get_books()
        for item in items:
            add_book = True
            for book in self.books:
                if book.book_reference_id == item['id']:
                    add_book = False
                    break
            if self.old_testament_check_box.checkState() == QtCore.Qt.Unchecked and item['testament_id'] == 1:
                add_book = False
            elif self.new_testament_check_box.checkState() == QtCore.Qt.Unchecked and item['testament_id'] == 2:
                add_book = False
            elif self.apocrypha_check_box.checkState() == QtCore.Qt.Unchecked and item['testament_id'] == 3:
                add_book = False
            if add_book:
                self.corresponding_combo_box.addItem(self.book_names[item['abbreviation']])

    def exec_(self, name, books, max_books):
        self.books = books
        log.debug(max_books)
        if max_books <= 27:
            self.old_testament_check_box.setCheckState(QtCore.Qt.Unchecked)
            self.apocrypha_check_box.setCheckState(QtCore.Qt.Unchecked)
        elif max_books <= 66:
            self.apocrypha_check_box.setCheckState(QtCore.Qt.Unchecked)
        self.reload_combo_box()
        self.current_book_label.setText(str(name))
        self.corresponding_combo_box.setFocus()
        return QDialog.exec_(self)

    def accept(self):
        if not self.corresponding_combo_box.currentText():
            critical_error_message_box(message=translate('BiblesPlugin.BookNameForm', 'You need to select a book.'))
            self.corresponding_combo_box.setFocus()
            return False
        else:
            cor_book = self.corresponding_combo_box.currentText()
            for character in '\\.^$*+?{}[]()':
                cor_book = cor_book.replace(character, '\\' + character)
            books = [key for key in list(self.book_names.keys()) if re.match(cor_book, str(self.book_names[key]), re.UNICODE)]
            books = [_f for _f in map(BiblesResourcesDB.get_book, books) if _f]
            if books:
                self.book_id = books[0]['id']
            return QDialog.accept(self)