def select_image(self, button):
"""
Show a file chooser dialog and let the user to select an image.
"""
dialog = Gtk.FileChooserDialog(_('Please select an image'), self.window, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
png_filter = Gtk.FileFilter()
png_filter.set_name("PNG files")
png_filter.add_mime_type("image/png")
png_filter.add_pattern("*.png")
dialog.add_filter(png_filter)
response = dialog.run()
if response == Gtk.ResponseType.OK:
self.break_config['image'] = dialog.get_filename()
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(self.break_config['image'], 16, 16, True)
self.img_break.set_from_pixbuf(pixbuf)
elif response == Gtk.ResponseType.CANCEL:
self.break_config.pop('image', None)
self.img_break.set_from_stock('gtk-missing-image', Gtk.IconSize.BUTTON)
dialog.destroy()
评论列表
文章目录