python - Create tree hierarchy using os.walk and gobject gtk+3 -


i trying create simple file browser. trying add tree hierarchy files. wrote sample method prints hierarchy correctly, having hard time model same concept create gtk.treestore object. following sample code list files:

def list_files(startpath):     dirname, subdirs, files in os.walk(startpath):         level = dirname.replace(startpath, '').count(os.sep)         indent = ' ' * 4 * (level)         print('{}{}/'.format(indent, os.path.basename(dirname)))         subindent = ' ' * 4 * (level + 1)         f in files:             print('{}{}'.format(subindent, f)) 

and following code create gtk.treestore:

def add_paned(self):     paned = gtk.paned.new(gtk.orientation.horizontal)      test_dir = '/home/myuser'     store = mytreestore(str)     store.generate_tree(test_dir)      treeview = gtk.treeview(store)     renderer = gtk.cellrenderertext()     column = gtk.treeviewcolumn("filename", renderer, text=0)     treeview.append_column(column)      paned.add1(treeview)     self.add(paned)     return paned 

mytreestore class:

from gi.repository import gtk import os  class mytreestore(gtk.treestore): def __init__(self, *arg):     super(mytreestore, self).__init__(*arg)  def generate_tree(self, path):     parent = none;     dirname, subdirs, files in sorted(os.walk(path)):         # level = dirname.replace(path, '').count(os.sep)         # iter = self.get_iter_from_string('{}'.format(level))         parent = self.append(parent, [os.path.basename(dirname)])         print(os.path.basename(dirname))         file in sorted(files):            self.append(parent, [file]) 

i stuck on creating proper iterators when appending file names. right above code nest directories since parent last directory appended store. ideas how go doing this?


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -