Difficulty getting started with a BWidget Tree

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Difficulty getting started with a BWidget Tree

gilcneth

Hello All:
 
I am trying to create a Tree, using PyBWidgets, but am unsure about how to actually create the initial parent and/or child nodes.  The documentation leads me to believe that I should use the' insert' command, but how?  The documentation indicates the following:
 
pathName insert index parent node ?option value...?
 
So, given my example below, if I want to add a node to my Tree, wouldn't I use the command TopTree.insert?  And, if so, I assume I start at index '0'?  OK, but now who's the parent?  I know this has to be simple, but I am just not figuring this one out.  Please share your thoughts.
 
Thank you!
 
 
-- Chris Nethery
 
 
from Tkinter import *
from bwidget import *
 
t = Tk()
 
TopTree = Tree(t, relief=GROOVE)
TopTree.pack()

t.mainloop()
 
 
 
 
 


_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Difficulty getting started with a BWidget Tree

Michael Lange
On Wed, 14 Sep 2005 23:46:57 -0400
"[hidden email]" <[hidden email]> wrote:

> Hello All:
>
> I am trying to create a Tree, using PyBWidgets, but am unsure about how to actually create the initial parent and/or child nodes.  The documentation leads me to believe that I should use the' insert' command, but how?  The documentation indicates the following:
>
> pathName insert index parent node ?option value...?
>
> So, given my example below, if I want to add a node to my Tree, wouldn't I use the command TopTree.insert?  And, if so, I assume I start at index '0'?  OK, but now who's the parent?  I know this has to be simple, but I am just not figuring this one out.  Please share your thoughts.
>
Hi Chris,

I wrote a directory Tree widget a while ago, rather a test than a usable widget, but maybe good
enough to get started. I had some problems with my release of pybwidget, because some icons were missing,
I believe the "plus" and "minus" icons for the Tree, but I don't remember exactly.
So, here's the code:

############ file DirTree.py ##############################
import Tkinter as tk
import bwidget as bw
import os

class DirTree(tk.Frame):
    def __init__(self, master, *args, **kw):
        tk.Frame.__init__(self, master)
        self.tree = tree = bw.Tree(self, opencmd=self.open_folder, closecmd=self.close_folder, *args, **kw)
        tree.pack(fill='both', expand=1)
       
        self.folder_icon = tk.PhotoImage(file='/usr/share/pybwidget/images/folder.gif')
        self.openfolder_icon = tk.PhotoImage(file='/usr/share/pybwidget/images/openfold.gif')
        self.file_icon = tk.PhotoImage(file='/usr/share/pybwidget/images/file.gif')
       
        node = self.tree.insert('end', 'root', text='/', image=self.folder_icon, drawcross='allways', data='/')
        self.tree.opentree(node, recurse=0)
   
    def close_folder(self, node):
        self.tree.itemconfigure(node, image=self.folder_icon)
   
    def open_folder(self, node):
        path = self.tree.itemcget(node, 'data')
        children = os.listdir(path)
        files, dirs = [], []
        for item in children:
            if os.path.isdir(os.path.join(path, item)):
                dirs.append(item)
            #else:
            #    files.append(item)
        dirs.sort()
        #files.sort()
        for item in dirs:
            newpath = os.path.join(path, item)
            self.tree.insert('end', node, text=item, image=self.folder_icon, drawcross='allways', data=newpath)
        #for item in files:
        #    newpath = os.path.join(path, item)
         #   self.tree.insert('end', node, text=item, image=self.file_icon, drawcross='never', data=newpath)
        self.tree.itemconfigure(node, image=self.openfolder_icon)
       

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()
##############################################################

I hope this helps

Michael
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Difficulty getting started with a BWidget Tree

gilcneth
In reply to this post by gilcneth
That does indeed help!  Thank you!

-- Chris


> [Original Message]
> From: Michael Lange <[hidden email]>
> To: <[hidden email]>
> Date: 9/15/2005 10:43:27 AM
> Subject: Re: [Tkinter-discuss] Difficulty getting started with a BWidget
Tree
>
> On Wed, 14 Sep 2005 23:46:57 -0400
> "[hidden email]" <[hidden email]> wrote:
>
> > Hello All:
> >
> > I am trying to create a Tree, using PyBWidgets, but am unsure about how
to actually create the initial parent and/or child nodes.  The
documentation leads me to believe that I should use the' insert' command,
but how?  The documentation indicates the following:
> >
> > pathName insert index parent node ?option value...?
> >
> > So, given my example below, if I want to add a node to my Tree,
wouldn't I use the command TopTree.insert?  And, if so, I assume I start at
index '0'?  OK, but now who's the parent?  I know this has to be simple,
but I am just not figuring this one out.  Please share your thoughts.
> >
> Hi Chris,
>
> I wrote a directory Tree widget a while ago, rather a test than a usable
widget, but maybe good
> enough to get started. I had some problems with my release of pybwidget,
because some icons were missing,
> I believe the "plus" and "minus" icons for the Tree, but I don't remember
exactly.

> So, here's the code:
>
> ############ file DirTree.py ##############################
> import Tkinter as tk
> import bwidget as bw
> import os
>
> class DirTree(tk.Frame):
>     def __init__(self, master, *args, **kw):
>         tk.Frame.__init__(self, master)
>         self.tree = tree = bw.Tree(self, opencmd=self.open_folder,
closecmd=self.close_folder, *args, **kw)
>         tree.pack(fill='both', expand=1)
>        
>         self.folder_icon =
tk.PhotoImage(file='/usr/share/pybwidget/images/folder.gif')
>         self.openfolder_icon =
tk.PhotoImage(file='/usr/share/pybwidget/images/openfold.gif')
>         self.file_icon =
tk.PhotoImage(file='/usr/share/pybwidget/images/file.gif')
>        
>         node = self.tree.insert('end', 'root', text='/',
image=self.folder_icon, drawcross='allways', data='/')

>         self.tree.opentree(node, recurse=0)
>    
>     def close_folder(self, node):
>         self.tree.itemconfigure(node, image=self.folder_icon)
>    
>     def open_folder(self, node):
>         path = self.tree.itemcget(node, 'data')
>         children = os.listdir(path)
>         files, dirs = [], []
>         for item in children:
>             if os.path.isdir(os.path.join(path, item)):
>                 dirs.append(item)
>             #else:
>             #    files.append(item)
>         dirs.sort()
>         #files.sort()
>         for item in dirs:
>             newpath = os.path.join(path, item)
>             self.tree.insert('end', node, text=item,
image=self.folder_icon, drawcross='allways', data=newpath)
>         #for item in files:
>         #    newpath = os.path.join(path, item)
>          #   self.tree.insert('end', node, text=item,
image=self.file_icon, drawcross='never', data=newpath)
>         self.tree.itemconfigure(node, image=self.openfolder_icon)
>        
>
> 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()
> ##############################################################
>
> I hope this helps
>
> Michael
> _______________________________________________
> Tkinter-discuss mailing list
> [hidden email]
> http://mail.python.org/mailman/listinfo/tkinter-discuss



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