kivy/doc/sources/gettingstarted/properties.rst

37 lines
2.1 KiB
ReStructuredText
Raw Normal View History

2012-04-18 19:12:50 +00:00
Kivy Properties
---------------
.. container:: title
2012-03-16 14:42:35 +00:00
2012-04-18 19:12:50 +00:00
Using Kivy's Properties
2012-04-04 10:04:52 +00:00
2012-05-28 16:42:11 +00:00
Kivy properties are an implementation of the `observer pattern
<http://en.wikipedia.org/wiki/Observer_pattern>`_ .
Kivy's properties are useful to:
2012-04-04 10:04:52 +00:00
2012-05-28 16:42:11 +00:00
- Allow manipulating your widgets in kv language more easily
2012-04-18 19:12:50 +00:00
- Automatically observe any changes and dispatch functions/code accordingly
- Check and validate values
- Optimize memory management
2012-04-04 10:04:52 +00:00
2012-05-28 16:42:11 +00:00
To use them, **you have to declare them at class level**. That is, directly in
the class, not în any method of the class. A property is a class attribute
2012-05-28 16:42:11 +00:00
that will automatically create instance attributes. Each property by default
provides an ``on_property`` event that is called whenever the property's
2012-05-28 16:42:11 +00:00
state/value changes .
2012-04-04 10:04:52 +00:00
2012-04-18 19:12:50 +00:00
Kivy provides the following properties:
`NumericProperty <http://kivy.org/docs/api-kivy.properties.html?highlight=properties#kivy.properties.NumericProperty>`_,
`StringProperty <http://kivy.org/docs/api-kivy.properties.html?highlight=properties#kivy.properties.StringProperty>`_,
`ListProperty <http://kivy.org/docs/api-kivy.properties.html?highlight=properties#kivy.properties.ListProperty>`_,
`ObjectProperty <http://kivy.org/docs/api-kivy.properties.html?highlight=properties#kivy.properties.ObjectProperty>`_,
`BooleanProperty <http://kivy.org/docs/api-kivy.properties.html?highlight=properties#kivy.properties.BooleanProperty>`_,
`BoundedNumericProperty <http://kivy.org/docs/api-kivy.properties.html?highlight=properties#kivy.properties.BoundedNumericProperty>`_,
`OptionProperty <http://kivy.org/docs/api-kivy.properties.html?highlight=properties#kivy.properties.OptionProperty>`_,
`ReferenceListProperty <http://kivy.org/docs/api-kivy.properties.html?highlight=properties#kivy.properties.ReferenceListProperty>`_,
`AliasProperty <http://kivy.org/docs/api-kivy.properties.html?highlight=properties#kivy.properties.AliasProperty>`_,
`DictProperty <http://kivy.org/docs/api-kivy.properties.html?highlight=properties#kivy.properties.DictProperty>`_,
2012-04-04 10:04:52 +00:00
For an in-depth look at how to use kivy properties, start `here. <http://kivy.org/docs/api-kivy.properties.html>`_