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 [email protected] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
