示例#1
0
    def GenerateIndex(self, mod, progress=lambda x: x):
        """Index.GenerateIndex - Collates book indexes"""
        template = VerseTemplate("$text\n")
        biblemgr.temporary_state(biblemgr.plainstate)
        log = SW.Log.getSystemLog()
        old_log_level = log.getLogLevel()
        log.setLogLevel(0)

        #apply template
        if not self.book.ModuleExists(mod):
            raise Exception, "Module %s not found" % mod

        oldmod = self.book.version

        try:
            self.book.SetModule(mod, notify=False)
            mod = self.book.mod

            self.book.templatelist.append(template)
            self.books.append(self.booktype(self.version))

            if self.booktype.gatherstatistics:
                self.GatherStatistics()

        finally:
            log.setLogLevel(old_log_level)

            biblemgr.restore_state()
            self.book.templatelist.pop()

            self.book.SetModule(oldmod, notify=False)
示例#2
0
    def GenerateIndex(self, mod, progress=lambda x: x):
        """Index.GenerateIndex - Collates book indexes"""
        template = VerseTemplate("$text\n")
        biblemgr.temporary_state(biblemgr.plainstate)
        log = SW.Log.getSystemLog()
        old_log_level = log.getLogLevel()
        log.setLogLevel(0)

        #apply template
        if not self.book.ModuleExists(mod):  #SetModule(mod):
            raise Exception, "Module %s not found" % mod

        oldmod = self.book.version

        try:
            self.book.SetModule(mod, notify=False)
            mod = self.book.mod

            self.book.templatelist.append(template)
            offsets = [0]
            books = 0
            for i in range(1, 3):
                offsets.append(books)
                books += vk.bookCount(i)
            for i in [1, 2]:
                for j in range(1, vk.bookCount(i) + 1):
                    bookname = vk.bookName(i, j)
                    # two translates in case of dashes
                    bookname_ui = pysw.locale.translate(
                        pysw.locale.translate(bookname)).decode(
                            pysw.locale_encoding)

                    continuing = progress(
                        (bookname_ui, 99 * (j + offsets[i]) / books))
                    if not continuing:
                        raise Cancelled

                    self.books.append(self.booktype(self.version, bookname))

            if (self.booktype.gatherstatistics):
                self.GatherStatistics()

        finally:
            log.setLogLevel(old_log_level)

            biblemgr.restore_state()
            self.book.templatelist.pop()

            self.book.SetModule(oldmod, notify=False)
示例#3
0
    def GetText(self, ref):
        print "Getting text for", ref
        template = VerseTemplate(header=self.template_panel.header.GetText(),
                                 body=self.template_panel.body.GetText(),
                                 footer=self.template_panel.footer.GetText())

        #no footnotes
        biblemgr.temporary_state(biblemgr.plainstate)
        if display_options.options["colour_speakers"] == "woc_in_red":
            biblemgr.set_option("Words of Christ in Red", "On")

        #apply template
        biblemgr.bible.templatelist.append(template)
        biblemgr.parser_mode = COPY_VERSES_PARSER_MODE

        data = biblemgr.bible.GetReference(ref)
        if data is None:
            data = config.MODULE_MISSING_STRING()

        if self.formatted:
            # TODO: make it scan CSS and amalgamate rules?
            data = data.replace("<span class='WoC'>",
                                "<span style='color: red'>")
            data = data.replace("<span class='divineName'>",
                                "<span style='font-variant:small-caps'>")

            # Use the font that has been selected for the module.
            # XXX: We could still use language specific fonts for particular
            # sections of the text, but I'm not sure it's worth doing.
            # It would probably only apply to Hebrew and Greek (which we
            # treat specially) anyway.
            default, (font, size, in_gui) = fonts.get_module_font_params(
                biblemgr.bible.mod)
            data = u"<span style=\"font-family: %s; font-size: %spt;\">%s</span>" % (
                font, size, data)
        else:
            data = string_util.br2nl(data)
            data = string_util.KillTags(data)
            data = string_util.amps_to_unicode(data)

        #restore
        biblemgr.restore_state()
        biblemgr.bible.templatelist.pop()
        biblemgr.parser_mode = NORMAL_PARSER_MODE
        return data
示例#4
0
 def __init__(self, parent, version=""):
     self.parent = parent
     self.mod = None
     self.observers = observerlist.ObserverList()
     self.cleanup_module = observerlist.ObserverList()
     self.template = VerseTemplate(body="$text")
     self.templatelist = [self.template]
     self.vk = VK()
     self.headings = False
     if self.ModuleExists(version):
         self.SetModule(version)
     else:
         mods = self.GetModuleList()
         if mods:
             self.SetModule(mods[0])
         else:
             dprint(WARNING, "No modules of type", self.type)
             self.SetModule(None)
示例#5
0
    def GenerateIndex(self, mod, progress=lambda x: x):
        """Index.GenerateIndex - Collates book indexes"""
        template = VerseTemplate("$text\n")
        biblemgr.temporary_state(biblemgr.plainstate)
        log = SW.Log.getSystemLog()
        old_log_level = log.getLogLevel()
        log.setLogLevel(0)

        #apply template
        if not self.book.ModuleExists(mod):
            raise Exception, "Module %s not found" % mod

        oldmod = self.book.version

        try:
            self.book.SetModule(mod, notify=False)
            topics = self.book.GetTopics()

            mod = self.book.mod

            self.book.templatelist.append(template)
            entry_size = 200
            for a in range(0, len(topics), entry_size):
                continuing = progress((topics[a], 95 * a / len(topics)))

                self.books.append(
                    self.booktype(self.version,
                                  start=topics[a],
                                  entries=entry_size))

                if not continuing:
                    raise Cancelled

            if self.booktype.gatherstatistics:
                progress(("index", 99))
                self.GatherStatistics()

        finally:
            log.setLogLevel(old_log_level)

            biblemgr.restore_state()
            self.book.templatelist.pop()

            self.book.SetModule(oldmod, notify=False)
示例#6
0
    def __init__(self, parent):
        super(GuessVerseFrame, self).__init__(parent)

        # This call makes sure that the reference display frame is loaded
        # with an empty reference.
        # This means that all future references displayed will be shown with
        # Javascript, and so there won't be any focus bugs.
        self.reference_frame.RefreshUI()

        self.reference_frame.template = VerseTemplate(body=u"$text",
                                                      headings="")

        self.show_answer_button.Bind(wx.EVT_BUTTON, self.on_show_answer)
        self.guess_button.Bind(wx.EVT_BUTTON, self.on_guess)
        self.books.AppendItems([unicode(book) for book in UserVK.books])
        self.books.Selection = 0
        self.new_guess()
        self.Children[0].Fit()
        self.Fit()
示例#7
0
	<a name="${osisRef}_end" osisRef="$osisRef"></a>''') % verse_number

bible_template = SmartVerseTemplate(body=body%'', preverse=preverse)
bible_template_without_headings = SmartVerseTemplate(body=body % '',
	headings=u'', preverse=preverse)


current_verse_template = SmartVerseTemplate(body % ' currentverse',
											preverse=preverse)


#, footer="<br>$range ($version)")


commentary_template = VerseTemplate(
	body=u"<div class='commentary_entry'><h3>$reference</h3>$text\n</div>"
)
dictionary_template = VerseTemplate(
	body=u"<div class='dictionary_entry'><h3>$reference</h3>$text\n</div>"
)
genbook_template = VerseTemplate(
	body=u"<div class='genbook_entry'><div class='genbook_key' level='$level'>$breadcrumbed_reference</div>$text\n</div>"
)

compare_verse_number = (verse_number % '').replace("$numbertype", "versenumber")

verse_compare_template = VerseTemplate(
	body=compare_verse_number + u" $text\n",
	header=u"<p><b>(<a href=\"%s://content/$version\">$version</a>)</b>"
			% BIBLE_VERSION_PROTOCOL
)
示例#8
0
    def _RefreshUI(self):
        if not self.reference:
            self.ShowReferenceHTML("")
            return

        ref_parts = self.reference.split(" - ")
        reference = ref_parts.pop(0)
        end_reference = None
        if ref_parts:
            end_reference = ref_parts[0]

        if self.parent.template:
            self.parent.book.templatelist.append(self.parent.template)

        data = self.parent.book.GetReference(reference, end_ref=end_reference)

        if self.parent.template:
            self.parent.book.templatelist.pop()

        # TODO: put a function in search to do this for us...
        biblemgr.temporary_state(biblemgr.plainstate)
        template = VerseTemplate(u"$text ")  #, headings=u"")
        self.parent.book.templatelist.append(template)

        content = self.parent.book.GetReference(reference,
                                                stripped=True,
                                                end_ref=end_reference)
        biblemgr.restore_state()
        self.parent.book.templatelist.pop()

        #TODO: highlight with \n's properly
        # e.g. /word\nanother/

        # remove non-canonical headings
        content = re.sub('(<h2 class="heading">.*?</h2>)', '', content)

        content = remove_amps(KillTags(ReplaceUnicode(content)))
        content = content.replace("\n", " ")
        content = removeformatting(content)

        data = highlight(
            content,
            data,
            is_bible=self.parent.book.mod.Type() == Bible.type,
            regexes=self.regexes,
            fields=self.fields,
        )

        # XXX: This replace should be done for us by the backend Bible
        # interface (or by Sword itself).
        data = data.replace("<!P>", "</p><p>")
        self.ShowReferenceHTML("%s" % data)

        # Scroll to the first highlighted match.
        # We scroll up one line from the highlight to make sure there is sufficient context,
        # particularly when displaying a Strong's match in Strong's Blocked mode.
        # However, we have to make sure that if the match is at the bottom of the page
        # we don't scroll up a line and half-obscure it.
        self.ExecuteScriptAfterDocumentLoaded("""
			window.location.hash = "highlight";
			if ($(".search_highlight:first").offset().top < window.scrollY + 15)	{
				window.scrollByLines(-1);
			}
		""")