File chooser dialogs look like this:
But is it possible to have a fullscreen window and have this take up, say, half of that window instead of being its own window?
File chooser dialogs look like this:
But is it possible to have a fullscreen window and have this take up, say, half of that window instead of being its own window?
You can use GtkFileChooserWidget (Gtkmm 2.24).
It's the basic widget that GtkFileChooserDialog uses. As the description says:
GtkFileChooserWidget is a widget suitable for selecting files. It is the main building block of a GtkFileChooserDialog. Most applications will only need to use the latter; you can use GtkFileChooserWidget as part of a larger window if you have special needs.
Note that GtkFileChooserWidget does not have any methods of its own. Instead, you should use the functions that work on a GtkFileChooser.
Note that if what you want to add to the FileChooserDialog
isn't too complicated, you could consider adding the extra functionality to the dialog itself, instead of creating a new window (with all the bureaucracy involved).
You can access the top part of the dialog (above the Ok/Cancel buttons) by calling get_content_area ()
. You'll get a reference to a VBox, to which you can then add more items, such as load or save options, formats, etc.
Here's a very simple example which adds a check button to the dialog:
#!/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))
Note that it is necessary to add .show()
to the added widgets.