如何在composer dump-autoload
?
这是一个简单的ChooserDialog:
GtkFileChooserDialog
如何添加图片预览?
答案 0 :(得分:1)
GtkFileChooser提供set_preview_widget功能。您可以创建GtkImage,将其设置为预览窗口小部件,并在发出update-preview
信号时更新图像:
from gi.repository import GdkPixbuf
preview_image= Gtk.Image()
filechooserdialog.set_preview_widget(preview_image)
def update_preview(dialog):
path= dialog.get_preview_filename()
try:
pixbuf= GdkPixbuf.Pixbuf.new_from_file(path)
except Exception:
dialog.set_preview_widget_active(False)
else:
#scale the image
maxwidth, maxheight= 300.0, 700.0 # as floats to avoid integer division in python2
width, height= pixbuf.get_width(), pixbuf.get_height()
scale= min(maxwidth/width, maxheight/height)
if scale<1:
width, height= int(width*scale), int(height*scale)
pixbuf= pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.BILINEAR)
preview_image.set_from_pixbuf(pixbuf)
dialog.set_preview_widget_active(True)
filechooserdialog.connect('update-preview', update_preview)