GTK文件选择器对话框可以成为窗口的一部分吗?

时间:2017-07-18 14:23:07

标签: c++ gtk gtk2 filechooser

文件选择器对话框如下所示:

{{3}}

但是有可能有一个全屏窗口,并且这个占据了那个窗口的一半而不是它自己的窗口吗?

2 个答案:

答案 0 :(得分:1)

您可以使用GtkFileChooserWidget (Gtkmm 2.24)。

它是GtkFileChooserDialog使用的基本小部件。正如描述所说:

  

GtkFileChooserWidget是一个适合选择文件的小部件。它是   GtkFileChooserDialog的主要构建块。大多数应用   只需要使用后者;你可以使用GtkFileChooserWidget作为   如果您有特殊需要,可以选择大窗户的一部分。

     

请注意,GtkFileChooserWidget没有自己的任何方法。   相反,您应该使用适用于GtkFileChooser的函数。

答案 1 :(得分:1)

请注意,如果要添加到FileChooserDialog的内容过于复杂,可以考虑在对话框中添加额外的功能,而不是创建新窗口(包含所有官僚作风) )。

您可以通过拨打get_content_area ()来访问对话框的顶部(在“确认/取消”按钮上方)。您将获得对VBox的引用,然后您可以向其添加更多项目,例如加载或保存选项,格式等。

这是一个非常简单的示例,它在对话框中添加了一个复选按钮:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
#  test_filechooser_extension.py
#
#  Copyright 2017 John Coppens <john@jcoppens.com>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#
#


from gi.repository import Gtk

class MainWindow(Gtk.Window):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.connect("destroy", lambda x: Gtk.main_quit())

        btn = Gtk.Button("Click to activate file chooser")
        btn.connect("clicked", self.button_clicked)

        self.add(btn)
        self.show_all()

    def run(self):
        Gtk.main()

    def button_clicked(self, btn):
        fc = Gtk.FileChooserDialog(
                    parent = self,
                    action = Gtk.FileChooserAction.OPEN,
                    buttons = ("Open", Gtk.ResponseType.OK,
                               "Cancel", Gtk.ResponseType.CANCEL))
        area = fc.get_content_area()
        option = Gtk.CheckButton("This could be an extra option")
        area.pack_start(option, False, False, 0)
        option.show()

        fc.run()
        fc.destroy()


def main(args):
    mainwdw = MainWindow()
    mainwdw.run()

    return 0

if __name__ == '__main__':
    import sys
    sys.exit(main(sys.argv))

请注意,有必要将.show()添加到添加的小部件中。

相关问题