Replies: 6 comments 3 replies
-
When you instantiate a progress bar, you get a reactive If you prefer to count number of steps instead of percentages, there's also a Is this clear enough? # In your function that does the looping operation
pb = self.query("#your-awesome-progress-bar")
while doing_stuff:
progress_percentage = compute_progress()
pb.percentage = progress_percentage
# Do your own things |
Beta Was this translation helpful? Give feedback.
-
Hi @rodrigogiraoserrao , thanks for your quick answer. Unfortunately, this does not seem to work as easy as most of the examples demonstrate. In my case, there is no I would be happy if you could have a quick look at my former post, as it shows an example structure of a more complex setting. The goal is still just to be able to "monitor" the progress of a loop operation situated within another Python module. I don't want to bother you and the community, but I was hoping that Anyway, thanks. I might have a look at one of the real and bigger applications out there when I have more time. |
Beta Was this translation helpful? Give feedback.
-
I use callbacks fired from the thing doing the updating. The method containing your loop would have a param called Another option is to set up a watchdog loop that monitors the internal state of your application's progress (ie, check the object about once per second, and if the state changes, do something). I've actually used both of the above to equip an existing library/application with TUIs. |
Beta Was this translation helpful? Give feedback.
-
To achieve this, you must broadcast the progress of a certain program or module. Let's assume you have a logical processing unit called The first approach that comes to mind is to have class Tui(App):
def on_progress_changed(self, cur, total):
# Update progress as suggested by @rodrigogiraoserrao
pass
class Worker:
def reg_progress_handler(self, obj, fun):
fun(obj, cur, total) Alternatively, if you don't want from functools import partial
class EventHandler:
def __init__(self):
self.on_process_changed_handler = None
def set_on_process_changed(self, obj, fun):
self.on_process_changed_handler = partial(fun, obj)
def on_progress_changed(self, cur, total):
if self.on_process_changed_handler:
self.on_process_changed_handler(cur, total)
class Tui(App):
def __init__(self):
event_handler.set_on_process_changed(self, self.on_progress_changed)
super().__init__()
def on_progress_changed(self, cur, total):
# Update progress as suggested by @rodrigogiraoserrao
pass
class Worker:
# Call this function to update progress without depending on Tui
def handle_progress(self, cur, total):
event_handler.on_progress_changed(cur, total) For simplicity, I haven't included necessary safety checks (e.g., ensuring the callable is not Clearly, the second solution involves more code, but this is a small trade-off for achieving decoupling. |
Beta Was this translation helpful? Give feedback.
-
Hi @rodrigogiraoserrao , @comalice and @Smalldy . Thanky for your suggestions and ideas so far. Unfortunately, I still didn't manage to achieve what I intended. And I still think that my own brain just does not get the obvious... So, please have a look at the following sequence diagram: The hatched parts of the lifelines are those where the (single) processor does some work. Either for the GUI side or the LIB side. The module for "LIB" is included into the "GUI" module via
As I think, the essence will be to answer the question: "is is possible to stop/resume execution at will between modules"? can this be done? without asyncio? how else could this be done? |
Beta Was this translation helpful? Give feedback.
-
no "leave", no "resume". Just funtion call. A long work function will block your code. A short function will not block your code. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I think, my former post was to long to be read (sorry for that).
I would like to know if there is a way to poke into an existing library function (source available) in order to display its progress in
textual
'sProgressBar
widget. After watching a couple of videos made by @rodrigogiraoserrao , I more and more understood howtextual
can be used to build up mechanisms for display and synchronization. But I haven't found out about how exactly the probing into library functions would work.How do I have to combine the existing mechanisms (
ProgressBar
,watches
,messages
,reactive
, ...) in combination withasyncio
in order to realize the synchronization bit within the following sequence:ProgressBar
gets rendered in a "neutral" way at start of the applicationtextual
'sProgressBar
widget, now showing the calculated progress valueIs this possible? Is there already a video describing this (I would think) common technical situation?
Beta Was this translation helpful? Give feedback.
All reactions