BWidgets Tree

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

BWidgets Tree

gilcneth

Hello Everyone.
 
I am working with the BWidgets tree, but am having difficulty understanding how Parent/Child node relationships are actually handled.  More specifically, I think that most people use Trees to REPRESENT hierarchies?...I would like to use the widget to CREATE them.  Having said this, the BWidget Tree looks like it is probably the best tree widget for this purpose. But,  like os.listdir is doing in Michael Lange's program, I  need to generate and cache lists reflecting the contents of each parent node.
 
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.  Now, I want to be able to create 'GrandChildren' from whichever node has focus (need to add highlighting later).  I also want to keep track of each node's level in the hierarchy because the level of the node will determine which icons will be used, not its 'state' (ie. open or closed).  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.  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.
 
If I seem excessively confused, I hope you'll forgive me.  It takes me a few nudges in the right direction before I start to catch on to things like this.
 
import Tkinter as tk
import bwidget as bw
 
class DirTree(tk.Frame):
 
 def __init__(self, master, *args, **kw):
  tk.Frame.__init__(self, master)
  treeFrame = tk.Frame(master, height=200, width=200)
  treeFrame.pack(side=tk.TOP)
  self.tree = bw.Tree(treeFrame, opencmd=self.open_folder, closecmd=self.close_folder, *args, **kw)
  self.tree.pack(fill='both', expand=1)
 

  self.data_element_icon = tk.PhotoImage(file='C:\Documents and Settings\John Doe\Desktop\Test_Icon.gif')
  self.node = self.tree.insert('end', 'root', text='/', image=self.data_element_icon, drawcross='allways', data='/')
  self.tree.opentree(self.node, recurse=0)
  buttonFrame = tk.Frame(master, height=200, width=200)
  buttonFrame.pack(side=tk.BOTTOM)
  self.button = tk.Button(buttonFrame, text='Create child node', command=self.create_node, relief=tk.GROOVE)
  self.button.pack()
  
 def close_folder(self, node):
  self.tree.itemconfigure(node, image=self.data_element_icon)
 
 def open_folder(self, node):
  path = self.tree.opentree(node, recurse=1)
 
 def create_node(self):
  if self.button:
   self.tree.insert('end', self.node, text='Hello There', image=self.data_element_icon, drawcross='allways')
 
def test():
 r = tk.Tk()
 t = DirTree(r, bg='white', selectbackground='blue4', selectforeground='white', deltax=18, deltay=18)
 t.pack(fill='both', expand=1)
 r.mainloop()
 
if __name__== '__main__':
 test()
 
 
Thank you and Best Regards,
 
Chris Nethery
 


_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss