diff options
| author | jvoisin | 2011-07-27 15:52:09 +0200 |
|---|---|---|
| committer | jvoisin | 2011-07-27 15:52:09 +0200 |
| commit | 9626ec1bcd7e333eb5169803b360333ba42a260a (patch) | |
| tree | b03433f2071e68b126ca28b0ff425840fe5c761f | |
| parent | e239c9e1ded521acb8b025701bc3d3b5a6084e37 (diff) | |
Retro-portage from gi module to gtk module
| -rw-r--r-- | gui.py | 124 |
1 files changed, 65 insertions, 59 deletions
| @@ -1,6 +1,9 @@ | |||
| 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
| 2 | 2 | ||
| 3 | from gi.repository import Gtk, GObject | 3 | #from gi.repository import gtk, GObject |
| 4 | import gtk | ||
| 5 | import gobject | ||
| 6 | |||
| 4 | import os | 7 | import os |
| 5 | import logging | 8 | import logging |
| 6 | from lib import mat | 9 | from lib import mat |
| @@ -13,17 +16,17 @@ logging.basicConfig(level=mat.LOGGING_LEVEL) | |||
| 13 | SUPPORTED = (('image/png', 'image/jpeg', 'image/gif', | 16 | SUPPORTED = (('image/png', 'image/jpeg', 'image/gif', |
| 14 | 'misc/pdf'), | 17 | 'misc/pdf'), |
| 15 | ('*.jpg', '*.jpeg', '*.png', '*.bmp', '*.pdf', | 18 | ('*.jpg', '*.jpeg', '*.png', '*.bmp', '*.pdf', |
| 16 | '*.tar', '*.tar.bz2', '*.tar.gz', '*.mp3')) | 19 | '*.tar', '*.tar.bz2', '*.tar.gz', '*.mp3',)) |
| 17 | 20 | ||
| 18 | 21 | ||
| 19 | class CFile(GObject.GObject): | 22 | class CFile(gobject.GObject): |
| 20 | ''' | 23 | ''' |
| 21 | Contain the class-file of the file "path" | 24 | Contain the class-file of the file "path" |
| 22 | This class exist just to be "around" my parser.Generic_parser class, | 25 | This class exist just to be "around" my parser.Generic_parser class, |
| 23 | since Gtk.ListStore does not accept it. | 26 | since gtk.ListStore does not accept it. |
| 24 | ''' | 27 | ''' |
| 25 | def __init__(self, path, backup, add2archive): | 28 | def __init__(self, path, backup, add2archive): |
| 26 | GObject.GObject.__init__(self) | 29 | gobject.GObject.__init__(self) |
| 27 | try: | 30 | try: |
| 28 | self.file = mat.create_class_file(path, backup, add2archive) | 31 | self.file = mat.create_class_file(path, backup, add2archive) |
| 29 | except: | 32 | except: |
| @@ -35,41 +38,41 @@ class ListStoreApp: | |||
| 35 | Main GUI class | 38 | Main GUI class |
| 36 | ''' | 39 | ''' |
| 37 | def __init__(self): | 40 | def __init__(self): |
| 38 | #preferences | 41 | # Preferences |
| 42 | self.add2archive = True | ||
| 39 | self.backup = True | 43 | self.backup = True |
| 40 | self.force = False | 44 | self.force = False |
| 41 | self.add2archive = True | ||
| 42 | 45 | ||
| 43 | self.window = Gtk.Window() | 46 | self.window = gtk.Window() |
| 44 | self.window.set_title('Metadata Anonymisation Toolkit %s' % | 47 | self.window.set_title('Metadata Anonymisation Toolkit %s' % |
| 45 | __version__) | 48 | __version__) |
| 46 | self.window.connect('destroy', Gtk.main_quit) | 49 | self.window.connect('destroy', gtk.main_quit) |
| 47 | self.window.set_default_size(800, 600) | 50 | self.window.set_default_size(800, 600) |
| 48 | 51 | ||
| 49 | vbox = Gtk.VBox() | 52 | vbox = gtk.VBox() |
| 50 | self.window.add(vbox) | 53 | self.window.add(vbox) |
| 51 | 54 | ||
| 52 | menubar = self.create_menu() | 55 | menubar = self.create_menu() |
| 53 | toolbar = self.create_toolbar() | 56 | toolbar = self.create_toolbar() |
| 54 | content = Gtk.ScrolledWindow() | 57 | content = gtk.ScrolledWindow() |
| 55 | vbox.pack_start(menubar, False, True, 0) | 58 | vbox.pack_start(menubar, False, True, 0) |
| 56 | vbox.pack_start(toolbar, False, True, 0) | 59 | vbox.pack_start(toolbar, False, True, 0) |
| 57 | vbox.pack_start(content, True, True, 0) | 60 | vbox.pack_start(content, True, True, 0) |
| 58 | 61 | ||
| 59 | #parser.class - name - type - cleaned | 62 | # parser.class - name - type - cleaned |
| 60 | self.liststore = Gtk.ListStore(CFile, str, str, str) | 63 | self.liststore = gtk.ListStore(CFile, str, str, str) |
| 61 | 64 | ||
| 62 | treeview = Gtk.TreeView(model=self.liststore) | 65 | treeview = gtk.TreeView(model=self.liststore) |
| 63 | treeview.set_search_column(1) # name column is searchable | 66 | treeview.set_search_column(1) # name column is searchable |
| 64 | treeview.set_rules_hint(True) # alternate colors for rows | 67 | treeview.set_rules_hint(True) # alternate colors for rows |
| 65 | treeview.set_rubber_banding(True) # mouse selection | 68 | treeview.set_rubber_banding(True) # mouse selection |
| 66 | self.add_columns(treeview) | 69 | self.add_columns(treeview) |
| 67 | self.selection = treeview.get_selection() | 70 | self.selection = treeview.get_selection() |
| 68 | self.selection.set_mode(Gtk.SelectionMode.MULTIPLE) | 71 | self.selection.set_mode(gtk.SELECTION_MULTIPLE) |
| 69 | 72 | ||
| 70 | content.add(treeview) | 73 | content.add(treeview) |
| 71 | 74 | ||
| 72 | self.statusbar = Gtk.Statusbar() | 75 | self.statusbar = gtk.Statusbar() |
| 73 | self.statusbar.push(1, 'Ready') | 76 | self.statusbar.push(1, 'Ready') |
| 74 | vbox.pack_start(self.statusbar, False, False, 0) | 77 | vbox.pack_start(self.statusbar, False, False, 0) |
| 75 | 78 | ||
| @@ -79,35 +82,37 @@ class ListStoreApp: | |||
| 79 | ''' | 82 | ''' |
| 80 | Returns a vbox object, which contains a toolbar with buttons | 83 | Returns a vbox object, which contains a toolbar with buttons |
| 81 | ''' | 84 | ''' |
| 82 | toolbar = Gtk.Toolbar() | 85 | toolbar = gtk.Toolbar() |
| 83 | 86 | ||
| 84 | toolbutton = Gtk.ToolButton(label='Add', stock_id=Gtk.STOCK_ADD) | 87 | toolbutton = gtk.ToolButton(gtk.STOCK_ADD) |
| 88 | toolbutton.set_label('Add') | ||
| 85 | toolbutton.connect('clicked', self.add_files) | 89 | toolbutton.connect('clicked', self.add_files) |
| 86 | toolbutton.set_tooltip_text('Add files') | 90 | toolbutton.set_tooltip_text('Add files') |
| 87 | toolbar.add(toolbutton) | 91 | toolbar.add(toolbutton) |
| 88 | 92 | ||
| 89 | toolbutton = Gtk.ToolButton(label='Clean', | 93 | toolbutton = gtk.ToolButton(gtk.STOCK_PRINT_REPORT) |
| 90 | stock_id=Gtk.STOCK_PRINT_REPORT) | 94 | toolbutton.set_label('Clean') |
| 91 | toolbutton.connect('clicked', self.mat_clean) | 95 | toolbutton.connect('clicked', self.mat_clean) |
| 92 | toolbutton.set_tooltip_text('Clean selected files without data loss') | 96 | toolbutton.set_tooltip_text('Clean selected files without data loss') |
| 93 | toolbar.add(toolbutton) | 97 | toolbar.add(toolbutton) |
| 94 | 98 | ||
| 95 | toolbutton = Gtk.ToolButton(label='Brute Clean', | 99 | toolbutton = gtk.ToolButton(gtk.STOCK_PRINT_WARNING) |
| 96 | stock_id=Gtk.STOCK_PRINT_WARNING) | 100 | toolbutton.set_label('Brute Clean') |
| 97 | toolbutton.set_tooltip_text('Clean selected files with possible data \ | 101 | toolbutton.set_tooltip_text('Clean selected files with possible data \ |
| 98 | loss') | 102 | loss') |
| 99 | toolbar.add(toolbutton) | 103 | toolbar.add(toolbutton) |
| 100 | 104 | ||
| 101 | toolbutton = Gtk.ToolButton(label='Check', stock_id=Gtk.STOCK_FIND) | 105 | toolbutton = gtk.ToolButton(gtk.STOCK_FIND) |
| 106 | toolbutton.set_label('Check') | ||
| 102 | toolbutton.connect('clicked', self.mat_check) | 107 | toolbutton.connect('clicked', self.mat_check) |
| 103 | toolbutton.set_tooltip_text('Check selected files for harmful meta') | 108 | toolbutton.set_tooltip_text('Check selected files for harmful meta') |
| 104 | toolbar.add(toolbutton) | 109 | toolbar.add(toolbutton) |
| 105 | 110 | ||
| 106 | toolbutton = Gtk.ToolButton(stock_id=Gtk.STOCK_QUIT) | 111 | toolbutton = gtk.ToolButton(stock_id=gtk.STOCK_QUIT) |
| 107 | toolbutton.connect('clicked', Gtk.main_quit) | 112 | toolbutton.connect('clicked', gtk.main_quit) |
| 108 | toolbar.add(toolbutton) | 113 | toolbar.add(toolbutton) |
| 109 | 114 | ||
| 110 | vbox = Gtk.VBox(spacing=3) | 115 | vbox = gtk.VBox(spacing=3) |
| 111 | vbox.pack_start(toolbar, False, False, 0) | 116 | vbox.pack_start(toolbar, False, False, 0) |
| 112 | return vbox | 117 | return vbox |
| 113 | 118 | ||
| @@ -118,8 +123,8 @@ class ListStoreApp: | |||
| 118 | colname = ['Filename', 'Mimetype', 'Cleaned'] | 123 | colname = ['Filename', 'Mimetype', 'Cleaned'] |
| 119 | 124 | ||
| 120 | for i, j in enumerate(colname): | 125 | for i, j in enumerate(colname): |
| 121 | filename_column = Gtk.CellRendererText() | 126 | filename_column = gtk.CellRendererText() |
| 122 | column = Gtk.TreeViewColumn(j, filename_column, text=i + 1) | 127 | column = gtk.TreeViewColumn(j, filename_column, text=i + 1) |
| 123 | column.set_sort_column_id(i + 1) | 128 | column.set_sort_column_id(i + 1) |
| 124 | treeview.append_column(column) | 129 | treeview.append_column(column) |
| 125 | 130 | ||
| @@ -127,8 +132,9 @@ class ListStoreApp: | |||
| 127 | ''' | 132 | ''' |
| 128 | Create a MenuItem() like Preferences, Quit, Add, Clean, ... | 133 | Create a MenuItem() like Preferences, Quit, Add, Clean, ... |
| 129 | ''' | 134 | ''' |
| 130 | item = Gtk.ImageMenuItem() | 135 | item = gtk.ImageMenuItem() |
| 131 | picture = Gtk.Image.new_from_stock(pix, Gtk.IconSize.MENU) | 136 | picture = gtk.Image() |
| 137 | picture.set_from_stock(pix, gtk.ICON_SIZE_MENU) | ||
| 132 | item.set_image(picture) | 138 | item.set_image(picture) |
| 133 | item.set_label(name) | 139 | item.set_label(name) |
| 134 | item.connect('activate', func) | 140 | item.connect('activate', func) |
| @@ -138,8 +144,8 @@ class ListStoreApp: | |||
| 138 | ''' | 144 | ''' |
| 139 | Create a submenu like File, Edit, Clean, ... | 145 | Create a submenu like File, Edit, Clean, ... |
| 140 | ''' | 146 | ''' |
| 141 | submenu = Gtk.Menu() | 147 | submenu = gtk.Menu() |
| 142 | menuitem = Gtk.MenuItem() | 148 | menuitem = gtk.MenuItem() |
| 143 | menuitem.set_submenu(submenu) | 149 | menuitem.set_submenu(submenu) |
| 144 | menuitem.set_label(name) | 150 | menuitem.set_label(name) |
| 145 | menubar.append(menuitem) | 151 | menubar.append(menuitem) |
| @@ -149,30 +155,30 @@ class ListStoreApp: | |||
| 149 | ''' | 155 | ''' |
| 150 | Return a MenuBar | 156 | Return a MenuBar |
| 151 | ''' | 157 | ''' |
| 152 | menubar = Gtk.MenuBar() | 158 | menubar = gtk.MenuBar() |
| 153 | 159 | ||
| 154 | file_menu = self.create_sub_menu('Files', menubar) | 160 | file_menu = self.create_sub_menu('Files', menubar) |
| 155 | self.create_menu_item('Add files', self.add_files, file_menu, | 161 | self.create_menu_item('Add files', self.add_files, file_menu, |
| 156 | Gtk.STOCK_ADD) | 162 | gtk.STOCK_ADD) |
| 157 | self.create_menu_item('Quit', Gtk.main_quit, file_menu, | 163 | self.create_menu_item('Quit', gtk.main_quit, file_menu, |
| 158 | Gtk.STOCK_QUIT) | 164 | gtk.STOCK_QUIT) |
| 159 | 165 | ||
| 160 | edit_menu = self.create_sub_menu('Edit', menubar) | 166 | edit_menu = self.create_sub_menu('Edit', menubar) |
| 161 | self.create_menu_item('Clear the filelist', self.clear_model, | 167 | self.create_menu_item('Clear the filelist', self.clear_model, |
| 162 | edit_menu, Gtk.STOCK_REMOVE) | 168 | edit_menu, gtk.STOCK_REMOVE) |
| 163 | self.create_menu_item('Preferences', self.preferences, edit_menu, | 169 | self.create_menu_item('Preferences', self.preferences, edit_menu, |
| 164 | Gtk.STOCK_PREFERENCES) | 170 | gtk.STOCK_PREFERENCES) |
| 165 | 171 | ||
| 166 | clean_menu = self.create_sub_menu('Clean', menubar) | 172 | clean_menu = self.create_sub_menu('Clean', menubar) |
| 167 | self.create_menu_item('Clean', self.mat_clean, clean_menu, | 173 | self.create_menu_item('Clean', self.mat_clean, clean_menu, |
| 168 | Gtk.STOCK_PRINT_REPORT) | 174 | gtk.STOCK_PRINT_REPORT) |
| 169 | self.create_menu_item('Clean (lossy way)', self.mat_clean_dirty, | 175 | self.create_menu_item('Clean (lossy way)', self.mat_clean_dirty, |
| 170 | clean_menu, Gtk.STOCK_PRINT_WARNING) | 176 | clean_menu, gtk.STOCK_PRINT_WARNING) |
| 171 | self.create_menu_item('Check', self.mat_check, clean_menu, | 177 | self.create_menu_item('Check', self.mat_check, clean_menu, |
| 172 | Gtk.STOCK_FIND) | 178 | gtk.STOCK_FIND) |
| 173 | 179 | ||
| 174 | help_menu = self.create_sub_menu('Help', menubar) | 180 | help_menu = self.create_sub_menu('Help', menubar) |
| 175 | self.create_menu_item('About', self.about, help_menu, Gtk.STOCK_ABOUT) | 181 | self.create_menu_item('About', self.about, help_menu, gtk.STOCK_ABOUT) |
| 176 | 182 | ||
| 177 | return menubar | 183 | return menubar |
| 178 | 184 | ||
| @@ -181,7 +187,7 @@ class ListStoreApp: | |||
| 181 | Return a filter for | 187 | Return a filter for |
| 182 | supported content | 188 | supported content |
| 183 | ''' | 189 | ''' |
| 184 | filter = Gtk.FileFilter() | 190 | filter = gtk.FileFilter() |
| 185 | filter.set_name('Supported files') | 191 | filter.set_name('Supported files') |
| 186 | for item in SUPPORTED[0]: # add by mime | 192 | for item in SUPPORTED[0]: # add by mime |
| 187 | filter.add_mime_type(item) | 193 | filter.add_mime_type(item) |
| @@ -193,15 +199,15 @@ class ListStoreApp: | |||
| 193 | ''' | 199 | ''' |
| 194 | Add the files chosed by the filechoser ("Add" button) | 200 | Add the files chosed by the filechoser ("Add" button) |
| 195 | ''' | 201 | ''' |
| 196 | chooser = Gtk.FileChooserDialog( | 202 | chooser = gtk.FileChooserDialog( |
| 197 | title='Choose files', | 203 | title='Choose files', |
| 198 | parent=None, | 204 | parent=None, |
| 199 | action=Gtk.FileChooserAction.OPEN, | 205 | action=gtk.FILE_CHOOSER_ACTION_OPEN, |
| 200 | buttons=(Gtk.STOCK_OK, 0, Gtk.STOCK_CANCEL, 1)) | 206 | buttons=(gtk.STOCK_OK, 0, gtk.STOCK_CANCEL, 1)) |
| 201 | chooser.set_default_response(0) | 207 | chooser.set_default_response(0) |
| 202 | chooser.set_select_multiple(True) | 208 | chooser.set_select_multiple(True) |
| 203 | 209 | ||
| 204 | filter = Gtk.FileFilter() | 210 | filter = gtk.FileFilter() |
| 205 | filter.set_name('All files') | 211 | filter.set_name('All files') |
| 206 | filter.add_pattern('*') | 212 | filter.add_pattern('*') |
| 207 | chooser.add_filter(filter) | 213 | chooser.add_filter(filter) |
| @@ -209,7 +215,7 @@ class ListStoreApp: | |||
| 209 | 215 | ||
| 210 | response = chooser.run() | 216 | response = chooser.run() |
| 211 | 217 | ||
| 212 | if response is 0: # Gtk.STOCK_OK | 218 | if response is 0: # gtk.STOCK_OK |
| 213 | filenames = chooser.get_filenames() | 219 | filenames = chooser.get_filenames() |
| 214 | chooser.destroy() | 220 | chooser.destroy() |
| 215 | for item in filenames: | 221 | for item in filenames: |
| @@ -234,7 +240,7 @@ class ListStoreApp: | |||
| 234 | ''' | 240 | ''' |
| 235 | About popup | 241 | About popup |
| 236 | ''' | 242 | ''' |
| 237 | w = Gtk.AboutDialog() | 243 | w = gtk.AboutDialog() |
| 238 | w.set_version(__version__) | 244 | w.set_version(__version__) |
| 239 | w.set_copyright('GNU Public License v2') | 245 | w.set_copyright('GNU Public License v2') |
| 240 | w.set_comments('This software was coded during the GSoC 2011') | 246 | w.set_comments('This software was coded during the GSoC 2011') |
| @@ -250,31 +256,31 @@ class ListStoreApp: | |||
| 250 | ''' | 256 | ''' |
| 251 | Preferences popup | 257 | Preferences popup |
| 252 | ''' | 258 | ''' |
| 253 | dialog = Gtk.Dialog('Preferences', self.window, 0, (Gtk.STOCK_OK, 0)) | 259 | dialog = gtk.Dialog('Preferences', self.window, 0, (gtk.STOCK_OK, 0)) |
| 254 | content_area = dialog.get_content_area() | 260 | content_area = dialog.get_content_area() |
| 255 | hbox = Gtk.HBox() | 261 | hbox = gtk.HBox() |
| 256 | content_area.pack_start(hbox, False, False, 0) | 262 | content_area.pack_start(hbox, False, False, 0) |
| 257 | icon = Gtk.Image(stock=Gtk.STOCK_PREFERENCES, | 263 | icon = gtk.Image() |
| 258 | icon_size=Gtk.IconSize.DIALOG) # the little picture on the left | 264 | icon.set_from_stock(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_DIALOG) |
| 259 | 265 | ||
| 260 | hbox.pack_start(icon, False, False, 0) | 266 | hbox.pack_start(icon, False, False, 0) |
| 261 | 267 | ||
| 262 | table = Gtk.Table(3, 2, False) # nb rows, nb lines | 268 | table = gtk.Table(3, 2, False) # nb rows, nb lines |
| 263 | table.set_row_spacings(4) | 269 | table.set_row_spacings(4) |
| 264 | table.set_col_spacings(4) | 270 | table.set_col_spacings(4) |
| 265 | hbox.pack_start(table, True, True, 0) | 271 | hbox.pack_start(table, True, True, 0) |
| 266 | 272 | ||
| 267 | force = Gtk.CheckButton('Force Clean', False) | 273 | force = gtk.CheckButton('Force Clean', False) |
| 268 | force.connect('toggled', self.invert, 'force') | 274 | force.connect('toggled', self.invert, 'force') |
| 269 | force.set_tooltip_text('Do not check if already clean before cleaning') | 275 | force.set_tooltip_text('Do not check if already clean before cleaning') |
| 270 | force.set_active(self.force) | 276 | force.set_active(self.force) |
| 271 | 277 | ||
| 272 | backup = Gtk.CheckButton('Backup', False) | 278 | backup = gtk.CheckButton('Backup', False) |
| 273 | backup.connect('toggled', self.invert, 'backup') | 279 | backup.connect('toggled', self.invert, 'backup') |
| 274 | backup.set_tooltip_text('Keep a backup copy') | 280 | backup.set_tooltip_text('Keep a backup copy') |
| 275 | backup.set_active(self.backup) | 281 | backup.set_active(self.backup) |
| 276 | 282 | ||
| 277 | add2archive = Gtk.CheckButton('Add unsupported file to archives', | 283 | add2archive = gtk.CheckButton('Add unsupported file to archives', |
| 278 | False) | 284 | False) |
| 279 | add2archive.connect('toggled', self.invert, 'add2archive') | 285 | add2archive.connect('toggled', self.invert, 'add2archive') |
| 280 | add2archive.set_tooltip_text('Add non-supported (and so \ | 286 | add2archive.set_tooltip_text('Add non-supported (and so \ |
| @@ -287,7 +293,7 @@ non-anonymised) file to outputed archive') | |||
| 287 | 293 | ||
| 288 | hbox.show_all() | 294 | hbox.show_all() |
| 289 | response = dialog.run() | 295 | response = dialog.run() |
| 290 | if response is 0: # Gtk.STOCK_OK | 296 | if response is 0: # gtk.STOCK_OK |
| 291 | dialog.destroy() | 297 | dialog.destroy() |
| 292 | 298 | ||
| 293 | def invert(self, button, name): # still not better :/ | 299 | def invert(self, button, name): # still not better :/ |
| @@ -363,4 +369,4 @@ non-anonymised) file to outputed archive') | |||
| 363 | 369 | ||
| 364 | if __name__ == '__main__': | 370 | if __name__ == '__main__': |
| 365 | ListStoreApp() | 371 | ListStoreApp() |
| 366 | Gtk.main() | 372 | gtk.main() |
