diff options
| -rw-r--r-- | gui.py | 87 |
1 files changed, 47 insertions, 40 deletions
| @@ -1,26 +1,17 @@ | |||
| 1 | #!/usr/bin/python2.7 | 1 | #!/usr/bin/python2.7 |
| 2 | 2 | ||
| 3 | from gi.repository import Gtk, GObject | 3 | from gi.repository import Gtk, GObject |
| 4 | import os | ||
| 4 | import cli | 5 | import cli |
| 6 | import mimetypes | ||
| 7 | from lib import mat | ||
| 5 | 8 | ||
| 6 | __version__ = '0.1' | 9 | __version__ = '0.1' |
| 7 | __author__ = 'jvoisin' | 10 | __author__ = 'jvoisin' |
| 8 | 11 | ||
| 9 | class File: | 12 | SUPPORTED = (('image/png', 'image/jpeg', 'image/gif'), |
| 10 | ''' | 13 | ('*.jpg', '*.jpeg', '*.png', '*.tiff', '*.pdf', |
| 11 | Represent a File | 14 | '*.tar', '*.tar.bz2', '*.tar.gz', '*.mp3')) |
| 12 | ''' | ||
| 13 | def __init__(self, name, fileformat, cleaned): | ||
| 14 | self.name = name | ||
| 15 | self.fileformat = fileformat | ||
| 16 | self.cleaned = cleaned | ||
| 17 | |||
| 18 | # initial data we use to fill in the store | ||
| 19 | DATA = [ | ||
| 20 | File('test.txt', 'PLAIN TEXT', 0), | ||
| 21 | File('ugly.pdf', 'UGLY_PDF', 2), | ||
| 22 | File('ugly.doc', 'UGLY_OL2', 1), | ||
| 23 | ] | ||
| 24 | 15 | ||
| 25 | class ListStoreApp: | 16 | class ListStoreApp: |
| 26 | ''' | 17 | ''' |
| @@ -32,7 +23,8 @@ class ListStoreApp: | |||
| 32 | NUM_COLUMNS) = range(4) | 23 | NUM_COLUMNS) = range(4) |
| 33 | 24 | ||
| 34 | def __init__(self): | 25 | def __init__(self): |
| 35 | self.filenames = [] | 26 | self.files = [] |
| 27 | self.backup = True | ||
| 36 | 28 | ||
| 37 | self.window = Gtk.Window() | 29 | self.window = Gtk.Window() |
| 38 | self.window.set_title('Metadata Anonymisation Toolkit %s' % __version__) | 30 | self.window.set_title('Metadata Anonymisation Toolkit %s' % __version__) |
| @@ -45,7 +37,7 @@ class ListStoreApp: | |||
| 45 | sw = Gtk.ScrolledWindow() | 37 | sw = Gtk.ScrolledWindow() |
| 46 | vbox.pack_start(sw, True, True, 0) | 38 | vbox.pack_start(sw, True, True, 0) |
| 47 | 39 | ||
| 48 | self.create_model() | 40 | self.model = Gtk.ListStore(str, str, str) #name - type - cleaned |
| 49 | 41 | ||
| 50 | treeview = Gtk.TreeView(model=self.model) | 42 | treeview = Gtk.TreeView(model=self.model) |
| 51 | treeview.set_rules_hint(True) | 43 | treeview.set_rules_hint(True) |
| @@ -65,7 +57,7 @@ class ListStoreApp: | |||
| 65 | toolbar = Gtk.Toolbar() | 57 | toolbar = Gtk.Toolbar() |
| 66 | 58 | ||
| 67 | toolbutton = Gtk.ToolButton(label = 'Add', stock_id=Gtk.STOCK_ADD) | 59 | toolbutton = Gtk.ToolButton(label = 'Add', stock_id=Gtk.STOCK_ADD) |
| 68 | toolbutton.connect('clicked', self.add_file) | 60 | toolbutton.connect('clicked', self.add_files) |
| 69 | toolbar.add(toolbutton) | 61 | toolbar.add(toolbutton) |
| 70 | 62 | ||
| 71 | toolbutton = Gtk.ToolButton(label = 'Clean', stock_id=Gtk.STOCK_CLEAR) | 63 | toolbutton = Gtk.ToolButton(label = 'Clean', stock_id=Gtk.STOCK_CLEAR) |
| @@ -86,20 +78,6 @@ class ListStoreApp: | |||
| 86 | vbox.pack_start(toolbar, False, False, 0) | 78 | vbox.pack_start(toolbar, False, False, 0) |
| 87 | return vbox | 79 | return vbox |
| 88 | 80 | ||
| 89 | def create_model(self): | ||
| 90 | ''' | ||
| 91 | Populate the sheet | ||
| 92 | ''' | ||
| 93 | self.model = Gtk.ListStore(str, str, str) #name - type - cleaned | ||
| 94 | for item in DATA: | ||
| 95 | if item.cleaned is 0: | ||
| 96 | state = 'clean' | ||
| 97 | elif item.cleaned is 1: | ||
| 98 | state = 'dirty' | ||
| 99 | else: | ||
| 100 | state = 'unknow' | ||
| 101 | self.model.append( [item.name, item.fileformat, state] ) | ||
| 102 | |||
| 103 | def add_columns(self, treeview): | 81 | def add_columns(self, treeview): |
| 104 | ''' | 82 | ''' |
| 105 | Crete the columns | 83 | Crete the columns |
| @@ -125,26 +103,55 @@ class ListStoreApp: | |||
| 125 | column.set_sort_column_id(self.COLUMN_CLEANED) | 103 | column.set_sort_column_id(self.COLUMN_CLEANED) |
| 126 | treeview.append_column(column) | 104 | treeview.append_column(column) |
| 127 | 105 | ||
| 128 | def add_file(self, button): | 106 | def create_filter(self): |
| 107 | ''' | ||
| 108 | Return a filter for | ||
| 109 | supported content | ||
| 110 | ''' | ||
| 111 | filter = Gtk.FileFilter() | ||
| 112 | filter.set_name('Supported files') | ||
| 113 | for item in SUPPORTED[0]: #add by mime | ||
| 114 | filter.add_mime_type(item) | ||
| 115 | for item in SUPPORTED[1]: #add by extension | ||
| 116 | filter.add_pattern(item) | ||
| 117 | return filter | ||
| 118 | |||
| 119 | def add_files(self, button): | ||
| 129 | chooser = Gtk.FileChooserDialog( | 120 | chooser = Gtk.FileChooserDialog( |
| 130 | title='Choose files', | 121 | title='Choose files', |
| 131 | parent=None, | 122 | parent=None, |
| 132 | action=Gtk.FileChooserAction.OPEN, | 123 | action=Gtk.FileChooserAction.OPEN, |
| 133 | buttons=(Gtk.STOCK_OK, 0, Gtk.STOCK_CANCEL, 1) | 124 | buttons=(Gtk.STOCK_OK, 0, Gtk.STOCK_CANCEL, 1) |
| 134 | ) | 125 | ) |
| 126 | chooser.set_default_response(0) | ||
| 135 | chooser.set_select_multiple(True) | 127 | chooser.set_select_multiple(True) |
| 128 | |||
| 129 | filter = Gtk.FileFilter() | ||
| 130 | filter.set_name('All files') | ||
| 131 | filter.add_pattern('*') | ||
| 132 | chooser.add_filter(filter) | ||
| 133 | |||
| 134 | chooser.add_filter(self.create_filter()) | ||
| 135 | |||
| 136 | response = chooser.run() | 136 | response = chooser.run() |
| 137 | 137 | ||
| 138 | if response is 0: | 138 | if response is 0: |
| 139 | self.filenames = chooser.get_filenames() | 139 | filenames = chooser.get_filenames() |
| 140 | self.populate() | 140 | self.populate(filenames) |
| 141 | elif response is 1: | ||
| 142 | pass | ||
| 143 | chooser.destroy() | 141 | chooser.destroy() |
| 144 | 142 | ||
| 145 | def populate(self): | 143 | def populate(self, filenames): |
| 146 | for item in self.filenames: | 144 | for item in filenames: |
| 147 | self.model.append([item, 'pouet', 'dirty']) | 145 | name = os.path.basename(item) |
| 146 | fileformat = mimetypes.guess_type(item)[0] | ||
| 147 | try: | ||
| 148 | class_file = mat.create_class_file(item, self.backup) | ||
| 149 | except: | ||
| 150 | class_file = None | ||
| 151 | |||
| 152 | if class_file is not None: | ||
| 153 | self.files.append(class_file) | ||
| 154 | self.model.append([name, fileformat, 'dirty']) | ||
| 148 | 155 | ||
| 149 | def main(): | 156 | def main(): |
| 150 | app = ListStoreApp() | 157 | app = ListStoreApp() |
