Re: [pygtk] Updating a progressbar inside a recursive function

2006-09-25 Thread Rafael Villar Burke

[EMAIL PROTECTED] wrote:

Hi again,

First of all, thanks Felix for the tips! I didn't know about os.walk,
which is very helpful.

Now eveything is worked as expected (using the gobject.idle_add trick). My
only problem now is that filling a treeview with 200 elements is s
slow if you do it this way.
You probably want to disconnect the model from the view while updating, 
to avoid that every addition regenerates the view. You set the model 
again at the end of each bunch of updates. You can see some tricks to 
improve the performance of treeviews at the pygtk.org FAQ.


Regards,

Rafael Villar Burke
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Updating a progressbar inside a recursive function

2006-09-25 Thread listas
Hi again,

First of all, thanks Felix for the tips! I didn't know about os.walk,
which is very helpful.

Now eveything is worked as expected (using the gobject.idle_add trick). My
only problem now is that filling a treeview with 200 elements is s
slow if you do it this way.

Anyway, thanks for helping everyone!
I hope i can release this app in the near future.

Thanks

-- adolfo

> Felix Rabe (public) wrote:
>> Hi Adolfo,
>>
>> You might not need to use recursive code, and generators aren't too
>> bad.  Have you looked at os.walk() already?
>
> Uno más: func_id = gobject.idle_add(func) //
> gobject.source_remove(func_id) (to interrupt)
> Junto con:
>
> def func([self]):
>   ...
>   return True (called again) or False (last call)
>
> I hope that gives you the connection points to use os.walk with PyGTK and
> the progress bar.  (At least that is how I would approach it.)
>
> Best wishes,
> Felix
>


___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Updating a progressbar inside a recursive function

2006-09-25 Thread Felix Rabe (public)

Felix Rabe (public) wrote:

Hi Adolfo,

You might not need to use recursive code, and generators aren't too 
bad.  Have you looked at os.walk() already?


Uno más: func_id = gobject.idle_add(func) // gobject.source_remove(func_id) (to 
interrupt)
Junto con:

def func([self]):
...
return True (called again) or False (last call)

I hope that gives you the connection points to use os.walk with PyGTK and the 
progress bar.  (At least that is how I would approach it.)

Best wishes,
Felix
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Updating a progressbar inside a recursive function

2006-09-25 Thread Felix Rabe (public)

Hi Adolfo,

You might not need to use recursive code, and generators aren't too bad.  Have 
you looked at os.walk() already?

I have PyGTK example code that uses it.  I have to package it up though, but 
I'll do that on (your) request.  Feel free to answer in Spanish if that's your 
mother tongue.

Greetings,
Felix

Adolfo González Blázquez wrote:

Hello,

I'm writing a little app to mass rename files. The gui has two parts, on
left a tree-like file browser for selecting the dir you want files to
rename. On right, theres a treeview that shows the files that are inside
the selected directory.

What i want to do is update a progressbar while populating the treeview
with the files.

The problem comes when the "add files recursively" option is enabled.
The app calls a recursive method to add everyfile inside that dir and
its subdirs. This function uses to take a while to end, so the gui
freezes till everyfile is read.

I've tried using the tips on
http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq23.020.htp
but they don't work for me:
- The while gtk.events_pending(): gtk.main_iteration() stuff seems to
work, but when reading a dir, and changing to another, it should stop
reading the first dir, clean the treeview, and read the new. But it
reads the new, and still keeps adding files from the old dir.
- I did not suceed trying the generator stuff, 'cause i dont know how to
apply the example to a recursive function.

I've tried threads also, but totally unsuccesful (new to threads...)


So if anyone can point me anyway to solve this, or a good example, i
will really appreciate it.


The two functions related to this problem are pasted below:
The complete .py file can be found here:
http://www.infinicode.org/code/renamer.py

Thank you very much in advance!

-- adolfo

---
def dir_selected(self, obj, dir):

...
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] Updating a progressbar inside a recursive function

2006-09-25 Thread Adolfo González Blázquez
Hello,

I'm writing a little app to mass rename files. The gui has two parts, on
left a tree-like file browser for selecting the dir you want files to
rename. On right, theres a treeview that shows the files that are inside
the selected directory.

What i want to do is update a progressbar while populating the treeview
with the files.

The problem comes when the "add files recursively" option is enabled.
The app calls a recursive method to add everyfile inside that dir and
its subdirs. This function uses to take a while to end, so the gui
freezes till everyfile is read.

I've tried using the tips on
http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq23.020.htp
but they don't work for me:
- The while gtk.events_pending(): gtk.main_iteration() stuff seems to
work, but when reading a dir, and changing to another, it should stop
reading the first dir, clean the treeview, and read the new. But it
reads the new, and still keeps adding files from the old dir.
- I did not suceed trying the generator stuff, 'cause i dont know how to
apply the example to a recursive function.

I've tried threads also, but totally unsuccesful (new to threads...)


So if anyone can point me anyway to solve this, or a good example, i
will really appreciate it.


The two functions related to this problem are pasted below:
The complete .py file can be found here:
http://www.infinicode.org/code/renamer.py

Thank you very much in advance!

-- adolfo

---
def dir_selected(self, obj, dir):
self.rename_button.set_sensitive(False)
self.file_selected_model.clear()
self.current_dir = dir

self.populate_selected_files(dir)   

self.selected_files.columns_autosize()
self.statusbar.push(self.statusbar_context, dir)


def populate_selected_files(self, dir): 
pattern = self.file_pattern.get_text()

# Add files from the current directory
list = renamerfilefuncs.get_file_listing(dir, pattern)
for elem in list:
iter = self.file_selected_model.insert_before(None, None)
self.file_selected_model.set_value(iter, 0, elem[0])
self.file_selected_model.set_value(iter, 1, elem[1])
self.progressbar.pulse()
#while gtk.events_pending(): gtk.main_iteration()
self.progressbar.set_fraction(0)

# If the Recursive option is enabled, look into subdirectories
for files
if self.add_recursive.get_active():
dirlist = renamerfilefuncs.get_dir_listing(dir)
for dir in dirlist:
self.populate_selected_files(dir[1])
---


signature.asc
Description: Esta parte del mensaje está firmada	digitalmente
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/