pywry.hot_reload¶
Hot reload manager for live CSS/JavaScript updates during development.
Hot Reload Manager¶
pywry.hot_reload.HotReloadManager
¶
HotReloadManager(settings: HotReloadSettings | None = None, asset_loader: AssetLoader | None = None, file_watcher: FileWatcher | None = None)
Manages hot reload for CSS and JavaScript files.
- CSS changes: Inject updated styles without page reload
- JS changes: Trigger full page refresh (with scroll position preservation)
Initialize the hot reload manager.
| PARAMETER | DESCRIPTION |
|---|---|
settings
|
Hot reload settings. Uses defaults if not provided.
TYPE:
|
asset_loader
|
Asset loader instance. Creates default if not provided.
TYPE:
|
file_watcher
|
File watcher instance. Creates default if not provided.
TYPE:
|
Attributes¶
Functions¶
set_inject_css_callback
¶
Set the callback for CSS injection.
| PARAMETER | DESCRIPTION |
|---|---|
callback
|
Function(label, css, asset_id) to inject CSS.
TYPE:
|
set_refresh_callback
¶
Set the callback for page refresh.
| PARAMETER | DESCRIPTION |
|---|---|
callback
|
Function(label) to refresh a window.
TYPE:
|
enable_for_window
¶
enable_for_window(label: str, content: HtmlContent) -> None
Enable hot reload for a window's assets.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label.
TYPE:
|
content
|
HTML content with file references.
TYPE:
|
disable_for_window
¶
Disable hot reload for a window.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label.
TYPE:
|
reload_css
¶
Reload CSS for a window.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label.
TYPE:
|
path
|
Specific CSS file to reload. If None, reloads all.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if CSS was injected, False otherwise. |
refresh_window
¶
Trigger a full page refresh for a window.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if refresh was triggered, False otherwise. |
_on_file_change
¶
Handle file change event.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to changed file.
TYPE:
|
label
|
Window label.
TYPE:
|
get_watched_files
¶
Get list of watched files.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Specific window label. If None, returns all.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, list[Path]]
|
Dict mapping labels to lists of watched paths. |
Factory Functions¶
pywry.hot_reload.get_hot_reload_manager
¶
get_hot_reload_manager(settings: HotReloadSettings | None = None) -> HotReloadManager
Get the global hot reload manager instance.
| PARAMETER | DESCRIPTION |
|---|---|
settings
|
Settings for new manager creation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
HotReloadManager
|
Global HotReloadManager instance. |
pywry.hot_reload.stop_hot_reload_manager
¶
Stop the global hot reload manager if running.