From dd943155a135d7460d9532a496649f9bd7098caf Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 25 Jul 2017 13:00:08 -0400 Subject: [PATCH] structure: Add a .keys() method and implement __str__ We are making it behave like a dict, so we should provide the same kind of utilities. --- gi/overrides/Gst.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gi/overrides/Gst.py b/gi/overrides/Gst.py index 8d754f1..2952f0b 100644 --- a/gi/overrides/Gst.py +++ b/gi/overrides/Gst.py @@ -29,6 +29,8 @@ import inspect from ..overrides import override from ..importer import modules +from gi.repository import GLib + if sys.version_info >= (3, 0): _basestring = str @@ -245,13 +247,27 @@ class Structure(Gst.Structure): raise TypeError("wrong arguments when creating GstStructure object") + def __init__(self, *args, **kwargs): + pass + def __getitem__(self, key): return self.get_value(key) + def keys(self): + keys = set() + def foreach(fid, value, unused1, udata): + keys.add(GLib.quark_to_string(fid)) + return True + + self.foreach(foreach, None, None) + return keys def __setitem__(self, key, value): return self.set_value(key, value) + def __str__(self): + return self.to_string() + Structure = override(Structure) __all__.append('Structure') -- 2.7.4