Example #1
0
    def SetReference(self, ref, ref_to_scroll_to=None, settings_changed=False):
        """Sets reference. This is set up to be an observer of the main frame,
		so don't call internally. To set verse reference, use notify"""
        self.reference = GetVerseStr(ref)

        has_selected_new_verse = False
        # If the settings have changed we want to do a complete reload anyway
        # (since it could be something that requires a complete reload, such as changing version).
        if self.dom_loaded:
            if settings_changed:
                self.reference, ref_to_scroll_to = self.GetCurrentReferenceAndPosition(
                )
            else:
                osisRef = VK(self.reference).getOSISRef()
                has_selected_new_verse = self.ExecuteScriptWithResult(
                    'select_new_verse("%s")' % osisRef)
                has_selected_new_verse = (has_selected_new_verse == "true")

        if has_selected_new_verse:
            self.NewReferenceLoaded()
        elif self.CheckChapterInBook(ref):
            self.OpenURIForCurrentBook("bpbible://content/page/%s/%s" %
                                       (self.book.version, self.reference))

        if ref_to_scroll_to:
            self.scroll_to_osis_ref(ref_to_scroll_to)

        chapter = GetBookChapter(self.reference)
        self.header_bar.set_current_chapter(pysw.internal_to_user(chapter),
                                            chapter)

        self.update_title()
Example #2
0
    def GetCurrentReferenceAndPosition(self):
        if not self.dom_loaded:
            return ('', None)

        current_reference = GetVerseStr(
            self.ExecuteScriptWithResult(
                'get_current_reference_on_screen()')) or self.reference
        ref_to_scroll_to = self.ExecuteScriptWithResult(
            'current_reference_at_top_of_screen')
        return (current_reference, ref_to_scroll_to)
Example #3
0
    def get_verified(self, ref):
        try:
            ref = GetVerseStr(ref,
                              "",
                              raiseError=True,
                              userInput=True,
                              userOutput=False)
            return ref

        except VerseParsingError, e:
            wx.MessageBox(str(e), config.name())
Example #4
0
    def end_scripRef(self, xmltag):
        if not filterutils.filter_settings["expand_thml_refs"]:

            self.success = SW.INHERITED
            return

        refList = self.scripRef_passage
        if self.u.module.Type() == "Biblical Texts":
            if refList:
                dprint(MESSAGE, "FOUND ThML reflist in Bible", refList)
                self.success = SW.INHERITED
                return

            else:
                refs = self.u.lastTextNode.c_str().split(";")
                self.buf += filterutils.ellipsize(refs, self.u.key.getText())

            self.u.suspendTextPassThru = False

            return

        # if we have a ref list, then we need to display the text and just
        # pop up usual thing
        if refList:
            self.buf += (
                "<a href=\"newbible://content/passagestudy.jsp?action=showRef&type=scripRef&value=%s&module=%s\">"
            ) % (SW.URL.encode(refList).c_str(), "")
            self.buf += self.u.lastTextNode.c_str()
            self.buf += "</a>"
        else:
            # break it up into its constituent parts and display each as a
            # separate link
            refList = self.u.lastTextNode.c_str()

            items = []
            last = GetVerseStr(self.u.key.getText())
            for item in refList.split(";"):
                vref = item
                vref = GetBestRange(to_unicode(vref),
                                    context=last,
                                    use_bpbible_locale=True)
                items.append('<a href="bible:%s">%s</a>' % (vref, item))
                last = vref
            self.buf += "; ".join(items)

        # let text resume to output again
        self.u.suspendTextPassThru = False
Example #5
0
    def GetReferences(self, ref, context="", max_verses=-1):
        """Gets a list of references.
		
		In: ref - list of references
			context: context of first in list
		Out: A list of verses
		"""
        # TODO: If we have a list passed in like this:
        # ref= ['104:6', '8, 10, 105:1', '3'], context = 'PS 104:14'
        # for second item, GetVerseStr will return Psalms 104:8, instead
        # of Psalms 105:1, so the third retrieved will be 104:3, not 105:3
        # Fixes:
        # Make GetVerseStr take last in list, not first as optional parameter
        results = []
        lastref = context
        for j in ref:
            #get text
            results.append(
                self.GetReference(j, context=lastref, max_verses=max_verses))
            # set context for next ref
            lastref = GetVerseStr(j, lastref)

        return results
Example #6
0
    def get_tree_item(self):
        root = self.tree.GetRootItem()

        text = self.GetValue()
        was_book = False
        for book in UserVK.books:
            if ("%s" % book) == text:
                was_book = True
                self.currentverse = book.bookname
                break
        else:
            try:
                # try updating verse based on user text
                # if we fail, just use old text (assuming there is any)
                self.currentverse = GetVerseStr(text,
                                                self.currentverse,
                                                raiseError=True,
                                                userInput=True,
                                                userOutput=False)

            except VerseParsingError:
                if not self.currentverse:
                    return self.tree.GetFirstChild(root)[0]

        verse_key = UserVK(VK(self.currentverse))
        single_chapter_book = verse_key.getChapterMax() == 1

        book, chapter = verse_key.getBookName(), verse_key.Chapter()
        verse = verse_key.Verse()
        chapter = process_digits(str(chapter), userOutput=True)
        verse = process_digits(str(verse), userOutput=True)
        if single_chapter_book:
            chapter = verse

        item, cookie = self.tree.GetFirstChild(root)
        while item:
            if self.tree.GetItemText(item) == book:
                break

            item, cookie = self.tree.GetNextChild(root, cookie)

        assert item, book + " not found!"

        if was_book or (single_chapter_book and not self.with_verses):
            return item

        self.tree.Expand(item)

        item2, cookie = self.tree.GetFirstChild(item)

        while item2:
            data = unicode(self.get_data(item2))
            if data == chapter:
                # if : isn't in there, we take it as a chapter reference
                if not self.with_verses or  ":" not in text \
                  or single_chapter_book:
                    return item2
                else:
                    break

            item2, cookie = self.tree.GetNextChild(item, cookie)

        assert item2, "Chapter '%s' not found in %s" % (chapter, book)
        assert not single_chapter_book, "Single chapter books, but chapterMax == 1?!?"

        self.tree.Expand(item2)

        item3, cookie = self.tree.GetFirstChild(item2)

        while item3:
            data = unicode(self.get_data(item3))
            if data == verse:
                return item3

            item3, cookie = self.tree.GetNextChild(item2, cookie)

        assert item3, "Verse '%s' not found in %s %s" % (verse, book, chapter)
Example #7
0
    def GetReference(self,
                     ref,
                     specialref="",
                     specialtemplate=None,
                     context="",
                     max_verses=177,
                     raw=False,
                     stripped=False,
                     template=None,
                     display_tags=None,
                     exclude_topic_tag=None,
                     end_ref=None,
                     headings=False,
                     verselist=None,
                     remove_extra_whitespace=False):
        """GetReference gets a reference from a Book.
		
		specialref is a ref (string) which will be specially formatted 
		according to specialtemplate.

		exclude_topic_tag: If this is not None, then it is a topic that
		should not have a tag generated, because it is obvious from the
		context (for example, the topic window for that topic).
		"""
        #only for bible keyed books
        if not self.mod:
            return None

        raw = raw or display_options.options["raw"]

        if template is None and self.templatelist:
            template = self.templatelist[-1]
        if context:
            lastverse = context
        else:
            lastverse = ""

        if display_tags is None:
            # if we don't have tags in, don't calculate them as it can be
            # expensive
            if "$tags" not in template.body.template:
                display_tags = False
            else:
                display_tags = passage_list.settings.display_tags

        assert not (verselist and end_ref), \
         "No end ref with a listkey!!!"

        if end_ref:
            ref += " - " + end_ref

        old_headings = self.vk.Headings(headings)

        if not verselist:
            verselist = self.vk.ParseVerseList(to_str(ref), to_str(lastverse),
                                               True)

        # if they pass in a verselist, they can also pass in the ref they
        # would like to go along with it. This can be useful if it also
        # includes headings that shouldn't be seen
        rangetext = GetBestRange(ref,
                                 context=context,
                                 userInput=False,
                                 userOutput=True,
                                 headings=headings)

        internal_rangetext = GetBestRange(ref,
                                          context=context,
                                          headings=headings)

        if rangetext == "":
            self.vk.Headings(old_headings)
            #if invalid reference, return empty string
            return u""

        if specialref:
            specialref = GetVerseStr(specialref)

        description = to_unicode(self.mod.Description(), self.mod)
        d = dict(range=rangetext,
                 internal_range=internal_rangetext,
                 version=self.mod.Name(),
                 description=description)

        text = template.header.safe_substitute(d)
        verses = []

        for body_dict, headings in self.GetReference_yield(
                verselist,
                max_verses,
                raw,
                stripped,
                exclude_topic_tag=exclude_topic_tag,
                display_tags=display_tags,
        ):
            # if we have exceeded the verse limit, body_dict will be None
            if body_dict is None:
                verses.append(config.MAX_VERSES_EXCEEDED() % max_verses)
                break

            body_dict.update(d)

            t = template

            if specialref == body_dict["internal_reference"]:
                t = specialtemplate

            verse = t.preverse.safe_substitute(body_dict)

            for heading_dict in headings:
                verse += t.headings.safe_substitute(heading_dict)

            verse += t.body.safe_substitute(body_dict)

            verses.append(verse)

        self.vk.Headings(old_headings)

        text += template.finalize(u''.join(verses))
        text += self.end_of_render
        text += template.footer.safe_substitute(d)
        return text