Table Of Contents
- RecycleView Views
RecycleDataAdapter
RecycleDataAdapter.attach_recycleview()
RecycleDataAdapter.create_view()
RecycleDataAdapter.detach_recycleview()
RecycleDataAdapter.get_view()
RecycleDataAdapter.get_visible_view()
RecycleDataAdapter.invalidate()
RecycleDataAdapter.make_view_dirty()
RecycleDataAdapter.make_views_dirty()
RecycleDataAdapter.recycleview
RecycleDataAdapter.refresh_view_attrs()
RecycleDataAdapter.refresh_view_layout()
RecycleDataAdapter.set_visible_views()
RecycleDataViewBehavior
RecycleKVIDsDataViewBehavior
RecycleView Views¶
New in version 1.10.0.
The adapter part of the RecycleView which together with the layout is the view part of the model-view-controller pattern.
The view module handles converting the data to a view using the adapter class which is then displayed by the layout. A view can be any Widget based class. However, inheriting from RecycleDataViewBehavior adds methods for converting the data to a view.
- TODO:
Make view caches specific to each view class type.
- class kivy.uix.recycleview.views.RecycleDataAdapter(**kwargs)[source]¶
Bases:
kivy.event.EventDispatcher
The class that converts data to a view.
— Internal details — A view can have 3 states.
It can be completely in sync with the data, which occurs when the view is displayed. These are stored in
views
.It can be dirty, which occurs when the view is in sync with the data, except for the size/pos parameters which is controlled by the layout. This occurs when the view is not currently displayed but the data has not changed. These views are stored in
dirty_views
.Finally the view can be dead which occurs when the data changes and the view was not updated or when a view is just created. Such views are typically added to the internal cache.
Typically what happens is that the layout manager lays out the data and then asks for views, using
set_visible_views()
, for some specific data items that it displays.These views are gotten from the current views, dirty or global cache. Then depending on the view state
refresh_view_attrs()
is called to bring the view up to date with the data (except for sizing parameters). Finally, the layout manager gets these views, updates their size and displays them.- attach_recycleview(rv)[source]¶
Associates a
RecycleViewBehavior
with this instance. It is stored inrecycleview
.
- create_view(index, data_item, viewclass)[source]¶
(internal) Creates and initializes the view for the data at index.
The returned view is synced with the data, except for the pos/size information.
- detach_recycleview()[source]¶
Removes the
RecycleViewBehavior
associated with this instance and clearsrecycleview
.
- get_view(index, data_item, viewclass)[source]¶
(internal) Returns a view instance for the data at index
It looks through the various caches and finally creates a view if it doesn’t exist. The returned view is synced with the data, except for the pos/size information.
If found in the cache it’s removed from the source before returning. It doesn’t check the current views.
- get_visible_view(index)[source]¶
Returns the currently visible view associated with
index
.If no view is currently displayed for
index
it returnsNone
.
- invalidate()[source]¶
Moves all the current views into the global cache.
As opposed to making a view dirty where the view is in sync with the data except for sizing information, this will completely disconnect the view from the data, as it is assumed the data has gone out of sync with the view.
This is typically called when the data changes.
- make_view_dirty(view, index)[source]¶
(internal) Used to flag this view as dirty, ready to be used for others. See
make_views_dirty()
.
- make_views_dirty()[source]¶
Makes all the current views dirty.
Dirty views are still in sync with the corresponding data. However, the size information may go out of sync. Therefore a dirty view can be reused by the same index by just updating the sizing information.
Once the underlying data of this index changes, the view should be removed from the dirty views and moved to the global cache with
invalidate()
.This is typically called when the layout manager needs to re-layout all the data.
- recycleview¶
The
RecycleViewBehavior
associated with this instance.
- refresh_view_attrs(index, data_item, view)[source]¶
(internal) Syncs the view and brings it up to date with the data.
This method calls
RecycleDataViewBehavior.refresh_view_attrs()
if the view inherits fromRecycleDataViewBehavior
. See that method for more details.Note
Any sizing and position info is skipped when syncing with the data.
- refresh_view_layout(index, layout, view, viewport)[source]¶
Updates the sizing information of the view.
viewport is in coordinates of the layout manager.
This method calls
RecycleDataViewBehavior.refresh_view_attrs()
if the view inherits fromRecycleDataViewBehavior
. See that method for more details.Note
Any sizing and position info is skipped when syncing with the data.
- set_visible_views(indices, data, viewclasses)[source]¶
Gets a 3-tuple of the new, remaining, and old views for the current viewport.
The new views are synced to the data except for the size/pos properties. The old views need to be removed from the layout, and the new views added.
The new views are not necessarily new, but are all the currently visible views.
- class kivy.uix.recycleview.views.RecycleDataViewBehavior[source]¶
Bases:
builtins.object
A optional base class for data views (
RecycleView
.viewclass). If a view inherits from this class, the class’s functions will be called when the view needs to be updated due to a data change or layout update.- refresh_view_attrs(rv, index, data)[source]¶
Called by the
RecycleAdapter
when the view is initially populated with the values from the data dictionary for this item.Any pos or size info should be removed because they are set subsequently with
refresh_view_layout
.- Parameters:
- rv:
RecycleView
instance The
RecycleView
that caused the update.- data: dict
The data dict used to populate this view.
- rv:
- refresh_view_layout(rv, index, layout, viewport)[source]¶
Called when the view’s size is updated by the layout manager,
RecycleLayoutManagerBehavior
.- Parameters:
- rv:
RecycleView
instance The
RecycleView
that caused the update.- viewport: 4-tuple
The coordinates of the bottom left and width height in layout manager coordinates. This may be larger than this view item.
- rv:
- Raises:
LayoutChangeException: If the sizing or data changed during a call to this method, raising a LayoutChangeException exception will force a refresh. Useful when data changed and we don’t want to layout further since it’ll be overwritten again soon.
- class kivy.uix.recycleview.views.RecycleKVIDsDataViewBehavior[source]¶
Bases:
kivy.uix.recycleview.views.RecycleDataViewBehavior
Similar to
RecycleDataViewBehavior
, except that the data keys can signify properties of an object named with an id in the root KV rule.E.g. given a KV rule:
<MyRule@RecycleKVIDsDataViewBehavior+BoxLayout>: Label: id: name Label: id: value
Then setting the data list with
rv.data = [{'name.text': 'Kivy user', 'value.text': '12'}]
would automatically set the corresponding labels.So, if the key doesn’t have a period, the named property of the root widget will be set to the corresponding value. If there is a period, the named property of the widget with the id listed before the period will be set to the corresponding value.
New in version 2.0.0.
- refresh_view_attrs(rv, index, data)[source]¶
Called by the
RecycleAdapter
when the view is initially populated with the values from the data dictionary for this item.Any pos or size info should be removed because they are set subsequently with
refresh_view_layout
.- Parameters:
- rv:
RecycleView
instance The
RecycleView
that caused the update.- data: dict
The data dict used to populate this view.
- rv: