mirror of https://github.com/kivy/kivy.git
Merge branch 'master' of ssh://github.com/kivy/kivy
This commit is contained in:
commit
e36637d860
12
kivy/lang.py
12
kivy/lang.py
|
@ -540,6 +540,7 @@ from kivy.cache import Cache
|
|||
from kivy import kivy_data_dir, require
|
||||
from kivy.lib.debug import make_traceback
|
||||
import kivy.metrics as metrics
|
||||
from weakref import ref
|
||||
|
||||
|
||||
trace = Logger.trace
|
||||
|
@ -1385,6 +1386,17 @@ class BuilderBase(object):
|
|||
# if we got an id, put it in the root rule for a later global usage
|
||||
if rule.id:
|
||||
rctx['ids'][rule.id] = widget
|
||||
# set id name as a attribute for root widget so one can in python
|
||||
# code simply access root_widget.id_name
|
||||
_ids = dict(rctx['ids'])
|
||||
_root = _ids.pop('root')
|
||||
_new_ids = _root.ids
|
||||
for _key in _ids.keys():
|
||||
if _ids[_key] == _root:
|
||||
# skip on self
|
||||
continue
|
||||
_new_ids[_key] = ref(_ids[_key])
|
||||
_root.ids = _new_ids
|
||||
|
||||
# first, ensure that the widget have all the properties used in
|
||||
# the rule if not, they will be created as ObjectProperty.
|
||||
|
|
|
@ -235,9 +235,11 @@ cdef class Property:
|
|||
|
||||
:Parameters:
|
||||
`errorhandler`: callable
|
||||
If set, must take a single argument and return a valid substitute value
|
||||
If set, must take a single argument and return a valid substitute
|
||||
value
|
||||
`errorvalue`: object
|
||||
If set, will replace an invalid property value (overrides errorhandler)
|
||||
If set, will replace an invalid property value (overrides
|
||||
errorhandler)
|
||||
|
||||
.. versionchanged:: 1.4.2
|
||||
Parameters errorhandler and errorvalue added
|
||||
|
@ -604,8 +606,34 @@ class ObservableDict(dict):
|
|||
self.obj = largs[1]
|
||||
super(ObservableDict, self).__init__(*largs[2:])
|
||||
|
||||
def _weak_return(self, item):
|
||||
if isinstance(item, ref):
|
||||
return item()
|
||||
return item
|
||||
|
||||
def __getattr__(self, attr):
|
||||
try:
|
||||
return self._weak_return(self.__getitem__(attr))
|
||||
except KeyError:
|
||||
try:
|
||||
return self._weak_return(
|
||||
super(ObservableDict, self).__getattr__(attr))
|
||||
except AttributeError:
|
||||
raise KeyError(attr)
|
||||
|
||||
def __setattr__(self, attr, value):
|
||||
if attr in ('prop', 'obj'):
|
||||
super(ObservableDict, self).__setattr__(attr, value)
|
||||
return
|
||||
self.__setitem__(attr, value)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
dict.__setitem__(self, key, value)
|
||||
if value is None:
|
||||
# remove attribute if value is None
|
||||
# is this really needed?
|
||||
self.__delitem__(key)
|
||||
else:
|
||||
dict.__setitem__(self, key, value)
|
||||
observable_dict_dispatch(self)
|
||||
|
||||
def __delitem__(self, key):
|
||||
|
|
|
@ -82,7 +82,7 @@ from kivy.event import EventDispatcher
|
|||
from kivy.factory import Factory
|
||||
from kivy.properties import NumericProperty, StringProperty, \
|
||||
AliasProperty, ReferenceListProperty, ObjectProperty, \
|
||||
ListProperty
|
||||
ListProperty, DictProperty
|
||||
from kivy.graphics import Canvas
|
||||
from kivy.base import EventLoop
|
||||
from kivy.lang import Builder
|
||||
|
@ -563,6 +563,16 @@ class Widget(EventDispatcher):
|
|||
dict.
|
||||
'''
|
||||
|
||||
ids = DictProperty({})
|
||||
'''This is a Dictionary of id's defined in your kv language. This will only
|
||||
be populated if you use id's in your kv language code.
|
||||
|
||||
.. versionadded:: 1.6.0
|
||||
|
||||
:data:`ids` is a :class:`~kivy.properties.DictProperty`, defaults to a empty
|
||||
dict {}.
|
||||
'''
|
||||
|
||||
opacity = NumericProperty(1.0)
|
||||
'''Opacity of the widget and all the children.
|
||||
|
||||
|
|
Loading…
Reference in New Issue