-
Hi, I'm very new to Textual and moderately experienced with Python async. I may have a misconception or a missing piece of information that's causing me a great deal of headache... I'm trying to write a progress bar that updates dynamically based on work done in a separate queue. I've got a callback system set up where work being completed should trigger either an increase in the bar's total or the bar's progress. It functions something like this: class Progress(Screen):
def compose(self) -> ComposeResult:
with Center():
with Middle():
yield ProgressBar(name="SNMP Tasks", id="snmp_bar")
yield ProgressBar(name="Connect Tasks", id="connect_bar")
yield ProgressBar(name="SSH Tasks", id="ssh_bar")
def on_mount(self) -> None:
add_queue_callback_func(self._bar_progress, queue_completions)
add_queue_callback_func(self._bar_total, queue_additions)
self.run_worker(do_async_queue_things())
def _bar_progress(self, key: SubKey) -> None:
if key[1] == "snmp":
logger.critical("GOT AN SNMP HIT")
self.query_one("#snmp_bar", ProgressBar).advance()
...
def _bar_total(self, key: SubKey, token: RequestToken) -> None:
def inc_total(bar: ProgressBar) -> None:
bar_total = bar.total
if bar_total is not None:
new_total = int(bar_total) + 1
else:
new_total = 1
bar.update(total=new_total)
if key[1] == "snmp":
logger.critical("GOT AN SNMP TOTAL")
inc_total(self.query_one("#snmp_bar", ProgressBar))
... The three ProgressBars will render when I create and push the Screen. The Does anyone have an idea on what I might be doing wrong here? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
It's a bit tricky to say exactly what might be the issue here given that this is only a snippet of some code. Do you think you might be able to reproduce the issue as some standalone code anyone can run? Meanwhile though, given that it seems you're writing something that involves doing work parallel to updating the display, perhaps Textual's worker API would be helpful here? |
Beta Was this translation helpful? Give feedback.
-
Issue was due to my own programming error. Closing discussion. Thanks davep! |
Beta Was this translation helpful? Give feedback.
Issue was due to my own programming error. Closing discussion. Thanks davep!