Version

Quick search

Table Of Contents

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 in recycleview.

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 clears recycleview.

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 returns None.

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 from RecycleDataViewBehavior. 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 from RecycleDataViewBehavior. 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.

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.

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.