diff options
| author | jvoisin | 2013-04-05 11:00:47 +0200 |
|---|---|---|
| committer | jvoisin | 2013-04-05 11:00:47 +0200 |
| commit | 8516bb77f86ebdcedb1e64f56f9acd673027ddcb (patch) | |
| tree | a93079693531263dfc5802ea42313c53dcaa0493 /mat-gui | |
| parent | 861996f614950c7061097a049efd56f5a0a4b6a5 (diff) | |
| parent | 3d8e11ce644833106f22778f3171c52a51ff69fe (diff) | |
Merge branches 'gi_jack' and 'gtk3'
Conflicts:
mat-gui
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,27 +105,27 @@ 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(gtk.STOCK_REMOVE) | 128 | toolbutton = Gtk.ToolButton(stock_id=Gtk.STOCK_REMOVE) |
| 125 | toolbutton.set_label(_('Clear the filelist')) | 129 | toolbutton.set_label(_('Clear the filelist')) |
| 126 | toolbutton.connect('clicked', lambda x: self.liststore.clear()) | 130 | toolbutton.connect('clicked', lambda x: self.liststore.clear()) |
| 127 | toolbutton.set_tooltip_text(_('Clear the filelist')) | 131 | toolbutton.set_tooltip_text(_('Clear the filelist')) |
| @@ -129,10 +133,10 @@ class GUI: | |||
| 129 | 133 | ||
| 130 | toolbutton = gtk.ToolButton(stock_id=gtk.STOCK_QUIT) | 134 | toolbutton = gtk.ToolButton(stock_id=gtk.STOCK_QUIT) |
| 131 | toolbutton.set_label(_('Quit')) | 135 | toolbutton.set_label(_('Quit')) |
| 132 | toolbutton.connect('clicked', gtk.main_quit) | 136 | toolbutton.connect('clicked', Gtk.main_quit) |
| 133 | toolbar.add(toolbutton) | 137 | toolbar.add(toolbutton) |
| 134 | 138 | ||
| 135 | vbox = gtk.VBox(spacing=3) | 139 | vbox = Gtk.VBox(spacing=3) |
| 136 | vbox.pack_start(toolbar, False, False, 0) | 140 | vbox.pack_start(toolbar, False, False, 0) |
| 137 | return vbox | 141 | return vbox |
| 138 | 142 | ||
| @@ -144,8 +148,8 @@ class GUI: | |||
| 144 | _('Cleaned file')] | 148 | _('Cleaned file')] |
| 145 | 149 | ||
| 146 | for i, j in enumerate(colname, 1): | 150 | for i, j in enumerate(colname, 1): |
| 147 | filename_column = gtk.CellRendererText() | 151 | filename_column = Gtk.CellRendererText() |
| 148 | column = gtk.TreeViewColumn(j, filename_column, text=i) | 152 | column = Gtk.TreeViewColumn(j, filename_column, text=i) |
| 149 | column.set_sort_column_id(i) | 153 | column.set_sort_column_id(i) |
| 150 | column.set_resizable(True) # column is resizeable | 154 | column.set_resizable(True) # column is resizeable |
| 151 | self.treeview.append_column(column) | 155 | self.treeview.append_column(column) |
| @@ -154,13 +158,13 @@ class GUI: | |||
| 154 | ''' | 158 | ''' |
| 155 | Create a MenuItem() like Preferences, Quit, Add, Clean, ... | 159 | Create a MenuItem() like Preferences, Quit, Add, Clean, ... |
| 156 | ''' | 160 | ''' |
| 157 | item = gtk.ImageMenuItem() | 161 | item = Gtk.ImageMenuItem() |
| 158 | if shortcut: | 162 | if shortcut: |
| 159 | key, mod = gtk.accelerator_parse(shortcut) | 163 | key, mod = Gtk.accelerator_parse(shortcut) |
| 160 | item.add_accelerator('activate', self.accelerator, | 164 | item.add_accelerator('activate', self.accelerator, |
| 161 | key, mod, gtk.ACCEL_VISIBLE) | 165 | key, mod, Gtk.AccelFlags.VISIBLE) |
| 162 | picture = gtk.Image() | 166 | picture = Gtk.Image() |
| 163 | picture.set_from_stock(pix, gtk.ICON_SIZE_MENU) | 167 | picture.set_from_stock(pix, Gtk.IconSize.MENU) |
| 164 | item.set_image(picture) | 168 | item.set_image(picture) |
| 165 | item.set_label('_' + name) | 169 | item.set_label('_' + name) |
| 166 | item.set_use_underline(True) | 170 | item.set_use_underline(True) |
| @@ -171,8 +175,8 @@ class GUI: | |||
| 171 | ''' | 175 | ''' |
| 172 | Create a submenu like File, Edit, Clean, ... | 176 | Create a submenu like File, Edit, Clean, ... |
| 173 | ''' | 177 | ''' |
| 174 | submenu = gtk.Menu() | 178 | submenu = Gtk.Menu() |
| 175 | menuitem = gtk.MenuItem() | 179 | menuitem = Gtk.MenuItem() |
| 176 | menuitem.set_submenu(submenu) | 180 | menuitem.set_submenu(submenu) |
| 177 | menuitem.set_label('_' + name) | 181 | menuitem.set_label('_' + name) |
| 178 | menuitem.set_use_underline(True) | 182 | menuitem.set_use_underline(True) |
| @@ -183,39 +187,39 @@ class GUI: | |||
| 183 | ''' | 187 | ''' |
| 184 | Return a MenuBar | 188 | Return a MenuBar |
| 185 | ''' | 189 | ''' |
| 186 | menubar = gtk.MenuBar() | 190 | menubar = Gtk.MenuBar() |
| 187 | 191 | ||
| 188 | file_menu = self.__create_sub_menu(_('Files'), menubar) | 192 | file_menu = self.__create_sub_menu(_('Files'), menubar) |
| 189 | self.__create_menu_item(_('Add files'), self.__add_files, file_menu, | 193 | self.__create_menu_item(_('Add files'), self.__add_files, file_menu, |
| 190 | gtk.STOCK_ADD, '<Control>O') | 194 | Gtk.STOCK_ADD, '<Control>O') |
| 191 | self.__create_menu_item(_('Quit'), gtk.main_quit, file_menu, | 195 | self.__create_menu_item(_('Quit'), Gtk.main_quit, file_menu, |
| 192 | gtk.STOCK_QUIT, '<Control>Q') | 196 | Gtk.STOCK_QUIT, '<Control>Q') |
| 193 | 197 | ||
| 194 | edit_menu = self.__create_sub_menu(_('Edit'), menubar) | 198 | edit_menu = self.__create_sub_menu(_('Edit'), menubar) |
| 195 | self.__create_menu_item(_('Clear the filelist'), | 199 | self.__create_menu_item(_('Clear the filelist'), |
| 196 | lambda x: self.liststore.clear(), edit_menu, gtk.STOCK_REMOVE, | 200 | lambda x: self.liststore.clear(), edit_menu, Gtk.STOCK_REMOVE, |
| 197 | None) | 201 | None) |
| 198 | self.__create_menu_item(_('Preferences'), self.__preferences, | 202 | self.__create_menu_item(_('Preferences'), self.__preferences, |
| 199 | edit_menu, gtk.STOCK_PREFERENCES, '<Control>P') | 203 | edit_menu, Gtk.STOCK_PREFERENCES, '<Control>P') |
| 200 | 204 | ||
| 201 | process_menu = self.__create_sub_menu(_('Process'), menubar) | 205 | process_menu = self.__create_sub_menu(_('Process'), menubar) |
| 202 | item = gtk.ImageMenuItem() | 206 | item = Gtk.ImageMenuItem() |
| 203 | key, mod = gtk.accelerator_parse('<Control>L') | 207 | key, mod = Gtk.accelerator_parse('<Control>L') |
| 204 | item.add_accelerator('activate', self.accelerator, | 208 | item.add_accelerator('activate', self.accelerator, |
| 205 | key, mod, gtk.ACCEL_VISIBLE) | 209 | key, mod, Gtk.AccelFlags.VISIBLE) |
| 206 | picture = gtk.Image() | 210 | picture = Gtk.Image() |
| 207 | picture.set_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_MENU) | 211 | picture.set_from_stock(Gtk.STOCK_CLEAR, Gtk.IconSize.MENU) |
| 208 | item.set_image(picture) | 212 | item.set_image(picture) |
| 209 | item.set_label(_('Clean')) | 213 | item.set_label(_('Clean')) |
| 210 | item.connect('activate', self.__process_files, self.__mat_clean) | 214 | item.connect('activate', self.__process_files, self.__mat_clean) |
| 211 | process_menu.append(item) | 215 | process_menu.append(item) |
| 212 | 216 | ||
| 213 | item = gtk.ImageMenuItem() | 217 | item = Gtk.ImageMenuItem() |
| 214 | key, mod = gtk.accelerator_parse('<Control>h') | 218 | key, mod = Gtk.accelerator_parse('<Control>h') |
| 215 | item.add_accelerator('activate', self.accelerator, | 219 | item.add_accelerator('activate', self.accelerator, |
| 216 | key, mod, gtk.ACCEL_VISIBLE) | 220 | key, mod, Gtk.AccelFlags.VISIBLE) |
| 217 | picture = gtk.Image() | 221 | picture = Gtk.Image() |
| 218 | picture.set_from_stock(gtk.STOCK_FIND, gtk.ICON_SIZE_MENU) | 222 | picture.set_from_stock(Gtk.STOCK_FIND, Gtk.IconSize.MENU) |
| 219 | item.set_image(picture) | 223 | item.set_image(picture) |
| 220 | item.set_label(_('Check')) | 224 | item.set_label(_('Check')) |
| 221 | item.connect('activate', self.__process_files, self.__mat_check) | 225 | item.connect('activate', self.__process_files, self.__mat_check) |
| @@ -223,9 +227,9 @@ class GUI: | |||
| 223 | 227 | ||
| 224 | help_menu = self.__create_sub_menu(_('Help'), menubar) | 228 | help_menu = self.__create_sub_menu(_('Help'), menubar) |
| 225 | self.__create_menu_item(_('Supported formats'), self.__supported, | 229 | self.__create_menu_item(_('Supported formats'), self.__supported, |
| 226 | help_menu, gtk.STOCK_INFO, False) | 230 | help_menu, Gtk.STOCK_INFO, False) |
| 227 | self.__create_menu_item(_('About'), self.__about, help_menu, | 231 | self.__create_menu_item(_('About'), self.__about, help_menu, |
| 228 | gtk.STOCK_ABOUT, False) | 232 | Gtk.STOCK_ABOUT, False) |
| 229 | 233 | ||
| 230 | return menubar | 234 | return menubar |
| 231 | 235 | ||
| @@ -234,7 +238,7 @@ class GUI: | |||
| 234 | Remove selected files from the treeview | 238 | Remove selected files from the treeview |
| 235 | when the use hit the 'suppr' key | 239 | when the use hit the 'suppr' key |
| 236 | ''' | 240 | ''' |
| 237 | if gtk.gdk.keyval_name(event.keyval) == "Delete": | 241 | if Gdk.keyval_name(event.keyval) == "Delete": |
| 238 | rows = [] | 242 | rows = [] |
| 239 | self.selection.selected_foreach( | 243 | self.selection.selected_foreach( |
| 240 | lambda model, path, iter: rows.append(iter)) | 244 | lambda model, path, iter: rows.append(iter)) |
| @@ -244,18 +248,18 @@ class GUI: | |||
| 244 | ''' | 248 | ''' |
| 245 | Add the files chosed by the filechoser ("Add" button) | 249 | Add the files chosed by the filechoser ("Add" button) |
| 246 | ''' | 250 | ''' |
| 247 | chooser = gtk.FileChooserDialog(title=_('Choose files'), | 251 | chooser = Gtk.FileChooserDialog(title=_('Choose files'), |
| 248 | parent=self.window, action=gtk.FILE_CHOOSER_ACTION_OPEN, | 252 | parent=self.window, action=Gtk.FileChooserAction.OPEN, |
| 249 | buttons=(gtk.STOCK_OK, 0, gtk.STOCK_CANCEL, 1)) | 253 | buttons=(Gtk.STOCK_OK, 0, Gtk.STOCK_CANCEL, 1)) |
| 250 | chooser.set_default_response(0) | 254 | chooser.set_default_response(0) |
| 251 | chooser.set_select_multiple(True) | 255 | chooser.set_select_multiple(True) |
| 252 | 256 | ||
| 253 | all_filter = gtk.FileFilter() # filter that shows all files | 257 | all_filter = Gtk.FileFilter() # filter that shows all files |
| 254 | all_filter.set_name(_('All files')) | 258 | all_filter.set_name(_('All files')) |
| 255 | all_filter.add_pattern('*') | 259 | all_filter.add_pattern('*') |
| 256 | chooser.add_filter(all_filter) | 260 | chooser.add_filter(all_filter) |
| 257 | 261 | ||
| 258 | supported_filter = gtk.FileFilter() | 262 | supported_filter = Gtk.FileFilter() |
| 259 | # filter that shows only supported formats | 263 | # filter that shows only supported formats |
| 260 | [supported_filter.add_mime_type(i) for i in strippers.STRIPPERS.keys()] | 264 | [supported_filter.add_mime_type(i) for i in strippers.STRIPPERS.keys()] |
| 261 | supported_filter.set_name(_('Supported files')) | 265 | supported_filter.set_name(_('Supported files')) |
| @@ -263,10 +267,10 @@ class GUI: | |||
| 263 | 267 | ||
| 264 | response = chooser.run() | 268 | response = chooser.run() |
| 265 | 269 | ||
| 266 | if not response: # gtk.STOCK_OK | 270 | if not response: # Gtk.STOCK_OK |
| 267 | filenames = chooser.get_filenames() | 271 | filenames = chooser.get_filenames() |
| 268 | task = self.populate(filenames) | 272 | task = self.populate(filenames) |
| 269 | gobject.idle_add(task.next) # asynchrone processing | 273 | GObject.idle_add(task.next) # asynchrone processing |
| 270 | chooser.destroy() | 274 | chooser.destroy() |
| 271 | 275 | ||
| 272 | def populate(self, filenames): | 276 | def populate(self, filenames): |
| @@ -322,15 +326,15 @@ class GUI: | |||
| 322 | name = '-<b>' + str(i) + '</b> : ' | 326 | name = '-<b>' + str(i) + '</b> : ' |
| 323 | meta += (name + str(j) + '\n') | 327 | meta += (name + str(j) + '\n') |
| 324 | 328 | ||
| 325 | w = gtk.MessageDialog(self.window, | 329 | w = Gtk.MessageDialog(self.window, |
| 326 | gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, | 330 | Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, |
| 327 | gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, label) | 331 | Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE, label) |
| 328 | w.set_resizable(True) | 332 | w.set_resizable(True) |
| 329 | w.set_size_request(400, 300) | 333 | w.set_size_request(400, 300) |
| 330 | scrolled_window = gtk.ScrolledWindow() | 334 | scrolled_window = Gtk.ScrolledWindow() |
| 331 | scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) | 335 | scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) |
| 332 | w.vbox.pack_start(scrolled_window, True, True, 0) | 336 | w.vbox.pack_start(scrolled_window, True, True, 0) |
| 333 | content = gtk.Label(meta) | 337 | content = Gtk.Label(label=meta) |
| 334 | content.set_selectable(True) | 338 | content.set_selectable(True) |
| 335 | content.set_alignment(0, 0) | 339 | content.set_alignment(0, 0) |
| 336 | content.set_use_markup(True) | 340 | content.set_use_markup(True) |
| @@ -346,11 +350,11 @@ class GUI: | |||
| 346 | Popup that warn the user about the unsupported files | 350 | Popup that warn the user about the unsupported files |
| 347 | that he want to process | 351 | that he want to process |
| 348 | ''' | 352 | ''' |
| 349 | dialog = gtk.Dialog(title=_('Not-supported'), parent=self.window, | 353 | dialog = Gtk.Dialog(title=_('Not-supported'), parent=self.window, |
| 350 | flags=0, buttons=(gtk.STOCK_OK, 0)) | 354 | flags=0, buttons=(Gtk.STOCK_OK, 0)) |
| 351 | vbox = gtk.VBox(spacing=5) | 355 | vbox = Gtk.VBox(spacing=5) |
| 352 | dialog.get_content_area().pack_start(vbox, True, True, 0) | 356 | dialog.get_content_area().pack_start(vbox, True, True, 0) |
| 353 | store = gtk.ListStore(str, str) | 357 | store = Gtk.ListStore(str, str) |
| 354 | 358 | ||
| 355 | # append filename - mimetype to the store | 359 | # append filename - mimetype to the store |
| 356 | #FIXME : I'm ugly | 360 | #FIXME : I'm ugly |
| @@ -361,14 +365,14 @@ class GUI: | |||
| 361 | else: | 365 | else: |
| 362 | store.append([item, 'unknown']) | 366 | store.append([item, 'unknown']) |
| 363 | 367 | ||
| 364 | treeview = gtk.TreeView(store) | 368 | treeview = Gtk.TreeView(store) |
| 365 | vbox.pack_start(treeview, True, True, 0) | 369 | vbox.pack_start(treeview, True, True, 0) |
| 366 | 370 | ||
| 367 | #create column | 371 | #create column |
| 368 | rendererText = gtk.CellRendererText() | 372 | rendererText = Gtk.CellRendererText() |
| 369 | column = gtk.TreeViewColumn(_('Filename'), rendererText, text=0) | 373 | column = Gtk.TreeViewColumn(_('Filename'), rendererText, text=0) |
| 370 | treeview.append_column(column) | 374 | treeview.append_column(column) |
| 371 | column = gtk.TreeViewColumn(_('Mimetype'), rendererText, text=1) | 375 | column = Gtk.TreeViewColumn(_('Mimetype'), rendererText, text=1) |
| 372 | treeview.append_column(column) | 376 | treeview.append_column(column) |
| 373 | 377 | ||
| 374 | dialog.show_all() | 378 | dialog.show_all() |
| @@ -380,17 +384,17 @@ class GUI: | |||
| 380 | ''' | 384 | ''' |
| 381 | About popup | 385 | About popup |
| 382 | ''' | 386 | ''' |
| 383 | w = gtk.AboutDialog() | 387 | w = Gtk.AboutDialog() |
| 384 | w.set_authors(['Julien (jvoisin) Voisin', ]) | 388 | w.set_authors(['Julien (jvoisin) Voisin', ]) |
| 385 | w.set_artists(['Marine Benoît', ]) | 389 | w.set_artists(['Marine Benoît', ]) |
| 386 | w.set_copyright('GNU Public License v2') | 390 | w.set_copyright('GNU Public License v2') |
| 387 | w.set_comments(_('This software was coded during the GSoC 2011')) | 391 | w.set_comments(_('This software was coded during the GSoC 2011')) |
| 388 | w.set_logo(gtk.gdk.pixbuf_new_from_file_at_size(self.logo, 400, 200)) | 392 | w.set_logo(GdkPixbuf.Pixbuf.new_from_file_at_size(self.logo, 400, 200)) |
| 389 | w.set_program_name('Metadata Anonymisation Toolkit') | 393 | w.set_program_name('Metadata Anonymisation Toolkit') |
| 390 | w.set_version(mat.__version__) | 394 | w.set_version(mat.__version__) |
| 391 | w.set_website('https://mat.boum.org') | 395 | w.set_website('https://mat.boum.org') |
| 392 | w.set_website_label(_('Website')) | 396 | w.set_website_label(_('Website')) |
| 393 | w.set_position(gtk.WIN_POS_CENTER) | 397 | w.set_position(Gtk.WindowPosition.CENTER) |
| 394 | w.run() | 398 | w.run() |
| 395 | w.destroy() | 399 | w.destroy() |
| 396 | 400 | ||
| @@ -398,12 +402,12 @@ class GUI: | |||
| 398 | ''' | 402 | ''' |
| 399 | List the supported formats | 403 | List the supported formats |
| 400 | ''' | 404 | ''' |
| 401 | dialog = gtk.Dialog(_('Supported formats'), self.window, 0, | 405 | dialog = Gtk.Dialog(_('Supported formats'), self.window, 0, |
| 402 | (gtk.STOCK_CLOSE, 0)) | 406 | (Gtk.STOCK_CLOSE, 0)) |
| 403 | vbox = gtk.VBox(spacing=5) | 407 | vbox = Gtk.VBox(spacing=5) |
| 404 | dialog.get_content_area().pack_start(vbox, True, True, 0) | 408 | dialog.get_content_area().pack_start(vbox, True, True, 0) |
| 405 | 409 | ||
| 406 | label = gtk.Label() | 410 | label = Gtk.Label() |
| 407 | label.set_markup('<big><u>Supported fileformats</u></big>') | 411 | label.set_markup('<big><u>Supported fileformats</u></big>') |
| 408 | vbox.pack_start(label, True, True, 0) | 412 | vbox.pack_start(label, True, True, 0) |
| 409 | 413 | ||
| @@ -417,7 +421,7 @@ class GUI: | |||
| 417 | 421 | ||
| 418 | def expander_callback(current): | 422 | def expander_callback(current): |
| 419 | ''' Close every expander except the current one ''' | 423 | ''' Close every expander except the current one ''' |
| 420 | for i in vbox.get_children()[1:]: # first child is a gtk.Label | 424 | for i in vbox.get_children()[1:]: # first child is a Gtk.Label |
| 421 | if i != current: | 425 | if i != current: |
| 422 | i.set_expanded(False) | 426 | i.set_expanded(False) |
| 423 | 427 | ||
| @@ -434,9 +438,9 @@ class GUI: | |||
| 434 | if item['support'] == 'partial': | 438 | if item['support'] == 'partial': |
| 435 | content += '\n\t<b>remaining</b> : ' + item['remaining'] | 439 | content += '\n\t<b>remaining</b> : ' + item['remaining'] |
| 436 | 440 | ||
| 437 | expander = gtk.Expander(title) | 441 | expander = Gtk.Expander(title) |
| 438 | vbox.pack_start(expander, False, False, 0) | 442 | vbox.pack_start(expander, False, False, 0) |
| 439 | label = gtk.Label() | 443 | label = Gtk.Label() |
| 440 | label.set_markup(content) | 444 | label.set_markup(content) |
| 441 | expander.add(label) | 445 | expander.add(label) |
| 442 | expander.connect('activate', expander_callback) | 446 | expander.connect('activate', expander_callback) |
| @@ -450,40 +454,40 @@ class GUI: | |||
| 450 | ''' | 454 | ''' |
| 451 | Preferences popup | 455 | Preferences popup |
| 452 | ''' | 456 | ''' |
| 453 | dialog = gtk.Dialog(_('Preferences'), self.window, 0, | 457 | dialog = Gtk.Dialog(_('Preferences'), self.window, 0, |
| 454 | (gtk.STOCK_OK, 0)) | 458 | (Gtk.STOCK_OK, 0)) |
| 455 | dialog.set_resizable(False) | 459 | dialog.set_resizable(False) |
| 456 | dialog.set_deletable(False) | 460 | dialog.set_deletable(False) |
| 457 | hbox = gtk.HBox() | 461 | hbox = Gtk.HBox() |
| 458 | dialog.get_content_area().pack_start(hbox, False, False, 0) | 462 | dialog.get_content_area().pack_start(hbox, False, False, 0) |
| 459 | 463 | ||
| 460 | icon = gtk.Image() | 464 | icon = Gtk.Image() |
| 461 | icon.set_from_stock(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_DIALOG) | 465 | icon.set_from_stock(Gtk.STOCK_PREFERENCES, Gtk.IconSize.DIALOG) |
| 462 | hbox.pack_start(icon, False, False, 20) | 466 | hbox.pack_start(icon, False, False, 20) |
| 463 | 467 | ||
| 464 | table = gtk.Table(3, 2, False) # nb rows, nb lines | 468 | table = Gtk.Table(3, 2, False) # nb rows, nb lines |
| 465 | hbox.pack_start(table, True, True, 0) | 469 | hbox.pack_start(table, True, True, 0) |
| 466 | 470 | ||
| 467 | force = gtk.CheckButton(_('Force Clean'), False) | 471 | force = Gtk.CheckButton(_('Force Clean'), False) |
| 468 | force.set_active(self.force) | 472 | force.set_active(self.force) |
| 469 | force.connect('toggled', self.__invert, 'force') | 473 | force.connect('toggled', self.__invert, 'force') |
| 470 | force.set_tooltip_text(_('Do not check if already clean before \ | 474 | force.set_tooltip_text(_('Do not check if already clean before \ |
| 471 | cleaning')) | 475 | cleaning')) |
| 472 | table.attach(force, 0, 1, 0, 1) | 476 | table.attach(force, 0, 1, 0, 1) |
| 473 | 477 | ||
| 474 | backup = gtk.CheckButton(_('Backup'), False) | 478 | backup = Gtk.CheckButton(_('Backup'), False) |
| 475 | backup.set_active(self.backup) | 479 | backup.set_active(self.backup) |
| 476 | backup.connect('toggled', self.__invert, 'backup') | 480 | backup.connect('toggled', self.__invert, 'backup') |
| 477 | backup.set_tooltip_text(_('Keep a backup copy')) | 481 | backup.set_tooltip_text(_('Keep a backup copy')) |
| 478 | table.attach(backup, 0, 1, 1, 2) | 482 | table.attach(backup, 0, 1, 1, 2) |
| 479 | 483 | ||
| 480 | pdf_quality = gtk.CheckButton(_('Reduce PDF quality'), False) | 484 | pdf_quality = Gtk.CheckButton(_('Reduce PDF quality'), False) |
| 481 | pdf_quality.set_active(self.pdf_quality) | 485 | pdf_quality.set_active(self.pdf_quality) |
| 482 | pdf_quality.connect('toggled', self.__invert, 'pdf_quality') | 486 | pdf_quality.connect('toggled', self.__invert, 'pdf_quality') |
| 483 | pdf_quality.set_tooltip_text(_('Reduce the produced PDF size and quality')) | 487 | pdf_quality.set_tooltip_text(_('Reduce the produced PDF size and quality')) |
| 484 | table.attach(pdf_quality, 0, 1, 2, 3) | 488 | table.attach(pdf_quality, 0, 1, 2, 3) |
| 485 | 489 | ||
| 486 | add2archive = gtk.CheckButton(_('Add unsupported file to archives'), | 490 | add2archive = Gtk.CheckButton(_('Add unsupported file to archives'), |
| 487 | False) | 491 | False) |
| 488 | add2archive.set_active(self.add2archive) | 492 | add2archive.set_active(self.add2archive) |
| 489 | add2archive.connect('toggled', self.__invert, 'add2archive') | 493 | add2archive.connect('toggled', self.__invert, 'add2archive') |
| @@ -492,7 +496,7 @@ non-anonymised) file to output archive')) | |||
| 492 | table.attach(add2archive, 0, 1, 3, 4) | 496 | table.attach(add2archive, 0, 1, 3, 4) |
| 493 | 497 | ||
| 494 | hbox.show_all() | 498 | hbox.show_all() |
| 495 | if not dialog.run(): # gtk.STOCK_OK | 499 | if not dialog.run(): # Gtk.STOCK_OK |
| 496 | for i in self.liststore: # update preferences | 500 | for i in self.liststore: # update preferences |
| 497 | i[0].backup = self.backup | 501 | i[0].backup = self.backup |
| 498 | i[0].add2archive = self.add2archive | 502 | i[0].add2archive = self.add2archive |
| @@ -527,7 +531,7 @@ non-anonymised) file to output archive')) | |||
| 527 | urls = selection.data.strip('\r\n\x00') # strip stupid characters | 531 | urls = selection.data.strip('\r\n\x00') # strip stupid characters |
| 528 | cleaned_urls = map(self.__clean_draged_file_path, urls.split('\n')) | 532 | cleaned_urls = map(self.__clean_draged_file_path, urls.split('\n')) |
| 529 | task = self.populate(cleaned_urls) | 533 | task = self.populate(cleaned_urls) |
| 530 | gobject.idle_add(task.next) # asynchrone processing | 534 | GObject.idle_add(task.next) # asynchrone processing |
| 531 | 535 | ||
| 532 | def __clean_draged_file_path(self, url): | 536 | def __clean_draged_file_path(self, url): |
| 533 | ''' | 537 | ''' |
| @@ -550,7 +554,7 @@ non-anonymised) file to output archive')) | |||
| 550 | if not iterator: # if nothing is selected : select everything | 554 | if not iterator: # if nothing is selected : select everything |
| 551 | iterator = xrange(len(self.liststore)) | 555 | iterator = xrange(len(self.liststore)) |
| 552 | task = func(iterator) # launch func() in an asynchrone way | 556 | task = func(iterator) # launch func() in an asynchrone way |
| 553 | gobject.idle_add(task.next) | 557 | GObject.idle_add(task.next) |
| 554 | 558 | ||
| 555 | def __mat_check(self, iterator): | 559 | def __mat_check(self, iterator): |
| 556 | ''' | 560 | ''' |
| @@ -595,6 +599,6 @@ if __name__ == '__main__': | |||
| 595 | infiles = [arg for arg in sys.argv[1:] if os.path.exists(arg)] | 599 | infiles = [arg for arg in sys.argv[1:] if os.path.exists(arg)] |
| 596 | if infiles: | 600 | if infiles: |
| 597 | task = gui.populate(infiles) | 601 | task = gui.populate(infiles) |
| 598 | gobject.idle_add(task.next) | 602 | GObject.idle_add(task.next) |
| 599 | 603 | ||
| 600 | gtk.main() | 604 | Gtk.main() |
