You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/env python3fromtextual.appimportApp, ComposeResultfromtextual.widgetsimportLabel, CollapsibleINSTRUCTIONS="""[u]Instructions:[/u]1. Wait for 2 seconds2. The label inside the collapsible changes, this is good3. The collapsible title remains unchanged, this is problematic4. Wait for 2 seconds again5. Both label and title change."""COLLAPSIBLE_TITLE_1='[#ff0000]title[/]'COLLAPSIBLE_TITLE_2='[#00ff00]title[/]'# color changeCOLLAPSIBLE_TITLE_3='[#00ff00]TITLE[/]'# color and text changeclassTextual3Collapsible(App):
defcompose(self) ->ComposeResult:
yieldLabel(INSTRUCTIONS)
withCollapsible(title=COLLAPSIBLE_TITLE_1, collapsed=False):
yieldLabel(COLLAPSIBLE_TITLE_1)
defchange(self, new_title) ->None:
self.query_one('Collapsible', Collapsible).title=new_titleself.query_one('Collapsible Label', Label).update(new_title)
defon_ready(self) ->None:
self.set_timer(2, self.change_1)
defchange_1(self) ->None:
self.change(COLLAPSIBLE_TITLE_2)
self.set_timer(2, self.change_2)
defchange_2(self) ->None:
self.change(COLLAPSIBLE_TITLE_3)
if__name__=="__main__":
app=Textual3Collapsible()
app.run()
At t=0: ok:
At t=2: not ok, the collapsible title remains unchanged:
At t=4: ok, the collapsible title changed
Additionally, Collapsible's title reactive is a string whereas CollapsibleTitle's label reactive is a ContentText created using Content.from_text(). It would be nice if we could pass a ContentText to Collapsible without vexing mypy.
Alternatively, being able to import CollapsibleTitle would allow mypy to understand what is happening when working on a CollapsibleTitle widget obtained through query_one().
It looks like there's a similar problem in the Button (and maybe other widgets?) where the "smart refresh" isn't invoked when the new content only updates the style.
I'm not sure what the correct fix is here, perhaps these reactives need marking as always_update=True?
fromtextual.appimportApp, ComposeResultfromtextual.widgetsimportButton, StaticCONTENT_PLAIN="Update styles"CONTENT_MARKUP=f"[magenta on yellow]{CONTENT_PLAIN}[/]"classExampleApp(App):
defcompose(self) ->ComposeResult:
yieldButton(CONTENT_PLAIN)
yieldStatic(CONTENT_PLAIN)
defon_button_pressed(self) ->None:
# This works...self.query_one(Static).update(CONTENT_MARKUP)
# ...but this doesn'tself.query_one(Button).label=CONTENT_MARKUPif__name__=="__main__":
app=ExampleApp()
app.run()
Have you checked closed issues? (https://github.com/Textualize/textual/issues?q=is%3Aissue+is%3Aclosed)
Have you checked against the most recent version of Textual? (https://pypi.org/search/?q=textual)
The bug
MRE
At t=0: ok:

At t=2: not ok, the collapsible title remains unchanged:

At t=4: ok, the collapsible title changed

Additionally, Collapsible's
title
reactive is a string whereas CollapsibleTitle'slabel
reactive is a ContentText created using Content.from_text(). It would be nice if we could pass a ContentText to Collapsible without vexing mypy.Alternatively, being able to import CollapsibleTitle would allow mypy to understand what is happening when working on a CollapsibleTitle widget obtained through query_one().
Textual Diagnostics
Versions
Python
Operating System
Terminal
Rich Console options
The text was updated successfully, but these errors were encountered: