Reactivity question #4161
Replies: 3 comments 4 replies
-
|
Stepping back from the reactive aspect of this for a moment (checking this first as your code seems to be battling against how self.path_show.update(f'Selected path: {event.path.as_posix()}')without the need to subclass |
Beta Was this translation helpful? Give feedback.
-
|
Hi @davep, I am trying to understand how Hope this makes sense. |
Beta Was this translation helpful? Give feedback.
-
|
Perhaps I'm missing something obvious, but there does seem to be something weird about the DirectoryTree message paths. Try the app below before and after uncommenting the notify line: from pathlib import Path
from textual import on
from textual.app import App, ComposeResult
from textual.reactive import reactive
from textual.widgets import DirectoryTree, Label
class PathLabel(Label):
path: reactive[str] = reactive("None")
def render(self) -> str:
return f"Selected path: {self.path}"
class WatchApp(App):
def compose(self) -> ComposeResult:
path = Path(__file__).parent
yield PathLabel()
yield DirectoryTree(path=path)
@on(DirectoryTree.DirectorySelected)
@on(DirectoryTree.FileSelected)
def update_path_label(
self,
event: DirectoryTree.FileSelected,
) -> None:
# self.notify(str(event.path))
self.query_one(PathLabel).path = str(event.path)
if __name__ == "__main__":
app = WatchApp()
app.run() |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I was looking at #1683 and I thought I understood how
reactiveworks after that.The idea I have is to show a
DirectoryTreeand then show whatever the user selected in aLabel. I created aReactiveLabelclass that uses therendermethod to show a reactive property.One widget is shown below:
And then we have the
ReactiveLabel:However, when I select any node, I can see the path reflected in
ReactiveLabelon screen on every other selection.I am really confused as I think this should work based on the discussion in the linked question, since the
reactiveproperty is in a separate object.What am I doing wrong and/or misunderstanding?
Beta Was this translation helpful? Give feedback.
All reactions