summaryrefslogtreecommitdiff
path: root/mat-gui
diff options
context:
space:
mode:
Diffstat (limited to 'mat-gui')
-rwxr-xr-xmat-gui110
1 files changed, 36 insertions, 74 deletions
diff --git a/mat-gui b/mat-gui
index 9f588bf..63aa735 100755
--- a/mat-gui
+++ b/mat-gui
@@ -29,8 +29,8 @@ class CFile(GObject.Object):
29 since the Gtk.ListStore does not accept it because it does not 29 since the Gtk.ListStore does not accept it because it does not
30 extends Gobject.Object 30 extends Gobject.Object
31 ''' 31 '''
32 def __init__(self, filename, backup, **kwargs): 32 def __init__(self, filename, **kwargs):
33 self.file = mat.create_class_file(filename, backup, **kwargs) 33 self.file = mat.create_class_file(filename, 0, **kwargs)
34 34
35 35
36class GUI(object): 36class GUI(object):
@@ -39,8 +39,6 @@ class GUI(object):
39 ''' 39 '''
40 def __init__(self): 40 def __init__(self):
41 # Preferences 41 # Preferences
42 self.force = False
43 self.backup = True
44 self.add2archive = True 42 self.add2archive = True
45 self.pdf_quality = False 43 self.pdf_quality = False
46 44
@@ -55,18 +53,13 @@ class GUI(object):
55 self.window = self.builder.get_object('MainWindow') 53 self.window = self.builder.get_object('MainWindow')
56 self.window.set_icon(icon) 54 self.window.set_icon(icon)
57 self.liststore = self.builder.get_object('Liststore') 55 self.liststore = self.builder.get_object('Liststore')
58 ''' The liststore contains: 56 ''' The Liststore contains:
59 0: a CFile instance which represent the file 57 0: The CFile instance that represents the file
60 1: the file's path 58 1: The file's name
61 2: the file's name 59 2: The file's state (Localised string)
62 3: the file's mimetype
63 4: the file's state (translated string)
64 5: the cleaned copy's path
65 6: the file's state (-1: unknown, 0: clean, 1: dirty)
66 ''' 60 '''
67 61
68 self.treeview = self.builder.get_object('Treeview') 62 self.treeview = self.builder.get_object('Treeview')
69 self.treeview.get_column(4).set_visible(self.backup)
70 63
71 self.statusbar = self.builder.get_object('Statusbar') 64 self.statusbar = self.builder.get_object('Statusbar')
72 self.statusbar.push(1, _('Ready')) 65 self.statusbar.push(1, _('Ready'))
@@ -77,7 +70,7 @@ class GUI(object):
77 self.window.show_all() 70 self.window.show_all()
78 71
79 def __init_supported_popup(self): 72 def __init_supported_popup(self):
80 ''' Initialize the "supported formats" popup ''' 73 ''' Initialise the "supported formats" popup '''
81 self.supported_dict = mat.XMLParser() 74 self.supported_dict = mat.XMLParser()
82 parser = xml.sax.make_parser() 75 parser = xml.sax.make_parser()
83 parser.setContentHandler(self.supported_dict) 76 parser.setContentHandler(self.supported_dict)
@@ -130,7 +123,7 @@ class GUI(object):
130 Gtk.main_quit() 123 Gtk.main_quit()
131 124
132 def cb_add_files(self, button): 125 def cb_add_files(self, button):
133 ''' Add the files chosed by the filechoser ("Add" button) ''' 126 ''' Add the files chosen by the filechoser ("Add" button) '''
134 chooser = Gtk.FileChooserDialog(title=_('Choose files'), 127 chooser = Gtk.FileChooserDialog(title=_('Choose files'),
135 parent=self.window, action=Gtk.FileChooserAction.OPEN, 128 parent=self.window, action=Gtk.FileChooserAction.OPEN,
136 buttons=(Gtk.STOCK_OK, 0, Gtk.STOCK_CANCEL, 1)) 129 buttons=(Gtk.STOCK_OK, 0, Gtk.STOCK_CANCEL, 1))
@@ -162,12 +155,11 @@ class GUI(object):
162 ''' 155 '''
163 label = _('<b>%s</b>\'s metadatas:\n') % self.liststore[row][1] 156 label = _('<b>%s</b>\'s metadatas:\n') % self.liststore[row][1]
164 meta = '' 157 meta = ''
165 if not self.liststore[row][6] or self.liststore[row][0].file.is_clean(): 158 if self.liststore[row][0].file.is_clean():
166 meta = _('No metadata found') 159 meta = _('No metadata found')
167 self.liststore[row][4] = _('Clean') 160 self.liststore[row][2] = _('Clean')
168 else: 161 else:
169 self.liststore[row][4] = _('Dirty') 162 self.liststore[row][2] = _('Dirty')
170 self.liststore[row][6] = 1
171 iterator = self.liststore[row][0].file.get_meta().iteritems() 163 iterator = self.liststore[row][0].file.get_meta().iteritems()
172 for i, j in iterator: 164 for i, j in iterator:
173 name = '-<b>' + str(i) + '</b>: ' 165 name = '-<b>' + str(i) + '</b>: '
@@ -222,11 +214,11 @@ class GUI(object):
222 214
223 def cb_mat_check(self, button): 215 def cb_mat_check(self, button):
224 ''' Callback for checking files ''' 216 ''' Callback for checking files '''
225 self.__process_files(self.mat_check) 217 self.__process_files(self.__mat_check)
226 218
227 def cb_mat_clean(self, button): 219 def cb_mat_clean(self, button):
228 ''' Callback for cleaning files ''' 220 ''' Callback for cleaning files '''
229 self.__process_files(self.mat_clean) 221 self.__process_files(self.__mat_clean)
230 222
231 def cb_preferences_popup(self, button): 223 def cb_preferences_popup(self, button):
232 ''' Preferences popup ''' 224 ''' Preferences popup '''
@@ -241,26 +233,14 @@ class GUI(object):
241 icon.set_from_stock(Gtk.STOCK_PREFERENCES, Gtk.IconSize.DIALOG) 233 icon.set_from_stock(Gtk.STOCK_PREFERENCES, Gtk.IconSize.DIALOG)
242 hbox.pack_start(icon, False, False, 20) 234 hbox.pack_start(icon, False, False, 20)
243 235
244 table = Gtk.Table(3, 2, False) # nb rows, nb lines 236 table = Gtk.Table(2, 2, False) # nb rows, nb lines
245 hbox.pack_start(table, True, True, 0) 237 hbox.pack_start(table, True, True, 0)
246 238
247 force = Gtk.CheckButton(_('Force Clean'), False)
248 force.set_active(self.force)
249 force.connect('toggled', self.__invert, 'force')
250 force.set_tooltip_text(_('Do not check if already clean before cleaning'))
251 table.attach(force, 0, 1, 0, 1)
252
253 backup = Gtk.CheckButton(_('Backup'), False)
254 backup.set_active(self.backup)
255 backup.connect('toggled', self.__invert, 'backup')
256 backup.set_tooltip_text(_('Keep a backup copy'))
257 table.attach(backup, 0, 1, 1, 2)
258
259 pdf_quality = Gtk.CheckButton(_('Reduce PDF quality'), False) 239 pdf_quality = Gtk.CheckButton(_('Reduce PDF quality'), False)
260 pdf_quality.set_active(self.pdf_quality) 240 pdf_quality.set_active(self.pdf_quality)
261 pdf_quality.connect('toggled', self.__invert, 'pdf_quality') 241 pdf_quality.connect('toggled', self.__invert, 'pdf_quality')
262 pdf_quality.set_tooltip_text(_('Reduce the produced PDF size and quality')) 242 pdf_quality.set_tooltip_text(_('Reduce the produced PDF size and quality'))
263 table.attach(pdf_quality, 0, 1, 2, 3) 243 table.attach(pdf_quality, 0, 1, 0, 1)
264 244
265 add2archive = Gtk.CheckButton(_('Add unsupported file to archives'), 245 add2archive = Gtk.CheckButton(_('Add unsupported file to archives'),
266 False) 246 False)
@@ -268,15 +248,14 @@ class GUI(object):
268 add2archive.connect('toggled', self.__invert, 'add2archive') 248 add2archive.connect('toggled', self.__invert, 'add2archive')
269 add2archive.set_tooltip_text(_('Add non-supported (and so \ 249 add2archive.set_tooltip_text(_('Add non-supported (and so \
270non-anonymised) file to output archive')) 250non-anonymised) file to output archive'))
271 table.attach(add2archive, 0, 1, 3, 4) 251 table.attach(add2archive, 0, 1, 1, 2)
272 252
273 hbox.show_all() 253 hbox.show_all()
274 if not dialog.run(): # Gtk.STOCK_OK 254 if not dialog.run(): # Gtk.STOCK_OK
275 for file in self.liststore: # update preferences 255 for file in self.liststore: # update preferences
276 file[0].backup = self.backup 256 file[0].file.add2archive = self.add2archive
277 file[0].add2archive = self.add2archive 257 if file[0].file.mime.startswith('pdf'):
278 if file[2].startswith('pdf'): 258 file[0].file.pdf_quality = self.pdf_quality
279 file[0].pdf_quality = self.pdf_quality
280 dialog.destroy() 259 dialog.destroy()
281 260
282 def cb_drag_data_received(self, widget, context, 261 def cb_drag_data_received(self, widget, context,
@@ -292,7 +271,7 @@ non-anonymised) file to output archive'))
292 Since the dragged urls are ugly, 271 Since the dragged urls are ugly,
293 we need to process them 272 we need to process them
294 ''' 273 '''
295 url = urllib2.unquote(url) # unescape stupid chars 274 url = urllib2.unquote(url) # unquote url
296 url = url.decode('utf-8') # decode in utf-8 275 url = url.decode('utf-8') # decode in utf-8
297 if url.startswith('file:\\\\\\'): # windows 276 if url.startswith('file:\\\\\\'): # windows
298 return url[8:] # 8 is len('file:///') 277 return url[8:] # 8 is len('file:///')
@@ -309,11 +288,10 @@ non-anonymised) file to output archive'))
309 ''' 288 '''
310 Add a file to the list if its format is supported 289 Add a file to the list if its format is supported
311 ''' 290 '''
312 cf = CFile(filename, self.backup, add2archive=self.add2archive, 291 cf = CFile(filename, add2archive=self.add2archive,
313 low_pdf_quality=self.pdf_quality) 292 low_pdf_quality=self.pdf_quality)
314 if cf.file: # if the file is supported by the mat 293 if cf.file: # if the file is supported by the mat
315 self.liststore.append([cf, os.path.dirname(cf.file.filename) + os.path.sep, 294 self.liststore.append([cf, cf.file.basename, _('Unknown')])
316 cf.file.basename, cf.file.mime, _('unknow'), 'None', -1])
317 return False 295 return False
318 return True 296 return True
319 297
@@ -329,18 +307,10 @@ non-anonymised) file to output archive'))
329 307
330 def __invert(self, button, name): 308 def __invert(self, button, name):
331 ''' Invert a preference state ''' 309 ''' Invert a preference state '''
332 if name == 'force': 310 if name == 'pdf_quality':
333 self.force = not self.force
334 elif name == 'pdf_quality':
335 self.pdf_quality = not self.pdf_quality 311 self.pdf_quality = not self.pdf_quality
336 elif name == 'add2archive': 312 elif name == 'add2archive':
337 self.add2archive = not self.add2archive 313 self.add2archive = not self.add2archive
338 elif name == 'backup':
339 self.backup = not self.backup
340 for line in xrange(len(self.liststore)):
341 # change the "backup" property of all files
342 self.liststore[line][0].file.backup = self.backup
343 self.treeview.get_column(4).set_visible(self.backup)
344 314
345 def populate(self, filenames): 315 def populate(self, filenames):
346 ''' 316 '''
@@ -385,7 +355,7 @@ non-anonymised) file to output archive'))
385 treeview = Gtk.TreeView(store) 355 treeview = Gtk.TreeView(store)
386 vbox.pack_start(treeview, True, True, 0) 356 vbox.pack_start(treeview, True, True, 0)
387 357
388 #create column 358 # create column
389 rendererText = Gtk.CellRendererText() 359 rendererText = Gtk.CellRendererText()
390 column = Gtk.TreeViewColumn(_('Filename'), rendererText, text=0) 360 column = Gtk.TreeViewColumn(_('Filename'), rendererText, text=0)
391 treeview.append_column(column) 361 treeview.append_column(column)
@@ -397,37 +367,29 @@ non-anonymised) file to output archive'))
397 if not click: # Ok button 367 if not click: # Ok button
398 dialog.destroy() 368 dialog.destroy()
399 369
400 def mat_check(self, iterator): 370 def __mat_check(self, iterator):
401 ''' Check elements in iterator are clean ''' 371 ''' Check elements in iterator are clean '''
402 for line in iterator: # for each file in selection 372 for line in iterator: # for each file in selection
403 msg = _('Checking %s') % self.liststore[line][2].decode('utf-8', 'replace') 373 msg = _('Checking %s') % self.liststore[line][1].decode('utf-8', 'replace')
404 logging.info(msg) 374 logging.info(msg)
405 self.statusbar.push(0, msg) 375 self.statusbar.push(0, msg)
406 376 if self.liststore[line][0].file.is_clean():
407 if self.force or self.liststore[line][6]: 377 self.liststore[line][2] = _('Clean')
408 if self.liststore[line][0].file.is_clean(): 378 else:
409 self.liststore[line][4] = _('Clean') 379 self.liststore[line][2] = _('Dirty')
410 self.liststore[line][6] = 0 380 logging.info('%s is %s' % (self.liststore[line][1], self.liststore[line][2]))
411 else: 381 yield True
412 self.liststore[line][4] = _('Dirty')
413 self.liststore[line][6] = 1
414 logging.info('%s is %s' % (self.liststore[line][1], self.liststore[line][4]))
415 yield True
416 self.statusbar.push(0, _('Ready')) 382 self.statusbar.push(0, _('Ready'))
417 yield False 383 yield False
418 384
419 def mat_clean(self, iterator): 385 def __mat_clean(self, iterator):
420 ''' Clean elements in iterator ''' 386 ''' Clean elements in iterator '''
421 for line in iterator: # for each file in selection 387 for line in iterator: # for each file in selection
422 msg = _('Cleaning %s') % self.liststore[line][2].decode('utf-8', 'replace') 388 msg = _('Cleaning %s') % self.liststore[line][2].decode('utf-8', 'replace')
423 logging.info(msg) 389 logging.info(msg)
424 self.statusbar.push(0, msg) 390 self.statusbar.push(0, msg)
425 if self.force or self.liststore[line][6]: 391 if self.liststore[line][0].file.remove_all():
426 if self.liststore[line][0].file.remove_all(): 392 self.liststore[line][2] = _('Clean')
427 self.liststore[line][4] = _('Clean')
428 self.liststore[line][6] = 0
429 if self.backup: # the backup copy state
430 self.liststore[line][5] = os.path.basename(self.liststore[line][0].file.output)
431 yield True 393 yield True
432 self.statusbar.push(0, _('Ready')) 394 self.statusbar.push(0, _('Ready'))
433 yield False 395 yield False
@@ -437,7 +399,7 @@ if __name__ == '__main__':
437 399
438 gui = GUI() 400 gui = GUI()
439 401
440 #Add files from command line 402 # Add files from command line
441 infiles = [arg for arg in sys.argv[1:] if os.path.exists(arg)] 403 infiles = [arg for arg in sys.argv[1:] if os.path.exists(arg)]
442 if infiles: 404 if infiles:
443 task = gui.populate(infiles) 405 task = gui.populate(infiles)