def on_button_pressed(self, widget):
dialog = Gtk.FileChooserDialog(title=_("Choose an Image File"),
action=Gtk.FileChooserAction.OPEN,
transient_for=self.get_toplevel(),
buttons=(_("_Cancel"), Gtk.ResponseType.CANCEL,
_("_Open"), Gtk.ResponseType.OK))
filter_text = Gtk.FileFilter()
filter_text.set_name(_("Image files"))
filter_text.add_mime_type("image/*")
dialog.add_filter(filter_text)
backgrounds = "/usr/share/backgrounds"
if os.path.exists(self.value):
dialog.set_filename(self.value)
if os.path.exists(backgrounds):
dialog.add_shortcut_folder(backgrounds)
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.frame = Gtk.Frame(visible=False, no_show_all=True)
preview = Gtk.Image(visible=True)
box.pack_start(self.frame, False, False, 0)
self.frame.add(preview)
dialog.set_preview_widget(box)
dialog.set_preview_widget_active(True)
dialog.set_use_preview_label(False)
box.set_margin_end(12)
box.set_margin_top(12)
box.set_size_request(320, -1)
dialog.connect("update-preview", self.update_icon_preview_cb, preview)
response = dialog.run()
if response == Gtk.ResponseType.OK:
filename = dialog.get_filename()
self.bind_object.set_text(filename)
dialog.destroy()
评论列表
文章目录