Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.0, 1.0.1, and 1.0.2

gdialog: break out icon loading code into it's own function

Changeset 01e05e797feb

Parent 4ded77010bd3

by Steve Borho

Changes to one file · Browse files at 01e05e797feb Showing diff from parent 4ded77010bd3 Diff from another changeset...

 
326
327
328
329
330
331
332
333
 
 
334
335
336
 
426
427
428
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429
430
431
 
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
 
532
533
534
 
326
327
328
 
 
 
 
 
329
330
331
332
333
 
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
 
526
527
528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
529
530
531
532
@@ -326,11 +326,8 @@
  if tip:   tbutton.set_tooltip(self.tooltips, tip)   if icon: - path = paths.get_tortoise_icon(icon) - if path: - image = gtk.Image() - image.set_from_file(path) - tbutton.set_icon_widget(image) + image = self.icon_from_name(icon) + tbutton.set_icon_widget(image)   tbutton.set_use_underline(True)   tbutton.set_label(label)   tbutton.connect('clicked', handler, userdata) @@ -426,6 +423,22 @@
  def setfocus(self, window, event):   self.lastpos = self.get_position()   + def icon_from_name(self, icon): + if icon.startswith('gtk'): + img = gtk.image_new_from_stock(icon, gtk.ICON_SIZE_MENU) + else: + img = gtk.Image() + ico = paths.get_tortoise_icon(icon) + if not ico: + return img + try: + width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) + buf = gtk.gdk.pixbuf_new_from_file_at_size(ico, width, height) + img.set_from_pixbuf(buf) + except: # don't let broken gtk+ to break dialogs + pass + return img +   def _setup_gtk(self):   self.set_title(self.get_title())   gtklib.set_tortoise_icon(self, self.get_icon()) @@ -513,22 +526,7 @@
  item.set_active(check)   elif icon:   item = gtk.ImageMenuItem(text) - if icon.startswith('gtk'): - img = gtk.image_new_from_stock( - icon, gtk.ICON_SIZE_MENU) - else: - img = gtk.Image() - ico = paths.get_tortoise_icon(icon) - if ico: - try: - width, height = gtk.icon_size_lookup( - gtk.ICON_SIZE_MENU) - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( - ico, width, height) - img.set_from_pixbuf(pixbuf) - except: - # don't let broken gtk+ to break dialogs - pass + img = self.icon_from_name(icon)   item.set_image(img)   else:   item = gtk.MenuItem(text)