New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
need help: insert item into listbox in thread #587
Comments
What version of Urwid are you running? This sounds a lot like the problem I'm experiencing with #575 , running against the latest master. |
No, threading works correctly. Asyncio based code has issues |
Correct way: class OrderListBox(urwid.ListBox):
def __init__(self, max_item_size=20):
super().__init__(urwid.SimpleListWalker([
urwid.AttrMap(urwid.Text(
'{} order content...'.format(0)), None, 'I say')
]))
self.max_item_size = max_item_size
self.idx: int = 1
def insert(self):
text = urwid.Text('{} order content...'.format(self.idx))
wrap = urwid.AttrMap(text, None, 'I say')
self.body.insert(0, wrap)
self.idx = self.idx + 1
if len(self.body) > self.max_item_size:
self.body = self.body[:self.max_item_size]
self._invalidate()
# this is the bottom-most widget, which was modified. All top-level widgets will be handled automatically
def keypress(self, size, key):
key = super().keypress(size, key) |
Also you can connect callback to the |
thanks for your reply, it help me a lot. |
As @penguinolog has left the correct approach, i will close this issue. |
Description:
I have a thread purpose to read some data, then insert the item with the data into a listbox,
but the listbox doesn't refresh automatically,
unless i press some key on the listbox. following is my code:
mainloop.draw_screen()
looks could force the whole screen to refresh,but i don't known if it is the correct way, maybe there are some better approach to do this?
The text was updated successfully, but these errors were encountered: