From 0647d0777e465c4c049b34aa943355a5c7fbea91 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Wed, 15 Dec 2010 02:35:38 +0100 Subject: [PATCH] properties: move the == comparaison in set() in compare_value() function. properties: add a NumpyProperty, that copy the default value instead of just using it + adapt comparaison for numpy matrices --- kivy/c_ext/properties.pyx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/kivy/c_ext/properties.pyx b/kivy/c_ext/properties.pyx index 17da3210a..4ba264e7b 100644 --- a/kivy/c_ext/properties.pyx +++ b/kivy/c_ext/properties.pyx @@ -66,13 +66,16 @@ cdef class Property: return self return self.get(obj) + cdef compare_value(self, a, b): + return a == b + cpdef set(self, obj, value): '''Set a new value for the property ''' value = self.convert(obj, value) d = self.storage[obj.__uid] realvalue = d['value'] - if realvalue == value: + if self.compare_value(realvalue, value): return False self.check(obj, value) d['value'] = value @@ -267,7 +270,7 @@ cdef class ReferenceListProperty(Property): cdef int idx storage = self.storage[obj.__uid] value = self.convert(obj, value) - if storage['value'] == value: + if self.compare_value(storage['value'], value): return False self.check(obj, value) # prevent dependice loop @@ -326,3 +329,11 @@ cdef class AliasProperty(Property): cpdef set(self, obj, value): self.storage[obj.__uid]['setter'](obj, value) +cdef class NumpyProperty(Property): + cdef init_storage(self, dict storage): + Property.init_storage(self, storage) + storage['value'] = self.defaultvalue.copy() + + cdef compare_value(self, a, b): + return (a == b).all() +