summaryrefslogtreecommitdiff
path: root/mat-gui
diff options
context:
space:
mode:
authorjvoisin2011-12-23 23:59:50 +0100
committerjvoisin2011-12-23 23:59:50 +0100
commit82776ce3beb8a3a7a4465832980e846498d1e542 (patch)
treee274cf1b2e0c7a7741bae068d979199fbc87a483 /mat-gui
parentc2bf35d22d57482288800424bcdc1bb173b81e05 (diff)
Fix more bug in gui !
Diffstat (limited to 'mat-gui')
-rwxr-xr-xmat-gui106
1 files changed, 55 insertions, 51 deletions
diff --git a/mat-gui b/mat-gui
index bb123a9..af50e60 100755
--- a/mat-gui
+++ b/mat-gui
@@ -59,8 +59,8 @@ class GUI:
59 vbox = gtk.VBox() 59 vbox = gtk.VBox()
60 self.window.add(vbox) 60 self.window.add(vbox)
61 61
62 menubar = self.create_menu() 62 menubar = self.__create_menu()
63 toolbar = self.create_toolbar() 63 toolbar = self.__create_toolbar()
64 content = gtk.ScrolledWindow() 64 content = gtk.ScrolledWindow()
65 vbox.pack_start(menubar, False, True, 0) 65 vbox.pack_start(menubar, False, True, 0)
66 vbox.pack_start(toolbar, False, True, 0) 66 vbox.pack_start(toolbar, False, True, 0)
@@ -73,11 +73,11 @@ class GUI:
73 self.treeview.set_search_column(1) # filename column is searchable 73 self.treeview.set_search_column(1) # filename column is searchable
74 self.treeview.set_rules_hint(True) # alternate colors for rows 74 self.treeview.set_rules_hint(True) # alternate colors for rows
75 self.treeview.set_rubber_banding(True) # mouse selection 75 self.treeview.set_rubber_banding(True) # mouse selection
76 self.treeview.connect('drag_data_received', self.on_drag_data_received) 76 self.treeview.connect('drag_data_received', self.__on_drag_data_received)
77 self.treeview.drag_dest_set(gtk.DEST_DEFAULT_MOTION | 77 self.treeview.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
78 gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP, 78 gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP,
79 [('text/uri-list', 0, 80)], gtk.gdk.ACTION_COPY) 79 [('text/uri-list', 0, 80)], gtk.gdk.ACTION_COPY)
80 self.add_columns() 80 self.__add_columns()
81 self.selection = self.treeview.get_selection() 81 self.selection = self.treeview.get_selection()
82 self.selection.set_mode(gtk.SELECTION_MULTIPLE) 82 self.selection.set_mode(gtk.SELECTION_MULTIPLE)
83 83
@@ -89,7 +89,7 @@ class GUI:
89 89
90 self.window.show_all() 90 self.window.show_all()
91 91
92 def create_toolbar(self): 92 def __create_toolbar(self):
93 ''' 93 '''
94 Returns a vbox object, which contains a toolbar with buttons 94 Returns a vbox object, which contains a toolbar with buttons
95 ''' 95 '''
@@ -97,28 +97,28 @@ class GUI:
97 97
98 toolbutton = gtk.ToolButton(gtk.STOCK_ADD) 98 toolbutton = gtk.ToolButton(gtk.STOCK_ADD)
99 toolbutton.set_label(_('Add')) 99 toolbutton.set_label(_('Add'))
100 toolbutton.connect('clicked', self.add_files) 100 toolbutton.connect('clicked', self.__add_files)
101 toolbutton.set_tooltip_text(_('Add files')) 101 toolbutton.set_tooltip_text(_('Add files'))
102 toolbar.add(toolbutton) 102 toolbar.add(toolbutton)
103 103
104 toolbutton = gtk.ToolButton(gtk.STOCK_PRINT_REPORT) 104 toolbutton = gtk.ToolButton(gtk.STOCK_PRINT_REPORT)
105 toolbutton.set_label(_('Clean (lossless)')) 105 toolbutton.set_label(_('Clean (lossless)'))
106 toolbutton.connect('clicked', self.process_files, self.mat_clean) 106 toolbutton.connect('clicked', self.__process_files, self.__mat_clean)
107 toolbutton.set_tooltip_text(_('Clean selected files without possible \ 107 toolbutton.set_tooltip_text(_('Clean selected files without possible \
108data loss')) 108data loss'))
109 toolbar.add(toolbutton) 109 toolbar.add(toolbutton)
110 110
111 toolbutton = gtk.ToolButton(gtk.STOCK_PRINT_WARNING) 111 toolbutton = gtk.ToolButton(gtk.STOCK_PRINT_WARNING)
112 toolbutton.set_label(_('Clean (strict)')) 112 toolbutton.set_label(_('Clean (strict)'))
113 toolbutton.connect('clicked', self.process_files, 113 toolbutton.connect('clicked', self.__process_files,
114 self.mat_clean_strict) 114 self.__mat_clean_strict)
115 toolbutton.set_tooltip_text(_('Clean selected files with possible \ 115 toolbutton.set_tooltip_text(_('Clean selected files with possible \
116data loss, but clean more efficiently')) 116data loss, but clean more efficiently'))
117 toolbar.add(toolbutton) 117 toolbar.add(toolbutton)
118 118
119 toolbutton = gtk.ToolButton(gtk.STOCK_FIND) 119 toolbutton = gtk.ToolButton(gtk.STOCK_FIND)
120 toolbutton.set_label(_('Check')) 120 toolbutton.set_label(_('Check'))
121 toolbutton.connect('clicked', self.process_files, self.mat_check) 121 toolbutton.connect('clicked', self.__process_files, self.__mat_check)
122 toolbutton.set_tooltip_text(_('Check selected files for harmful meta')) 122 toolbutton.set_tooltip_text(_('Check selected files for harmful meta'))
123 toolbar.add(toolbutton) 123 toolbar.add(toolbutton)
124 124
@@ -131,7 +131,7 @@ data loss, but clean more efficiently'))
131 vbox.pack_start(toolbar, False, False, 0) 131 vbox.pack_start(toolbar, False, False, 0)
132 return vbox 132 return vbox
133 133
134 def add_columns(self): 134 def __add_columns(self):
135 ''' 135 '''
136 Create the columns, and add them to the treeview 136 Create the columns, and add them to the treeview
137 ''' 137 '''
@@ -148,7 +148,7 @@ data loss, but clean more efficiently'))
148 tips.add_view(self.treeview) 148 tips.add_view(self.treeview)
149 self.treeview.append_column(column) 149 self.treeview.append_column(column)
150 150
151 def create_menu_item(self, name, func, menu, pix, shortcut): 151 def __create_menu_item(self, name, func, menu, pix, shortcut):
152 ''' 152 '''
153 Create a MenuItem() like Preferences, Quit, Add, Clean, ... 153 Create a MenuItem() like Preferences, Quit, Add, Clean, ...
154 ''' 154 '''
@@ -164,7 +164,7 @@ data loss, but clean more efficiently'))
164 item.connect('activate', func) 164 item.connect('activate', func)
165 menu.append(item) 165 menu.append(item)
166 166
167 def create_sub_menu(self, name, menubar): 167 def __create_sub_menu(self, name, menubar):
168 ''' 168 '''
169 Create a submenu like File, Edit, Clean, ... 169 Create a submenu like File, Edit, Clean, ...
170 ''' 170 '''
@@ -175,26 +175,26 @@ data loss, but clean more efficiently'))
175 menubar.append(menuitem) 175 menubar.append(menuitem)
176 return submenu 176 return submenu
177 177
178 def create_menu(self): 178 def __create_menu(self):
179 ''' 179 '''
180 Return a MenuBar 180 Return a MenuBar
181 ''' 181 '''
182 menubar = gtk.MenuBar() 182 menubar = gtk.MenuBar()
183 183
184 file_menu = self.create_sub_menu(_('Files'), menubar) 184 file_menu = self.__create_sub_menu(_('Files'), menubar)
185 self.create_menu_item(_('Add files'), self.add_files, file_menu, 185 self.__create_menu_item(_('Add files'), self.__add_files, file_menu,
186 gtk.STOCK_ADD, '<Control>O') 186 gtk.STOCK_ADD, '<Control>O')
187 self.create_menu_item(_('Quit'), gtk.main_quit, file_menu, 187 self.__create_menu_item(_('Quit'), gtk.main_quit, file_menu,
188 gtk.STOCK_QUIT, '<Control>Q') 188 gtk.STOCK_QUIT, '<Control>Q')
189 189
190 edit_menu = self.create_sub_menu(_('Edit'), menubar) 190 edit_menu = self.__create_sub_menu(_('Edit'), menubar)
191 self.create_menu_item(_('Clear the filelist'), 191 self.__create_menu_item(_('Clear the filelist'),
192 lambda x: self.liststore.clear(), edit_menu, gtk.STOCK_REMOVE, 192 lambda x: self.liststore.clear(), edit_menu, gtk.STOCK_REMOVE,
193 '<Control>L') 193 '<Control>L')
194 self.create_menu_item(_('Preferences'), self.preferences, edit_menu, 194 self.__create_menu_item(_('Preferences'), self.__preferences, edit_menu,
195 gtk.STOCK_PREFERENCES, '<Control>P') 195 gtk.STOCK_PREFERENCES, '<Control>P')
196 196
197 process_menu = self.create_sub_menu(_('Process'), menubar) 197 process_menu = self.__create_sub_menu(_('Process'), menubar)
198 item = gtk.ImageMenuItem() 198 item = gtk.ImageMenuItem()
199 key, mod = gtk.accelerator_parse('<Control>L') 199 key, mod = gtk.accelerator_parse('<Control>L')
200 item.add_accelerator('activate', self.accelerator, 200 item.add_accelerator('activate', self.accelerator,
@@ -203,7 +203,7 @@ data loss, but clean more efficiently'))
203 picture.set_from_stock(gtk.STOCK_PRINT_REPORT, gtk.ICON_SIZE_MENU) 203 picture.set_from_stock(gtk.STOCK_PRINT_REPORT, gtk.ICON_SIZE_MENU)
204 item.set_image(picture) 204 item.set_image(picture)
205 item.set_label(_('Clean (lossless)')) 205 item.set_label(_('Clean (lossless)'))
206 item.connect('activate', self.process_files, self.mat_clean) 206 item.connect('activate', self.__process_files, self.__mat_clean)
207 process_menu.append(item) 207 process_menu.append(item)
208 208
209 item = gtk.ImageMenuItem() 209 item = gtk.ImageMenuItem()
@@ -214,7 +214,7 @@ data loss, but clean more efficiently'))
214 picture.set_from_stock(gtk.STOCK_PRINT_WARNING, gtk.ICON_SIZE_MENU) 214 picture.set_from_stock(gtk.STOCK_PRINT_WARNING, gtk.ICON_SIZE_MENU)
215 item.set_image(picture) 215 item.set_image(picture)
216 item.set_label(_('Clean (strict)')) 216 item.set_label(_('Clean (strict)'))
217 item.connect('activate', self.process_files, self.mat_clean_strict) 217 item.connect('activate', self.__process_files, self.__mat_clean_strict)
218 process_menu.append(item) 218 process_menu.append(item)
219 219
220 item = gtk.ImageMenuItem() 220 item = gtk.ImageMenuItem()
@@ -225,18 +225,18 @@ data loss, but clean more efficiently'))
225 picture.set_from_stock(gtk.STOCK_FIND, gtk.ICON_SIZE_MENU) 225 picture.set_from_stock(gtk.STOCK_FIND, gtk.ICON_SIZE_MENU)
226 item.set_image(picture) 226 item.set_image(picture)
227 item.set_label(_('Check')) 227 item.set_label(_('Check'))
228 item.connect('activate', self.process_files, self.mat_check) 228 item.connect('activate', self.__process_files, self.__mat_check)
229 process_menu.append(item) 229 process_menu.append(item)
230 230
231 help_menu = self.create_sub_menu(_('Help'), menubar) 231 help_menu = self.__create_sub_menu(_('Help'), menubar)
232 self.create_menu_item(_('Supported formats'), self.supported, 232 self.__create_menu_item(_('Supported formats'), self.__supported,
233 help_menu, gtk.STOCK_INFO, False) 233 help_menu, gtk.STOCK_INFO, False)
234 self.create_menu_item(_('About'), self.about, help_menu, 234 self.__create_menu_item(_('About'), self.__about, help_menu,
235 gtk.STOCK_ABOUT, False) 235 gtk.STOCK_ABOUT, False)
236 236
237 return menubar 237 return menubar
238 238
239 def add_files(self, button): 239 def __add_files(self, button):
240 ''' 240 '''
241 Add the files chosed by the filechoser ("Add" button) 241 Add the files chosed by the filechoser ("Add" button)
242 ''' 242 '''
@@ -261,11 +261,11 @@ data loss, but clean more efficiently'))
261 261
262 if response is 0: # gtk.STOCK_OK 262 if response is 0: # gtk.STOCK_OK
263 filenames = chooser.get_filenames() 263 filenames = chooser.get_filenames()
264 task = self.populate(filenames) 264 task = self.__populate(filenames)
265 gobject.idle_add(task.next) # asynchrone processing 265 gobject.idle_add(task.next) # asynchrone processing
266 chooser.destroy() 266 chooser.destroy()
267 267
268 def populate(self, filenames): 268 def __populate(self, filenames):
269 ''' 269 '''
270 Append selected files by add_file to the self.liststore 270 Append selected files by add_file to the self.liststore
271 ''' 271 '''
@@ -276,17 +276,17 @@ data loss, but clean more efficiently'))
276 for item in files: 276 for item in files:
277 path_to_file = os.path.join(root, item) 277 path_to_file = os.path.join(root, item)
278 278
279 if self.add_file_to_treeview(path_to_file): 279 if self.__add_file_to_treeview(path_to_file):
280 not_supported.append(item) 280 not_supported.append(item)
281 else: # filename is a regular file 281 else: # filename is a regular file
282 if self.add_file_to_treeview(filename): 282 if self.__add_file_to_treeview(filename):
283 not_supported.append(filename) 283 not_supported.append(filename)
284 yield True 284 yield True
285 if not_supported: 285 if not_supported:
286 self.popup_non_supported(not_supported) 286 self.__popup_non_supported(not_supported)
287 yield False 287 yield False
288 288
289 def add_file_to_treeview(self, filename): 289 def __add_file_to_treeview(self, filename):
290 ''' 290 '''
291 Add a file to the list if it's format is supported 291 Add a file to the list if it's format is supported
292 ''' 292 '''
@@ -302,7 +302,7 @@ data loss, but clean more efficiently'))
302 else: 302 else:
303 return True 303 return True
304 304
305 def popup_non_supported(self, filelist): 305 def __popup_non_supported(self, filelist):
306 ''' 306 '''
307 Popup that warn the user about the unsupported files 307 Popup that warn the user about the unsupported files
308 that he want to process 308 that he want to process
@@ -337,7 +337,7 @@ data loss, but clean more efficiently'))
337 if click is 0: # Ok button 337 if click is 0: # Ok button
338 dialog.destroy() 338 dialog.destroy()
339 339
340 def about(self, button): 340 def __about(self, button):
341 ''' 341 '''
342 About popup 342 About popup
343 ''' 343 '''
@@ -353,7 +353,7 @@ data loss, but clean more efficiently'))
353 if click: 353 if click:
354 w.destroy() 354 w.destroy()
355 355
356 def supported(self, button): 356 def __supported(self, button):
357 ''' 357 '''
358 List the supported formats 358 List the supported formats
359 ''' 359 '''
@@ -394,7 +394,7 @@ data loss, but clean more efficiently'))
394 if click is 0: # Close 394 if click is 0: # Close
395 dialog.destroy() 395 dialog.destroy()
396 396
397 def preferences(self, button): 397 def __preferences(self, button):
398 ''' 398 '''
399 Preferences popup 399 Preferences popup
400 ''' 400 '''
@@ -411,21 +411,21 @@ data loss, but clean more efficiently'))
411 411
412 force = gtk.CheckButton(_('Force Clean'), False) 412 force = gtk.CheckButton(_('Force Clean'), False)
413 force.set_active(self.force) 413 force.set_active(self.force)
414 force.connect('toggled', self.invert, 'force') 414 force.connect('toggled', self.__invert, 'force')
415 force.set_tooltip_text(_('Do not check if already clean before \ 415 force.set_tooltip_text(_('Do not check if already clean before \
416cleaning')) 416cleaning'))
417 table.attach(force, 0, 1, 0, 1) 417 table.attach(force, 0, 1, 0, 1)
418 418
419 backup = gtk.CheckButton(_('Backup'), False) 419 backup = gtk.CheckButton(_('Backup'), False)
420 backup.set_active(self.backup) 420 backup.set_active(self.backup)
421 backup.connect('toggled', self.invert, 'backup') 421 backup.connect('toggled', self.__invert, 'backup')
422 backup.set_tooltip_text(_('Keep a backup copy')) 422 backup.set_tooltip_text(_('Keep a backup copy'))
423 table.attach(backup, 0, 1, 1, 2) 423 table.attach(backup, 0, 1, 1, 2)
424 424
425 add2archive = gtk.CheckButton(_('Add unsupported file to archives'), 425 add2archive = gtk.CheckButton(_('Add unsupported file to archives'),
426 False) 426 False)
427 add2archive.set_active(self.add2archive) 427 add2archive.set_active(self.add2archive)
428 add2archive.connect('toggled', self.invert, 'add2archive') 428 add2archive.connect('toggled', self.__invert, 'add2archive')
429 add2archive.set_tooltip_text(_('Add non-supported (and so \ 429 add2archive.set_tooltip_text(_('Add non-supported (and so \
430non-anonymised) file to output archive')) 430non-anonymised) file to output archive'))
431 table.attach(add2archive, 0, 1, 2, 3) 431 table.attach(add2archive, 0, 1, 2, 3)
@@ -435,7 +435,7 @@ non-anonymised) file to output archive'))
435 if response is 0: # gtk.STOCK_OK 435 if response is 0: # gtk.STOCK_OK
436 dialog.destroy() 436 dialog.destroy()
437 437
438 def invert(self, button, name): 438 def __invert(self, button, name):
439 ''' 439 '''
440 Invert a preference state 440 Invert a preference state
441 ''' 441 '''
@@ -450,7 +450,7 @@ non-anonymised) file to output archive'))
450 elif name == 'add2archive': 450 elif name == 'add2archive':
451 self.add2archive = not self.add2archive 451 self.add2archive = not self.add2archive
452 452
453 def on_drag_data_received(self, widget, context, 453 def __on_drag_data_received(self, widget, context,
454 x, y, selection, target_type, timestamp): 454 x, y, selection, target_type, timestamp):
455 ''' 455 '''
456 This function is called when something is 456 This function is called when something is
@@ -458,11 +458,11 @@ non-anonymised) file to output archive'))
458 It basically add files. 458 It basically add files.
459 ''' 459 '''
460 urls = selection.data.strip('\r\n\x00') # strip stupid characters 460 urls = selection.data.strip('\r\n\x00') # strip stupid characters
461 cleaned_urls = map(self.clean_draged_file_path, urls.split('\n')) 461 cleaned_urls = map(self.__clean_draged_file_path, urls.split('\n'))
462 task = self.populate(cleaned_urls) 462 task = self.__populate(cleaned_urls)
463 gobject.idle_add(task.next) # asynchrone processing 463 gobject.idle_add(task.next) # asynchrone processing
464 464
465 def clean_draged_file_path(self, url): 465 def __clean_draged_file_path(self, url):
466 ''' 466 '''
467 Since the dragged urls are ugly, 467 Since the dragged urls are ugly,
468 we need to process them 468 we need to process them
@@ -475,7 +475,7 @@ non-anonymised) file to output archive'))
475 elif url.startswith('file:'): # xffm 475 elif url.startswith('file:'): # xffm
476 return url[5:] # 5 is len('file:') 476 return url[5:] # 5 is len('file:')
477 477
478 def process_files(self, button, func): 478 def __process_files(self, button, func):
479 ''' 479 '''
480 Launch the function "func" in a asynchrone way 480 Launch the function "func" in a asynchrone way
481 ''' 481 '''
@@ -485,7 +485,7 @@ non-anonymised) file to output archive'))
485 task = func(iterator) # launch func() in an asynchrone way 485 task = func(iterator) # launch func() in an asynchrone way
486 gobject.idle_add(task.next) 486 gobject.idle_add(task.next)
487 487
488 def mat_check(self, iterator): 488 def __mat_check(self, iterator):
489 ''' 489 '''
490 Check if selected elements are clean 490 Check if selected elements are clean
491 ''' 491 '''
@@ -502,7 +502,7 @@ non-anonymised) file to output archive'))
502 self.statusbar.push(0, _('Ready')) 502 self.statusbar.push(0, _('Ready'))
503 yield False 503 yield False
504 504
505 def mat_clean(self, iterator): 505 def __mat_clean(self, iterator):
506 ''' 506 '''
507 Clean selected elements 507 Clean selected elements
508 ''' 508 '''
@@ -510,8 +510,10 @@ non-anonymised) file to output archive'))
510 logging.info('Cleaning (lossless) %s' % self.liststore[line][1]) 510 logging.info('Cleaning (lossless) %s' % self.liststore[line][1])
511 self.statusbar.push(0, _('Cleaning %s...') % self.liststore[line][1]) 511 self.statusbar.push(0, _('Cleaning %s...') % self.liststore[line][1])
512 if self.liststore[line][3] != _('Clean (strict)'): 512 if self.liststore[line][3] != _('Clean (strict)'):
513 # if the file is not already strict cleaned
513 if self.force or not self.liststore[line][0].file.is_clean(): 514 if self.force or not self.liststore[line][0].file.is_clean():
514 if self.liststore[line][0].file.remove_all(): 515 if self.liststore[line][0].file.remove_all():
516 # if everything went fine
515 self.liststore[line][3] = _('Clean (lossless)') 517 self.liststore[line][3] = _('Clean (lossless)')
516 if self.backup: # the backup copy state 518 if self.backup: # the backup copy state
517 self.liststore[line][4] = self.liststore[line][0].file.output 519 self.liststore[line][4] = self.liststore[line][0].file.output
@@ -519,7 +521,7 @@ non-anonymised) file to output archive'))
519 self.statusbar.push(0, _('Ready')) 521 self.statusbar.push(0, _('Ready'))
520 yield False 522 yield False
521 523
522 def mat_clean_strict(self, iterator): 524 def __mat_clean_strict(self, iterator):
523 ''' 525 '''
524 Clean selected elements (ugly way) 526 Clean selected elements (ugly way)
525 ''' 527 '''
@@ -527,8 +529,10 @@ non-anonymised) file to output archive'))
527 logging.info(_('Cleaning (strict) %s') % self.liststore[line][1]) 529 logging.info(_('Cleaning (strict) %s') % self.liststore[line][1])
528 self.statusbar.push(0, _('Cleaning %s...') % self.liststore[line][1]) 530 self.statusbar.push(0, _('Cleaning %s...') % self.liststore[line][1])
529 if self.liststore[line][3] != _('Clean (strict)'): 531 if self.liststore[line][3] != _('Clean (strict)'):
532 # if the file is not already strict cleaned
530 if self.force or not self.liststore[line][0].file.is_clean(): 533 if self.force or not self.liststore[line][0].file.is_clean():
531 if self.liststore[line][0].file.remove_all_ugly(): 534 if self.liststore[line][0].file.remove_all_ugly():
535 # if everything went fine
532 self.liststore[line][3] = _('Clean (strict)') 536 self.liststore[line][3] = _('Clean (strict)')
533 if self.backup: # the backup copy state 537 if self.backup: # the backup copy state
534 self.liststore[line][4] = self.liststore[line][0].file.output 538 self.liststore[line][4] = self.liststore[line][0].file.output
@@ -682,7 +686,7 @@ if __name__ == '__main__':
682 #Add files from command line 686 #Add files from command line
683 infiles = [arg for arg in sys.argv[1:] if os.path.exists(arg)] 687 infiles = [arg for arg in sys.argv[1:] if os.path.exists(arg)]
684 if infiles: 688 if infiles:
685 task = gui.populate(infiles) 689 task = gui.__populate(infiles)
686 gobject.idle_add(task.next) 690 gobject.idle_add(task.next)
687 691
688 gtk.main() 692 gtk.main()