pywry.watcher¶
File watcher for hot reload support.
Data Types¶
pywry.watcher.WatchedFile
dataclass
¶
WatchedFile(path: Path, callback: Callable[[Path, str], None], label: str, last_triggered: float = 0.0)
Information about a watched file.
pywry.watcher.WindowDebouncer
dataclass
¶
Per-window debounce state.
File Watcher¶
pywry.watcher.FileWatcher
¶
Watch files for changes and trigger callbacks with debouncing.
Supports per-window debouncing so rapid saves across multiple files trigger a single callback per window.
Initialize the file watcher.
| PARAMETER | DESCRIPTION |
|---|---|
debounce_ms
|
Debounce time in milliseconds. Changes within this window will be batched into a single callback.
TYPE:
|
Attributes¶
Functions¶
watch
¶
Watch a file for changes.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to the file to watch.
TYPE:
|
callback
|
Function to call when file changes. Receives (path, label) as arguments.
TYPE:
|
label
|
Window label for grouping debounce.
TYPE:
|
unwatch
¶
Stop watching a file.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to stop watching.
TYPE:
|
label
|
If provided, only remove watches for this label.
TYPE:
|
unwatch_label
¶
Stop watching all files for a window.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label to unwatch.
TYPE:
|
Factory Functions¶
pywry.watcher.get_file_watcher
¶
get_file_watcher(debounce_ms: int = 100) -> FileWatcher
Get the global file watcher instance.
| PARAMETER | DESCRIPTION |
|---|---|
debounce_ms
|
Debounce time for new watcher.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FileWatcher
|
Global FileWatcher instance. |
pywry.watcher.stop_file_watcher
¶
Stop the global file watcher if running.