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?
#!/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()
