HotReload#
#
Added in version 1.0.0.
Hot reload tool - is a fork of the project tito/kaki
Note
Since the project is not developing, we decided to include it in the KivvMD library and hope that the further development of the hot reload tool in the KivyMD project will develop faster.
This library enhance Kivy frameworks with opiniated features such as:
Auto reloading kv or py (watchdog required, limited to some uses cases);
Idle detection support;
Foreground lock (Windows OS only);
Usage#
Note
See create project with hot reload for more information.
TODO#
Add automatic reloading of Python classes;
Add save application state on reloading;
FIXME#
On Windows, hot reloading of Python files may not work;
API - kivymd.tools.hotreload.app
#
- kivymd.tools.hotreload.app.original_argv#
- kivymd.tools.hotreload.app.monotonic#
- kivymd.tools.hotreload.app.PY3 = True#
- class kivymd.tools.hotreload.app.ExceptionClass#
Base handler that catches exceptions in
runTouchApp()
. You can subclass and extend it as follows:class E(ExceptionHandler): def handle_exception(self, inst): Logger.exception('Exception caught by ExceptionHandler') return ExceptionManager.PASS ExceptionManager.add_handler(E())
Then, all exceptions will be set to PASS, and logged to the console!
- handle_exception(inst)#
Called by
ExceptionManagerBase
to handle a exception.Defaults to returning
ExceptionManager.RAISE
that re-raises the exception. ReturnExceptionManager.PASS
to indicate that the exception was handled and should be ignored.This may be called multiple times with the same exception, if
ExceptionManager.RAISE
is returned as the exception bubbles through multiple kivy exception handling levels.
- class kivymd.tools.hotreload.app.MDApp(**kwargs)#
HotReload Application class.
- property appname#
Return the name of the application class.
- DEBUG#
Control either we activate debugging in the app or not. Defaults depend if ‘DEBUG’ exists in os.environ.
DEBUG
is aBooleanProperty
.
- FOREGROUND_LOCK#
If True it will require the foreground lock on windows.
FOREGROUND_LOCK
is aBooleanProperty
and defaults to False.
- KV_FILES#
List of KV files under management for auto reloader.
KV_FILES
is aListProperty
and defaults to [].
- KV_DIRS#
List of managed KV directories for autoloader.
KV_DIRS
is aListProperty
and defaults to [].
- AUTORELOADER_PATHS#
List of path to watch for auto reloading.
AUTORELOADER_PATHS
is aListProperty
and defaults to ([(“.”, {“recursive”: True})].
- AUTORELOADER_IGNORE_PATTERNS#
List of extensions to ignore.
AUTORELOADER_IGNORE_PATTERNS
is aListProperty
and defaults to [‘*.pyc’, ‘*__pycache__*’].
- CLASSES#
Factory classes managed by hotreload.
CLASSES
is aDictProperty
and defaults to {}.
- IDLE_DETECTION#
Idle detection (if True, event on_idle/on_wakeup will be fired). Rearming idle can also be done with rearm_idle().
IDLE_DETECTION
is aBooleanProperty
and defaults to False.
- IDLE_TIMEOUT#
Default idle timeout.
IDLE_TIMEOUT
is aNumericProperty
and defaults to 60.
- RAISE_ERROR#
Raise error. When the DEBUG is activated, it will raise any error instead of showing it on the screen. If you still want to show the error when not in DEBUG, put this to False.
RAISE_ERROR
is aBooleanProperty
and defaults to True.
- build()#
Initializes the application; it will be called only once. If this method returns a widget (tree), it will be used as the root widget and added to the window.
- Returns:
None or a root
Widget
instance if no self.root exists.
- get_root()#
Return a root widget, that will contains your application. It should not be your application widget itself, as it may be destroyed and recreated from scratch when reloading.
By default, it returns a RelativeLayout, but it could be a Viewport.
- get_root_path()#
Return the root file path.
- abstract build_app(first=False)#
Must return your application widget.
If first is set, it means that will be your first time ever that the application is built. Act according to it.
- unload_app_dependencies()#
Called when all the application dependencies must be unloaded. Usually happen before a reload
- load_app_dependencies()#
Load all the application dependencies. This is called before rebuild.
- rebuild(*args, **kwargs)#
- set_error(exc, tb=None)#
- bind_key(key, callback)#
Bind a key (keycode) to a callback (cannot be unbind).
- enable_autoreload()#
Enable autoreload manually. It is activated automatically if “DEBUG” exists in environ. It requires the watchdog module.
- prepare_foreground_lock()#
Try forcing app to front permanently to avoid windows pop ups and notifications etc.app.
Requires fake full screen and borderless.
Note
This function is called automatically if FOREGROUND_LOCK is set
- set_widget(wid)#
Clear the root container, and set the new approot widget to wid.
- apply_state(state)#
Whatever the current state is, reapply the current state.
- install_idle(timeout=60)#
Install the idle detector. Default timeout is 60s. Once installed, it will check every second if the idle timer expired. The timer can be rearm using
rearm_idle()
.
- rearm_idle(*args)#
Rearm the idle timer.
- patch_builder()#
- on_idle(*args)#
Event fired when the application enter the idle mode.
- on_wakeup(*args)#
Event fired when the application leaves idle mode.