Progress Loader¶
Progressbar downloads files from the server.
Example¶
import os
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.factory import Factory
from kivymd.uix.progressloader import MDProgressLoader
from kivymd.theming import ThemeManager
from kivymd.toast import toast
Builder.load_string('''
<Root@BoxLayout>
orientation: 'vertical'
spacing: dp(5)
MDToolbar:
id: toolbar
title: 'MD Progress Loader'
left_action_items: [['menu', lambda x: None]]
elevation: 10
md_bg_color: app.theme_cls.primary_color
FloatLayout:
id: box
MDRoundFlatIconButton:
text: "Download file"
icon: "download"
pos_hint: {'center_x': .5, 'center_y': .6}
on_release: app.show_example_download_file()
''')
class Test(MDApp):
def build(self):
self.main_widget = Factory.Root()
return self.main_widget
def set_chevron_back_screen(self):
'''Sets the return chevron to the previous screen in ToolBar.'''
self.main_widget.ids.toolbar.right_action_items = []
def download_progress_hide(self, instance_progress, value):
'''Hides progress progress.'''
self.main_widget.ids.toolbar.right_action_items = [['download',
lambda x: self.download_progress_show(instance_progress)]]
def download_progress_show(self, instance_progress):
self.set_chevron_back_screen()
instance_progress.open()
instance_progress.animation_progress_from_fade()
def show_example_download_file(self):
link = 'https://www.python.org/ftp/python/3.5.1/python-3.5.1-embed-win32.zip'
progress = MDProgressLoader(
url_on_image=link,
path_to_file=os.path.join(self.directory, 'python-3.5.1.zip'),
download_complete=self.download_complete,
download_hide=self.download_progress_hide
)
progress.start(self.main_widget.ids.box)
def download_complete(self):
self.set_chevron_back_screen()
toast('Done')
Test().run()
API - kivymd.uix.progressloader
¶
-
class
kivymd.uix.progressloader.
MDProgressLoader
(**kwargs)¶ Widget class. See module documentation for more information.
- Events
- on_touch_down: (touch, )
Fired when a new touch event occurs. touch is the touch object.
- on_touch_move: (touch, )
Fired when an existing touch moves. touch is the touch object.
- on_touch_up: (touch, )
Fired when an existing touch disappears. touch is the touch object.
- on_kv_post: (base_widget, )
Fired after all the kv rules associated with the widget and all other widgets that are in any of those rules have had all their kv rules applied. base_widget is the base-most widget whose instantiation triggered the kv rules (i.e. the widget instantiated from Python, e.g.
MyWidget()
).Changed in version 1.11.0.
Warning
Adding a __del__ method to a class derived from Widget with Python prior to 3.4 will disable automatic garbage collection for instances of that class. This is because the Widget class creates reference cycles, thereby preventing garbage collection.
Changed in version 1.0.9: Everything related to event properties has been moved to the
EventDispatcher
. Event properties can now be used when contructing a simple class without subclassingWidget
.Changed in version 1.5.0: The constructor now accepts on_* arguments to automatically bind callbacks to properties or events, as in the Kv language.
-
path_to_file
¶ The path to which the uploaded file will be saved.
-
url_on_image
¶ Link to uploaded file.
-
label_downloading_text
¶ Default text before downloading.
-
downloading_text
¶ Signature of the downloaded file.
-
download_complete
¶ Function, called after a successful file upload.
-
download_hide
¶ Function that is called when the download window is closed.
-
download_flag
¶ If True - the download process is in progress.
-
request
¶ UrlRequest object.
-
start
(self, root_instance)¶
-
open
(self)¶
-
draw_progress
(self, percent)¶ - Parameters
percent (int;) – loading percentage;
-
animation_progress_to_fade
(self, interval)¶
-
animation_progress_from_fade
(self)¶
-
retrieve_progress_load
(self, url, path)¶ - Parameters
url (str;) – link to content;
path (str;) – path to save content;
-
update_progress
(self, request, current_size, total_size)¶
-
on_success
(self, request, result)¶