2017-07-18 5 views

答えて

1

あなたはGtkFileChooserWidget(gtkmmの2.24)を使用することができます。

GtkFileChooserDialogが使用する基本的なウィジェットです。説明のとおり:

GtkFileChooserWidgetはファイルを選択するのに適したウィジェットです。 GtkFileChooserDialogのメインビルディングブロックは です。ほとんどのアプリケーション は後者を使うだけです。特別なニーズがある場合は、GtkFileChooserWidgetを 大きなウィンドウの一部として使用できます。

GtkFileChooserWidgetには、それ自身のメソッドはありません。 代わりに、GtkFileChooserで機能する関数を使用する必要があります。あなたがFileChooserDialogに追加することはあまりにも複雑ではない場合、あなたはダイアログ自体に余分な機能を追加するのではなく、(関係するすべての官僚との)新しいウィンドウを作成することを検討できること

1

注意。

get_content_area()を呼び出して、ダイアログの上部([OK /キャンセル]ボタンの上)にアクセスできます。 VBoxへの参照を取得し、オプションのロードや保存、書式などの追加を行うことができます。

ダイアログにチェックボタンを追加する例を以下に示します。

追加のウィジェットに .show()を添加することが必要であること
#!/usr/bin/env python3 
# -*- coding: utf-8 -*- 
# 
# test_filechooser_extension.py 
# 
# Copyright 2017 John Coppens <[email protected]> 
# 
# 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)) 

注。

関連する問題