HotReloadViewer

Note

The HotReloadViewer class is based on the KvViewerApp class

HotReloadViewer, for KV-Viewer, is a simple tool allowing you to dynamically display a KV file, taking its changes into account (thanks to watchdog). The idea is to facilitate design using the KV language.

Usage

from kivy.lang import Builder

from kivymd.app import MDApp

KV = '''
#:import KivyLexer kivy.extras.highlight.KivyLexer
#:import HotReloadViewer kivymd.utils.hot_reload_viewer.HotReloadViewer


BoxLayout:

    CodeInput:
        lexer: KivyLexer()
        style_name: "native"
        on_text: app.update_kv_file(self.text)
        size_hint_x: .7

    HotReloadViewer:
        size_hint_x: .3
        path: app.path_to_kv_file
        errors: True
        errors_text_color: 1, 1, 0, 1
        errors_background_color: app.theme_cls.bg_dark
'''


class Example(MDApp):
    path_to_kv_file = "kv_file.kv"

    def build(self):
        self.theme_cls.theme_style = "Dark"
        return Builder.load_string(KV)

    def update_kv_file(self, text):
        with open(self.path_to_kv_file, "w") as kv_file:
            kv_file.write(text)


Example().run()

This will display the test.kv and automatically update the display when the file changes.

This scripts uses watchdog to listen for file changes. To install watchdog.

pip install watchdog

API - kivymd.utils.hot_reload_viewer

class kivymd.utils.hot_reload_viewer.HotReloadErrorText(**kwargs)

ScrollView class. See module documentation for more information.

Events
on_scroll_start

Generic event fired when scrolling starts from touch.

on_scroll_move

Generic event fired when scrolling move from touch.

on_scroll_stop

Generic event fired when scrolling stops from touch.

Changed in version 1.9.0: on_scroll_start, on_scroll_move and on_scroll_stop events are now dispatched when scrolling to handle nested ScrollViews.

Changed in version 1.7.0: auto_scroll, scroll_friction, scroll_moves, scroll_stoptime’ has been deprecated, use :attr:`effect_cls instead.

text

Text errors.

text is an StringProperty and defaults to ‘’.

errors_text_color

Error text color.

errors_text_color is an ColorProperty and defaults to None.

class kivymd.utils.hot_reload_viewer.HotReloadHandler(callback, target, **kwargs)
on_any_event(self, event)
class kivymd.utils.hot_reload_viewer.HotReloadViewer(**kwargs)
Events

on_error

Called when an error occurs in the KV-file that the user is editing.

path

Path to KV file.

path is an StringProperty and defaults to ‘’.

errors

Show errors while editing KV-file.

errors is an BooleanProperty and defaults to False.

errors_background_color

Error background color.

errors_background_color is an ColorProperty and defaults to None.

errors_text_color

Error text color.

errors_text_color is an ColorProperty and defaults to None.

update(self, *args)

Updates and displays the KV-file that the user edits.

show_error(self, error)

Displays text with a current error.

on_error(self, *args)

Called when an error occurs in the KV-file that the user is editing.

on_errors_text_color(self, instance, value)
on_path(self, instance, value)