예제 #1
0
	def _get_document_parts_for_ref(self, module_name, ref, do_current_ref=True):
		t = default_timer()

		stylesheets = list(self.bible_stylesheets)
		scripts = self.standard_scripts + self.bible_scripts + ["highlight.js", "bpbible_html.js", "contrib/hyphenate.js", "columns.js"]

		book = biblemgr.get_module_book_wrapper(module_name)
		assert book, "Module wrapper not found for book " + module_name
		module = book.mod
		if book.chapter_view:
			scripts.append("bpbible_html_chapter_view.js")
			#stylesheets.append("bpbible_chapter_view.css")
			#stylesheets.append("bpbible://content/quotes_skin/")
		else:
			scripts.append("bpbible_html_page_view.js")
			stylesheets.append("bpbible_page_view.css")			
	
		if is_debugging():
			stylesheets.append("bpbible_html_debug.css")

		if book.is_verse_keyed:
			if book.chapter_view:
				if do_current_ref:
					c = book.GetChapter(ref, ref, config.current_verse_template)
				else:
					c = book.GetChapter(ref)

				ref_id = VK(ref).get_chapter_osis_ref()
				
			else:
				c = book.GetReference(ref, headings=True)
				ref_id = VK(ref).getOSISRef()


		elif book.is_dictionary:
			c = book.GetReference(ref)
			ref_id = ref

		elif book.is_genbook:
			c = book.GetReference(ref)
			ref_id = ref
		else:
			dprint(ERROR, "Book `%s' not found." % module_name)
			c = ''
		c = c.replace("<!P>", "</p><p>")

		clas = ""
		if not c:
			clas = " nocontent"

		lang = module.Lang() if module else "en",
		c = convert_language(c, lang)
		c = '<div class="segment%s" ref_id="%s">%s</div>' % (clas, urllib.quote(ref_id.encode("utf8")), c)

		return dict(
			module=module, content=c,
			bodyattrs=self._get_body_attrs(module),
			stylesheets=stylesheets,
			scripts=scripts,
			timer="<div class='timer'>Time taken: %.3f (ref_id %s)</div>" % (default_timer() - t, ref_id))
예제 #2
0
    def _get_html(self,
                  module,
                  content,
                  bodyattrs="",
                  timer="",
                  stylesheets=[],
                  scripts=[],
                  javascript_block="",
                  styles="",
                  contentclass="",
                  include_wrapper_divs=True):
        resources = []

        ### Should we keep using the file:/// protocol?
        ### For the XUL port we intended to switch to using the chrome:/// protocol.
        prefix = "file:///" + os.getcwd() + "/"
        css_dir = "css"
        script_dir = "js"
        for item in stylesheets:
            if "://" in item:
                resources.append(
                    '<link rel="stylesheet" type="text/css" href="%s"/ >' %
                    (item))
            else:
                resources.append(
                    '<link rel="stylesheet" type="text/css" href="%s/%s/%s"/ >'
                    % (prefix, css_dir, item))

        for item in scripts:
            resources.append(
                '<script type="text/javascript" src="%s/%s/%s"></script>' %
                (prefix, script_dir, item))

        if styles:
            resources.append('<style type="text/css">%s</style>' % styles)

        if javascript_block:
            resources.append('<script type="text/javascript">%s</script>' %
                             javascript_block)

        if include_wrapper_divs:
            content = '<div id="content" class="%(contentclass)s">\n%(content)s\n</div>' % locals(
            )

        text = BASE_HTML % dict(lang=module.Lang() if module else "en",
                                head='\n'.join(resources),
                                bodyattrs=bodyattrs,
                                content=content,
                                timer=timer)

        if is_debugging():
            self.log_generated_html(text)

        return text
예제 #3
0
	def _get_html(self, module, content, bodyattrs="", timer="", 
		stylesheets=[], scripts=[], javascript_block="", styles="", contentclass="",
		include_wrapper_divs=True):
		resources = []

		### Should we keep using the file:/// protocol?
		### For the XUL port we intended to switch to using the chrome:/// protocol.
		prefix = "file:///" + os.getcwd() + "/"
		css_dir = "css"
		script_dir = "js"
		for item in stylesheets:
			if "://" in item:
				resources.append('<link rel="stylesheet" type="text/css" href="%s"/ >' % (item))
			else:
				resources.append('<link rel="stylesheet" type="text/css" href="%s/%s/%s"/ >' % (prefix, css_dir, item))

		for item in scripts:
			resources.append('<script type="text/javascript" src="%s/%s/%s"></script>' % (prefix, script_dir, item))

		if styles:
			resources.append('<style type="text/css">%s</style>' % styles)

		if javascript_block:
			resources.append('<script type="text/javascript">%s</script>' % javascript_block)

		if include_wrapper_divs:
			content = '<div id="content" class="%(contentclass)s">\n%(content)s\n</div>' % locals()

		text = BASE_HTML % dict(
			lang=module.Lang() if module else "en",
			head='\n'.join(resources),
			bodyattrs=bodyattrs, 
			content=content, 
			timer=timer)

		if is_debugging():
			self.log_generated_html(text)

		return text
예제 #4
0
class IndexedText(object):
    """A bit of text, one reference per line, with an index built against it"""
    gatherstatistics = True

    def __init__(self, version, bookname=None, create_index=True):
        self.index = []  # ref, start, length
        self.text = ""
        self.field_data = {}

        self.bookname = bookname or version
        self.version = version
        module = self.load_module(version)
        self.errors_on_collection = []
        self._has_xml_errors = False
        if create_index:
            self.collect_text(module)

    def collect_text(self, module):
        """Collect the text for a given module, into a reference per line
		format, then build an index against it"""
        # this is a guaranteed non-character...
        # so it shouldn't be used in text
        # http://en.wikibooks.org/wiki/Unicode/Character_reference/F000-FFFF
        MAGIC_TOKEN = u"\uFDD0"

        xml_token = "&#%d;" % ord(MAGIC_TOKEN)
        items = []

        old_key = module.getKey()
        if not ord(old_key.Persist()):
            # if it wasn't a persistent key, the module owns it
            # so take a copy of it, and say we own it
            old_key = old_key.clone()
            old_key.thisown = True

        entries = self.get_entries()

        key = self.get_key(module)
        key.Persist(1)

        module.setKey(key)
        if not entries:
            module.setPosition(TOP)

        key_entry = self.get_key_entry(key)

        # clear the error
        module.Error()

        i = 0
        if not entries:
            entries = sys.maxint

        # gather the text
        while not ord(module.Error()) and i < entries:
            items.append((key_entry(), module.getRawEntry()))
            module.increment(1)
            i += 1

        # the key's headings attribute gets set to 1 at the end of the
        # previous loop...
        if isinstance(key, VK): key.Headings(0)

        # try and do smart parsing
        content = None

        processor = {
            SW.FMT_OSIS: process_text.ParseOSIS,
            SW.FMT_THML: process_text.ParseThML,
        }.get(ord(module.Markup()), None)

        if processor:
            xml_items = [
                "<KeyedEntry key='%s'>%s</KeyedEntry>" % i for i in items
            ]

            # fix its encoding if necessary
            if ord(module.Encoding()) == SW.ENC_LATIN1:
                xml_items = [
                    # ignore any errors
                    item.decode("cp1252", "ignore").encode("utf8", "ignore")
                    for item in xml_items
                ]

            try:
                content = processor().parse(xml_token.join(xml_items))

            except Exception, e:
                self._has_xml_errors = True
                import traceback
                traceback.print_exc(file=sys.stdout)
                print self.get_key(module).getText()

        if content is None:
            # fallback, don't want to have to do this...

            # encode the token as utf-8 so that we end up with a string from
            # here
            content = MAGIC_TOKEN.encode("utf8").join(
                module.StripText(item) for key, item in items)

        content = content.decode("utf-8", "ignore")
        content = removeformatting(content)
        self.text = re.sub("\s*%s\s*" % MAGIC_TOKEN, "\n", content)
        self.text, self.field_data = self.extract_strongs(self.text)

        if self.text.count('\n') + 1 != len(items):
            # it is possible that decoding the utf8 of the book above
            # may lead to problems which will gobble up our magic token
            # so we check that we have the expected number here. If we don't,
            # scream, as it may lead to incorrect results
            self.errors_on_collection.append(
                _("Invalid encoding: Searching may not work or may "
                  "display the wrong results"))

            if is_debugging():
                for k, item in items:
                    try:
                        # TODO: sword ThMLPlain filter outputs &...; as
                        # latin1, not utf-8. This makes big problems...
                        module.StripText(item).decode("utf-8")
                    except UnicodeDecodeError:
                        self.errors_on_collection.append(k)

        self.create_index_against_text(module, key)

        module.setKey(old_key)

        # IMPORTANT: clear the error indicator
        # otherwise the highlighted search frame may end up blank the first
        # time the user uses it!
        module.Error()
예제 #5
0
 def SetWebPreferences(self):
     prefs = wx.wc.WebControl.preferences
     prefs['browser.dom.window.dump.enabled'] = is_debugging()
예제 #6
0
        if sys.argv[1].endswith(".py"):
            f = sys.argv.pop(1)
            return execfile(f, globals(), globals())

    inspection_imported = False
    try:
        from wx.lib.mixins.inspect import InspectionMixin
        inspection_imported = True
    except ImportError, e:
        try:
            from wx.lib.mixins.inspection import InspectionMixin
            inspection_imported = True
        except ImportError, e:
            pass

    if inspection_imported and is_debugging():

        class InspectableApp(MyApp, InspectionMixin):
            def OnInit(self):
                return_value = super(InspectableApp, self).OnInit()
                if not return_value:
                    return False
                self.Init()
                return True

        app = InspectableApp(0)
    else:
        if is_debugging():
            dprint(WARNING, "Could not load inspection")

        app = MyApp(0)
예제 #7
0
    def _get_document_parts_for_ref(self,
                                    module_name,
                                    ref,
                                    do_current_ref=True):
        t = default_timer()

        stylesheets = list(self.bible_stylesheets)
        scripts = self.standard_scripts + self.bible_scripts + [
            "highlight.js", "bpbible_html.js", "contrib/hyphenate.js",
            "columns.js"
        ]

        book = biblemgr.get_module_book_wrapper(module_name)
        assert book, "Module wrapper not found for book " + module_name
        module = book.mod
        if book.chapter_view:
            scripts.append("bpbible_html_chapter_view.js")
            #stylesheets.append("bpbible_chapter_view.css")
            #stylesheets.append("bpbible://content/quotes_skin/")
        else:
            scripts.append("bpbible_html_page_view.js")
            stylesheets.append("bpbible_page_view.css")

        if is_debugging():
            stylesheets.append("bpbible_html_debug.css")

        if book.is_verse_keyed:
            if book.chapter_view:
                if do_current_ref:
                    c = book.GetChapter(ref, ref,
                                        config.current_verse_template)
                else:
                    c = book.GetChapter(ref)

                ref_id = VK(ref).get_chapter_osis_ref()

            else:
                c = book.GetReference(ref, headings=True)
                ref_id = VK(ref).getOSISRef()

        elif book.is_dictionary:
            c = book.GetReference(ref)
            ref_id = ref

        elif book.is_genbook:
            c = book.GetReference(ref)
            ref_id = ref
        else:
            dprint(ERROR, "Book `%s' not found." % module_name)
            c = ''
        c = c.replace("<!P>", "</p><p>")

        clas = ""
        if not c:
            clas = " nocontent"

        lang = module.Lang() if module else "en",
        c = convert_language(c, lang)
        c = '<div class="segment%s" ref_id="%s">%s</div>' % (
            clas, urllib.quote(ref_id.encode("utf8")), c)

        return dict(
            module=module,
            content=c,
            bodyattrs=self._get_body_attrs(module),
            stylesheets=stylesheets,
            scripts=scripts,
            timer="<div class='timer'>Time taken: %.3f (ref_id %s)</div>" %
            (default_timer() - t, ref_id))
예제 #8
0
		if sys.argv[1].endswith(".py"):
			f = sys.argv.pop(1)
			return execfile(f, globals(), globals())

	inspection_imported = False
	try:
		from wx.lib.mixins.inspect import InspectionMixin
		inspection_imported = True
	except ImportError, e:
		try:
			from wx.lib.mixins.inspection import InspectionMixin
			inspection_imported = True
		except ImportError, e:
			pass
			
	if inspection_imported and is_debugging():
		class InspectableApp(MyApp, InspectionMixin):
			def OnInit(self):
				return_value = super(InspectableApp, self).OnInit()
				if not return_value:
					return False
				self.Init()
				return True

		app = InspectableApp(0)
	else:
		if is_debugging():
			dprint(WARNING, "Could not load inspection")

		app = MyApp(0)