mirror of https://github.com/kivy/kivy.git
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
This commit is contained in:
parent
0cc61bbf32
commit
0647d0777e
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue