def _RefreshUI(self, *args, **kwargs):
		if not self.reference:
			self.ShowReferenceHTML("")
			return

		template = self.template
		if template:
			kwargs["template"] = template

		data = biblemgr.bible.GetReference(self.reference, *args, **kwargs)
		if self.show_reference_string:
			reference_text = GetBestRange(self.reference, userOutput=True)
			reference_string = (u'<p><a href="bible:%s"><small><em>'
					'%s (%s)</em></small></a></p><br>' %
					(self.reference, reference_text, self.book.version))
		else:
			reference_string = ""
		if data is None:
			data = config.MODULE_MISSING_STRING()

		else:
			# 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%s" % (reference_string, data))
Exemple #2
0
    def ShowDialog(self, text):
        # set the reference
        self.reference.SetValue(
            GetBestRange(text, userInput=False, userOutput=True))

        # update the text
        self.update()

        super(CopyVerseDialog, self).Show()
Exemple #3
0
    def get_verified_multi_verses(self, ref):
        try:
            ref = GetBestRange(ref,
                               self.reference,
                               raiseError=True,
                               userInput=True,
                               userOutput=False)
            return ref

        except VerseParsingError, e:
            wx.MessageBox(str(e), config.name())
Exemple #4
0
        def update_ui(event):
            text = self.SelectionToText()

            if not text and is_search:
                # only display text reference if
                if href:
                    match = (re.match(
                        u'n?bible:([^#]*)(#.*)?', href) or re.match(
                            u'passagestudy.jsp\?action=showRef&type=scripRef&'
                            'value=([^&]*)&module=.*', href))
                    if match:
                        ref = SW.URL.decode(str(match.group(1))).c_str()
                        text = GetBestRange(ref, userOutput=True)

                    if text:
                        event.SetText(lookup_text % text)
                        return

            if (not text) and (href.startswith('strongs')
                               or href.startswith('morph')):
                text = self.get_link_text_from_href(href)

            if not text:
                text = self.get_clicked_cell_text()

            if text:
                text = self.strip_text(text)

            if not text:
                event.Enable(False)
                event.SetText(lookup_text % _("the selected word"))
                return

            event.Enable(True)
            item = "'%s'" % text
            if text.find(" ") != -1:
                item = _("the selected phrase")

            event.SetText(lookup_text % item)
Exemple #5
0
		def update_ui(event):
			text = self.SelectionToText()

			if not text and is_search:
				# only display text reference if 
				if href:
					match = (re.match(u'n?bible:([^#]*)(#.*)?', href) or
						re.match(
							u'passagestudy.jsp\?action=showRef&type=scripRef&'
							'value=([^&]*)&module=.*', href))
					if match:
						ref = SW.URL.decode(str(match.group(1))).c_str()
						text = GetBestRange(ref, userOutput=True)
						
					if text:
						event.SetText(lookup_text % text)
						return

			if (not text) and (href.startswith('strongs') or href.startswith('morph')):
				text = self.get_link_text_from_href(href)
								
			if not text:
				text = self.get_clicked_cell_text()

			if text:
				text = self.strip_text(text)

			if not text:
				event.Enable(False)
				event.SetText(lookup_text % _("the selected word"))
				return

			event.Enable(True)
			item = "'%s'" % text
			if text.find(" ") != -1:
				item = _("the selected phrase")

			event.SetText(lookup_text % item)
Exemple #6
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
Exemple #7
0
	def end_reference(self, xmltag):
		if self.ref is None:
			self.success = SW.INHERITED
			return

		self.u.suspendLevel -= 1
		self.u.suspendTextPassThru = self.u.suspendLevel

		if self.was_sword_ref:
			self.buf += '<a href="%s">%s</a>' % (
				self.ref, self.u.lastTextNode.c_str()
			)
		else:			
			ref = GetBestRange(self.ref, abbrev=True, use_bpbible_locale=True)
			self.buf += '<a href="bible:%s">%s</a>' % (
				ref, self.u.lastTextNode.c_str()
			)
Exemple #8
0
    def start_harmonytable(self, xmltag):
        references = xmltag.getAttribute('refs').split("|")
        if not references:
            return

        header_row = u"<tr>%s</tr>" % (u"".join(
            u"<th>%s</th>" % GetBestRange(reference, userOutput=True)
            for reference in references))
        # This is a nasty hack to work around the fact that ThML rendering in
        # SWORD is not properly reentrant.
        # Without copying the internal dictionary some references do not
        # display at all.
        my_internal_dict = self.__dict__.copy()
        body_row = u"<tr>%s</tr>" % (u"".join(
            u"<td>%s</td>" % self.biblemgr.bible.GetReference(reference)
            for reference in references))
        self.__dict__ = my_internal_dict
        table = u'<table class="harmonytable chapterview">%s%s</table>' % (
            header_row, body_row)
        self.buf += table.encode("utf8")
Exemple #9
0
    def SetReference(self, ref, reload=False, settings_changed=False):
        if not ref:
            return

        last_reference = verse_comparison_settings["reference"]
        if VerseList(last_reference).VerseInRange(ref):
            ref = last_reference

        if ref == self.reference and not reload: return
        text = "<h3>%s</h3>" % ref
        self.reference = ref
        verse_comparison_settings["reference"] = ref

        text_func = [self.get_compare_text, self.get_parallel_text
                     ][verse_comparison_settings["parallel"]]

        self.SetPage(text_func(ref))

        self.gui_reference.SetValue(GetBestRange(ref, userOutput=True))
        self.gui_reference.currentverse = ref
        self.update_title()
Exemple #10
0
    def set_refs(self, refs, update=True):
        references = []
        try:
            context = "%s" % self.references[-1]
        except TypeError:
            context = ""
        for ref in refs:
            new_ref = self.get_verified_multi_verses("%s" % ref, context)
            if new_ref is None:
                return

            context = new_ref
            references.append(new_ref)

        self.references = references

        reference_strings = '|'.join(
            GetBestRange(ref, userOutput=True) for ref in self.references)
        if self.toolbar.gui_reference:
            self.toolbar.gui_reference.ChangeValue(reference_strings)

        if update:
            self.tooltip_changed()
Exemple #11
0
    def GetRangeSelected(self):
        text = self.ExecuteScriptWithResult("""
			(function()	{
				var selectionRange = window.getSelection().getRangeAt(0);
				if (selectionRange.collapsed)	{
					return "";
				}
				var links = $("a.vnumber");
				var selectionStart = "";
				var selectionEnd = "";
				var linkRange = document.createRange();
				links.each(function()	{
					linkRange.selectNode(this);
					if (selectionRange.compareBoundaryPoints(Range.START_TO_START, linkRange) > 0)	{
						selectionStart = this.getAttribute("osisRef");
					}
					if (selectionRange.compareBoundaryPoints(Range.END_TO_END, linkRange) > 0)	{
						selectionEnd = this.getAttribute("osisRef");
					}
				});

				// If the selection is before the first verse marker (e.g. a chapter number) or after the last verse marker
				// then we should just use the first/last verse on the page.
				if (links.length > 0 && !selectionStart)	{
					selectionStart = links.get(0).getAttribute("osisRef");
				}
				if (links.length > 0 && !selectionEnd)	{
					selectionEnd = links.get(links.length - 1).getAttribute("osisRef");
				}
				return (selectionStart && selectionEnd) ? selectionStart + " - " + selectionEnd : "";
			})();
		""")
        if not text:
            return

        return GetBestRange(text)
Exemple #12
0
 def get_internal_reference(self):
     return GetBestRange(self.reference.GetValue(),
                         userInput=True,
                         userOutput=False)
Exemple #13
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
Exemple #14
0
 def format_ref(self, module, ref):
     return GetBestRange(ref, userOutput=True)
Exemple #15
0
 def update_title(self, shown=None):
     m = guiconfig.mainfrm
     p = m.get_pane_for_frame(self)
     ref = GetBestRange(self.reference, userOutput=True)
     text = "%s - %s" % (self.title, ref)
     m.set_pane_title(p.name, text)
Exemple #16
0
 def get_title(self):
     return "; ".join(
         GetBestRange(ref, userOutput=True) for ref in self.references)