test.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 textarea('Text area', codemirror={
  18. 'mode': "python",
  19. 'lineNumbers': True, # 显示行数
  20. 'indentUnit': 4, # 缩进单位为4
  21. 'styleActiveLine': True, # 当前行背景高亮
  22. 'matchBrackets': True, # 括号匹配
  23. 'lineWrapping': True, # 自动换行
  24. 'theme': 'darcula', # 使用monokai模版 ,darcula:IDEA,
  25. })
  26. text_print(res)
  27. res = await actions('Action button', [
  28. {'value': '1', 'label': 'One', 'disabled': False},
  29. {'value': '2', 'label': 'Two', 'disabled': False},
  30. {'value': '3', 'label': 'Three', 'disabled': True},
  31. ])
  32. text_print('Your input:%s' % res)
  33. res = await select('This is select input', [
  34. {'value': 1, 'label': 'one', 'selected': False, 'disabled': False},
  35. {'value': 2, 'label': 'two', 'selected': True, 'disabled': False},
  36. {'value': 2, 'label': 'three disabled', 'selected': False, 'disabled': True},
  37. ], type=SELECT, multiple=False)
  38. text_print('Your input:%s' % res)
  39. res = await select('This is multiple select input', [
  40. {'value': 1, 'label': 'one', 'selected': True, 'disabled': False},
  41. {'value': 2, 'label': 'two', 'selected': True, 'disabled': False},
  42. {'value': 2, 'label': 'three disabled', 'selected': False, 'disabled': True},
  43. ], type=SELECT, multiple=True)
  44. text_print('Your input:%s' % res)
  45. res = await select('This is RADIO input', [
  46. {'value': 1, 'label': 'one', 'selected': False, 'disabled': False},
  47. {'value': 2, 'label': 'two', 'selected': True, 'disabled': False},
  48. {'value': 2, 'label': 'three disabled', 'selected': False, 'disabled': True},
  49. ], type=RADIO)
  50. text_print('Your input:%s' % res)
  51. res = await select('This is CHECKBOX input', [
  52. {'value': 1, 'label': 'one', 'selected': False, 'disabled': False},
  53. {'value': 2, 'label': 'two', 'selected': True, 'disabled': False},
  54. {'value': 2, 'label': 'three disabled', 'selected': False, 'disabled': True},
  55. ], type=CHECKBOX)
  56. text_print('Your input:%s' % res)
  57. res = await input('This is single input')
  58. text_print('Your input:%s' % res)
  59. res = await input('This is another single input')
  60. text_print('Your input:%s' % res)
  61. res = await input_group('Group input', [
  62. input('Input 1', name='one'),
  63. input('Input 2', name='two'),
  64. select('Input 2', options=['A', 'B', 'C'], type=CHECKBOX, name='three')
  65. ])
  66. text_print('Your input:')
  67. json_print(res)
  68. start_ioloop(say_hello)