run_client.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. from sccd.cd.parser.xml import *
  2. from sccd.controller.controller import *
  3. import threading
  4. import queue
  5. from sccd.realtime.eventloop import *
  6. from sccd.realtime.tkinter import *
  7. def main():
  8. cd = load_cd("model_chatclient.xml")
  9. def on_output(event: OutputEvent):
  10. if event.port == "network":
  11. network.add_input(event.name, event.params)
  12. from lib import ui, network_client
  13. controller = Controller(cd, output_callback=on_output)
  14. eventloop = ThreadSafeEventLoop(controller, TkInterImplementation(ui.window))
  15. ui.init(eventloop)
  16. network = network_client.NetworkClient(eventloop)
  17. # This starts the network client in a new thread.
  18. network.start()
  19. # This only sets the 'start time' to the current wall-clock time, initializes the statechart and lets it run for a bit (in this thread) if there are already due events (events with timestamp zero). Then returns.
  20. eventloop.start()
  21. # This takes control of the current thread and runs tk's event loop in it.
  22. ui.window.mainloop()
  23. if __name__ == '__main__':
  24. main()