diff options
Diffstat (limited to 'mat-gui')
| -rwxr-xr-x | mat-gui | 200 |
1 files changed, 102 insertions, 98 deletions
| @@ -5,8 +5,9 @@ | |||
| 5 | Metadata anonymisation toolkit - GUI edition | 5 | Metadata anonymisation toolkit - GUI edition |
| 6 | ''' | 6 | ''' |
| 7 | 7 | ||
| 8 | import gtk | 8 | import gi |
| 9 | import gobject | 9 | from gi.repository import GObject |
| 10 | from gi.repository import Gtk, Gdk, GdkPixbuf | ||
| 10 | 11 | ||
| 11 | import gettext | 12 | import gettext |
| 12 | #import locale | 13 | #import locale |
| @@ -28,7 +29,7 @@ class CFile(object): | |||
| 28 | ''' | 29 | ''' |
| 29 | Contain the "parser" class of the file "filename" | 30 | Contain the "parser" class of the file "filename" |
| 30 | This class exist just to be "around" my parser.Generic_parser class, | 31 | This class exist just to be "around" my parser.Generic_parser class, |
| 31 | since the gtk.ListStore does not accept it. | 32 | since the Gtk.ListStore does not accept it. |
| 32 | ''' | 33 | ''' |
| 33 | def __init__(self, filename, backup, **kwargs): | 34 | def __init__(self, filename, backup, **kwargs): |
| 34 | try: | 35 | try: |
| @@ -49,32 +50,32 @@ class GUI: | |||
| 49 | self.pdf_quality = False | 50 | self.pdf_quality = False |
| 50 | 51 | ||
| 51 | # Main window | 52 | # Main window |
| 52 | self.window = gtk.Window() | 53 | self.window = Gtk.Window() |
| 53 | self.window.set_title('Metadata Anonymisation Toolkit') | 54 | self.window.set_title('Metadata Anonymisation Toolkit') |
| 54 | self.window.connect('destroy', gtk.main_quit) | 55 | self.window.connect('destroy', Gtk.main_quit) |
| 55 | self.window.set_default_size(800, 600) | 56 | self.window.set_default_size(800, 600) |
| 56 | self.logo = mat.get_logo() | 57 | self.logo = mat.get_logo() |
| 57 | icon = gtk.gdk.pixbuf_new_from_file_at_size(self.logo, 50, 50) | 58 | icon = GdkPixbuf.Pixbuf.new_from_file_at_size(self.logo, 50, 50) |
| 58 | self.window.set_icon(icon) | 59 | self.window.set_icon(icon) |
| 59 | 60 | ||
| 60 | self.accelerator = gtk.AccelGroup() | 61 | self.accelerator = Gtk.AccelGroup() |
| 61 | self.window.add_accel_group(self.accelerator) | 62 | self.window.add_accel_group(self.accelerator) |
| 62 | 63 | ||
| 63 | vbox = gtk.VBox() | 64 | vbox = Gtk.VBox() |
| 64 | self.window.add(vbox) | 65 | self.window.add(vbox) |
| 65 | 66 | ||
| 66 | menubar = self.__create_menu() | 67 | menubar = self.__create_menu() |
| 67 | toolbar = self.__create_toolbar() | 68 | toolbar = self.__create_toolbar() |
| 68 | content = gtk.ScrolledWindow() | 69 | content = Gtk.ScrolledWindow() |
| 69 | content.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) | 70 | content.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) |
| 70 | vbox.pack_start(menubar, False, True, 0) | 71 | vbox.pack_start(menubar, False, True, 0) |
| 71 | vbox.pack_start(toolbar, False, True, 0) | 72 | vbox.pack_start(toolbar, False, True, 0) |
| 72 | vbox.pack_start(content, True, True, 0) | 73 | vbox.pack_start(content, True, True, 0) |
| 73 | 74 | ||
| 74 | # parser.class - name - path - type - cleaned | 75 | # parser.class - name - path - type - cleaned |
| 75 | self.liststore = gtk.ListStore(object, str, str, str, str, str) | 76 | self.liststore = Gtk.ListStore(object, str, str, str, str, str) |
| 76 | 77 | ||
| 77 | self.treeview = gtk.TreeView(model=self.liststore) | 78 | self.treeview = Gtk.TreeView(model=self.liststore) |
| 78 | self.treeview.set_search_column(1) # filename column is searchable | 79 | self.treeview.set_search_column(1) # filename column is searchable |
| 79 | self.treeview.set_rules_hint(True) # alternate colors for rows | 80 | self.treeview.set_rules_hint(True) # alternate colors for rows |
| 80 | self.treeview.set_rubber_banding(True) # mouse selection | 81 | self.treeview.set_rubber_banding(True) # mouse selection |
| @@ -82,16 +83,19 @@ class GUI: | |||
| 82 | self.treeview.connect('row-activated', self.__popup_metadata) | 83 | self.treeview.connect('row-activated', self.__popup_metadata) |
| 83 | self.treeview.connect('drag_data_received', | 84 | self.treeview.connect('drag_data_received', |
| 84 | self.__on_drag_data_received) | 85 | self.__on_drag_data_received) |
| 85 | self.treeview.drag_dest_set(gtk.DEST_DEFAULT_MOTION | | 86 | self.treeview.drag_dest_set(Gtk.DestDefaults.MOTION | |
| 86 | gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP, | 87 | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, |
| 87 | [('text/uri-list', 0, 80), ], gtk.gdk.ACTION_COPY) | 88 | [], Gdk.DragAction.COPY) |
| 89 | targets = Gtk.TargetList.new([]) | ||
| 90 | targets.add_uri_targets(80) | ||
| 91 | self.treeview.drag_dest_set_target_list(targets) | ||
| 88 | self.__add_columns() | 92 | self.__add_columns() |
| 89 | self.selection = self.treeview.get_selection() | 93 | self.selection = self.treeview.get_selection() |
| 90 | self.selection.set_mode(gtk.SELECTION_MULTIPLE) | 94 | self.selection.set_mode(Gtk.SelectionMode.MULTIPLE) |
| 91 | 95 | ||
| 92 | content.add(self.treeview) | 96 | content.add(self.treeview) |
| 93 | 97 | ||
| 94 | self.statusbar = gtk.Statusbar() | 98 | self.statusbar = Gtk.Statusbar() |
| 95 | self.statusbar.push(1, _('Ready')) | 99 | self.statusbar.push(1, _('Ready')) |
| 96 | vbox.pack_start(self.statusbar, False, False, 0) | 100 | vbox.pack_start(self.statusbar, False, False, 0) |
| 97 | 101 | ||
| @@ -101,32 +105,32 @@ class GUI: | |||
| 101 | ''' | 105 | ''' |
| 102 | Returns a vbox object, which contains a toolbar with buttons | 106 | Returns a vbox object, which contains a toolbar with buttons |
| 103 | ''' | 107 | ''' |
| 104 | toolbar = gtk.Toolbar() | 108 | toolbar = Gtk.Toolbar() |
| 105 | 109 | ||
| 106 | toolbutton = gtk.ToolButton(gtk.STOCK_ADD) | 110 | toolbutton = Gtk.ToolButton(Gtk.STOCK_ADD) |
| 107 | toolbutton.set_label(_('Add')) | 111 | toolbutton.set_label(_('Add')) |
| 108 | toolbutton.connect('clicked', self.__add_files) | 112 | toolbutton.connect('clicked', self.__add_files) |
| 109 | toolbutton.set_tooltip_text(_('Add files')) | 113 | toolbutton.set_tooltip_text(_('Add files')) |
| 110 | toolbar.add(toolbutton) | 114 | toolbar.add(toolbutton) |
| 111 | 115 | ||
| 112 | toolbutton = gtk.ToolButton(gtk.STOCK_CLEAR) | 116 | toolbutton = Gtk.ToolButton(Gtk.STOCK_CLEAR) |
| 113 | toolbutton.set_label(_('Clean')) | 117 | toolbutton.set_label(_('Clean')) |
| 114 | toolbutton.connect('clicked', self.__process_files, self.__mat_clean) | 118 | toolbutton.connect('clicked', self.__process_files, self.__mat_clean) |
| 115 | toolbutton.set_tooltip_text(_('Clean selected files')) | 119 | toolbutton.set_tooltip_text(_('Clean selected files')) |
| 116 | toolbar.add(toolbutton) | 120 | toolbar.add(toolbutton) |
| 117 | 121 | ||
| 118 | toolbutton = gtk.ToolButton(gtk.STOCK_FIND) | 122 | toolbutton = Gtk.ToolButton(Gtk.STOCK_FIND) |
| 119 | toolbutton.set_label(_('Check')) | 123 | toolbutton.set_label(_('Check')) |
| 120 | toolbutton.connect('clicked', self.__process_files, self.__mat_check) | 124 | toolbutton.connect('clicked', self.__process_files, self.__mat_check) |
| 121 | toolbutton.set_tooltip_text(_('Check selected files for harmful meta')) | 125 | toolbutton.set_tooltip_text(_('Check selected files for harmful meta')) |
| 122 | toolbar.add(toolbutton) | 126 | toolbar.add(toolbutton) |
| 123 | 127 | ||
| 124 | toolbutton = gtk.ToolButton(stock_id=gtk.STOCK_QUIT) | 128 | toolbutton = Gtk.ToolButton(stock_id=Gtk.STOCK_QUIT) |
| 125 | toolbutton.set_label(_('Quit')) | 129 | toolbutton.set_label(_('Quit')) |
| 126 | toolbutton.connect('clicked', gtk.main_quit) | 130 | toolbutton.connect('clicked', Gtk.main_quit) |
| 127 | toolbar.add(toolbutton) | 131 | toolbar.add(toolbutton) |
| 128 | 132 | ||
| 129 | vbox = gtk.VBox(spacing=3) | 133 | vbox = Gtk.VBox(spacing=3) |
| 130 | vbox.pack_start(toolbar, False, False, 0) | 134 | vbox.pack_start(toolbar, False, False, 0) |
| 131 | return vbox | 135 | return vbox |
| 132 | 136 | ||
| @@ -138,8 +142,8 @@ class GUI: | |||
| 138 | _('Cleaned file')] | 142 | _('Cleaned file')] |
| 139 | 143 | ||
| 140 | for i, j in enumerate(colname, 1): | 144 | for i, j in enumerate(colname, 1): |
| 141 | filename_column = gtk.CellRendererText() | 145 | filename_column = Gtk.CellRendererText() |
| 142 | column = gtk.TreeViewColumn(j, filename_column, text=i) | 146 | column = Gtk.TreeViewColumn(j, filename_column, text=i) |
| 143 | column.set_sort_column_id(i) | 147 | column.set_sort_column_id(i) |
| 144 | column.set_resizable(True) # column is resizeable | 148 | column.set_resizable(True) # column is resizeable |
| 145 | self.treeview.append_column(column) | 149 | self.treeview.append_column(column) |
| @@ -148,13 +152,13 @@ class GUI: | |||
| 148 | ''' | 152 | ''' |
| 149 | Create a MenuItem() like Preferences, Quit, Add, Clean, ... | 153 | Create a MenuItem() like Preferences, Quit, Add, Clean, ... |
| 150 | ''' | 154 | ''' |
| 151 | item = gtk.ImageMenuItem() | 155 | item = Gtk.ImageMenuItem() |
| 152 | if shortcut: | 156 | if shortcut: |
| 153 | key, mod = gtk.accelerator_parse(shortcut) | 157 | key, mod = Gtk.accelerator_parse(shortcut) |
| 154 | item.add_accelerator('activate', self.accelerator, | 158 | item.add_accelerator('activate', self.accelerator, |
| 155 | key, mod, gtk.ACCEL_VISIBLE) | 159 | key, mod, Gtk.AccelFlags.VISIBLE) |
| 156 | picture = gtk.Image() | 160 | picture = Gtk.Image() |
| 157 | picture.set_from_stock(pix, gtk.ICON_SIZE_MENU) | 161 | picture.set_from_stock(pix, Gtk.IconSize.MENU) |
| 158 | item.set_image(picture) | 162 | item.set_image(picture) |
| 159 | item.set_label('_' + name) | 163 | item.set_label('_' + name) |
| 160 | item.set_use_underline(True) | 164 | item.set_use_underline(True) |
| @@ -165,8 +169,8 @@ class GUI: | |||
| 165 | ''' | 169 | ''' |
| 166 | Create a submenu like File, Edit, Clean, ... | 170 | Create a submenu like File, Edit, Clean, ... |
| 167 | ''' | 171 | ''' |
| 168 | submenu = gtk.Menu() | 172 | submenu = Gtk.Menu() |
| 169 | menuitem = gtk.MenuItem() | 173 | menuitem = Gtk.MenuItem() |
| 170 | menuitem.set_submenu(submenu) | 174 | menuitem.set_submenu(submenu) |
| 171 | menuitem.set_label('_' + name) | 175 | menuitem.set_label('_' + name) |
| 172 | menuitem.set_use_underline(True) | 176 | menuitem.set_use_underline(True) |
| @@ -177,39 +181,39 @@ class GUI: | |||
| 177 | ''' | 181 | ''' |
| 178 | Return a MenuBar | 182 | Return a MenuBar |
| 179 | ''' | 183 | ''' |
| 180 | menubar = gtk.MenuBar() | 184 | menubar = Gtk.MenuBar() |
| 181 | 185 | ||
| 182 | file_menu = self.__create_sub_menu(_('Files'), menubar) | 186 | file_menu = self.__create_sub_menu(_('Files'), menubar) |
| 183 | self.__create_menu_item(_('Add files'), self.__add_files, file_menu, | 187 | self.__create_menu_item(_('Add files'), self.__add_files, file_menu, |
| 184 | gtk.STOCK_ADD, '<Control>O') | 188 | Gtk.STOCK_ADD, '<Control>O') |
| 185 | self.__create_menu_item(_('Quit'), gtk.main_quit, file_menu, | 189 | self.__create_menu_item(_('Quit'), Gtk.main_quit, file_menu, |
| 186 | gtk.STOCK_QUIT, '<Control>Q') | 190 | Gtk.STOCK_QUIT, '<Control>Q') |
| 187 | 191 | ||
| 188 | edit_menu = self.__create_sub_menu(_('Edit'), menubar) | 192 | edit_menu = self.__create_sub_menu(_('Edit'), menubar) |
| 189 | self.__create_menu_item(_('Clear the filelist'), | 193 | self.__create_menu_item(_('Clear the filelist'), |
| 190 | lambda x: self.liststore.clear(), edit_menu, gtk.STOCK_REMOVE, | 194 | lambda x: self.liststore.clear(), edit_menu, Gtk.STOCK_REMOVE, |
| 191 | None) | 195 | None) |
| 192 | self.__create_menu_item(_('Preferences'), self.__preferences, | 196 | self.__create_menu_item(_('Preferences'), self.__preferences, |
| 193 | edit_menu, gtk.STOCK_PREFERENCES, '<Control>P') | 197 | edit_menu, Gtk.STOCK_PREFERENCES, '<Control>P') |
| 194 | 198 | ||
| 195 | process_menu = self.__create_sub_menu(_('Process'), menubar) | 199 | process_menu = self.__create_sub_menu(_('Process'), menubar) |
| 196 | item = gtk.ImageMenuItem() | 200 | item = Gtk.ImageMenuItem() |
| 197 | key, mod = gtk.accelerator_parse('<Control>L') | 201 | key, mod = Gtk.accelerator_parse('<Control>L') |
| 198 | item.add_accelerator('activate', self.accelerator, | 202 | item.add_accelerator('activate', self.accelerator, |
| 199 | key, mod, gtk.ACCEL_VISIBLE) | 203 | key, mod, Gtk.AccelFlags.VISIBLE) |
| 200 | picture = gtk.Image() | 204 | picture = Gtk.Image() |
| 201 | picture.set_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_MENU) | 205 | picture.set_from_stock(Gtk.STOCK_CLEAR, Gtk.IconSize.MENU) |
| 202 | item.set_image(picture) | 206 | item.set_image(picture) |
| 203 | item.set_label(_('Clean')) | 207 | item.set_label(_('Clean')) |
| 204 | item.connect('activate', self.__process_files, self.__mat_clean) | 208 | item.connect('activate', self.__process_files, self.__mat_clean) |
| 205 | process_menu.append(item) | 209 | process_menu.append(item) |
| 206 | 210 | ||
| 207 | item = gtk.ImageMenuItem() | 211 | item = Gtk.ImageMenuItem() |
| 208 | key, mod = gtk.accelerator_parse('<Control>h') | 212 | key, mod = Gtk.accelerator_parse('<Control>h') |
| 209 | item.add_accelerator('activate', self.accelerator, | 213 | item.add_accelerator('activate', self.accelerator, |
| 210 | key, mod, gtk.ACCEL_VISIBLE) | 214 | key, mod, Gtk.AccelFlags.VISIBLE) |
| 211 | picture = gtk.Image() | 215 | picture = Gtk.Image() |
| 212 | picture.set_from_stock(gtk.STOCK_FIND, gtk.ICON_SIZE_MENU) | 216 | picture.set_from_stock(Gtk.STOCK_FIND, Gtk.IconSize.MENU) |
| 213 | item.set_image(picture) | 217 | item.set_image(picture) |
| 214 | item.set_label(_('Check')) | 218 | item.set_label(_('Check')) |
| 215 | item.connect('activate', self.__process_files, self.__mat_check) | 219 | item.connect('activate', self.__process_files, self.__mat_check) |
| @@ -217,9 +221,9 @@ class GUI: | |||
| 217 | 221 | ||
| 218 | help_menu = self.__create_sub_menu(_('Help'), menubar) | 222 | help_menu = self.__create_sub_menu(_('Help'), menubar) |
| 219 | self.__create_menu_item(_('Supported formats'), self.__supported, | 223 | self.__create_menu_item(_('Supported formats'), self.__supported, |
| 220 | help_menu, gtk.STOCK_INFO, False) | 224 | help_menu, Gtk.STOCK_INFO, False) |
| 221 | self.__create_menu_item(_('About'), self.__about, help_menu, | 225 | self.__create_menu_item(_('About'), self.__about, help_menu, |
| 222 | gtk.STOCK_ABOUT, False) | 226 | Gtk.STOCK_ABOUT, False) |
| 223 | 227 | ||
| 224 | return menubar | 228 | return menubar |
| 225 | 229 | ||
| @@ -228,7 +232,7 @@ class GUI: | |||
| 228 | Remove selected files from the treeview | 232 | Remove selected files from the treeview |
| 229 | when the use hit the 'suppr' key | 233 | when the use hit the 'suppr' key |
| 230 | ''' | 234 | ''' |
| 231 | if gtk.gdk.keyval_name(event.keyval) == "Delete": | 235 | if Gdk.keyval_name(event.keyval) == "Delete": |
| 232 | rows = [] | 236 | rows = [] |
| 233 | self.selection.selected_foreach( | 237 | self.selection.selected_foreach( |
| 234 | lambda model, path, iter: rows.append(iter)) | 238 | lambda model, path, iter: rows.append(iter)) |
| @@ -238,18 +242,18 @@ class GUI: | |||
| 238 | ''' | 242 | ''' |
| 239 | Add the files chosed by the filechoser ("Add" button) | 243 | Add the files chosed by the filechoser ("Add" button) |
| 240 | ''' | 244 | ''' |
| 241 | chooser = gtk.FileChooserDialog(title=_('Choose files'), | 245 | chooser = Gtk.FileChooserDialog(title=_('Choose files'), |
| 242 | parent=self.window, action=gtk.FILE_CHOOSER_ACTION_OPEN, | 246 | parent=self.window, action=Gtk.FileChooserAction.OPEN, |
| 243 | buttons=(gtk.STOCK_OK, 0, gtk.STOCK_CANCEL, 1)) | 247 | buttons=(Gtk.STOCK_OK, 0, Gtk.STOCK_CANCEL, 1)) |
| 244 | chooser.set_default_response(0) | 248 | chooser.set_default_response(0) |
| 245 | chooser.set_select_multiple(True) | 249 | chooser.set_select_multiple(True) |
| 246 | 250 | ||
| 247 | all_filter = gtk.FileFilter() # filter that shows all files | 251 | all_filter = Gtk.FileFilter() # filter that shows all files |
| 248 | all_filter.set_name(_('All files')) | 252 | all_filter.set_name(_('All files')) |
| 249 | all_filter.add_pattern('*') | 253 | all_filter.add_pattern('*') |
| 250 | chooser.add_filter(all_filter) | 254 | chooser.add_filter(all_filter) |
| 251 | 255 | ||
| 252 | supported_filter = gtk.FileFilter() | 256 | supported_filter = Gtk.FileFilter() |
| 253 | # filter that shows only supported formats | 257 | # filter that shows only supported formats |
| 254 | [supported_filter.add_mime_type(i) for i in strippers.STRIPPERS.keys()] | 258 | [supported_filter.add_mime_type(i) for i in strippers.STRIPPERS.keys()] |
| 255 | supported_filter.set_name(_('Supported files')) | 259 | supported_filter.set_name(_('Supported files')) |
| @@ -257,10 +261,10 @@ class GUI: | |||
| 257 | 261 | ||
| 258 | response = chooser.run() | 262 | response = chooser.run() |
| 259 | 263 | ||
| 260 | if not response: # gtk.STOCK_OK | 264 | if not response: # Gtk.STOCK_OK |
| 261 | filenames = chooser.get_filenames() | 265 | filenames = chooser.get_filenames() |
| 262 | task = self.populate(filenames) | 266 | task = self.populate(filenames) |
| 263 | gobject.idle_add(task.next) # asynchrone processing | 267 | GObject.idle_add(task.next) # asynchrone processing |
| 264 | chooser.destroy() | 268 | chooser.destroy() |
| 265 | 269 | ||
| 266 | def populate(self, filenames): | 270 | def populate(self, filenames): |
| @@ -316,15 +320,15 @@ class GUI: | |||
| 316 | name = '-<b>' + str(i) + '</b> : ' | 320 | name = '-<b>' + str(i) + '</b> : ' |
| 317 | meta += (name + str(j) + '\n') | 321 | meta += (name + str(j) + '\n') |
| 318 | 322 | ||
| 319 | w = gtk.MessageDialog(self.window, | 323 | w = Gtk.MessageDialog(self.window, |
| 320 | gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, | 324 | Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, |
| 321 | gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, label) | 325 | Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE, label) |
| 322 | w.set_resizable(True) | 326 | w.set_resizable(True) |
| 323 | w.set_size_request(400, 300) | 327 | w.set_size_request(400, 300) |
| 324 | scrolled_window = gtk.ScrolledWindow() | 328 | scrolled_window = Gtk.ScrolledWindow() |
| 325 | scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) | 329 | scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) |
| 326 | w.vbox.pack_start(scrolled_window, True, True, 0) | 330 | w.vbox.pack_start(scrolled_window, True, True, 0) |
| 327 | content = gtk.Label(meta) | 331 | content = Gtk.Label(label=meta) |
| 328 | content.set_selectable(True) | 332 | content.set_selectable(True) |
| 329 | content.set_alignment(0, 0) | 333 | content.set_alignment(0, 0) |
| 330 | content.set_use_markup(True) | 334 | content.set_use_markup(True) |
| @@ -340,11 +344,11 @@ class GUI: | |||
| 340 | Popup that warn the user about the unsupported files | 344 | Popup that warn the user about the unsupported files |
| 341 | that he want to process | 345 | that he want to process |
| 342 | ''' | 346 | ''' |
| 343 | dialog = gtk.Dialog(title=_('Not-supported'), parent=self.window, | 347 | dialog = Gtk.Dialog(title=_('Not-supported'), parent=self.window, |
| 344 | flags=0, buttons=(gtk.STOCK_OK, 0)) | 348 | flags=0, buttons=(Gtk.STOCK_OK, 0)) |
| 345 | vbox = gtk.VBox(spacing=5) | 349 | vbox = Gtk.VBox(spacing=5) |
| 346 | dialog.get_content_area().pack_start(vbox, True, True, 0) | 350 | dialog.get_content_area().pack_start(vbox, True, True, 0) |
| 347 | store = gtk.ListStore(str, str) | 351 | store = Gtk.ListStore(str, str) |
| 348 | 352 | ||
| 349 | # append filename - mimetype to the store | 353 | # append filename - mimetype to the store |
| 350 | #FIXME : I'm ugly | 354 | #FIXME : I'm ugly |
| @@ -355,14 +359,14 @@ class GUI: | |||
| 355 | else: | 359 | else: |
| 356 | store.append([item, 'unknown']) | 360 | store.append([item, 'unknown']) |
| 357 | 361 | ||
| 358 | treeview = gtk.TreeView(store) | 362 | treeview = Gtk.TreeView(store) |
| 359 | vbox.pack_start(treeview, True, True, 0) | 363 | vbox.pack_start(treeview, True, True, 0) |
| 360 | 364 | ||
| 361 | #create column | 365 | #create column |
| 362 | rendererText = gtk.CellRendererText() | 366 | rendererText = Gtk.CellRendererText() |
| 363 | column = gtk.TreeViewColumn(_('Filename'), rendererText, text=0) | 367 | column = Gtk.TreeViewColumn(_('Filename'), rendererText, text=0) |
| 364 | treeview.append_column(column) | 368 | treeview.append_column(column) |
| 365 | column = gtk.TreeViewColumn(_('Mimetype'), rendererText, text=1) | 369 | column = Gtk.TreeViewColumn(_('Mimetype'), rendererText, text=1) |
| 366 | treeview.append_column(column) | 370 | treeview.append_column(column) |
| 367 | 371 | ||
| 368 | dialog.show_all() | 372 | dialog.show_all() |
| @@ -374,17 +378,17 @@ class GUI: | |||
| 374 | ''' | 378 | ''' |
| 375 | About popup | 379 | About popup |
| 376 | ''' | 380 | ''' |
| 377 | w = gtk.AboutDialog() | 381 | w = Gtk.AboutDialog() |
| 378 | w.set_authors(['Julien (jvoisin) Voisin', ]) | 382 | w.set_authors(['Julien (jvoisin) Voisin', ]) |
| 379 | w.set_artists(['Marine Benoît', ]) | 383 | w.set_artists(['Marine Benoît', ]) |
| 380 | w.set_copyright('GNU Public License v2') | 384 | w.set_copyright('GNU Public License v2') |
| 381 | w.set_comments(_('This software was coded during the GSoC 2011')) | 385 | w.set_comments(_('This software was coded during the GSoC 2011')) |
| 382 | w.set_logo(gtk.gdk.pixbuf_new_from_file_at_size(self.logo, 400, 200)) | 386 | w.set_logo(Gdk.Pixbuf.new_from_file_at_size(self.logo, 400, 200)) |
| 383 | w.set_program_name('Metadata Anonymisation Toolkit') | 387 | w.set_program_name('Metadata Anonymisation Toolkit') |
| 384 | w.set_version(mat.__version__) | 388 | w.set_version(mat.__version__) |
| 385 | w.set_website('https://mat.boum.org') | 389 | w.set_website('https://mat.boum.org') |
| 386 | w.set_website_label(_('Website')) | 390 | w.set_website_label(_('Website')) |
| 387 | w.set_position(gtk.WIN_POS_CENTER) | 391 | w.set_position(Gtk.WindowPosition.CENTER) |
| 388 | w.run() | 392 | w.run() |
| 389 | w.destroy() | 393 | w.destroy() |
| 390 | 394 | ||
| @@ -392,12 +396,12 @@ class GUI: | |||
| 392 | ''' | 396 | ''' |
| 393 | List the supported formats | 397 | List the supported formats |
| 394 | ''' | 398 | ''' |
| 395 | dialog = gtk.Dialog(_('Supported formats'), self.window, 0, | 399 | dialog = Gtk.Dialog(_('Supported formats'), self.window, 0, |
| 396 | (gtk.STOCK_CLOSE, 0)) | 400 | (Gtk.STOCK_CLOSE, 0)) |
| 397 | vbox = gtk.VBox(spacing=5) | 401 | vbox = Gtk.VBox(spacing=5) |
| 398 | dialog.get_content_area().pack_start(vbox, True, True, 0) | 402 | dialog.get_content_area().pack_start(vbox, True, True, 0) |
| 399 | 403 | ||
| 400 | label = gtk.Label() | 404 | label = Gtk.Label() |
| 401 | label.set_markup('<big><u>Supported fileformats</u></big>') | 405 | label.set_markup('<big><u>Supported fileformats</u></big>') |
| 402 | vbox.pack_start(label, True, True, 0) | 406 | vbox.pack_start(label, True, True, 0) |
| 403 | 407 | ||
| @@ -411,7 +415,7 @@ class GUI: | |||
| 411 | 415 | ||
| 412 | def expander_callback(current): | 416 | def expander_callback(current): |
| 413 | ''' Close every expander except the current one ''' | 417 | ''' Close every expander except the current one ''' |
| 414 | for i in vbox.get_children()[1:]: # first child is a gtk.Label | 418 | for i in vbox.get_children()[1:]: # first child is a Gtk.Label |
| 415 | if i != current: | 419 | if i != current: |
| 416 | i.set_expanded(False) | 420 | i.set_expanded(False) |
| 417 | 421 | ||
| @@ -428,9 +432,9 @@ class GUI: | |||
| 428 | if item['support'] == 'partial': | 432 | if item['support'] == 'partial': |
| 429 | content += '\n\t<b>remaining</b> : ' + item['remaining'] | 433 | content += '\n\t<b>remaining</b> : ' + item['remaining'] |
| 430 | 434 | ||
| 431 | expander = gtk.Expander(title) | 435 | expander = Gtk.Expander(title) |
| 432 | vbox.pack_start(expander, False, False, 0) | 436 | vbox.pack_start(expander, False, False, 0) |
| 433 | label = gtk.Label() | 437 | label = Gtk.Label() |
| 434 | label.set_markup(content) | 438 | label.set_markup(content) |
| 435 | expander.add(label) | 439 | expander.add(label) |
| 436 | expander.connect('activate', expander_callback) | 440 | expander.connect('activate', expander_callback) |
| @@ -444,40 +448,40 @@ class GUI: | |||
| 444 | ''' | 448 | ''' |
| 445 | Preferences popup | 449 | Preferences popup |
| 446 | ''' | 450 | ''' |
| 447 | dialog = gtk.Dialog(_('Preferences'), self.window, 0, | 451 | dialog = Gtk.Dialog(_('Preferences'), self.window, 0, |
| 448 | (gtk.STOCK_OK, 0)) | 452 | (Gtk.STOCK_OK, 0)) |
| 449 | dialog.set_resizable(False) | 453 | dialog.set_resizable(False) |
| 450 | dialog.set_deletable(False) | 454 | dialog.set_deletable(False) |
| 451 | hbox = gtk.HBox() | 455 | hbox = Gtk.HBox() |
| 452 | dialog.get_content_area().pack_start(hbox, False, False, 0) | 456 | dialog.get_content_area().pack_start(hbox, False, False, 0) |
| 453 | 457 | ||
| 454 | icon = gtk.Image() | 458 | icon = Gtk.Image() |
| 455 | icon.set_from_stock(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_DIALOG) | 459 | icon.set_from_stock(Gtk.STOCK_PREFERENCES, Gtk.IconSize.DIALOG) |
| 456 | hbox.pack_start(icon, False, False, 20) | 460 | hbox.pack_start(icon, False, False, 20) |
| 457 | 461 | ||
| 458 | table = gtk.Table(3, 2, False) # nb rows, nb lines | 462 | table = Gtk.Table(3, 2, False) # nb rows, nb lines |
| 459 | hbox.pack_start(table, True, True, 0) | 463 | hbox.pack_start(table, True, True, 0) |
| 460 | 464 | ||
| 461 | force = gtk.CheckButton(_('Force Clean'), False) | 465 | force = Gtk.CheckButton(_('Force Clean'), False) |
| 462 | force.set_active(self.force) | 466 | force.set_active(self.force) |
| 463 | force.connect('toggled', self.__invert, 'force') | 467 | force.connect('toggled', self.__invert, 'force') |
| 464 | force.set_tooltip_text(_('Do not check if already clean before \ | 468 | force.set_tooltip_text(_('Do not check if already clean before \ |
| 465 | cleaning')) | 469 | cleaning')) |
| 466 | table.attach(force, 0, 1, 0, 1) | 470 | table.attach(force, 0, 1, 0, 1) |
| 467 | 471 | ||
| 468 | backup = gtk.CheckButton(_('Backup'), False) | 472 | backup = Gtk.CheckButton(_('Backup'), False) |
| 469 | backup.set_active(self.backup) | 473 | backup.set_active(self.backup) |
| 470 | backup.connect('toggled', self.__invert, 'backup') | 474 | backup.connect('toggled', self.__invert, 'backup') |
| 471 | backup.set_tooltip_text(_('Keep a backup copy')) | 475 | backup.set_tooltip_text(_('Keep a backup copy')) |
| 472 | table.attach(backup, 0, 1, 1, 2) | 476 | table.attach(backup, 0, 1, 1, 2) |
| 473 | 477 | ||
| 474 | pdf_quality = gtk.CheckButton(_('Reduce PDF quality'), False) | 478 | pdf_quality = Gtk.CheckButton(_('Reduce PDF quality'), False) |
| 475 | pdf_quality.set_active(self.pdf_quality) | 479 | pdf_quality.set_active(self.pdf_quality) |
| 476 | pdf_quality.connect('toggled', self.__invert, 'pdf_quality') | 480 | pdf_quality.connect('toggled', self.__invert, 'pdf_quality') |
| 477 | pdf_quality.set_tooltip_text(_('Reduce the produced PDF size and quality')) | 481 | pdf_quality.set_tooltip_text(_('Reduce the produced PDF size and quality')) |
| 478 | table.attach(pdf_quality, 0, 1, 2, 3) | 482 | table.attach(pdf_quality, 0, 1, 2, 3) |
| 479 | 483 | ||
| 480 | add2archive = gtk.CheckButton(_('Add unsupported file to archives'), | 484 | add2archive = Gtk.CheckButton(_('Add unsupported file to archives'), |
| 481 | False) | 485 | False) |
| 482 | add2archive.set_active(self.add2archive) | 486 | add2archive.set_active(self.add2archive) |
| 483 | add2archive.connect('toggled', self.__invert, 'add2archive') | 487 | add2archive.connect('toggled', self.__invert, 'add2archive') |
| @@ -486,7 +490,7 @@ non-anonymised) file to output archive')) | |||
| 486 | table.attach(add2archive, 0, 1, 3, 4) | 490 | table.attach(add2archive, 0, 1, 3, 4) |
| 487 | 491 | ||
| 488 | hbox.show_all() | 492 | hbox.show_all() |
| 489 | if not dialog.run(): # gtk.STOCK_OK | 493 | if not dialog.run(): # Gtk.STOCK_OK |
| 490 | for i in self.liststore: # update preferences | 494 | for i in self.liststore: # update preferences |
| 491 | i[0].backup = self.backup | 495 | i[0].backup = self.backup |
| 492 | i[0].add2archive = self.add2archive | 496 | i[0].add2archive = self.add2archive |
| @@ -521,7 +525,7 @@ non-anonymised) file to output archive')) | |||
| 521 | urls = selection.data.strip('\r\n\x00') # strip stupid characters | 525 | urls = selection.data.strip('\r\n\x00') # strip stupid characters |
| 522 | cleaned_urls = map(self.__clean_draged_file_path, urls.split('\n')) | 526 | cleaned_urls = map(self.__clean_draged_file_path, urls.split('\n')) |
| 523 | task = self.populate(cleaned_urls) | 527 | task = self.populate(cleaned_urls) |
| 524 | gobject.idle_add(task.next) # asynchrone processing | 528 | GObject.idle_add(task.next) # asynchrone processing |
| 525 | 529 | ||
| 526 | def __clean_draged_file_path(self, url): | 530 | def __clean_draged_file_path(self, url): |
| 527 | ''' | 531 | ''' |
| @@ -544,7 +548,7 @@ non-anonymised) file to output archive')) | |||
| 544 | if not iterator: # if nothing is selected : select everything | 548 | if not iterator: # if nothing is selected : select everything |
| 545 | iterator = xrange(len(self.liststore)) | 549 | iterator = xrange(len(self.liststore)) |
| 546 | task = func(iterator) # launch func() in an asynchrone way | 550 | task = func(iterator) # launch func() in an asynchrone way |
| 547 | gobject.idle_add(task.next) | 551 | GObject.idle_add(task.next) |
| 548 | 552 | ||
| 549 | def __mat_check(self, iterator): | 553 | def __mat_check(self, iterator): |
| 550 | ''' | 554 | ''' |
| @@ -589,6 +593,6 @@ if __name__ == '__main__': | |||
| 589 | infiles = [arg for arg in sys.argv[1:] if os.path.exists(arg)] | 593 | infiles = [arg for arg in sys.argv[1:] if os.path.exists(arg)] |
| 590 | if infiles: | 594 | if infiles: |
| 591 | task = gui.populate(infiles) | 595 | task = gui.populate(infiles) |
| 592 | gobject.idle_add(task.next) | 596 | GObject.idle_add(task.next) |
| 593 | 597 | ||
| 594 | gtk.main() | 598 | Gtk.main() |
