diff options
| author | jvoisin | 2011-08-08 20:23:35 +0200 |
|---|---|---|
| committer | jvoisin | 2011-08-08 20:23:35 +0200 |
| commit | cbe66667fa129ccaca7737d0b950271c1b694159 (patch) | |
| tree | 9072a5839c32593a1b22092e91145fbedab8ca5a | |
| parent | 74a5189408f1cd0a90dcb7b28e3a6d71e47d8b29 (diff) | |
Preliminary support for internationalization, and fix a stupid bug related to toolbar.
| -rw-r--r-- | gui.py | 127 |
1 files changed, 76 insertions, 51 deletions
| @@ -7,8 +7,9 @@ | |||
| 7 | import gtk | 7 | import gtk |
| 8 | import gobject | 8 | import gobject |
| 9 | 9 | ||
| 10 | import os | 10 | import gettext |
| 11 | import logging | 11 | import logging |
| 12 | import os | ||
| 12 | import xml.sax | 13 | import xml.sax |
| 13 | 14 | ||
| 14 | from lib import mat | 15 | from lib import mat |
| @@ -16,6 +17,9 @@ from lib import mat | |||
| 16 | __version__ = '0.1' | 17 | __version__ = '0.1' |
| 17 | __author__ = 'jvoisin' | 18 | __author__ = 'jvoisin' |
| 18 | 19 | ||
| 20 | t = gettext.translation('gui', 'locale', fallback=True) | ||
| 21 | _ = t.ugettext | ||
| 22 | |||
| 19 | logging.basicConfig(level=mat.LOGGING_LEVEL) | 23 | logging.basicConfig(level=mat.LOGGING_LEVEL) |
| 20 | 24 | ||
| 21 | 25 | ||
| @@ -73,7 +77,7 @@ class ListStoreApp: | |||
| 73 | content.add(treeview) | 77 | content.add(treeview) |
| 74 | 78 | ||
| 75 | self.statusbar = gtk.Statusbar() | 79 | self.statusbar = gtk.Statusbar() |
| 76 | self.statusbar.push(1, 'Ready') | 80 | self.statusbar.push(1, _('Ready')) |
| 77 | vbox.pack_start(self.statusbar, False, False, 0) | 81 | vbox.pack_start(self.statusbar, False, False, 0) |
| 78 | 82 | ||
| 79 | self.window.show_all() | 83 | self.window.show_all() |
| @@ -85,31 +89,32 @@ class ListStoreApp: | |||
| 85 | toolbar = gtk.Toolbar() | 89 | toolbar = gtk.Toolbar() |
| 86 | 90 | ||
| 87 | toolbutton = gtk.ToolButton(gtk.STOCK_ADD) | 91 | toolbutton = gtk.ToolButton(gtk.STOCK_ADD) |
| 88 | toolbutton.set_label('Add') | 92 | toolbutton.set_label(_('Add')) |
| 89 | toolbutton.connect('clicked', self.add_files) | 93 | toolbutton.connect('clicked', self.add_files) |
| 90 | toolbutton.set_tooltip_text('Add files') | 94 | toolbutton.set_tooltip_text(_('Add files')) |
| 91 | toolbar.add(toolbutton) | 95 | toolbar.add(toolbutton) |
| 92 | 96 | ||
| 93 | toolbutton = gtk.ToolButton(gtk.STOCK_PRINT_REPORT) | 97 | toolbutton = gtk.ToolButton(gtk.STOCK_PRINT_REPORT) |
| 94 | toolbutton.set_label('Clean') | 98 | toolbutton.set_label(_('Clean')) |
| 95 | toolbutton.connect('clicked', self.process_files, self.mat_clean) | 99 | toolbutton.connect('clicked', self.process_files, self.mat_clean) |
| 96 | toolbutton.set_tooltip_text('Clean selected files without data loss') | 100 | toolbutton.set_tooltip_text(_('Clean selected files without data loss')) |
| 97 | toolbar.add(toolbutton) | 101 | toolbar.add(toolbutton) |
| 98 | 102 | ||
| 99 | toolbutton = gtk.ToolButton(gtk.STOCK_PRINT_WARNING) | 103 | toolbutton = gtk.ToolButton(gtk.STOCK_PRINT_WARNING) |
| 100 | toolbutton.set_label('Brute Clean') | 104 | toolbutton.set_label(_('Brute Clean')) |
| 101 | toolbutton.connect('clicked', self.mat_clean_dirty) | 105 | toolbutton.connect('clicked', self.mat_clean_dirty) |
| 102 | toolbutton.set_tooltip_text('Clean selected files with possible data \ | 106 | toolbutton.set_tooltip_text(_('Clean selected files with possible \ |
| 103 | loss') | 107 | data loss')) |
| 104 | toolbar.add(toolbutton) | 108 | toolbar.add(toolbutton) |
| 105 | 109 | ||
| 106 | toolbutton = gtk.ToolButton(gtk.STOCK_FIND) | 110 | toolbutton = gtk.ToolButton(gtk.STOCK_FIND) |
| 107 | toolbutton.set_label('Check') | 111 | toolbutton.set_label(_('Check')) |
| 108 | toolbutton.connect('clicked', self.process_files, self.mat_check) | 112 | toolbutton.connect('clicked', self.process_files, self.mat_check) |
| 109 | toolbutton.set_tooltip_text('Check selected files for harmful meta') | 113 | toolbutton.set_tooltip_text(_('Check selected files for harmful meta')) |
| 110 | toolbar.add(toolbutton) | 114 | toolbar.add(toolbutton) |
| 111 | 115 | ||
| 112 | toolbutton = gtk.ToolButton(stock_id=gtk.STOCK_QUIT) | 116 | toolbutton = gtk.ToolButton(stock_id=gtk.STOCK_QUIT) |
| 117 | toolbutton.set_label(_('Quit')) | ||
| 113 | toolbutton.connect('clicked', gtk.main_quit) | 118 | toolbutton.connect('clicked', gtk.main_quit) |
| 114 | toolbar.add(toolbutton) | 119 | toolbar.add(toolbutton) |
| 115 | 120 | ||
| @@ -121,7 +126,7 @@ loss') | |||
| 121 | ''' | 126 | ''' |
| 122 | Create the columns, and add them to the treeview | 127 | Create the columns, and add them to the treeview |
| 123 | ''' | 128 | ''' |
| 124 | colname = ['Filename', 'Mimetype', 'State'] | 129 | colname = [_('Filename'), _('Mimetype'), _('State')] |
| 125 | 130 | ||
| 126 | for i, j in enumerate(colname): | 131 | for i, j in enumerate(colname): |
| 127 | filename_column = gtk.CellRendererText() | 132 | filename_column = gtk.CellRendererText() |
| @@ -141,7 +146,7 @@ loss') | |||
| 141 | picture.set_from_stock(pix, gtk.ICON_SIZE_MENU) | 146 | picture.set_from_stock(pix, gtk.ICON_SIZE_MENU) |
| 142 | item.set_image(picture) | 147 | item.set_image(picture) |
| 143 | item.set_label(name) | 148 | item.set_label(name) |
| 144 | item.connect('activate', self.process_files, func) | 149 | item.connect('activate', func) |
| 145 | menu.append(item) | 150 | menu.append(item) |
| 146 | 151 | ||
| 147 | def create_sub_menu(self, name, menubar): | 152 | def create_sub_menu(self, name, menubar): |
| @@ -161,34 +166,52 @@ loss') | |||
| 161 | ''' | 166 | ''' |
| 162 | menubar = gtk.MenuBar() | 167 | menubar = gtk.MenuBar() |
| 163 | 168 | ||
| 164 | file_menu = self.create_sub_menu('Files', menubar) | 169 | file_menu = self.create_sub_menu(_('Files'), menubar) |
| 165 | self.create_menu_item('Add files', self.add_files, file_menu, | 170 | self.create_menu_item(_('Add files'), self.add_files, file_menu, |
| 166 | gtk.STOCK_ADD) | 171 | gtk.STOCK_ADD) |
| 167 | self.create_menu_item('Quit', gtk.main_quit, file_menu, | 172 | self.create_menu_item(_('Quit'), gtk.main_quit, file_menu, |
| 168 | gtk.STOCK_QUIT) | 173 | gtk.STOCK_QUIT) |
| 169 | 174 | ||
| 170 | edit_menu = self.create_sub_menu('Edit', menubar) | 175 | edit_menu = self.create_sub_menu(_('Edit'), menubar) |
| 171 | self.create_menu_item('Clear the filelist', | 176 | self.create_menu_item(_('Clear the filelist'), |
| 172 | lambda x: self.liststore.clear(), edit_menu, gtk.STOCK_REMOVE) | 177 | lambda x: self.liststore.clear(), edit_menu, gtk.STOCK_REMOVE) |
| 173 | self.create_menu_item('Preferences', self.preferences, edit_menu, | 178 | self.create_menu_item(_('Preferences'), self.preferences, edit_menu, |
| 174 | gtk.STOCK_PREFERENCES) | 179 | gtk.STOCK_PREFERENCES) |
| 175 | 180 | ||
| 176 | clean_menu = self.create_sub_menu('Clean', menubar) | 181 | process_menu = self.create_sub_menu(_('Process'), menubar) |
| 177 | self.create_menu_item('Clean', self.mat_clean, clean_menu, | 182 | item = gtk.ImageMenuItem() |
| 178 | gtk.STOCK_PRINT_REPORT) | 183 | picture = gtk.Image() |
| 179 | self.create_menu_item('Clean (lossy way)', self.mat_clean_dirty, | 184 | picture.set_from_stock(gtk.STOCK_PRINT_REPORT, gtk.ICON_SIZE_MENU) |
| 180 | clean_menu, gtk.STOCK_PRINT_WARNING) | 185 | item.set_image(picture) |
| 181 | self.create_menu_item('Check', self.mat_check, clean_menu, | 186 | item.set_label(_('Clean')) |
| 182 | gtk.STOCK_FIND) | 187 | item.connect('activate', self.process_files, self.mat_clean) |
| 188 | process_menu.append(item) | ||
| 189 | |||
| 190 | item = gtk.ImageMenuItem() | ||
| 191 | picture = gtk.Image() | ||
| 192 | picture.set_from_stock(gtk.STOCK_PRINT_WARNING, gtk.ICON_SIZE_MENU) | ||
| 193 | item.set_image(picture) | ||
| 194 | item.set_label(_('Clean (lossy way)')) | ||
| 195 | item.connect('activate', self.process_files, self.mat_clean_dirty) | ||
| 196 | process_menu.append(item) | ||
| 197 | |||
| 198 | item = gtk.ImageMenuItem() | ||
| 199 | picture = gtk.Image() | ||
| 200 | picture.set_from_stock(gtk.STOCK_FIND, gtk.ICON_SIZE_MENU) | ||
| 201 | item.set_image(picture) | ||
| 202 | item.set_label(_('Check')) | ||
| 203 | item.connect('activate', self.process_files, self.mat_check) | ||
| 204 | process_menu.append(item) | ||
| 205 | |||
| 183 | 206 | ||
| 184 | help_menu = self.create_sub_menu('Help', menubar) | 207 | help_menu = self.create_sub_menu(_('Help'), menubar) |
| 185 | self.create_menu_item('Supported formats', self.supported, help_menu, | 208 | self.create_menu_item(_('Supported formats'), self.supported, help_menu, |
| 186 | gtk.STOCK_INFO) | 209 | gtk.STOCK_INFO) |
| 187 | self.create_menu_item('About', self.about, help_menu, gtk.STOCK_ABOUT) | 210 | self.create_menu_item('About', self.about, help_menu, gtk.STOCK_ABOUT) |
| 188 | 211 | ||
| 189 | return menubar | 212 | return menubar |
| 190 | 213 | ||
| 191 | def add_files(self, _): | 214 | def add_files(self, button): |
| 192 | ''' | 215 | ''' |
| 193 | Add the files chosed by the filechoser ("Add" button) | 216 | Add the files chosed by the filechoser ("Add" button) |
| 194 | ''' | 217 | ''' |
| @@ -222,12 +245,12 @@ loss') | |||
| 222 | Append selected files by add_file to the self.liststore | 245 | Append selected files by add_file to the self.liststore |
| 223 | ''' | 246 | ''' |
| 224 | for filename in filenames: # filenames : all selected files/folders | 247 | for filename in filenames: # filenames : all selected files/folders |
| 225 | if os.path.isdir(filename): # directory | 248 | if os.path.isdir(filename): # if "filename" is a directory |
| 226 | for root, dirs, files in os.walk(filename): | 249 | for root, dirs, files in os.walk(filename): |
| 227 | for item in files: | 250 | for item in files: |
| 228 | path_to_file = os.path.join(root, item) | 251 | path_to_file = os.path.join(root, item) |
| 229 | self.add_file_to_treeview(path_to_file) | 252 | self.add_file_to_treeview(path_to_file) |
| 230 | else: | 253 | else: # filename is a regular file |
| 231 | self.add_file_to_treeview(filename) | 254 | self.add_file_to_treeview(filename) |
| 232 | yield True | 255 | yield True |
| 233 | yield False | 256 | yield False |
| @@ -242,7 +265,7 @@ loss') | |||
| 242 | cf.file.mime, 'unknow']) | 265 | cf.file.mime, 'unknow']) |
| 243 | 266 | ||
| 244 | 267 | ||
| 245 | def about(self, _): | 268 | def about(self, button): |
| 246 | ''' | 269 | ''' |
| 247 | About popup | 270 | About popup |
| 248 | ''' | 271 | ''' |
| @@ -258,7 +281,7 @@ loss') | |||
| 258 | if click: | 281 | if click: |
| 259 | w.destroy() | 282 | w.destroy() |
| 260 | 283 | ||
| 261 | def supported(self, _): | 284 | def supported(self, button): |
| 262 | ''' | 285 | ''' |
| 263 | List the supported formats | 286 | List the supported formats |
| 264 | ''' | 287 | ''' |
| @@ -281,7 +304,8 @@ loss') | |||
| 281 | for item in handler.list: # list of dict : one dict per format | 304 | for item in handler.list: # list of dict : one dict per format |
| 282 | #create one expander per format | 305 | #create one expander per format |
| 283 | title = '%s (%s)' % (item['name'], item['extension']) | 306 | title = '%s (%s)' % (item['name'], item['extension']) |
| 284 | support = '\t<b>support</b> : ' + item['support'] | 307 | support = ('\t<b>%s</b> : %s' % (_('support'), item['support'])) |
| 308 | #support = '\t<b>support</b> : ' + item['support'] | ||
| 285 | metadata = '\n\t<b>metadata</b> : ' + item['metadata'] | 309 | metadata = '\n\t<b>metadata</b> : ' + item['metadata'] |
| 286 | method = '\n\t<b>method</b> : ' + item['method'] | 310 | method = '\n\t<b>method</b> : ' + item['method'] |
| 287 | content = support + metadata + method | 311 | content = support + metadata + method |
| @@ -299,11 +323,11 @@ loss') | |||
| 299 | if click is 0: # Close | 323 | if click is 0: # Close |
| 300 | dialog.destroy() | 324 | dialog.destroy() |
| 301 | 325 | ||
| 302 | def preferences(self, _): | 326 | def preferences(self, button): |
| 303 | ''' | 327 | ''' |
| 304 | Preferences popup | 328 | Preferences popup |
| 305 | ''' | 329 | ''' |
| 306 | dialog = gtk.Dialog('Preferences', self.window, 0, (gtk.STOCK_OK, 0)) | 330 | dialog = gtk.Dialog(_('Preferences'), self.window, 0, (gtk.STOCK_OK, 0)) |
| 307 | hbox = gtk.HBox() | 331 | hbox = gtk.HBox() |
| 308 | dialog.get_content_area().pack_start(hbox, False, False, 0) | 332 | dialog.get_content_area().pack_start(hbox, False, False, 0) |
| 309 | 333 | ||
| @@ -314,24 +338,25 @@ loss') | |||
| 314 | table = gtk.Table(3, 2, False) # nb rows, nb lines | 338 | table = gtk.Table(3, 2, False) # nb rows, nb lines |
| 315 | hbox.pack_start(table, True, True, 0) | 339 | hbox.pack_start(table, True, True, 0) |
| 316 | 340 | ||
| 317 | force = gtk.CheckButton('Force Clean', False) | 341 | force = gtk.CheckButton(_('Force Clean'), False) |
| 318 | force.set_active(self.force) | 342 | force.set_active(self.force) |
| 319 | force.connect('toggled', self.invert, 'force') | 343 | force.connect('toggled', self.invert, 'force') |
| 320 | force.set_tooltip_text('Do not check if already clean before cleaning') | 344 | force.set_tooltip_text(_('Do not check if already clean before \ |
| 345 | cleaning')) | ||
| 321 | table.attach(force, 0, 1, 0, 1) | 346 | table.attach(force, 0, 1, 0, 1) |
| 322 | 347 | ||
| 323 | backup = gtk.CheckButton('Backup', False) | 348 | backup = gtk.CheckButton(_('Backup'), False) |
| 324 | backup.set_active(self.backup) | 349 | backup.set_active(self.backup) |
| 325 | backup.connect('toggled', self.invert, 'backup') | 350 | backup.connect('toggled', self.invert, 'backup') |
| 326 | backup.set_tooltip_text('Keep a backup copy') | 351 | backup.set_tooltip_text(_('Keep a backup copy')) |
| 327 | table.attach(backup, 0, 1, 1, 2) | 352 | table.attach(backup, 0, 1, 1, 2) |
| 328 | 353 | ||
| 329 | add2archive = gtk.CheckButton('Add unsupported file to archives', | 354 | add2archive = gtk.CheckButton(_('Add unsupported file to archives'), |
| 330 | False) | 355 | False) |
| 331 | add2archive.set_active(self.add2archive) | 356 | add2archive.set_active(self.add2archive) |
| 332 | add2archive.connect('toggled', self.invert, 'add2archive') | 357 | add2archive.connect('toggled', self.invert, 'add2archive') |
| 333 | add2archive.set_tooltip_text('Add non-supported (and so \ | 358 | add2archive.set_tooltip_text(_('Add non-supported (and so \ |
| 334 | non-anonymised) file to outputed archive') | 359 | non-anonymised) file to outputed archive')) |
| 335 | table.attach(add2archive, 0, 1, 2, 3) | 360 | table.attach(add2archive, 0, 1, 2, 3) |
| 336 | 361 | ||
| 337 | hbox.show_all() | 362 | hbox.show_all() |
| @@ -366,9 +391,9 @@ non-anonymised) file to outputed archive') | |||
| 366 | ''' | 391 | ''' |
| 367 | for line in iterator: # for each file in selection | 392 | for line in iterator: # for each file in selection |
| 368 | if self.liststore[line][0].file.is_clean(): | 393 | if self.liststore[line][0].file.is_clean(): |
| 369 | string = 'clean' | 394 | string = _('clean') |
| 370 | else: | 395 | else: |
| 371 | string = 'dirty' | 396 | string = _('dirty') |
| 372 | logging.info('%s is %s' % (self.liststore[line][1], string)) | 397 | logging.info('%s is %s' % (self.liststore[line][1], string)) |
| 373 | self.liststore[line][3] = string | 398 | self.liststore[line][3] = string |
| 374 | yield True | 399 | yield True |
| @@ -380,10 +405,10 @@ non-anonymised) file to outputed archive') | |||
| 380 | ''' | 405 | ''' |
| 381 | for line in iterator: # for each file in selection | 406 | for line in iterator: # for each file in selection |
| 382 | logging.info('Cleaning %s' % self.liststore[line][1]) | 407 | logging.info('Cleaning %s' % self.liststore[line][1]) |
| 383 | if self.liststore[line][3] is not 'clean': | 408 | if self.liststore[line][3] is not _('clean'): |
| 384 | if self.force or not self.liststore[line][0].file.is_clean(): | 409 | if self.force or not self.liststore[line][0].file.is_clean(): |
| 385 | self.liststore[line][0].file.remove_all() | 410 | self.liststore[line][0].file.remove_all() |
| 386 | self.liststore[line][3] = 'clean' | 411 | self.liststore[line][3] = _('clean') |
| 387 | yield True | 412 | yield True |
| 388 | yield False | 413 | yield False |
| 389 | 414 | ||
| @@ -393,10 +418,10 @@ non-anonymised) file to outputed archive') | |||
| 393 | ''' | 418 | ''' |
| 394 | for line in iterator: # for each file in selection | 419 | for line in iterator: # for each file in selection |
| 395 | logging.info('Cleaning (lossy way) %s' % self.liststore[line][1]) | 420 | logging.info('Cleaning (lossy way) %s' % self.liststore[line][1]) |
| 396 | if self.liststore[line][3] is not 'clean': | 421 | if self.liststore[line][3] is not _('clean'): |
| 397 | if self.force or not self.liststore[line][0].file.is_clean(): | 422 | if self.force or not self.liststore[line][0].file.is_clean(): |
| 398 | self.liststore[line][0].file.remove_all_ugly() | 423 | self.liststore[line][0].file.remove_all_ugly() |
| 399 | self.liststore[line][3] = 'clean' | 424 | self.liststore[line][3] = _('clean') |
| 400 | yield True | 425 | yield True |
| 401 | yield False | 426 | yield False |
| 402 | 427 | ||
| @@ -522,8 +547,8 @@ class TreeViewTooltips(object): | |||
| 522 | ''' | 547 | ''' |
| 523 | add a gtk.TreeView to the tooltip | 548 | add a gtk.TreeView to the tooltip |
| 524 | ''' | 549 | ''' |
| 525 | view.connect("motion-notify-event", self.__motion_handler) | 550 | view.connect('motion-notify-event', self.__motion_handler) |
| 526 | view.connect("leave-notify-event", lambda i, j: self.__hide()) | 551 | view.connect('leave-notify-event', lambda i, j: self.__hide()) |
| 527 | 552 | ||
| 528 | def get_tooltip(self, view, column, path): | 553 | def get_tooltip(self, view, column, path): |
| 529 | ''' | 554 | ''' |
