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 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