run_chatwindow.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/env python2
  2. import Tkinter as tk
  3. import chatwindow
  4. from sccd.runtime.statecharts_core import Event
  5. from sccd.runtime.tkinter_eventloop import *
  6. import threading
  7. import sys
  8. from sccd_widget import SCCDWidget
  9. class Root(tk.Tk, SCCDWidget):
  10. def __init__(self):
  11. tk.Tk.__init__(self)
  12. SCCDWidget.__init__(self)
  13. root = Root()
  14. root.withdraw()
  15. controller = chatwindow.Controller(TkEventLoop(root))
  16. SCCDWidget.controller = controller
  17. def stdin_poller(controller):
  18. while 1:
  19. controller.addInput(Event("stdin_input", "stdin_port", [raw_input()]))
  20. def stdout_printer(controller):
  21. port = controller.addOutputListener("stdout_port")
  22. while 1:
  23. sys.stdout.write(port.fetch(-1).parameters[0] + "\n")
  24. sys.stdout.flush()
  25. input_thread = threading.Thread(target=stdin_poller, args=[controller])
  26. input_thread.daemon = True
  27. input_thread.start()
  28. output_thread = threading.Thread(target=stdout_printer, args=[controller])
  29. output_thread.daemon = True
  30. output_thread.start()
  31. controller.start()
  32. root.mainloop()