GTK4 FileChooser(Dialog|Native) don't fully support parent argument
There is a parent
argument to gtk_file_chooser_dialog_new
and gtk_file_chooser_native_new
, but pygobject does not support it on either.
Using the following code:
import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk, Gio # noqa
app = Gtk.Application.new('com.example.Example',
Gio.ApplicationFlags.NON_UNIQUE)
app.connect('activate', lambda *args, **kwargs: None)
app.register()
win = Gtk.Window()
app.add_window(win)
win.show()
#
# Create dialog here.
#
dialog = ...
dialog.show()
app.run()
Then, creating a FileChooserDialog
with new
:
dialog = Gtk.FileChooserDialog.new(title='Foo', parent=win,
action=Gtk.FileChooserAction.SAVE)
fails entirely:
Traceback (most recent call last):
File "gtk4-test.py", line 15, in <module>
dialog = Gtk.FileChooserDialog.new(title='Foo', parent=win,
TypeError: Dialog constructor cannot be used to create instances of a subclass FileChooserDialog
Passing it to the class directly:
dialog = Gtk.FileChooserDialog(title='Foo', parent=win,
action=Gtk.FileChooserAction.SAVE)
warns from both sides:
/usr/lib/python3.9/site-packages/gi/overrides/Gtk.py:522: Warning: g_object_new_is_valid_property: property 'parent' of object class 'GtkFileChooserDialog' is not writable
_window_init(self, *args, **kwargs)
Gtk-Message: 01:50:45.646: GtkDialog mapped without a transient parent. This is discouraged.
though it does appear.
Creating a native file chooser using the class name:
native = Gtk.FileChooserNative(title='Foo', parent=win,
action=Gtk.FileChooserAction.SAVE)
fails and doesn't run:
Traceback (most recent call last):
File "/home/elliott/code/matplotlib/gtk4-test.py", line 23, in <module>
native = Gtk.FileChooserNative(title='Foo', parent=win,
TypeError: gobject `GtkFileChooserNative' doesn't support property `parent'
Using new
instead does appear to work?
native = Gtk.FileChooserNative.new(title='Foo', parent=win,
action=Gtk.FileChooserAction.SAVE)
but the inspector says it doesn't have a parent. I'm not sure if that's the correct way to check that.