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)
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)
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])
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])
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)
def format_ref(self, module, ref): k = TK(module.getKey(), module) k.text = ref return k.breadcrumb(delimiter=">")
def SetReference_from_string(self, string): key = TK(self.book.mod.getKey(), self.book.mod) key.text = string self.go_to_key(key)