2017-07-18 27 views

Répondre

1

Vous pouvez utiliser GtkFileChooserWidget (Gtkmm 2.24).

C'est le widget de base que GtkFileChooserDialog utilise. Comme la description le dit:

GtkFileChooserWidget est un widget adapté à la sélection de fichiers. C'est le bloc de construction principal d'un GtkFileChooserDialog. La plupart des applications auront seulement besoin d'utiliser ce dernier; vous pouvez utiliser GtkFileChooserWidget comme partie d'une plus grande fenêtre si vous avez des besoins spéciaux.

Notez que GtkFileChooserWidget n'a aucune méthode propre. Au lieu de cela, vous devez utiliser les fonctions qui fonctionnent sur un GtkFileChooser.

1

Notez que si ce que vous voulez ajouter à la FileChooserDialog est pas trop compliqué, vous pourriez envisager d'ajouter la fonctionnalité supplémentaire à la boîte de dialogue lui-même, au lieu de créer une nouvelle fenêtre (avec toute la bureaucratie).

Vous pouvez accéder à la partie supérieure de la boîte de dialogue (au-dessus des boutons Ok/Cancel) en appelant le get_content_area(). Vous obtenez une référence à un VBox, auquel vous pouvez ajouter d'autres éléments, tels que la charge ou enregistrer les options, les formats, etc.

Voici un exemple très simple qui ajoute un bouton de contrôle à la boîte de dialogue:

#!/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)) 

Notez qu'il est nécessaire d'ajouter .show() aux widgets ajoutés.