Search code examples
pygobjectgtk3

gtk3 get settings value from GtkSettings


I want to programmatically retrieve the value of the word wrap setting for GEdit3 from inside a Python plugin.

The GtkSettings class provides a method to set a string property, but how does one retrieve the value of a string property? I see no "getter" method.

I have also consulted pydoc gi.repository.Gtk.Settings - the methods listed there are the same as the online docs.

I am able to retrieve the property value of interest with the gsettings CLI utility. The command gsettings get org.gnome.gedit.preferences.editor wrap-mode yields the value 'word'. I was hoping not to have to use subprocess.Popen() just to retrieve this property, however.


Solution

  • This will work

    from gi.repository import Gio
    a = Gio.Settings('org.gnome.gedit.preferences.editor')
    a.get_string('wrap-mode')
    

    Since you're using automatic generated bindings, C code samples will work just fine for you, it is just about changing the syntax.