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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
HotReloadSettings or None
|
Hot reload settings. Uses defaults if not provided. |
None
|
asset_loader
|
AssetLoader or None
|
Asset loader instance. Creates default if not provided. |
None
|
file_watcher
|
FileWatcher or None
|
File watcher instance. Creates default if not provided. |
None
|
Attributes¶
Functions¶
set_inject_css_callback
¶
Set the callback for CSS injection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[..., Any]
|
Function(label, css, asset_id) to inject CSS. |
required |
set_refresh_callback
¶
Set the callback for page refresh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[..., Any]
|
Function(label) to refresh a window. |
required |
enable_for_window
¶
enable_for_window(label: str, content: HtmlContent) -> None
Enable hot reload for a window's assets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label. |
required |
content
|
HtmlContent
|
HTML content with file references. |
required |
disable_for_window
¶
Disable hot reload for a window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label. |
required |
reload_css
¶
Reload CSS for a window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label. |
required |
path
|
Path or None
|
Specific CSS file to reload. If None, reloads all. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if CSS was injected, False otherwise. |
refresh_window
¶
Trigger a full page refresh for a window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if refresh was triggered, False otherwise. |
_on_file_change
¶
Handle file change event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to changed file. |
required |
label
|
str
|
Window label. |
required |
get_watched_files
¶
Get list of watched files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str or None
|
Specific window label. If None, returns all. |
None
|
Returns:
| Type | 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
HotReloadSettings or None
|
Settings for new manager creation. |
None
|
Returns:
| Type | Description |
|---|---|
HotReloadManager
|
Global HotReloadManager instance. |
pywry.hot_reload.stop_hot_reload_manager
¶
Stop the global hot reload manager if running.