def set_value(self, py_value): gtype = self.__g_type if gtype == TYPE_CHAR: self.set_char(py_value) elif gtype == TYPE_UCHAR: self.set_uchar(py_value) elif gtype == TYPE_STRING: if not isinstance(py_value, str) and py_value is not None: raise TypeError("Expected string but got %s%s" % (py_value, type(py_value))) _gi._gvalue_set(self, py_value) elif gtype == TYPE_PARAM: self.set_param(py_value) elif gtype.is_a(TYPE_FLAGS): self.set_flags(py_value) elif gtype == TYPE_POINTER: self.set_pointer(py_value) elif gtype == TYPE_GTYPE: self.set_gtype(py_value) elif gtype == TYPE_VARIANT: self.set_variant(py_value) else: # Fall back to _gvalue_set which handles some more cases # like fundamentals for which a converter is registered try: _gi._gvalue_set(self, py_value) except TypeError: if gtype == TYPE_INVALID: raise TypeError("GObject.Value needs to be initialized first") raise
def set_boxed(self, boxed): if not self.__g_type.is_a(TYPE_BOXED): warnings.warn('Calling set_boxed() on a non-boxed type deprecated', PyGIDeprecationWarning, stacklevel=2) # Workaround the introspection marshalers inability to know # these methods should be marshaling boxed types. This is because # the type information is stored on the GValue. _gi._gvalue_set(self, boxed)
def set_value(self, py_value): gtype = self.g_type if gtype == _gi.TYPE_INVALID: raise TypeError("GObject.Value needs to be initialized first") elif gtype == TYPE_BOOLEAN: self.set_boolean(py_value) elif gtype == TYPE_CHAR: self.set_char(py_value) elif gtype == TYPE_UCHAR: self.set_uchar(py_value) elif gtype == TYPE_INT: self.set_int(py_value) elif gtype == TYPE_UINT: self.set_uint(py_value) elif gtype == TYPE_LONG: self.set_long(py_value) elif gtype == TYPE_ULONG: self.set_ulong(py_value) elif gtype == TYPE_INT64: self.set_int64(py_value) elif gtype == TYPE_UINT64: self.set_uint64(py_value) elif gtype == TYPE_FLOAT: self.set_float(py_value) elif gtype == TYPE_DOUBLE: self.set_double(py_value) elif gtype == TYPE_STRING: if isinstance(py_value, str): py_value = str(py_value) elif PY2: if isinstance(py_value, text_type): py_value = py_value.encode('UTF-8') else: raise ValueError( "Expected string or unicode but got %s%s" % (py_value, type(py_value))) else: raise ValueError("Expected string but got %s%s" % (py_value, type(py_value))) self.set_string(py_value) elif gtype == TYPE_PARAM: self.set_param(py_value) elif gtype.is_a(TYPE_ENUM): self.set_enum(py_value) elif gtype.is_a(TYPE_FLAGS): self.set_flags(py_value) elif gtype.is_a(TYPE_BOXED): self.set_boxed(py_value) elif gtype == TYPE_POINTER: self.set_pointer(py_value) elif gtype.is_a(TYPE_OBJECT): self.set_object(py_value) elif gtype == TYPE_UNICHAR: self.set_uint(int(py_value)) # elif gtype == TYPE_OVERRIDE: # pass elif gtype == TYPE_GTYPE: self.set_gtype(py_value) elif gtype == TYPE_VARIANT: self.set_variant(py_value) elif gtype == TYPE_PYOBJECT: self.set_boxed(py_value) else: # Fall back to _gvalue_set which handles some more cases # like fundamentals for which a converter is registered _gi._gvalue_set(self, py_value)
def set_boxed(self, boxed): # Workaround the introspection marshalers inability to know # these methods should be marshaling boxed types. This is because # the type information is stored on the GValue. _gi._gvalue_set(self, boxed)