Search code examples
pythonlinuxubuntugnome

What is the meaning of the a(ss) type in the dconf, and what are the correct methods of gi.repository.Gio.Settings to get/set such fields?


On Gnome I have been playing around with the dconf. I am trying to write some Python scripts to manipulate some of the entries myself. Some of them have the type a(ss). So my first question is: what does this type mean?

I'm handling the dconf thus:

from gi.repository import Gio
entries = Gio.Settings.new(path)
value1 = entries.get_string(key1) # for reading a string value
entries.set_string(key2, value2)  # for writing a string value

This works fine, until I try to work with a key whose type is a(ss). The methods get_string() and set_string() fail because of a wrong type. So my second question is: what are the right methods to use in this case?

I am using Python 3.4.2 on Ubuntu 14.10.


Solution

  • Well, my searches haven't revealed anything, but by playing around with the various methods I've managed to come up with a solution:

    from gi.overrides import GLib
    value1 = entries.get_value(key1).unpack() # returns e.g. [("a", "b"), ("c", "d")]
    entries.set_value(key2, GLib.Variant("a(ss)", value2)) # value2 is e.g. [("a", "b"), ("c", "d")]
    

    As this is merely a (working) piece of code I've managed to come up with myself, without completely understanding what's going on, I will wait for some time to see if someone can shed some more light on the issue and/or offer a neater solution (or at least reassure me that I've done it right) before accepting my own answer.