Ejemplo n.º 1
0
def on_genbook_click(frame, href, url):
	if frame != guiconfig.mainfrm.genbooktext:
		frame = guiconfig.mainfrm.genbooktext

	if url is None:
		url = SW.URL(href)
	
	host = to_unicode(
		url.getHostName(),
		frame.reference.module
	)

	if host == "previous":
		frame.chapter_back()

	elif host == "next":
		frame.chapter_forward()

	elif host.startswith("parent"):
		frame.go_to_parent(int(host[6:]))
	
	else:
		key = TK(frame.book.mod.getKey(), frame.book.mod)
		path = to_unicode(
			url.getPath(),
			frame.reference.module
		)
		ref = u"/%s" % host
		if path:
			ref += "/%s" % path
		key.text = ref
		
		frame.go_to_key(key)
Ejemplo n.º 2
0
def on_genbook_click(frame, href, url):
    if frame != guiconfig.mainfrm.genbooktext:
        frame = guiconfig.mainfrm.genbooktext

    if url is None:
        url = SW.URL(href)

    host = to_unicode(url.getHostName(), frame.reference.module)

    if host == "previous":
        frame.chapter_back()

    elif host == "next":
        frame.chapter_forward()

    elif host.startswith("parent"):
        frame.go_to_parent(int(host[6:]))

    else:
        key = TK(frame.book.mod.getKey(), frame.book.mod)
        path = to_unicode(url.getPath(), frame.reference.module)
        ref = u"/%s" % host
        if path:
            ref += "/%s" % path
        key.text = ref

        frame.go_to_key(key)
Ejemplo n.º 3
0
	def GetKey(self, key_text=None):
		if not self.mod:
			return None
		mod_tk = SW.TreeKey.castTo(self.mod.getKey())
		mod_tk.root()
		tk = TK(mod_tk, self.mod)
		if key_text is not None:
			tk.setText(to_str(key_text, self.mod))
		return tk
Ejemplo n.º 4
0
	def SetBook(self, book, old=""):
		### TODO: the following code triggers treekey detected mutating
		### exceptions. Haven't found out why they are changing yet.
		#for item in self.data_items:
		#	item.check_changed()

		#for item in self.data_items:
		#	print `item.Persist()`, `item.getText()`
		#	if not item.thisown:
		#		print "*** WARNING: not thisown (%r)" % item
		#	else:
		#		item.thisown = False
		#		item.__swig_destroy__(item)

		self.tree.DeleteAllItems()#Children(self.tree.RootItem)
		#import gc;gc.collect()
		root = self.tree.AddRoot("<hidden root>")
		
		
		self.book = book
			

		if book.mod:
			tk = TK(book.mod.getKey(), book.mod)
			tk.root()
			itk = ImmutableTK(tk)
			self.tree.SetPyData(root, (itk, False))
			#self.data_items = [itk]

			self.AddItems(root)
			
			# clear error
			tk.Error()


			if old:
				tk.text = old
			first_child = self.tree.GetFirstChild(root)[0]
			if first_child:
				if not ord(tk.Error()) and tk.text:
					self.go_to_key(tk)
			
				else:
					self.set_value(first_child)
			
				return
		
		self.tree.SetPyData(root, (["<empty>"], False))
		self.AddItems(root)
		self.set_value(self.tree.GetFirstChild(root)[0])
Ejemplo n.º 5
0
	def _load_harmony_references(self, module_name):
		pickle_filename = "resources/%s.refidx" % module_name
		if os.path.exists(pickle_filename):
			pickle_file = open(pickle_filename, "rb")
			return pickle.load(pickle_file)

		mod_tk = SW.TreeKey.castTo(self.mod.getKey())
		mod_tk.root()
		tk = TK(mod_tk, self.mod)
		references = []

		def add_references(tk, references):
			self.mod.setKey(tk)
			entry = self.mod.getRawEntry()
			entry_references = '|'.join(re.findall('<harmonytable refs="([^"]*)"></harmonytable>', entry))
			if entry_references:
				references.append((
					tk.getText(),
					[VerseList(reference, userInput=False) for reference in entry_references.split('|')]
				))

			for child_tk in tk:
				add_references(child_tk, references)

		add_references(tk, references)

		pickle_file = open(pickle_filename, "wb")
		pickle.dump(references, pickle_file)

		return references
Ejemplo n.º 6
0
	def GetTopicsTree(self):#gets topic lists
		if not self.mod:
			return None
		mod_tk = SW.TreeKey.castTo(self.mod.getKey())
		mod_tk.root()
		tk = TK(mod_tk, self.mod)
		root = TreeNode(None, None)

		def AddTopic(parent, tk):
			me = parent.AddChild(tk.getText())
			for a in tk:
				AddTopic(me, a)

		AddTopic(root, tk)
		return root.children[0]
Ejemplo n.º 7
0
    def SetBook(self, book, old=""):
        ### TODO: the following code triggers treekey detected mutating
        ### exceptions. Haven't found out why they are changing yet.
        #for item in self.data_items:
        #	item.check_changed()

        #for item in self.data_items:
        #	print `item.Persist()`, `item.getText()`
        #	if not item.thisown:
        #		print "*** WARNING: not thisown (%r)" % item
        #	else:
        #		item.thisown = False
        #		item.__swig_destroy__(item)

        self.tree.DeleteAllItems()  #Children(self.tree.RootItem)
        #import gc;gc.collect()
        root = self.tree.AddRoot("<hidden root>")

        self.book = book

        if book.mod:
            tk = TK(book.mod.getKey(), book.mod)
            tk.root()
            itk = ImmutableTK(tk)
            self.tree.SetPyData(root, (itk, False))
            #self.data_items = [itk]

            self.AddItems(root)

            # clear error
            tk.Error()

            if old:
                tk.text = old
            first_child = self.tree.GetFirstChild(root)[0]
            if first_child:
                if not ord(tk.Error()) and tk.text:
                    self.go_to_key(tk)

                else:
                    self.set_value(first_child)

                return

        self.tree.SetPyData(root, (["<empty>"], False))
        self.AddItems(root)
        self.set_value(self.tree.GetFirstChild(root)[0])
Ejemplo n.º 8
0
    def SetReference(self, ref, settings_changed=False):
        if isinstance(ref, TK):
            ref = TK(ref)
        self.reference = ref

        if isinstance(ref, basestring) and ref == "<empty>":
            if self.book.mod is None:
                data = config.MODULE_MISSING_STRING()
            else:
                data = """This book is empty"""

            self.reference_text = "<empty>"

            self.SetPage(data)
            self.update_title()
            return

        self.reference_text = self.reference.text
        if self.do_not_reload_page:
            self.update_title()
            self.do_not_reload_page = False
        else:
            self.ChangeReference(self.reference_text, settings_changed)
Ejemplo n.º 9
0
 def current_segment_changed(self, new_segment_ref):
     key = TK(self.book.mod.getKey(), self.book.mod)
     key.text = "/" + new_segment_ref
     self.do_not_reload_page = True
     self.go_to_key(key)
Ejemplo n.º 10
0
 def format_ref(self, module, ref):
     k = TK(module.getKey(), module)
     k.text = ref
     return k.breadcrumb(delimiter=">")
Ejemplo n.º 11
0
 def SetReference_from_string(self, string):
     key = TK(self.book.mod.getKey(), self.book.mod)
     key.text = string
     self.go_to_key(key)
Ejemplo n.º 12
0
	def GetReference(self, ref, context = None, max_verses = 500,
			stripped=False, end_ref=None):
		"""Get a reference from a genbook.

		ref should be either a TK or a string. If it is a TK, it is guaranteed
		not to change its position."""
		if not self.mod:
			return None
		
		template = self.templatelist[-1]
		render_text, render_start, render_end = self.get_rendertext()
		#TODO: use render_start and render_end?
		
		module = self.mod
		
		if isinstance(ref, TK) and end_ref:
			# we will move, so take a copy to move
			ref = TK(ref)
		
		if isinstance(ref, basestring):
			key = TK(module.getKey(), module)
			key.setText(to_str(ref, module))
			ref = key
		
		if isinstance(end_ref, basestring):
			key = TK(module.getKey(), module)
			key.setText(to_str(end_ref, module))
			end_ref = key

		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
		
		ref.Persist(1)
		module.setKey(ref)
		
		# snap to it
		entry = module.getRawEntry()
		
		# We have to get KeyText after getRawEntry, otherwise our
		# KeyText will be wrong
		d = dict(range = module.KeyText(), version = module.Name())
		verses = template.header.substitute(d)
		
		d1 = d.copy()
		
		raw = display_options.options["raw"]
	
		while True:
			if stripped:
				text = module.StripText(entry).decode("utf-8", "replace")
			else:
				# we can't specify entry here for the same reasons as in
				# book.py
				text = render_text(#entry
				).decode("utf-8", "replace")

			if raw:
				text = self.process_raw(entry, text, ref, module)

			d1["reference"] = to_unicode(module.getKeyText(), module)
			d1["reference_encoded"] = \
				SW.URL.encode(module.getKeyText()).c_str()
			
			d1["text"] = text
			d1["breadcrumbed_reference"] = ref.breadcrumb(delimiter=" > ")		
			d1["level"] = ref.getLevel()
			
			verses += template.body.substitute(d1)
			if not end_ref or end_ref == ref:
				break
			
			ref.increment(1)
			entry = module.getRawEntry()

		verses += template.footer.substitute(d)
		module.setKey(old_key)
		
		return verses
Ejemplo n.º 13
0
	def current_segment_changed(self, new_segment_ref):
		key = TK(self.book.mod.getKey(), self.book.mod)
		key.text = "/" + new_segment_ref
		self.do_not_reload_page = True
		self.go_to_key(key)
Ejemplo n.º 14
0
	def format_ref(self, module, ref):
		k = TK(module.getKey(), module)
		k.text = ref		
		return k.breadcrumb(delimiter=">")
Ejemplo n.º 15
0
	def SetReference_from_string(self, string):
		key = TK(self.book.mod.getKey(), self.book.mod)
		key.text = string
		self.go_to_key(key)
Ejemplo n.º 16
0
 def get_key(self, module):
     key = module.getKey()
     key.setText(to_str(self.start, module))
     return TK(key)
Ejemplo n.º 17
0
	def get_display_level_root(self, key):
		"""
		Return the root of the view, and whether to 
		display sub-levels for this node
		"""
		assert key.module == self.mod, \
			"Mismatched module and key: %s, %s" % (
				key.module.Name(),
				self.mod.Name()
			)

		display_level = self.display_level()
		if display_level != 1:
			# display levels:
			# if we are a leaf, just climb up the given number of levels
			# if we are inbetween the above and below cases here, then go down
			# first as far as possible, then up
			# if our display-level'th first child is a leaf, then display
			# all below here.
			# if we are in between those two
			count = 0
			
			ref = TK(key)
			while ref.firstChild() and count < display_level:
				count += 1
		
			if count < display_level:
				# it was a close enough to being a leaf, go up now
				parents_count = 1
				root = TK(key)
				root.root()
				last_ref = TK(ref)
				ref.parent()
				while ref != root and parents_count < display_level:
					last_ref = TK(ref)
					ref.parent()
					parents_count += 1

				# show that reference and all its children
				return last_ref, True

		# don't show any children for this
		return key, False