这很奇怪,但是当我运行程序时,它只更新了 20 次屏幕中的 1 次......而且如果我按任意键 - 它也不会更新。如果像python code.py 2>log
. 而且mylog.log
我用于内部日志记录 - 它说refresh()
工作正确......
import urwid
from random import randint
import thread,logging
from time import sleep
logging.basicConfig(format = u'%(levelname)-8s [%(asctime)s] %(message)s', level = logging.CRITICAL, filename = u'mylog.log')
class ArRow (urwid.WidgetWrap):
def __init__ (self):
self.build_row()
w = urwid.Columns(self.item)
self.__super.__init__(w)
def build_row(self):
w=5
self.item = [
('fixed',w,urwid.AttrWrap(urwid.Text(str(randint(1,100))), 'body', 'focus')),
('fixed',w,urwid.AttrWrap(urwid.Text(str(randint(1,100))), 'body', 'focus')),
('fixed',w,urwid.AttrWrap(urwid.Text(str(randint(1,100))), 'body', 'focus')),
]
def refresh(self):
self.build_row()
w = urwid.Columns(self.item)
self.__super.__init__(w)
logging.critical(str(self.item))
def selectable (self):
return True
def keypress(self, size, key):
return key
palette = [
('body','dark cyan', '', 'standout','#0f6',''),
('focus','dark red', '', 'standout','light red',''),
]
def keystroke (input):
if input in ('q', 'Q'):
raise urwid.ExitMainLoop()
items=[ArRow()]#,ArRow(),ArRow(),ArRow(),ArRow()]
listbox = urwid.ListBox(urwid.SimpleListWalker(items))
view = urwid.Frame(urwid.AttrWrap(listbox, 'body'))
loop = urwid.MainLoop(view, palette, unhandled_input=keystroke)
loop.screen.set_terminal_properties(colors=256)
def live_report(*a):
while True:
items[0].refresh()
loop.draw_screen()
sleep(2)
thread.start_new(live_report,(0,))
loop.run()