Mar-03-2018, 11:35 PM
I am trying output some test to the screen, but I have to update the text when some external data changes.
So I made this test program, and even though it works, I think I am doing something very wrong, since it seems like I am creating loops within loops.
Can someone tell me what i am doing wrong?
So I made this test program, and even though it works, I think I am doing something very wrong, since it seems like I am creating loops within loops.
Can someone tell me what i am doing wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#!/usr/bin/python import urwid def unhandled_input(key): if key = = 'q' : raise urwid.ExitMainLoop() def refresh(_loop,_data): outputTxt = [ 'COMP3 ' , (red_bg, 'DOWN ' ), "Bla\n" ] outputTxt + = [ 'COMP4 ' , (green_bg, 'UP ' ), "Bla bla\n" ] txt = urwid.Text(outputTxt) fill = urwid.Filler(txt, 'top' ) loop = urwid.MainLoop(fill, unhandled_input = unhandled_input) loop.set_alarm_in( 1 ,refresh) loop.run() red_bg = urwid.AttrSpec( 'default' , 'dark red' ) green_bg = urwid.AttrSpec( 'default' , 'dark green' ) outputTxt = [ 'COMP1 ' , (red_bg, 'DOWN ' ), "Bla\n" ] outputTxt + = [ 'COMP2 ' , (green_bg, 'UP ' ), "Bla bla\n" ] txt = urwid.Text(outputTxt) fill = urwid.Filler(txt, 'top' ) loop = urwid.MainLoop(fill, unhandled_input = unhandled_input) loop.set_alarm_in( 1 ,refresh) loop.run() |