test.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. def other():
  9. text_print("Welcome from other!!!")
  10. event = yield from get_response("input_group", spec={
  11. "label": 'other',
  12. "inputs": [{
  13. 'name': 'other',
  14. 'type': 'text',
  15. 'autofocus': True,
  16. 'label': 'other',
  17. 'help_text': 'other help_text',
  18. }]
  19. })
  20. idx = 0
  21. while 1:
  22. yield sleep(0.5)
  23. text_print(str(idx))
  24. # 业务逻辑 协程
  25. def say_hello():
  26. # yield sleep(0.5)
  27. # 向用户输出文字
  28. text_print("Welcome!!!")
  29. # run_async(other())
  30. # name = yield from text_input_coro('input your name')
  31. event = yield from get_response("input_group", spec={
  32. "label": 'another',
  33. "inputs": [{
  34. 'name': 'name',
  35. 'type': 'text',
  36. 'autofocus': True,
  37. 'label': 'another text',
  38. 'help_text': 'another text help_text',
  39. }]
  40. })
  41. event = yield from get_response("input_group", spec={
  42. "label": 'label',
  43. "inputs": [{
  44. 'name': 'name',
  45. 'type': 'text',
  46. 'autofocus': True,
  47. 'label': 'text',
  48. 'help_text': 'text help_text',
  49. },
  50. {
  51. 'name': 'checkbox',
  52. 'type': 'checkbox',
  53. 'inline': True,
  54. 'label': '性别',
  55. 'help_text': 'help_text',
  56. 'options': [
  57. {'value': 'man', 'label': '男', 'checked': True},
  58. {'value': 'woman', 'label': '女', 'checked': False}
  59. ]
  60. }
  61. ]
  62. })
  63. json_print(event)
  64. while event['event'] != 'from_submit':
  65. json_print(event)
  66. if event['event'] == 'input_event':
  67. send_msg("update_input", spec={
  68. 'target_name': event['data']['name'],
  69. 'attributes': {
  70. 'valid_status': True,
  71. 'valid_feedback': 'ok'
  72. }
  73. })
  74. event = yield
  75. yield sleep(0.5)
  76. text_print("收到")
  77. yield from get_response("destroy_form", spec={})
  78. text_print("Bye ")
  79. yield sleep(1)
  80. start_ioloop(say_hello)