Bing to GSettings key of type 'as'

Is there any GType for which a property of that type could be bound directly (without having to use g_settings_bind_with_mapping) to a GSettings key of string-array type?

I tried GList and GtkStringList and both of these do not bind without using mapping.

The type is G_TYPE_STRV which is just a gchar **, you can use utilities like GStrvBuilder to create them and then use g_settings_get_strv and g_settings_set_strv.

1 Like

So, no direct binding then.

No, but g_settings_bind() is really just a wrapper around g_settings_bind_with_mapping() with a special case for G_SETTINGS_BIND_INVERT_BOOLEAN. Except that flag it’s equivalent to:

g_settings_bind_with_mapping (settings, key, object, property, flags,
                              NULL, NULL, NULL, NULL);

I do know that but I am using the python bindings and bind_with_mapping is not available for bindings. I do have a pure python version of that function but I do not want to rely on it too much.

Also, I was just looking for convenience. Instead of having to write two mapping functions, it would be more convenient to not have to write them.

Yeah, Gio.Settings.bind_with_mapping() is marked as (skip) for bindings. There’s a similar issue for GJS, so the best advice is to open a request in the issue tracker for pygobject, or contribute to the issue in GLib for a binding-friendly variant.

Yes, you can direct bind, why not? Here is a simple example with python.

import gi
from gi.repository import GLib, GObject, Gio

class MyObj(GObject.Object):
    _opts = []
    @GObject.Property(type=GObject.TYPE_STRV)
    def opts(self):
        return self._opts
    @opts.setter
    def opts(self, value):
        self._opts = value

settings = Gio.Settings.new('org.gnome.desktop.input-sources')

obj = MyObj()
obj.connect('notify', lambda i, p: print('changed:', i.opts))
settings.bind('xkb-options', obj, 'opts', Gio.SettingsBindFlags.GET)

loop = GLib.MainLoop.new(None, False)
loop.run()
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.