view.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # This file is part of DarkFi (https://dark.fi)
  2. #
  3. # Copyright (C) 2020-2023 Dyne.org foundation
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. import urwid, asyncio
  18. class Demo:
  19. palette = [('body','light gray','black', 'standout')]
  20. def __init__(self, data=None):
  21. self.listbox_content = []
  22. self.listwalker = urwid.SimpleListWalker(self.listbox_content)
  23. self.list = urwid.ListBox(self.listwalker)
  24. self.ui = urwid.Frame(urwid.AttrWrap( self.list, 'body' ))
  25. self.ev = asyncio.new_event_loop()
  26. asyncio.set_event_loop(self.ev)
  27. def main(self):
  28. self.loop = urwid.MainLoop(self.ui, self.palette,
  29. event_loop=urwid.AsyncioEventLoop(loop=self.ev),
  30. unhandled_input=self.unhandled_input)
  31. self.ev.create_task(self.say_hello())
  32. self.loop.run()
  33. def unhandled_input(self, k):
  34. if k in ('q','Q'):
  35. raise urwid.ExitMainLoop()
  36. async def say_hello(self):
  37. while True:
  38. await asyncio.sleep(0.1)
  39. self.listwalker.contents.append(urwid.Text("hello"))
  40. if __name__ == '__main__':
  41. demo = Demo()
  42. demo.main()