I am trying to define a GLib.Variant data type in Python to use it with the pydbus library. This is my attempt to do so:
#!/usr/bin/python
from gi.repository import GLib
from pydbus import SessionBus
var1 = GLib.Variant.new_variant('draw-cursor', False)
var2 = GLib.Variant.new_variant('framerate', 30)
bus = SessionBus()
calling = bus.get('org.gnome.Shell.Screencast', '/org/gnome/Shell/Screencast')
calling.Screencast('out.webm', {var1, var2})
However it says TypeError: GLib.Variant.new_variant() takes exactly 1 argument (2 given). And I can see that clear. But then how can I assign the values for what I will define? Shouldn't it be a dictionary like {'framerate': 30}?
The second failure (
AttributeError: 'Variant' object has no attribute 'items') seems to be becausepydbusexpects you to pass in adict, rather than aGLib.Variant, and it unconditionally wraps whatever you pass it in aGLib.Variant. This means it tries to get theitemsfrom theoptionsvariant, which fails becauseGLib.Variantdoesn’t support that.This code works with
pydbus: