Philipp Keller wrote on 2010-09-04 03:02:
> Hi there
>
> I've got a queue (multiprocessing.queue) that is fed by subprocesses and
> is consisting of entries like ("server01", "unpacking /tmp/my.tar.gz").
> I want to read from the queue and put the server/message couple into
> urwid via Columns, like this:
>
> from urwid.curses_display import Screen
>
> columns = urwid.Columns(listboxes)
> screen = Screen()
> screen.start()
> while is_alive(processes):
> if not display_queue.empty():
> server, message = display_queue.get()
> add_to_listbox(server, listboxes)
> screen.draw_screen((cols,rows), columns)
> else:
> time.sleep(0.05)
> screen.stop()
A simple, but inefficient way of making that work would be:
size = screen.get_cols_rows()
screen.draw_screen(size, columns.render(size))
(note that you do need to render columns, not just pass it to draw_screen)
> I've got 2 questions:
>
> 1. what do I need to put into (cols, rows) in the draw_screen call?
>
> 2. am I completely on the wrong track? What would be a better solution
> to "be in control myself" because I
> a) want to quit the drawing whenever all the subprocesses finished
> b) need to periodically check if there are new messages in the queue?
Ideally you should be doing nothing when there is nothing new to
display, and the screen should update when only the user resizes the
terminal or the contents are modified. Waking up 20x a second can be
bad for battery life :-)
A nice solution would involve using MainLoop and a thread to block on
the Queue, empty it when there are new items and wake the UI thread to
update the screen. MainLoop will handle the redrawing required by
resizing the terminal and any user input you might want. You can still
exit when the subprocess is done by raising ExitMainLoop in the UI thread.
Ian
_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid