summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui.py77
1 files changed, 34 insertions, 43 deletions
diff --git a/gui.py b/gui.py
index 571db55..b8f6d2a 100644
--- a/gui.py
+++ b/gui.py
@@ -21,13 +21,13 @@ logging.basicConfig(level=mat.LOGGING_LEVEL)
21 21
22class CFile(object): 22class CFile(object):
23 ''' 23 '''
24 Contain the class-file of the file "path" 24 Contain the "parser" class of the file "filename"
25 This class exist just to be "around" my parser.Generic_parser class, 25 This class exist just to be "around" my parser.Generic_parser class,
26 since gtk.ListStore does not accept it. 26 since the gtk.ListStore does not accept it.
27 ''' 27 '''
28 def __init__(self, path, backup, add2archive): 28 def __init__(self, filename, backup, add2archive):
29 try: 29 try:
30 self.file = mat.create_class_file(path, backup, add2archive) 30 self.file = mat.create_class_file(filename, backup, add2archive)
31 except: 31 except:
32 self.file = None 32 self.file = None
33 33
@@ -42,6 +42,7 @@ class ListStoreApp:
42 self.backup = True 42 self.backup = True
43 self.add2archive = True 43 self.add2archive = True
44 44
45 # Main window
45 self.window = gtk.Window() 46 self.window = gtk.Window()
46 self.window.set_title('Metadata Anonymisation Toolkit %s' % 47 self.window.set_title('Metadata Anonymisation Toolkit %s' %
47 __version__) 48 __version__)
@@ -117,9 +118,9 @@ loss')
117 118
118 def add_columns(self, treeview): 119 def add_columns(self, treeview):
119 ''' 120 '''
120 Create the columns 121 Create the columns, and add them to the treeview
121 ''' 122 '''
122 colname = ['Filename', 'Mimetype', 'Cleaned'] 123 colname = ['Filename', 'Mimetype', 'State']
123 124
124 for i, j in enumerate(colname): 125 for i, j in enumerate(colname):
125 filename_column = gtk.CellRendererText() 126 filename_column = gtk.CellRendererText()
@@ -166,8 +167,8 @@ loss')
166 gtk.STOCK_QUIT) 167 gtk.STOCK_QUIT)
167 168
168 edit_menu = self.create_sub_menu('Edit', menubar) 169 edit_menu = self.create_sub_menu('Edit', menubar)
169 self.create_menu_item('Clear the filelist', self.clear_model, 170 self.create_menu_item('Clear the filelist',
170 edit_menu, gtk.STOCK_REMOVE) 171 lambda x: self.liststore.clear(), edit_menu, gtk.STOCK_REMOVE)
171 self.create_menu_item('Preferences', self.preferences, edit_menu, 172 self.create_menu_item('Preferences', self.preferences, edit_menu,
172 gtk.STOCK_PREFERENCES) 173 gtk.STOCK_PREFERENCES)
173 174
@@ -180,9 +181,9 @@ loss')
180 gtk.STOCK_FIND) 181 gtk.STOCK_FIND)
181 182
182 help_menu = self.create_sub_menu('Help', menubar) 183 help_menu = self.create_sub_menu('Help', menubar)
183 self.create_menu_item('About', self.about, help_menu, gtk.STOCK_ABOUT)
184 self.create_menu_item('Supported formats', self.supported, help_menu, 184 self.create_menu_item('Supported formats', self.supported, help_menu,
185 gtk.STOCK_INFO) 185 gtk.STOCK_INFO)
186 self.create_menu_item('About', self.about, help_menu, gtk.STOCK_ABOUT)
186 187
187 return menubar 188 return menubar
188 189
@@ -211,14 +212,10 @@ loss')
211 212
212 if response is 0: # gtk.STOCK_OK 213 if response is 0: # gtk.STOCK_OK
213 filenames = chooser.get_filenames() 214 filenames = chooser.get_filenames()
214 chooser.destroy() 215 # filenames contains files and folders
215 for item in filenames: 216 for item in filenames:
216 if os.path.isdir(item): # directory 217 for root, dirs, files in os.walk(item):
217 for root, dirs, files in os.walk(item): 218 [self.populate(os.path.join(root, name)) for name in files]
218 for name in files:
219 self.populate(os.path.join(root, name))
220 else: # regular file
221 self.populate(item)
222 chooser.destroy() 219 chooser.destroy()
223 220
224 def populate(self, item): 221 def populate(self, item):
@@ -284,7 +281,7 @@ loss')
284 281
285 dialog.show_all() 282 dialog.show_all()
286 click = dialog.run() 283 click = dialog.run()
287 if click is 0: 284 if click is 0: # Close
288 dialog.destroy() 285 dialog.destroy()
289 286
290 def preferences(self, _): 287 def preferences(self, _):
@@ -327,7 +324,7 @@ non-anonymised) file to outputed archive')
327 if response is 0: # gtk.STOCK_OK 324 if response is 0: # gtk.STOCK_OK
328 dialog.destroy() 325 dialog.destroy()
329 326
330 def invert(self, button, name): # still not better :/ 327 def invert(self, button, name):
331 ''' 328 '''
332 Invert a preference state 329 Invert a preference state
333 ''' 330 '''
@@ -338,20 +335,14 @@ non-anonymised) file to outputed archive')
338 elif name == 'add2archive': 335 elif name == 'add2archive':
339 self.add2archive = not self.add2archive 336 self.add2archive = not self.add2archive
340 337
341 def clear_model(self, _):
342 '''
343 Clear the whole list of files
344 '''
345 self.liststore.clear()
346
347 def all_if_empy(self, iterator): 338 def all_if_empy(self, iterator):
348 ''' 339 '''
349 if no elements are selected, all elements are processed 340 If no elements are selected, all elements are processed
350 thank's to this function 341 thank's to this function
351 ''' 342 '''
352 if iterator: 343 if iterator: # if the selection is not empty, process it
353 return iterator 344 return iterator
354 else: 345 else: # else, return a range of the liststore's size
355 return xrange(len(self.liststore)) 346 return xrange(len(self.liststore))
356 347
357 def mat_check(self, _): 348 def mat_check(self, _):
@@ -360,13 +351,13 @@ non-anonymised) file to outputed archive')
360 ''' 351 '''
361 _, iterator = self.selection.get_selected_rows() 352 _, iterator = self.selection.get_selected_rows()
362 iterator = self.all_if_empy(iterator) 353 iterator = self.all_if_empy(iterator)
363 for i in iterator: 354 for line in iterator:
364 if self.liststore[i][0].file.is_clean(): 355 if self.liststore[line][0].file.is_clean():
365 string = 'clean' 356 string = 'clean'
366 else: 357 else:
367 string = 'dirty' 358 string = 'dirty'
368 logging.info('%s is %s' % (self.liststore[i][1], string)) 359 logging.info('%s is %s' % (self.liststore[line][1], string))
369 self.liststore[i][3] = string 360 self.liststore[line][3] = string
370 361
371 def mat_clean(self, _): 362 def mat_clean(self, _):
372 ''' 363 '''
@@ -374,12 +365,12 @@ non-anonymised) file to outputed archive')
374 ''' 365 '''
375 _, iterator = self.selection.get_selected_rows() 366 _, iterator = self.selection.get_selected_rows()
376 iterator = self.all_if_empy(iterator) 367 iterator = self.all_if_empy(iterator)
377 for i in iterator: 368 for line in iterator:
378 logging.info('Cleaning %s' % self.liststore[i][1]) 369 logging.info('Cleaning %s' % self.liststore[line][1])
379 if self.liststore[i][3] is not 'clean': 370 if self.liststore[line][3] is not 'clean':
380 if self.force or not self.liststore[i][0].file.is_clean(): 371 if self.force or not self.liststore[line][0].file.is_clean():
381 self.liststore[i][0].file.remove_all() 372 self.liststore[line][0].file.remove_all()
382 self.liststore[i][3] = 'clean' 373 self.liststore[line][3] = 'clean'
383 374
384 def mat_clean_dirty(self, _): 375 def mat_clean_dirty(self, _):
385 ''' 376 '''
@@ -387,12 +378,12 @@ non-anonymised) file to outputed archive')
387 ''' 378 '''
388 _, iterator = self.selection.get_selected_rows() 379 _, iterator = self.selection.get_selected_rows()
389 iterator = self.all_if_empy(iterator) 380 iterator = self.all_if_empy(iterator)
390 for i in iterator: 381 for line in iterator:
391 logging.info('Cleaning (lossy way) %s' % self.liststore[i][1]) 382 logging.info('Cleaning (lossy way) %s' % self.liststore[line][1])
392 if self.liststore[i][3] is not 'clean': 383 if self.liststore[line][3] is not 'clean':
393 if self.force or not self.liststore[i][0].file.is_clean(): 384 if self.force or not self.liststore[line][0].file.is_clean():
394 self.liststore[i][0].file.remove_all_ugly() 385 self.liststore[line][0].file.remove_all_ugly()
395 self.liststore[i][3] = 'clean' 386 self.liststore[line][3] = 'clean'
396 387
397 388
398class TreeViewTooltips(object): 389class TreeViewTooltips(object):