Discussion:
[urwid] Update screen automatically
taitd
2018-05-28 08:51:04 UTC
Permalink
Hi there,

I have problem with updating screen automatically. I have one client
receiving information from one server and saving the information to a file.
My server will send new information every 1 second so my file will be
update new content after every 1 second. My program using urwid has to
show file content on a status screen dynamically. It means the status
screen has to show the content which will be modified every second. But the
status screen is only updated when I press a key which is used to update
screen. I wonder if there is any way to update screen automatically? Could
you give me an example to solve my problem?

Thank you.
--
You received this message because you are subscribed to the Google Groups "Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to urwid+***@excess.org.
To post to this group, send email to ***@excess.org.
For more options, visit https://groups.google.com/a/excess.org/d/optout.
Robert Urban
2018-05-28 10:58:54 UTC
Permalink
Hello taitd,

urwid (and generally any UI) must run a so-called "event loop" and respond to
events. This is urwid's MainLoop . Pressing  a key causes an event of type
"keypress" to be generated, which is handled (or not) by the event loop.

You can solve your problem by using the "watch_file" of the loop object to
generate events when a file descriptor has data available that can be read. You
can use this on some sort of file-based IPC (inter-process communication)
mechanism, such as a socket, to allow your urwid program to respond when new
data is available.

rob
Post by taitd
Hi there,
I have problem with updating screen automatically. I have one client receiving
information from one server and saving the information to a file. My server
will send new information every 1 second so my file will be update new content
after every 1 second.  My program using urwid has to show file content on a
status screen dynamically. It means the status screen has to show the content
which will be modified every second. But the status screen is only updated
when I press a key which is used to update screen. I wonder if there is any
way to update screen automatically? Could you give me an example to solve my
problem?
Thank you.
--
You received this message because you are subscribed to the Google Groups
"Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/a/excess.org/d/optout.
--
You received this message because you are subscribed to the Google Groups "Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to urwid+***@excess.org.
To post to this group, send email to ***@excess.org.
For more options, visit https://groups.google.com/a/excess.org/d/optout.
taitd
2018-06-01 06:38:18 UTC
Permalink
Thank Rob! With your suggestion about watch_file, I have solved my problem.
However, there is another issue occurred: I cannot modify any Edit widgets
anymore. I am not sure the reason is watch_file but is it possible, the
events of watch_file function can stop interactions of other widgets?

Another question is about the efficiency of watch_file in this case.
Watch_file seems to call the loop back more frequently than the file
updating rate (1 second). So, in this case, is using set_alarm_in function
more efficient?
--
You received this message because you are subscribed to the Google Groups "Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to urwid+***@excess.org.
To post to this group, send email to ***@excess.org.
For more options, visit https://groups.google.com/a/excess.org/d/optout.
Robert Urban
2018-06-01 11:05:48 UTC
Permalink
Hello taitd,

it does not sound like you are using watch_file() correctly. The usual
procedure for asking for help in such situations is to reduce your
program to the bare minimum necessary to demonstrate the problem and
then provide the test program.

cheers,

rob
Post by taitd
Thank Rob! With your suggestion about watch_file, I have solved my
problem. However, there is another issue occurred: I cannot modify any
Edit widgets anymore. I am not sure the reason is watch_file but is it
possible, the events of watch_file function can stop interactions of
other widgets?
Another question is about the efficiency of watch_file in this case.
Watch_file seems to call the loop back more frequently than the file
updating rate (1 second). So, in this case, is using set_alarm_in
function more efficient? 
--
You received this message because you are subscribed to the Google
Groups "Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/a/excess.org/d/optout.
--
You received this message because you are subscribed to the Google Groups "Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to urwid+***@excess.org.
To post to this group, send email to ***@excess.org.
For more options, visit https://groups.google.com/a/excess.org/d/optout.
Loading...