daily pastebin goal
21%
SHARE
TWEET

my.pyx

GugaF Jun 18th, 2018 74 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. from kivy.properties cimport Property, PropertyStorage
  2. from kivy._event cimport EventDispatcher
  3.  
  4. cdef inline void observable_object_dispatch(object self, str name):
  5.     cdef Property prop = self.prop
  6.     prop.dispatch(self.obj, name)
  7.  
  8.  
  9. class ObservableObject(object):
  10.  
  11.     # Internal class to observe changes inside a native python object.
  12.     def __init__(self, *largs):
  13.         self.prop = largs[0]
  14.         self.obj = largs[1]
  15.         super(ObservableObject, self).__init__()
  16.  
  17.     def __setattr__(self, name, value):
  18.         object.__setattr__(self, name, value)
  19.         observable_object_dispatch(self, name)
  20.  
  21.  
  22. cdef class DocProperty(Property):
  23.  
  24.     def __init__(self, defaultvalue=None, rebind=False, **kw):
  25.         self.baseclass = kw.get('baseclass', object)
  26.         super(DocProperty, self).__init__(defaultvalue, **kw)
  27.         self.rebind = rebind
  28.  
  29.     cpdef link(self, EventDispatcher obj, str name):
  30.         Property.link(self, obj, name)
  31.         cdef PropertyStorage ps = obj.__storage[self._name]
  32.         ps.value = ObservableObject(self, obj, ps.value)
  33.  
  34.     cdef check(self, EventDispatcher obj, value):
  35.         if Property.check(self, obj, value):
  36.             return True
  37.         if not isinstance(value, object):
  38.             raise ValueError('{}.{} accept only object based on {}'.format(
  39.             obj.__class__.__name__,
  40.             self.name,
  41.             self.baseclass.__name__))
  42.  
  43.     cpdef dispatch(self, EventDispatcher obj, str name):
  44.         '''Dispatch the value change to all observers.
  45.        .. versionchanged:: 1.1.0
  46.            The method is now accessible from Python.
  47.        This can be used to force the dispatch of the property, even if the
  48.        value didn't change::
  49.            button = Button()
  50.            # get the Property class instance
  51.            prop = button.property('text')
  52.            # dispatch this property on the button instance
  53.            prop.dispatch(button)
  54.        '''
  55.         cdef PropertyStorage ps = obj.__storage[self._name]
  56.         ps.observers.dispatch(obj, ps.value, (name,), None, 0)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top