<HTML style="FONT-SIZE: x-small; FONT-FAMILY: MS Sans Serif"><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1251">
<META content="MSHTML 6.00.2800.1498" name=GENERATOR></HEAD>
<BODY>
<P>
<DIV>Hello Everyone.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I am working with the BWidgets tree, but am having difficulty understanding how Parent/Child node relationships are actually handled.&nbsp; More specifically, I think that most people use Trees to REPRESENT hierarchies?...I would like to use the widget to CREATE them.&nbsp; Having said this, the BWidget Tree looks like it is probably the best tree widget for this purpose.&nbsp;But,&nbsp;&nbsp;like os.listdir is doing in Michael Lange's program, I &nbsp;need to generate and cache&nbsp;lists reflecting the contents of each parent node.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Anyway, if you run the program I have included (you'll have to use other icons), I am (so far) able to generate Child-nodes.&nbsp; Now, I want to be able to create 'GrandChildren' from whichever node&nbsp;has focus (need to add highlighting later).&nbsp;&nbsp;I also want to keep track of each node's&nbsp;level in the hierarchy because the level of the node will determine which icons will be used, not its 'state' (ie. open or closed).&nbsp; I think I should be able to do this just fine, once I can gain access to the Parent nodes' names and the Child index positions.&nbsp; However, when I try to grab index positions, parent-names, etc., I am receiving errors because I am trying to grab data from the widget instances, rather than the widgets themselves.</DIV>
<DIV>&nbsp;</DIV>
<DIV>If I seem excessively confused, I hope you'll forgive me.&nbsp; It takes me a few nudges in the right direction before I start to catch on to&nbsp;things like this.</DIV>
<DIV>&nbsp;</DIV>
<DIV>import Tkinter as tk<BR>import bwidget as bw</DIV>
<DIV>&nbsp;</DIV>
<DIV>class DirTree(tk.Frame):</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;def __init__(self, master, *args, **kw):<BR>&nbsp;&nbsp;tk.Frame.__init__(self, master)<BR>&nbsp;&nbsp;treeFrame = tk.Frame(master, height=200, width=200)<BR>&nbsp;&nbsp;treeFrame.pack(side=tk.TOP)<BR>&nbsp;&nbsp;self.tree = bw.Tree(treeFrame, opencmd=self.open_folder, closecmd=self.close_folder, *args, **kw)<BR>&nbsp;&nbsp;self.tree.pack(fill='both', expand=1)</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>&nbsp;&nbsp;self.data_element_icon = tk.PhotoImage(file='C:\Documents and Settings\John Doe\Desktop\Test_Icon.gif')<BR>&nbsp;&nbsp;self.node = self.tree.insert('end', 'root', text='/', image=self.data_element_icon, drawcross='allways', data='/')<BR>&nbsp;&nbsp;self.tree.opentree(self.node, recurse=0)<BR>&nbsp;&nbsp;buttonFrame = tk.Frame(master, height=200, width=200)<BR>&nbsp;&nbsp;buttonFrame.pack(side=tk.BOTTOM)<BR>&nbsp;&nbsp;self.button = tk.Button(buttonFrame, text='Create child node', command=self.create_node, relief=tk.GROOVE)<BR>&nbsp;&nbsp;self.button.pack()<BR>&nbsp;&nbsp;<BR>&nbsp;def close_folder(self, node):<BR>&nbsp;&nbsp;self.tree.itemconfigure(node, image=self.data_element_icon)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;def open_folder(self, node):<BR>&nbsp;&nbsp;path = self.tree.opentree(node, recurse=1)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;def create_node(self):<BR>&nbsp;&nbsp;if self.button:<BR>&nbsp;&nbsp;&nbsp;self.tree.insert('end', self.node, text='Hello There', image=self.data_element_icon, drawcross='allways')</DIV>
<DIV>&nbsp;</DIV>
<DIV>def test():<BR>&nbsp;r = tk.Tk()<BR>&nbsp;t = DirTree(r, bg='white', selectbackground='blue4', selectforeground='white', deltax=18, deltay=18)<BR>&nbsp;t.pack(fill='both', expand=1)<BR>&nbsp;r.mainloop()</DIV>
<DIV>&nbsp;</DIV>
<DIV>if __name__== '__main__':<BR>&nbsp;test()</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thank you and Best Regards,</DIV>
<DIV>&nbsp;</DIV>
<DIV>Chris Nethery</DIV>
<DIV><A href="mailto:gilcneth@earthlink.net">gilcneth@earthlink.net</A></DIV>
<DIV>&nbsp;</DIV>
<P></P></BODY></HTML>