run_client.py 958 B

1234567891011121314151617181920212223242526272829303132333435
  1. """
  2. Runner script for the TkInter chat window SCCD model.
  3. Author: Yentl Van Tendeloo
  4. """
  5. import Tkinter as tk
  6. import chatclient
  7. import socket2event
  8. from python_runtime.statecharts_core import Event
  9. from python_runtime.tkinter_eventloop import *
  10. from chatwindowGUI import ChatWindowGUI
  11. def keypress(key):
  12. global controller
  13. try:
  14. str(key.char)
  15. if len(key.char) == 1:
  16. controller.addInput(Event("input", "tkinter_input", [key.char]), 0.0)
  17. # Don't do anything for empty characters, as these are control characters (e.g. press shift)
  18. except UnicodeEncodeError:
  19. print("Unicode input is not supported for simplicity")
  20. root = ChatWindowGUI(keypress)
  21. if __name__ == "__main__":
  22. global controller
  23. controller = chatclient.Controller(root, TkEventLoop(root))
  24. socket2event.boot_translation_service(controller)
  25. controller.start()
  26. try:
  27. root.mainloop()
  28. except:
  29. controller.stop()