diff options
| author | jvoisin | 2011-07-26 14:06:38 +0200 |
|---|---|---|
| committer | jvoisin | 2011-07-26 14:06:38 +0200 |
| commit | e62ae6a87f630cbd389cf1b75672b06cd56973c8 (patch) | |
| tree | 5433e5bde0d0448795626190f8014c61b38ac1c5 /gui.py | |
| parent | f6e3d57173604dab7228c830e84415ead02e169b (diff) | |
Pyflakes and pep8 validation
Diffstat (limited to '')
| -rw-r--r-- | gui.py | 74 |
1 files changed, 39 insertions, 35 deletions
| @@ -1,21 +1,21 @@ | |||
| 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
| 2 | 2 | ||
| 3 | from gi.repository import Gtk, GObject, Gdk | 3 | from gi.repository import Gtk, GObject |
| 4 | import os | 4 | import os |
| 5 | import glob | ||
| 6 | import logging | 5 | import logging |
| 7 | from lib import mat | 6 | from lib import mat |
| 8 | 7 | ||
| 9 | __version__ = '0.1' | 8 | __version__ = '0.1' |
| 10 | __author__ = 'jvoisin' | 9 | __author__ = 'jvoisin' |
| 11 | 10 | ||
| 12 | logging.basicConfig(level = mat.LOGGING_LEVEL) | 11 | logging.basicConfig(level=mat.LOGGING_LEVEL) |
| 13 | 12 | ||
| 14 | SUPPORTED = (('image/png', 'image/jpeg', 'image/gif', | 13 | SUPPORTED = (('image/png', 'image/jpeg', 'image/gif', |
| 15 | 'misc/pdf'), | 14 | 'misc/pdf'), |
| 16 | ('*.jpg', '*.jpeg', '*.png', '*.bmp', '*.pdf', | 15 | ('*.jpg', '*.jpeg', '*.png', '*.bmp', '*.pdf', |
| 17 | '*.tar', '*.tar.bz2', '*.tar.gz', '*.mp3')) | 16 | '*.tar', '*.tar.bz2', '*.tar.gz', '*.mp3')) |
| 18 | 17 | ||
| 18 | |||
| 19 | class cfile(GObject.GObject): | 19 | class cfile(GObject.GObject): |
| 20 | ''' | 20 | ''' |
| 21 | Contain the class-file of the file "path" | 21 | Contain the class-file of the file "path" |
| @@ -29,6 +29,7 @@ class cfile(GObject.GObject): | |||
| 29 | except: | 29 | except: |
| 30 | self.file = None | 30 | self.file = None |
| 31 | 31 | ||
| 32 | |||
| 32 | class ListStoreApp: | 33 | class ListStoreApp: |
| 33 | ''' | 34 | ''' |
| 34 | Main GUI class | 35 | Main GUI class |
| @@ -40,7 +41,8 @@ class ListStoreApp: | |||
| 40 | self.add2archive = True | 41 | self.add2archive = True |
| 41 | 42 | ||
| 42 | self.window = Gtk.Window() | 43 | self.window = Gtk.Window() |
| 43 | self.window.set_title('Metadata Anonymisation Toolkit %s' % __version__) | 44 | self.window.set_title('Metadata Anonymisation Toolkit %s' % |
| 45 | __version__) | ||
| 44 | self.window.connect('destroy', Gtk.main_quit) | 46 | self.window.connect('destroy', Gtk.main_quit) |
| 45 | self.window.set_default_size(800, 600) | 47 | self.window.set_default_size(800, 600) |
| 46 | 48 | ||
| @@ -55,13 +57,12 @@ class ListStoreApp: | |||
| 55 | vbox.pack_start(content, True, True, 0) | 57 | vbox.pack_start(content, True, True, 0) |
| 56 | 58 | ||
| 57 | #parser.class - name - type - cleaned | 59 | #parser.class - name - type - cleaned |
| 58 | self.liststore= Gtk.ListStore(cfile ,str, str, str) | 60 | self.liststore= Gtk.ListStore(cfile, str, str, str) |
| 59 | 61 | ||
| 60 | treeview = Gtk.TreeView(model=self.liststore) | 62 | treeview = Gtk.TreeView(model=self.liststore) |
| 61 | treeview.set_search_column(1) #name column is searchable | 63 | treeview.set_search_column(1) # name column is searchable |
| 62 | treeview.set_rules_hint(True) #alternate colors for rows | 64 | treeview.set_rules_hint(True) # alternate colors for rows |
| 63 | treeview.set_rubber_banding(True) #mouse selection | 65 | treeview.set_rubber_banding(True) # mouse selection |
| 64 | treeview.drag_dest_set(Gtk.DestDefaults.ALL, None, Gdk.DragAction.COPY) | ||
| 65 | self.add_columns(treeview) | 66 | self.add_columns(treeview) |
| 66 | self.selection = treeview.get_selection() | 67 | self.selection = treeview.get_selection() |
| 67 | self.selection.set_mode(Gtk.SelectionMode.MULTIPLE) | 68 | self.selection.set_mode(Gtk.SelectionMode.MULTIPLE) |
| @@ -80,12 +81,12 @@ class ListStoreApp: | |||
| 80 | ''' | 81 | ''' |
| 81 | toolbar = Gtk.Toolbar() | 82 | toolbar = Gtk.Toolbar() |
| 82 | 83 | ||
| 83 | toolbutton = Gtk.ToolButton(label = 'Add', stock_id=Gtk.STOCK_ADD) | 84 | toolbutton = Gtk.ToolButton(label='Add', stock_id=Gtk.STOCK_ADD) |
| 84 | toolbutton.connect('clicked', self.add_files) | 85 | toolbutton.connect('clicked', self.add_files) |
| 85 | toolbutton.set_tooltip_text('Add files') | 86 | toolbutton.set_tooltip_text('Add files') |
| 86 | toolbar.add(toolbutton) | 87 | toolbar.add(toolbutton) |
| 87 | 88 | ||
| 88 | toolbutton = Gtk.ToolButton(label = 'Clean', | 89 | toolbutton = Gtk.ToolButton(label='Clean', |
| 89 | stock_id=Gtk.STOCK_PRINT_REPORT) | 90 | stock_id=Gtk.STOCK_PRINT_REPORT) |
| 90 | toolbutton.connect('clicked', self.mat_clean) | 91 | toolbutton.connect('clicked', self.mat_clean) |
| 91 | toolbutton.set_tooltip_text('Clean selected files without data loss') | 92 | toolbutton.set_tooltip_text('Clean selected files without data loss') |
| @@ -93,7 +94,8 @@ class ListStoreApp: | |||
| 93 | 94 | ||
| 94 | toolbutton = Gtk.ToolButton(label='Brute Clean', | 95 | toolbutton = Gtk.ToolButton(label='Brute Clean', |
| 95 | stock_id=Gtk.STOCK_PRINT_WARNING) | 96 | stock_id=Gtk.STOCK_PRINT_WARNING) |
| 96 | toolbutton.set_tooltip_text('Clean selected files with possible data loss') | 97 | toolbutton.set_tooltip_text('Clean selected files with possible data \ |
| 98 | loss') | ||
| 97 | toolbar.add(toolbutton) | 99 | toolbar.add(toolbutton) |
| 98 | 100 | ||
| 99 | toolbutton = Gtk.ToolButton(label='Check', stock_id=Gtk.STOCK_FIND) | 101 | toolbutton = Gtk.ToolButton(label='Check', stock_id=Gtk.STOCK_FIND) |
| @@ -117,8 +119,8 @@ class ListStoreApp: | |||
| 117 | 119 | ||
| 118 | for i, j in enumerate(colname): | 120 | for i, j in enumerate(colname): |
| 119 | filenameColumn = Gtk.CellRendererText() | 121 | filenameColumn = Gtk.CellRendererText() |
| 120 | column = Gtk.TreeViewColumn(j, filenameColumn, text=i+1) | 122 | column = Gtk.TreeViewColumn(j, filenameColumn, text=i + 1) |
| 121 | column.set_sort_column_id(i+1) | 123 | column.set_sort_column_id(i + 1) |
| 122 | treeview.append_column(column) | 124 | treeview.append_column(column) |
| 123 | 125 | ||
| 124 | def create_menu_item(self, name, func, menu, pix): | 126 | def create_menu_item(self, name, func, menu, pix): |
| @@ -156,8 +158,8 @@ class ListStoreApp: | |||
| 156 | Gtk.STOCK_QUIT) | 158 | Gtk.STOCK_QUIT) |
| 157 | 159 | ||
| 158 | edit_menu = self.create_sub_menu('Edit', menubar) | 160 | edit_menu = self.create_sub_menu('Edit', menubar) |
| 159 | self.create_menu_item('Clear the filelist', self.clear_model, edit_menu, | 161 | self.create_menu_item('Clear the filelist', self.clear_model, |
| 160 | Gtk.STOCK_REMOVE) | 162 | edit_menu, Gtk.STOCK_REMOVE) |
| 161 | self.create_menu_item('Preferences', self.preferences, edit_menu, | 163 | self.create_menu_item('Preferences', self.preferences, edit_menu, |
| 162 | Gtk.STOCK_PREFERENCES) | 164 | Gtk.STOCK_PREFERENCES) |
| 163 | 165 | ||
| @@ -181,9 +183,9 @@ class ListStoreApp: | |||
| 181 | ''' | 183 | ''' |
| 182 | filter = Gtk.FileFilter() | 184 | filter = Gtk.FileFilter() |
| 183 | filter.set_name('Supported files') | 185 | filter.set_name('Supported files') |
| 184 | for item in SUPPORTED[0]: #add by mime | 186 | for item in SUPPORTED[0]: # add by mime |
| 185 | filter.add_mime_type(item) | 187 | filter.add_mime_type(item) |
| 186 | for item in SUPPORTED[1]: #add by extension | 188 | for item in SUPPORTED[1]: # add by extension |
| 187 | filter.add_pattern(item) | 189 | filter.add_pattern(item) |
| 188 | return filter | 190 | return filter |
| 189 | 191 | ||
| @@ -195,8 +197,7 @@ class ListStoreApp: | |||
| 195 | title='Choose files', | 197 | title='Choose files', |
| 196 | parent=None, | 198 | parent=None, |
| 197 | action=Gtk.FileChooserAction.OPEN, | 199 | action=Gtk.FileChooserAction.OPEN, |
| 198 | buttons=(Gtk.STOCK_OK, 0, Gtk.STOCK_CANCEL, 1) | 200 | buttons=(Gtk.STOCK_OK, 0, Gtk.STOCK_CANCEL, 1)) |
| 199 | ) | ||
| 200 | chooser.set_default_response(0) | 201 | chooser.set_default_response(0) |
| 201 | chooser.set_select_multiple(True) | 202 | chooser.set_select_multiple(True) |
| 202 | 203 | ||
| @@ -208,15 +209,15 @@ class ListStoreApp: | |||
| 208 | 209 | ||
| 209 | response = chooser.run() | 210 | response = chooser.run() |
| 210 | 211 | ||
| 211 | if response is 0: #Gtk.STOCK_OK | 212 | if response is 0: # Gtk.STOCK_OK |
| 212 | filenames = chooser.get_filenames() | 213 | filenames = chooser.get_filenames() |
| 213 | chooser.destroy() | 214 | chooser.destroy() |
| 214 | for item in filenames: | 215 | for item in filenames: |
| 215 | if os.path.isdir(item): #directory | 216 | if os.path.isdir(item): # directory |
| 216 | for root, dirs, files in os.walk(item): | 217 | for root, dirs, files in os.walk(item): |
| 217 | for name in files: | 218 | for name in files: |
| 218 | self.populate(os.path.join(root, name)) | 219 | self.populate(os.path.join(root, name)) |
| 219 | else: #regular file | 220 | else: # regular file |
| 220 | self.populate(item) | 221 | self.populate(item) |
| 221 | chooser.destroy() | 222 | chooser.destroy() |
| 222 | 223 | ||
| @@ -226,7 +227,8 @@ class ListStoreApp: | |||
| 226 | ''' | 227 | ''' |
| 227 | cf = cfile(item, self.backup, self.add2archive) | 228 | cf = cfile(item, self.backup, self.add2archive) |
| 228 | if cf.file is not None: | 229 | if cf.file is not None: |
| 229 | self.liststore.append([cf, cf.file.filename, cf.file.mime,'unknow']) | 230 | self.liststore.append([cf, cf.file.filename, |
| 231 | cf.file.mime, 'unknow']) | ||
| 230 | 232 | ||
| 231 | def about(self, button=None): | 233 | def about(self, button=None): |
| 232 | w = Gtk.AboutDialog() | 234 | w = Gtk.AboutDialog() |
| @@ -235,7 +237,7 @@ class ListStoreApp: | |||
| 235 | w.set_comments('This software was coded during the GSoC 2011') | 237 | w.set_comments('This software was coded during the GSoC 2011') |
| 236 | w.set_website('https://gitweb.torproject.org/user/jvoisin/mat.git') | 238 | w.set_website('https://gitweb.torproject.org/user/jvoisin/mat.git') |
| 237 | w.set_website_label('Website') | 239 | w.set_website_label('Website') |
| 238 | w.set_authors(['Julien (jvoisin) Voisin',]) | 240 | w.set_authors(['Julien (jvoisin) Voisin', ]) |
| 239 | w.set_program_name('Metadata Anonymistion Toolkit') | 241 | w.set_program_name('Metadata Anonymistion Toolkit') |
| 240 | click = w.run() | 242 | click = w.run() |
| 241 | if click: | 243 | if click: |
| @@ -250,29 +252,30 @@ class ListStoreApp: | |||
| 250 | hbox = Gtk.HBox() | 252 | hbox = Gtk.HBox() |
| 251 | content_area.pack_start(hbox, False, False, 0) | 253 | content_area.pack_start(hbox, False, False, 0) |
| 252 | icon = Gtk.Image(stock=Gtk.STOCK_PREFERENCES, | 254 | icon = Gtk.Image(stock=Gtk.STOCK_PREFERENCES, |
| 253 | icon_size=Gtk.IconSize.DIALOG)#the little picture on the left | 255 | icon_size=Gtk.IconSize.DIALOG) # the little picture on the left |
| 254 | 256 | ||
| 255 | hbox.pack_start(icon, False, False, 0) | 257 | hbox.pack_start(icon, False, False, 0) |
| 256 | 258 | ||
| 257 | table = Gtk.Table(3, 2, False)#nb rows, nb lines | 259 | table = Gtk.Table(3, 2, False) # nb rows, nb lines |
| 258 | table.set_row_spacings(4) | 260 | table.set_row_spacings(4) |
| 259 | table.set_col_spacings(4) | 261 | table.set_col_spacings(4) |
| 260 | hbox.pack_start(table, True, True, 0) | 262 | hbox.pack_start(table, True, True, 0) |
| 261 | 263 | ||
| 262 | force = Gtk.CheckButton('Force Clean', False) | 264 | force = Gtk.CheckButton('Force Clean', False) |
| 263 | force.connect('toggled', self.invert, 'force') | 265 | force.connect('toggled', self.invert, 'force') |
| 264 | force.set_tooltip_text('Do not check if already clean before cleaning.') | 266 | force.set_tooltip_text('Do not check if already clean before cleaning') |
| 265 | force.set_active(self.force) | 267 | force.set_active(self.force) |
| 266 | 268 | ||
| 267 | backup = Gtk.CheckButton('Backup', False) | 269 | backup = Gtk.CheckButton('Backup', False) |
| 268 | backup.connect('toggled', self.invert, 'backup') | 270 | backup.connect('toggled', self.invert, 'backup') |
| 269 | backup.set_tooltip_text('Keep a backup copy.') | 271 | backup.set_tooltip_text('Keep a backup copy') |
| 270 | backup.set_active(self.backup) | 272 | backup.set_active(self.backup) |
| 271 | 273 | ||
| 272 | add2archive = Gtk.CheckButton('Add unsupported file to archives', False) | 274 | add2archive = Gtk.CheckButton('Add unsupported file to archives', |
| 275 | False) | ||
| 273 | add2archive.connect('toggled', self.invert, 'add2archive') | 276 | add2archive.connect('toggled', self.invert, 'add2archive') |
| 274 | add2archive.set_tooltip_text('Add non-supported (and so non-anonymised)\ | 277 | add2archive.set_tooltip_text('Add non-supported (and so \ |
| 275 | file to outputed archive.') | 278 | non-anonymised) file to outputed archive') |
| 276 | add2archive.set_active(self.add2archive) | 279 | add2archive.set_active(self.add2archive) |
| 277 | 280 | ||
| 278 | table.attach_defaults(force, 0, 1, 0, 1) | 281 | table.attach_defaults(force, 0, 1, 0, 1) |
| @@ -281,10 +284,10 @@ class ListStoreApp: | |||
| 281 | 284 | ||
| 282 | hbox.show_all() | 285 | hbox.show_all() |
| 283 | response = dialog.run() | 286 | response = dialog.run() |
| 284 | if response is 0:#Gtk.STOCK_OK | 287 | if response is 0: # Gtk.STOCK_OK |
| 285 | dialog.destroy() | 288 | dialog.destroy() |
| 286 | 289 | ||
| 287 | def invert(self, button, name): #Still not better :/ | 290 | def invert(self, button, name): # still not better :/ |
| 288 | if name is 'force': | 291 | if name is 'force': |
| 289 | self.force = not self.force | 292 | self.force = not self.force |
| 290 | elif name is 'ugly': | 293 | elif name is 'ugly': |
| @@ -338,8 +341,9 @@ class ListStoreApp: | |||
| 338 | self.liststore[i][0].file.remove_all_ugly() | 341 | self.liststore[i][0].file.remove_all_ugly() |
| 339 | self.liststore[i][3] = 'clean' | 342 | self.liststore[i][3] = 'clean' |
| 340 | 343 | ||
| 344 | |||
| 341 | def main(): | 345 | def main(): |
| 342 | app = ListStoreApp() | 346 | ListStoreApp() |
| 343 | Gtk.main() | 347 | Gtk.main() |
| 344 | 348 | ||
| 345 | if __name__ == '__main__': | 349 | if __name__ == '__main__': |
