Gtk小部件一次接收和显示一个图像

时间:2015-11-28 21:36:18

标签: gtk vala

如何创建应用程序的简单vala Gtk代码以打开文件夹的图像并一次显示一个?

我必须创建一个Vala应用程序来打开图像文件夹并一次显示一个图像。

我有一个Gtk.Stack只显示Gtk.FileChooserDialog收到的一张图片,但我不能用Gtk.Filechooser.Dialog接收更多元素并显示它们。

由于

1 个答案:

答案 0 :(得分:0)

有两种解决方案:

  1. 您想从同一个文件夹中选择多个文件:然后只需执行chooser.select_multiple = true;,即可通过chooser.get_uris()

  2. 获取文件URI的SLIST
  3. 您只需选择文件夹:然后使用正确的操作(Gtk.FileChooserAction.SELECT_FOLDER)创建FileChooserDialog:

    var chooser = new Gtk.FileChooserDialog (
                "Pick the folder to load the images", this, 
                Gtk.FileChooserAction.SELECT_FOLDER,
                "_Cancel",
                Gtk.ResponseType.CANCEL,
                "_Open",
                Gtk.ResponseType.ACCEPT);
    

    当你得到合适的文件夹时:

    if (chooser.run () == Gtk.ResponseType.ACCEPT) {
        var folder = File.new_from_uri (chooser.get_uri ());
        if (folder.query_exists() && folder.query_file_type (0) == FileType.DIRECTORY) {
        // It's a directory and exists, so enumerate the children and do you stuff   
        }
    }
    chooser.close ();
    
相关问题