[pyclutter/wip/introspection] Add overrides for Animator.set_key() and State.set_key()
- From: Bastian Winkler <bwinkler src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pyclutter/wip/introspection] Add overrides for Animator.set_key() and State.set_key()
- Date: Sat, 12 Nov 2011 17:23:03 +0000 (UTC)
commit 6bcdda7050303ff7257f03c20d76a549a61a7749
Author: Bastian Winkler <buz netbuz org>
Date: Sat Nov 12 18:03:27 2011 +0100
Add overrides for Animator.set_key() and State.set_key()
This is done by putting some specific values in a GValue container to
make sure to pass to correct value type.
introspection/Clutter.py | 71 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 70 insertions(+), 1 deletions(-)
---
diff --git a/introspection/Clutter.py b/introspection/Clutter.py
index 03fcb68..379f866 100644
--- a/introspection/Clutter.py
+++ b/introspection/Clutter.py
@@ -23,7 +23,7 @@
import sys
from ..overrides import override
from ..importer import modules
-import keysyms
+from gi.repository import GObject
Clutter = modules['Clutter']._introspection_module
@@ -550,6 +550,75 @@ Shader = override(Shader)
__all__.append('Shader')
+def _gvalue_from_python(obj, prop_name, v):
+ try:
+ pspec = getattr(obj.__class__.props, prop_name)
+ except AttributeError:
+ raise AttributeError("Objects of type %s don't have a property '%s" %
+ (type(obj), prop_name))
+ value = GObject.Value()
+ value.init(pspec.value_type)
+ if pspec.value_type == GObject.TYPE_INT:
+ value.set_int(int(v))
+ elif pspec.value_type == GObject.TYPE_UINT:
+ value.set_uint(int(v))
+ elif pspec.value_type == GObject.TYPE_CHAR:
+ value.set_char(int(v))
+ elif pspec.value_type == GObject.TYPE_UCHAR:
+ value.set_uint(int(v))
+ elif pspec.value_type == GObject.TYPE_FLOAT:
+ value.set_float(float(v))
+ elif pspec.value_type == GObject.TYPE_DOUBLE:
+ value.set_double(float(v))
+ elif pspec.value_type == GObject.TYPE_LONG:
+ value.set_long(long(v))
+ elif pspec.value_type == GObject.TYPE_ULONG:
+ value.set_ulong(long(v))
+ elif pspec.value_type == GObject.TYPE_INT64:
+ value.set_int64(long(v))
+ elif pspec.value_type == GObject.TYPE_UINT64:
+ value.set_uint64(long(v))
+ elif pspec.value_type == GObject.TYPE_BOOLEAN:
+ value.set_boolean(bool(v))
+ elif pspec.value_type == GObject.TYPE_STRING:
+ if isinstance(v, str):
+ v = str(v)
+ elif sys.version_info < (3, 0):
+ if isinstance(v, unicode):
+ v = v.encode('UTF-8')
+ else:
+ raise ValueError("Expected string or unicode for property " + \
+ "%s but got %s%s" % (prop_name, v, type(v)))
+ else:
+ raise ValueError("Expected string or unicode for property " + \
+ "%s but got %s%s" % (prop_name, v, type(v)))
+ value.set_string(str(v))
+ else:
+ return v
+ return value
+
+
+class Animator(Clutter.Animator):
+ def set_key(self, obj, prop, mode, progress, value):
+ return Clutter.Animator.set_key(self, obj, prop, mode, progress,
+ _gvalue_from_python(obj, prop, value))
+
+
+Animator = override(Animator)
+__all__.append('Animator')
+
+
+class State(Clutter.State):
+ def set_key(self, source_state, target_state, obj, prop, mode,
+ value, pre_delay=0.0, post_delay=0.0):
+ return Clutter.State.set_key(self, source_state, target_state, obj,
+ prop, mode, _gvalue_from_python(obj, prop, value),
+ pre_delay, post_delay)
+
+State = override(State)
+__all__.append('State')
+
+
# override the main_quit function to ignore additional arguments. This enables
# common stuff like stage.connect('destroy', Clutter.main_quit)
def main_quit(*args, **kwargs):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]