GtkTree is broken use GtkCTree which is crap but at least works.
If you relly must use GtkTree here is a trivial example which shows that
dnd is broken
#!/usr/bin/env python
from gtk import *
from GDK import *
class myTree(GtkTree):
def __init__(self):
GtkTree.__init__(self)
self.targets = [('text/plain', 0, -1)]
self.createTreeItems(self)
aSubTree = GtkTree()
self.children()[2].set_subtree(aSubTree)
self.createTreeItems(aSubTree)
def createTreeItems(self, aTree):
for i in range(4):
aTreeItem = GtkTreeItem("tree item " + str(i))
aTree.append(aTreeItem)
aTreeItem.drag_dest_set(DEST_DEFAULT_ALL, self.targets,
ACTION_COPY | ACTION_MOVE)
aTreeItem.drag_source_set(SHIFT_MASK | BUTTON1_MASK,
self.targets, ACTION_COPY | ACTION_MOVE )
aTreeItem.connect('drag_data_get', self.dndDragDataGet_cb)
aTreeItem.connect('drag_data_received',
self.dndDragDataReceived_cb)
aTreeItem.show()
def dndDragDataGet_cb(self,w,context,selection_data,info, time):
dnd_string = "hello world"
selection_data.set(selection_data.target, 8, dnd_string)
def dndDragDataReceived_cb(self,item, context, x, y, data, info, time):
if data and data.format == 8:
msg = "Drop data of type %s was:\n\n%s" % \
(data.target, data.data)
print msg
if __name__ == '__main__':
gtkWindow = GtkWindow(WINDOW_TOPLEVEL)
gtkWindow.connect("destroy", mainquit)
gtkWindow.add(myTree())
gtkWindow.show_all()
mainloop()
nb show_all is broken for gtkTree so you have to call show all over the
place
There is probably a better example in the testgtk.py stuff. (hmm I just
looked and couldn't see one)
If your building your tree from something which is tree like (such as a
file system or DOM) than the easyist way is with a recursive function. The
only examples I have of this are in C so I didn't bother including them.
A word of warning if you use GtkCTree it gets very confused if you set a
node as branch and then don't add any leaves to it or vica verca.
On Tue, 10 Apr 2001 00:59:02 David Robertson wrote:
>
> I am trying to build a simple tree using the following code:
>
> mytree = GtkTree()
> myitem = GtkTreeItem("something")
> mytree.append(myitem)
>
> my question is, how to actually build the nodes and leafelets... I have
> the
> GTK reference but it is in C and I had given up on C 10 years ago so it
> is
> pretty greek to me. Any help on any functions or classes I am overlooking
> would be appreciated. I tried tinkering with GtkTreeItem.set_submenu to
> no
> avail.
>
> Thanks for your help.
>
> Another quick question. Is there an actual reference for the python GTK
> wrapper?
>
no
>
_______________________________________________
> pygtk mailing list [EMAIL PROTECTED]
> http://www.daa.com.au/mailman/listinfo/pygtk
>
rob
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk