test.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from tornado import gen
  2. from tornado.ioloop import IOLoop
  3. from tornado import websocket
  4. import json
  5. from wsrepl.ioloop import start_ioloop
  6. from wsrepl.interact import *
  7. from tornado.gen import sleep
  8. # 业务逻辑 协程
  9. async def say_hello():
  10. """
  11. 有返回值的交互函数需要yield from
  12. :return:
  13. """
  14. set_title("This is title")
  15. # 向用户输出文字
  16. text_print("Welcome!!!")
  17. res = await actions('Action button', [
  18. {'value': '1', 'label': 'One', 'disabled': False},
  19. {'value': '2', 'label': 'Two', 'disabled': False},
  20. {'value': '3', 'label': 'Three', 'disabled': True},
  21. ])
  22. text_print('Your input:%s' % res)
  23. res = await select('This is select input', [
  24. {'value': 1, 'label': 'one', 'selected': False, 'disabled': False},
  25. {'value': 2, 'label': 'two', 'selected': True, 'disabled': False},
  26. {'value': 2, 'label': 'three disabled', 'selected': False, 'disabled': True},
  27. ], type=SELECT, multiple=False)
  28. text_print('Your input:%s' % res)
  29. res = await select('This is multiple select input', [
  30. {'value': 1, 'label': 'one', 'selected': True, 'disabled': False},
  31. {'value': 2, 'label': 'two', 'selected': True, 'disabled': False},
  32. {'value': 2, 'label': 'three disabled', 'selected': False, 'disabled': True},
  33. ], type=SELECT, multiple=True)
  34. text_print('Your input:%s' % res)
  35. res = await select('This is RADIO input', [
  36. {'value': 1, 'label': 'one', 'selected': False, 'disabled': False},
  37. {'value': 2, 'label': 'two', 'selected': True, 'disabled': False},
  38. {'value': 2, 'label': 'three disabled', 'selected': False, 'disabled': True},
  39. ], type=RADIO)
  40. text_print('Your input:%s' % res)
  41. res = await select('This is CHECKBOX input', [
  42. {'value': 1, 'label': 'one', 'selected': False, 'disabled': False},
  43. {'value': 2, 'label': 'two', 'selected': True, 'disabled': False},
  44. {'value': 2, 'label': 'three disabled', 'selected': False, 'disabled': True},
  45. ], type=CHECKBOX)
  46. text_print('Your input:%s' % res)
  47. res = await input('This is single input')
  48. text_print('Your input:%s' % res)
  49. res = await input('This is another single input')
  50. text_print('Your input:%s' % res)
  51. res = await input_group('Group input', [
  52. input('Input 1', name='one'),
  53. input('Input 2', name='two'),
  54. select('Input 2', options=['A', 'B', 'C'], type=CHECKBOX, name='three')
  55. ])
  56. text_print('Your input:')
  57. json_print(res)
  58. start_ioloop(say_hello)