MCPcopy
hub / github.com/Textualize/textual / watch_path

Method watch_path

examples/code_browser.py:65–80  ·  view source on GitHub ↗

Called when path changes.

(self, path: str | None)

Source from the content-addressed store, hash-verified

63 self.path = str(event.path)
64
65 def watch_path(self, path: str | None) -> None:
66 """Called when path changes."""
67 code_view = self.query_one("#code", Static)
68 if path is None:
69 code_view.update("")
70 return
71 try:
72 code = Path(path).read_text(encoding="utf-8")
73 syntax = highlight(code, path=path)
74 except Exception:
75 code_view.update(Traceback(theme="github-dark", width=None))
76 self.sub_title = "ERROR"
77 else:
78 code_view.update(syntax)
79 self.query_one("#code-view").scroll_home(animate=False)
80 self.sub_title = path
81
82 def action_toggle_files(self) -> None:
83 """Called in response to key binding."""

Callers 1

theme_changeMethod · 0.95

Calls 4

highlightFunction · 0.90
query_oneMethod · 0.80
scroll_homeMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected