RefreshLayout#
#
Example#
from kivy.clock import Clock
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.icon_definitions import md_icons
from kivymd.uix.list import (
MDListItem, MDListItemHeadlineText, MDListItemTrailingIcon
)
import asynckivy
KV = '''
MDScreen:
md_bg_color: self.theme_cls.backgroundColor
MDBoxLayout:
orientation: 'vertical'
MDTopAppBar:
MDTopAppBarLeadingButtonContainer:
MDActionTopAppBarButton:
icon: 'menu'
MDTopAppBarTitle:
text: 'Example Refresh Layout'
MDScrollViewRefreshLayout:
id: refresh_layout
refresh_callback: app.refresh_callback
root_layout: root
spinner_color: "brown"
circle_color: "white"
MDGridLayout:
id: box
adaptive_height: True
cols: 1
'''
class Example(MDApp):
x = 0
y = 15
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
return Builder.load_string(KV)
def on_start(self):
self.set_list()
def set_list(self):
async def set_list():
names_icons_list = list(md_icons.keys())[self.x:self.y]
for name_icon in names_icons_list:
await asynckivy.sleep(0)
self.root.ids.box.add_widget(
MDListItem(
MDListItemHeadlineText(
text=name_icon
),
MDListItemTrailingIcon(
icon=name_icon
)
)
)
asynckivy.start(set_list())
def refresh_callback(self, *args):
'''
A method that updates the state of your application
while the spinner remains on the screen.
'''
def refresh_callback(interval):
self.root.ids.box.clear_widgets()
if self.x == 0:
self.x, self.y = 15, 30
else:
self.x, self.y = 0, 15
self.set_list()
self.root.ids.refresh_layout.refresh_done()
self.tick = 0
Clock.schedule_once(refresh_callback, 1)
Example().run()
from kivy.clock import Clock
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.icon_definitions import md_icons
from kivymd.uix.floatlayout import MDFloatLayout
from kivymd.uix.gridlayout import MDGridLayout
from kivymd.uix.refreshlayout import MDScrollViewRefreshLayout
from kivymd.uix.list import (
MDListItem, MDListItemHeadlineText, MDListItemTrailingIcon
)
from kivymd.uix.appbar import (
MDTopAppBar,
MDTopAppBarLeadingButtonContainer,
MDActionTopAppBarButton,
MDTopAppBarTitle,
)
import asynckivy
class Example(MDApp):
x = 0
y = 15
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
return (
MDFloatLayout(
MDBoxLayout(
MDTopAppBar(
MDTopAppBarLeadingButtonContainer(
MDActionTopAppBarButton(
icon='menu'
)
),
MDTopAppBarTitle(
text='Example Refresh Layout'
)
),
MDScrollViewRefreshLayout(
MDGridLayout(
id="box",
adaptive_height=True,
cols=1,
),
id="refresh_layout",
refresh_callback=self.refresh_callback,
spinner_color="red",
circle_color="white",
),
orientation='vertical'
),
md_bg_color=self.theme_cls.backgroundColor
)
)
def on_start(self):
self.root.get_ids().refresh_layout.root_layout = self.root
self.set_list()
def set_list(self):
async def set_list():
names_icons_list = list(md_icons.keys())[self.x:self.y]
for name_icon in names_icons_list:
await asynckivy.sleep(0)
self.root.get_ids().box.add_widget(
MDListItem(
MDListItemHeadlineText(
text=name_icon
),
MDListItemTrailingIcon(
icon=name_icon
)
)
)
asynckivy.start(set_list())
def refresh_callback(self, *args):
'''
A method that updates the state of your application
while the spinner remains on the screen.
'''
def refresh_callback(interval):
self.root.get_ids().box.clear_widgets()
if self.x == 0:
self.x, self.y = 15, 30
else:
self.x, self.y = 0, 15
self.set_list()
self.root.get_ids().refresh_layout.refresh_done()
self.tick = 0
Clock.schedule_once(refresh_callback, 1)
Example().run()
API - kivymd.uix.refreshlayout.refreshlayout#
- class kivymd.uix.refreshlayout.refreshlayout.MDScrollViewRefreshLayout(*args, **kwargs)#
Refresh layout class.
For more information, see in the
MDScrollViewandThemableBehaviorclass documentation.- root_layout#
The spinner will be attached to this layout.
root_layoutis aObjectPropertyand defaults to None.
- refresh_callback#
The method that will be called at the on_touch_up event, provided that the overscroll of the list has been registered.
refresh_callbackis aObjectPropertyand defaults to None.
- spinner_color#
Color of the spinner in (r, g, b, a) or string format.
Added in version 1.2.0.
spinner_coloris aColorPropertyand defaults to [1, 1, 1, 1].
- circle_color#
Color of the ellipse around the spinner in (r, g, b, a) or string format.
Added in version 1.2.0.
circle_coloris aColorPropertyand defaults to None.
- show_transition#
Transition of the spinner’s opening.
Added in version 1.2.0.
show_transitionis aStringPropertyand defaults to ‘out_elastic’.
- show_duration#
Duration of the spinner display.
Added in version 1.2.0.
show_durationis aNumericPropertyand defaults to 0.8.
- hide_transition#
Transition of hiding the spinner.
Added in version 1.2.0.
hide_transitionis aStringPropertyand defaults to ‘out_elastic’.
- hide_duration#
Duration of hiding the spinner.
Added in version 1.2.0.
hide_durationis aNumericPropertyand defaults to 0.8.
- on_touch_up(*args)#
Receive a touch up event. The touch is in parent coordinates.
See
on_touch_down()for more information.