Ejemplo n.º 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)
Ejemplo n.º 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):
			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)
Ejemplo n.º 3
0
	def get_text(self):
		try:
			template = SmartVerseTemplate(
				header="<a href='nbible:$internal_range'><b>$range</b></a><br>",
				body=(config.body % ''),
			)

			#no footnotes
			if tooltip_settings["plain_xrefs"]:
				biblemgr.temporary_state(biblemgr.plainstate)
			#apply template
			biblemgr.bible.templatelist.append(template)

			import displayframe
			text = "<hr>".join(
				displayframe.process_html_for_module(biblemgr.bible.mod, item) 
				for item in biblemgr.bible.GetReferences(self.references)
			)

			return text

		finally:
			if tooltip_settings["plain_xrefs"]:
				biblemgr.restore_state()
			biblemgr.bible.templatelist.pop()
Ejemplo n.º 4
0
def get_content(module_name="ESV", verse_per_line=False):
	biblemgr.temporary_state(biblemgr.plainstate)
	old_expand_crossref = filterutils.filter_settings["footnote_ellipsis_level"]
	try:
		book = biblemgr.get_module_book_wrapper(module_name)
		biblemgr.set_option("Footnotes", True)
		biblemgr.set_option("Cross-references", True)
		filterutils.filter_settings["footnote_ellipsis_level"] = 0
		content = []

		#vk = VK()
		for bible_book in [bible_book for bible_book in UserVK.books
			#if len(bible_book.chapters) < N
			if not RESTRICTED or (
				bible_book.bookname in ("Psalms", "Matthew")
			)
		]:#VK.books:
			print "Processing", bible_book
			content.append(get_book(book, bible_book, verse_per_line=verse_per_line))
		#	if bible_book.bookname == "Genesis": break
		#	if bible_book.bookname == "Joshua": break
	finally:
		filterutils.filter_settings["footnote_ellipsis_level"] = old_expand_crossref
		biblemgr.restore_state()
	
	return content
Ejemplo n.º 5
0
def get_content(module_name="ESV", verse_per_line=False):
    biblemgr.temporary_state(biblemgr.plainstate)
    old_expand_crossref = filterutils.filter_settings[
        "footnote_ellipsis_level"]
    try:
        book = biblemgr.get_module_book_wrapper(module_name)
        biblemgr.set_option("Footnotes", True)
        biblemgr.set_option("Cross-references", True)
        filterutils.filter_settings["footnote_ellipsis_level"] = 0
        content = []

        #vk = VK()
        for bible_book in [
                bible_book for bible_book in UserVK.books
                #if len(bible_book.chapters) < N
                if not RESTRICTED or (bible_book.bookname in ("Psalms",
                                                              "Matthew"))
        ]:  #VK.books:
            print "Processing", bible_book
            content.append(
                get_book(book, bible_book, verse_per_line=verse_per_line))
        #	if bible_book.bookname == "Genesis": break
        #	if bible_book.bookname == "Joshua": break
    finally:
        filterutils.filter_settings[
            "footnote_ellipsis_level"] = old_expand_crossref
        biblemgr.restore_state()

    return content
Ejemplo n.º 6
0
	def _RefreshUI(self, *args, **kwargs):
		try:
			biblemgr.temporary_state(biblemgr.plainstate)
		
			return super(PlainReferenceDisplayFrame, self)._RefreshUI(
				*args, **kwargs
			)
		finally:
			biblemgr.restore_state()
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
def get_chapter_headings(chapter):
	"""Get chapter headings from the current Bible for a given chapter

	chapter must be a whole chapter reference, not a verse in the chapter
	Returns list of (VK, heading text)
	"""
	if biblemgr.bible.mod is None:
		return []

	version_headings = headings_cache.setdefault(biblemgr.bible.version, {})
	if chapter in version_headings:
		return version_headings[chapter]
		
	# put ourselves into a plain state
	biblemgr.temporary_state(biblemgr.plainstate)

	# and turn on headings
	biblemgr.set_option("Headings", True)

	vk = EncodedVK(("%s:0" % chapter, chapter), headings=True)

	mod = biblemgr.bible.mod
	headings = []
	for item in vk:	
		mod.setKey(item)
		content = to_unicode(mod.RenderText(), mod)

		# if it was in verse 0, link to verse 1 for now
		if item.Verse() == 0:
			item.Verse(1)
		
		hs = biblemgr.bible.get_headings(item.getText())

		# see comment in book.py for why we are checking if it starts with <
		# (short version - pre-verse div's)
		# try to handle pre-verse headings in div's
		content = '\n'.join(to_unicode(mod.RenderText(heading), mod)
			for heading, canonical in hs if heading.startswith("<")) + content
		
		# and non-div pre-verse headings
		headings += ((item, to_unicode(mod.RenderText(heading), mod))
			for heading, canonical in hs if not heading.startswith("<"))

		headings += ((item, text) for heading, text in re.findall(
			'(<h2 class="heading(?: canonical)?">(.*?)</h2>)', 
			content, re.U) if text)
		
	biblemgr.restore_state()
	version_headings[chapter] = headings
	return headings
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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
Ejemplo n.º 12
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)
Ejemplo n.º 13
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
Ejemplo n.º 14
0
    def get_text(self):
        try:
            template = SmartVerseTemplate(
                header="<a href='nbible:$internal_range'><b>$range</b></a><br>",
                body=(config.body % ''),
            )

            #no footnotes
            if tooltip_settings["plain_xrefs"]:
                biblemgr.temporary_state(biblemgr.plainstate)
            #apply template
            biblemgr.bible.templatelist.append(template)

            import displayframe
            text = "<hr>".join(
                displayframe.process_html_for_module(biblemgr.bible.mod, item)
                for item in biblemgr.bible.GetReferences(self.references))

            return text

        finally:
            if tooltip_settings["plain_xrefs"]:
                biblemgr.restore_state()
            biblemgr.bible.templatelist.pop()
Ejemplo n.º 15
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);
			}
		""")
Ejemplo n.º 16
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);
			}
		""")