summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2011-08-07 22:00:39 +0200
committerjvoisin2011-08-07 22:00:39 +0200
commit74c556310ede8b613d3eb9db1f7f771b37c3dac0 (patch)
tree2a547634492af53b1851bff2c798cd93ca168c6a
parentee3a83cf509e8329bba144ad108a806611cc51cd (diff)
Everything is now processed in a (nice and smooth) asynchrone way
Diffstat (limited to '')
-rw-r--r--gui.py59
1 files changed, 33 insertions, 26 deletions
diff --git a/gui.py b/gui.py
index b8f6d2a..520bc5a 100644
--- a/gui.py
+++ b/gui.py
@@ -92,19 +92,20 @@ class ListStoreApp:
92 92
93 toolbutton = gtk.ToolButton(gtk.STOCK_PRINT_REPORT) 93 toolbutton = gtk.ToolButton(gtk.STOCK_PRINT_REPORT)
94 toolbutton.set_label('Clean') 94 toolbutton.set_label('Clean')
95 toolbutton.connect('clicked', self.mat_clean) 95 toolbutton.connect('clicked', self.process_files, self.mat_clean)
96 toolbutton.set_tooltip_text('Clean selected files without data loss') 96 toolbutton.set_tooltip_text('Clean selected files without data loss')
97 toolbar.add(toolbutton) 97 toolbar.add(toolbutton)
98 98
99 toolbutton = gtk.ToolButton(gtk.STOCK_PRINT_WARNING) 99 toolbutton = gtk.ToolButton(gtk.STOCK_PRINT_WARNING)
100 toolbutton.set_label('Brute Clean') 100 toolbutton.set_label('Brute Clean')
101 toolbutton.connect('clicked', self.mat_clean_dirty)
101 toolbutton.set_tooltip_text('Clean selected files with possible data \ 102 toolbutton.set_tooltip_text('Clean selected files with possible data \
102loss') 103loss')
103 toolbar.add(toolbutton) 104 toolbar.add(toolbutton)
104 105
105 toolbutton = gtk.ToolButton(gtk.STOCK_FIND) 106 toolbutton = gtk.ToolButton(gtk.STOCK_FIND)
106 toolbutton.set_label('Check') 107 toolbutton.set_label('Check')
107 toolbutton.connect('clicked', self.mat_check) 108 toolbutton.connect('clicked', self.process_files, self.mat_check)
108 toolbutton.set_tooltip_text('Check selected files for harmful meta') 109 toolbutton.set_tooltip_text('Check selected files for harmful meta')
109 toolbar.add(toolbutton) 110 toolbar.add(toolbutton)
110 111
@@ -140,7 +141,7 @@ loss')
140 picture.set_from_stock(pix, gtk.ICON_SIZE_MENU) 141 picture.set_from_stock(pix, gtk.ICON_SIZE_MENU)
141 item.set_image(picture) 142 item.set_image(picture)
142 item.set_label(name) 143 item.set_label(name)
143 item.connect('activate', func) 144 item.connect('activate', self.process_files, func)
144 menu.append(item) 145 menu.append(item)
145 146
146 def create_sub_menu(self, name, menubar): 147 def create_sub_menu(self, name, menubar):
@@ -212,20 +213,24 @@ loss')
212 213
213 if response is 0: # gtk.STOCK_OK 214 if response is 0: # gtk.STOCK_OK
214 filenames = chooser.get_filenames() 215 filenames = chooser.get_filenames()
215 # filenames contains files and folders 216 task = self.populate(filenames)
216 for item in filenames: 217 gobject.idle_add(task.next) # asynchrone processing
217 for root, dirs, files in os.walk(item):
218 [self.populate(os.path.join(root, name)) for name in files]
219 chooser.destroy() 218 chooser.destroy()
220 219
221 def populate(self, item): 220 def populate(self, filenames):
222 ''' 221 '''
223 Append selected files by add_file to the self.liststore 222 Append selected files by add_file to the self.liststore
224 ''' 223 '''
225 cf = CFile(item, self.backup, self.add2archive) 224 for filename in filenames: # filenames : all selected files/folders
226 if cf.file is not None: 225 for root, dirs, files in os.walk(filename):
227 self.liststore.append([cf, cf.file.basename, cf.file.mime, 226 for item in files:
228 'unknow']) 227 path_to_file = os.path.join(root, item)
228 cf = CFile(path_to_file, self.backup, self.add2archive)
229 if cf.file is not None:
230 self.liststore.append([cf, cf.file.basename,
231 cf.file.mime, 'unknow'])
232 yield True
233 yield False
229 234
230 def about(self, _): 235 def about(self, _):
231 ''' 236 '''
@@ -335,22 +340,20 @@ non-anonymised) file to outputed archive')
335 elif name == 'add2archive': 340 elif name == 'add2archive':
336 self.add2archive = not self.add2archive 341 self.add2archive = not self.add2archive
337 342
338 def all_if_empy(self, iterator): 343 def process_files(self, button, function):
339 ''' 344 '''
340 If no elements are selected, all elements are processed 345 Launch the function "function" in a asynchrone way
341 thank's to this function
342 ''' 346 '''
343 if iterator: # if the selection is not empty, process it 347 iterator = self.selection.get_selected_rows()[1]
344 return iterator 348 if not iterator: # if nothing is selected : select everything
345 else: # else, return a range of the liststore's size 349 iterator = xrange(len(self.liststore))
346 return xrange(len(self.liststore)) 350 task = function(iterator) # asynchrone way
351 gobject.idle_add(task.next)
347 352
348 def mat_check(self, _): 353 def mat_check(self, iterator):
349 ''' 354 '''
350 Check if selected elements are clean 355 Check if selected elements are clean
351 ''' 356 '''
352 _, iterator = self.selection.get_selected_rows()
353 iterator = self.all_if_empy(iterator)
354 for line in iterator: 357 for line in iterator:
355 if self.liststore[line][0].file.is_clean(): 358 if self.liststore[line][0].file.is_clean():
356 string = 'clean' 359 string = 'clean'
@@ -358,21 +361,23 @@ non-anonymised) file to outputed archive')
358 string = 'dirty' 361 string = 'dirty'
359 logging.info('%s is %s' % (self.liststore[line][1], string)) 362 logging.info('%s is %s' % (self.liststore[line][1], string))
360 self.liststore[line][3] = string 363 self.liststore[line][3] = string
364 yield True
365 yield False
361 366
362 def mat_clean(self, _): 367 def mat_clean(self, iterator):
363 ''' 368 '''
364 Clean selected elements 369 Clean selected elements
365 ''' 370 '''
366 _, iterator = self.selection.get_selected_rows()
367 iterator = self.all_if_empy(iterator)
368 for line in iterator: 371 for line in iterator:
369 logging.info('Cleaning %s' % self.liststore[line][1]) 372 logging.info('Cleaning %s' % self.liststore[line][1])
370 if self.liststore[line][3] is not 'clean': 373 if self.liststore[line][3] is not 'clean':
371 if self.force or not self.liststore[line][0].file.is_clean(): 374 if self.force or not self.liststore[line][0].file.is_clean():
372 self.liststore[line][0].file.remove_all() 375 self.liststore[line][0].file.remove_all()
373 self.liststore[line][3] = 'clean' 376 self.liststore[line][3] = 'clean'
377 yield True
378 yield False
374 379
375 def mat_clean_dirty(self, _): 380 def mat_clean_dirty(self, iterator):
376 ''' 381 '''
377 Clean selected elements (ugly way) 382 Clean selected elements (ugly way)
378 ''' 383 '''
@@ -384,6 +389,8 @@ non-anonymised) file to outputed archive')
384 if self.force or not self.liststore[line][0].file.is_clean(): 389 if self.force or not self.liststore[line][0].file.is_clean():
385 self.liststore[line][0].file.remove_all_ugly() 390 self.liststore[line][0].file.remove_all_ugly()
386 self.liststore[line][3] = 'clean' 391 self.liststore[line][3] = 'clean'
392 yield True
393 yield False
387 394
388 395
389class TreeViewTooltips(object): 396class TreeViewTooltips(object):