Can someone help me do this? I have grossly hacked up code from the archive
that nested strings which I can do, but translating that to dictionaries is
beyond me. The deal is that there is a main dictionary of arbitrarily
nested dictionaries. The program will not know how deep. Dictionary example
is available but probably unnecessary. Innermost dictionary is contains
many elements. Actually I'd prefer the innermost to be a tuple, but I
thought it would be easier with an innermost dictionary to not mix types.
The code I have so far is below. As is obvious, I don't quite understand
the underlying philosophy. I'm sure that once I see it it will make sense.
For one, there's a tuple returning Thank you.


----------cut here----------

    def tree_expand(self, tree, node):
        """catch the tree-expand signal, if the directory has not
        been updated, read all of the accounts in the dictionary and
        add them to the tree.  Remove the account from the list
        of unexpanded directories and remove the bookeeping node"""
        try:
            # this try block freezes the tree updates until
            # all information to be displayed is actually inside the
            # tree.  If anything fails inside this block, the finally
            # clauses will repaint the tree.  (This prevents users
            #  from staring at an un-updated window)
            self.tree.freeze()
            key = self.tree.node_get_row_data(node)
            if key in self.unexpanded_accounts.keys():

                # add the files in the directory
                expand_node, bookkeeping_node =
self.unexpanded_accounts[key]
                self.__add_accounts(self.unexpanded_accounts[key],
                             expand_node)
                # remove the path from the list of unexpanded paths
                del self.unexpanded_accounts[key]
                # remove the bookeeping node
                self.tree.remove_node(bookkeeping_node)
            # resize the columns
            self.tree.columns_autosize()
        finally:
            # no matter what, always thaw the tree
            self.tree.thaw()


    def __add_accounts(self, dict, parent=None):
        """Add a account dictionary to the tree as a child of parent.
        If parent is None, then add to the root of the tree"""

        try:
            for key,value in dict.items():
                if type(value).__name__ == 'dictionary':
                    is_leaf = gtk.FALSE
                else:
                    is_leaf = gtk.TRUE
                
                node = self.tree.insert_node(parent, None,
                                             text = [key,
                                                    
self.__get_balance(key)],
                                             is_leaf = is_leaf,
                                             expanded = gtk.FALSE)
                if not is_leaf:            
                    bookkeep_node = self.tree.insert_node(node, None,
                                                 text = ['book','node'],
                                                 is_leaf = gtk.TRUE,
                                                 expanded = gtk.FALSE)
                    self.unexpanded_accounts[key] = (node, bookkeep_node)

                    self.tree.node_set_row_data(node,key)
           
--
 Jonathan Pennington | [EMAIL PROTECTED]

"It's hard to take life too seriously when you realize yours is a joke."
-me 

_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to