8
8
This code is still experimental, and its API is subject to change in a
9
9
future version.
10
10
11
- Provides namespace functionality for Kivy objects. It allows kivy objects
12
- to be named and then accessed using the namespace.
11
+ The :class:`KNSpaceBehavior` `mixin <https://en.wikipedia.org/wiki/Mixin>`_
12
+ class provides namespace functionality for Kivy objects. It allows kivy objects
13
+ to be named and then accessed using namespaces.
13
14
14
15
:class:`KNSpace` instances are the namespaces that store the named objects
15
16
in Kivy :class:`~kivy.properties.ObjectProperty` instances.
18
19
namespace and will point to a :attr:`~kivy.uix.widget.proxy_ref` of the
19
20
derived object.
20
21
21
-
22
22
Basic examples
23
23
--------------
24
24
25
- By default, there's only a single namespace; the :attr:`knspace` namespace. The
25
+ By default, there's only a single namespace: the :attr:`knspace` namespace. The
26
26
simplest example is adding a widget to the namespace:
27
27
28
28
.. code-block:: python
31
31
widget = Widget()
32
32
knspace.my_widget = widget
33
33
34
- This adds an kivy :class:`~kivy.properties.ObjectProperty` with `rebind=True`
35
- and `allownone=True` to the :attr:`knspace` namespace with property name
34
+ This adds a kivy :class:`~kivy.properties.ObjectProperty` with `rebind=True`
35
+ and `allownone=True` to the :attr:`knspace` namespace with a property name
36
36
`my_widget`. And the property now also points to this widget.
37
37
38
38
This can be done automatically with:
@@ -68,7 +68,7 @@ class MyWidget(KNSpaceBehavior, Widget):
68
68
Setting the namespace
69
69
---------------------
70
70
71
- One can also create their own namespace rather than using the default
71
+ One can also create ones own namespace rather than using the default
72
72
:attr:`knspace` by directly setting :attr:`KNSpaceBehavior.knspace`:
73
73
74
74
.. code-block:: python
@@ -83,7 +83,7 @@ class MyWidget(KNSpaceBehavior, Widget):
83
83
Initially, `my_widget` is added to the default namespace, but when the widget's
84
84
namespace is changed to `my_new_namespace`, the reference to `my_widget` is
85
85
moved to that namespace. We could have also of course first set the namespace
86
- to `my_new_namespace` and then named the widget as `my_widget`, thereby
86
+ to `my_new_namespace` and then have named the widget `my_widget`, thereby
87
87
avoiding the initial assignment to the default namespace.
88
88
89
89
Similarly, in kv:
@@ -100,7 +100,7 @@ class MyWidget(KNSpaceBehavior, Widget):
100
100
------------------------
101
101
102
102
In the previous example, we directly set the namespace we wished to use.
103
- In the following example we inherit it from our parent, so we only have to set
103
+ In the following example, we inherit it from the parent, so we only have to set
104
104
it once:
105
105
106
106
.. code-block:: kv
@@ -128,7 +128,7 @@ class MyWidget(KNSpaceBehavior, Widget):
128
128
use. If none are found, it uses the default :attr:`knspace`.
129
129
130
130
When `MyComplexWidget` is created, it still used the default namespace.
131
- However, when we assigned to the root widget its new_namespace , all its
131
+ However, when we assigned the root widget its new namespace , all its
132
132
children switched to using that new namespace as well. So `new_knspace` now
133
133
contains `label1` and `label2` as well as `my_complex`.
134
134
@@ -196,7 +196,7 @@ class MyWidget(KNSpaceBehavior, Widget):
196
196
197
197
Further, because both the namespace :class:`~kivy.properties.ObjectProperty`
198
198
references, and :atrr:`KNSpaceBehavior.knspace` have `rebind=True`, the
199
- text of the `MyComplexWidget` label is rebind to match the text of
199
+ text of the `MyComplexWidget` label is rebound to match the text of
200
200
`MyPrettyWidget` when either the root's namespace changes or when the
201
201
`root.knspace.pretty` property changes, as expected.
202
202
@@ -379,11 +379,12 @@ def fork(self):
379
379
380
380
381
381
class KNSpaceBehavior (object ):
382
- '''Inheriting from this class allows naming of the inherited object , which
383
- is then added to the associated namespace :attr:`knspace` and accessible
382
+ '''Inheriting from this class allows naming of the inherited objects , which
383
+ are then added to the associated namespace :attr:`knspace` and accessible
384
384
through it.
385
385
386
- See :mod:`~kivy.uix.behaviors.knspace` for details.
386
+ Please see the :mod:`knspace behaviors module <kivy.uix.behaviors.knspace>`
387
+ documentation for more information.
387
388
'''
388
389
389
390
_knspace = ObjectProperty (None , allownone = True )
0 commit comments