def LoadFromDict(self, node, adict): # XXX extend this to work with objects items = adict.items() items.sort() for key, value in items: if isinstance(value, dict): child = self.AppendItem(node, utils.asstring(key)) self.SetPyData(child, None) # hmm... self.LoadFromDict(child, value) else: child = self.AppendItem(node, utils.asstring(key)) self.SetPyData(child, value)
def LoadFromNestedList(self, root, list): """ loads a nested list of (key, value, [children]) tuples (or lists) as children of the given root node. preserves the order of elements as they appear in the list. """ for item in list: if (type(item) not in (types.TupleType, types.ListType) or len(item) not in (0, 3)): raise Exception, "LoadFromNestedList requires a list of (key, value, children) tuples" (key, value, children) = item node = self.AppendItem(root, utils.asstring(key)) self.SetPyData(node, value) if type(children) == types.ListType: self.LoadFromNestedList(node, children)
def __setitem__(self, index, value): assert isinstance(index, tuple) and len(index) == 2 row, column = index self.ExpandTo(row+1) # make sure we have enough rows self.SetStringItem(row, column, utils.asstring(value))
def InsertRow(self, row, *args): self.InsertStringItem(row, '') for i in range(len(args)): self.SetStringItem(row, i, utils.asstring(args[i])) self.SetItemData(row, row) return row
def __setitem__(self, index, value): assert isinstance(index, tuple) and len(index) == 2 row, column = index self.ExpandTo(row + 1) # make sure we have enough rows self.SetStringItem(row, column, utils.asstring(value))