It is not possible to create a recursive function over a pyGTK treeStore

2007-06-29 Thread sebastien . abeille
Hello,

I would like to create a minimalist file browser using pyGTK.

Having read lot of tutorials, it seems to me that that in my case, the
best solution is
to have a gtk.TreeStore containing all the files and folders so that
it would map the
file system hierarchy.

I wrote a recursive function that would go through the file system
tree.

My problem is that a sub-node of a gtk.TreeStore is not a
gtk.TreeStore, but
a gtk.TreeIter. And gtk.treeter has almost no functions I would be
able to use (like "append")
Therefore I can not explore the whole file system.

Do you have another way so that I would be able to put all the file
system hierarchy
into a gtk.TreeStore?
I was quite happy with my recursive solution ...



===
code :
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk, gobject, os


prefdir="/tmp/a"

class InfoModele:

def matchPathTreetoModelTree(self, path, treeStoreNode):
files = [f for f in os.listdir(path) if f[0] <> '.']
for i in range(len(files)):
if os.path.isfile(path+'/'+files[i]):
print path+'/'+files[i]+" is a file"
treeStoreNode.append( None, (path+'/'+files[i], 
None) )
if os.path.isdir(path+'/'+files[i]): #is a directory, go
recursively
print path+'/'+files[i]+" is a directory"
mother = self.tree_store.append( None, 
(path+'/'+files[i], None) )

self.matchPathTreetoModelTree(path+'/'+files[i], mother)

def __init__(self):
self.tree_store = gtk.TreeStore( gobject.TYPE_STRING,
gobject.TYPE_STRING)
path=prefdir
self.matchPathTreetoModelTree(prefdir, self.tree_store)

if __name__ == "__main__":
i=InfoModele()

=
file system :
a
|-ab/
   |-abc/
   |-abcd


Program output :
/tmp/a/ab is a directory
/tmp/a/ab/abc is a file
Traceback (most recent call last):
  File "question.py", line 28, in 
i=InfoModele()
  File "question.py", line 25, in __init__
self.matchPathTreetoModelTree(prefdir, self.tree_store)
  File "question.py", line 20, in matchPathTreetoModelTree
self.matchPathTreetoModelTree(path+'/'+files[i], mother)
  File "question.py", line 16, in matchPathTreetoModelTree
treeStoreNode.append( None, (path+'/'+files[i], None) )
AttributeError: 'gtk.TreeIter' object has no attribute 'append'

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: It is not possible to create a recursive function over a pyGTK treeStore

2007-06-29 Thread sebastien . abeille
A little update : I finally found an example of a file browser using
gtkTreestore that parse the file system recursively :
http://www.koders.com/python/fidDB37D29C69F526E5EEA9A7D8B4FC5B87E92A78CC.aspx?s=filter_out_extensions#L113

I still need to check how it works, but I am sure that it will answer
my question.
Thank you


On 29 juin, 13:30, [EMAIL PROTECTED] wrote:
> Hello,
>
> I would like to create a minimalist file browser using pyGTK.
>
> Having read lot of tutorials, it seems to me that that in my case, the
> best solution is
> to have a gtk.TreeStore containing all the files and folders so that
> it would map the
> file system hierarchy.
>
> I wrote a recursive function that would go through the file system
> tree.
>
> My problem is that a sub-node of a gtk.TreeStore is not a
> gtk.TreeStore, but
> a gtk.TreeIter. And gtk.treeter has almost no functions I would be
> able to use (like "append")
> Therefore I can not explore the whole file system.
>
> Do you have another way so that I would be able to put all the file
> system hierarchy
> into a gtk.TreeStore?
> I was quite happy with my recursive solution ...
>
> ===
> code :
> #!/usr/bin/env python
> import pygtk
> pygtk.require('2.0')
> import gtk, gobject, os
>
> prefdir="/tmp/a"
>
> class InfoModele:
>
> def matchPathTreetoModelTree(self, path, treeStoreNode):
> files = [f for f in os.listdir(path) if f[0] <> '.']
> for i in range(len(files)):
> if os.path.isfile(path+'/'+files[i]):
> print path+'/'+files[i]+" is a file"
> treeStoreNode.append( None, 
> (path+'/'+files[i], None) )
> if os.path.isdir(path+'/'+files[i]): #is a directory, 
> go
> recursively
> print path+'/'+files[i]+" is a directory"
> mother = self.tree_store.append( None, 
> (path+'/'+files[i], None) )
> 
> self.matchPathTreetoModelTree(path+'/'+files[i], mother)
>
> def __init__(self):
> self.tree_store = gtk.TreeStore( gobject.TYPE_STRING,
> gobject.TYPE_STRING)
> path=prefdir
> self.matchPathTreetoModelTree(prefdir, self.tree_store)
>
> if __name__ == "__main__":
> i=InfoModele()
>
> =
> file system :
> a
> |-ab/
>|-abc/
>|-abcd
>
> 
> Program output :
> /tmp/a/ab is a directory
> /tmp/a/ab/abc is a file
> Traceback (most recent call last):
>   File "question.py", line 28, in 
> i=InfoModele()
>   File "question.py", line 25, in __init__
> self.matchPathTreetoModelTree(prefdir, self.tree_store)
>   File "question.py", line 20, in matchPathTreetoModelTree
> self.matchPathTreetoModelTree(path+'/'+files[i], mother)
>   File "question.py", line 16, in matchPathTreetoModelTree
> treeStoreNode.append( None, (path+'/'+files[i], None) )
> AttributeError: 'gtk.TreeIter' object has no attribute 'append'


-- 
http://mail.python.org/mailman/listinfo/python-list