Anders and Briegel in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

30 lignes
860B

  1. """
  2. Allows us to visualize the state in a browser
  3. """
  4. import atexit, json, time
  5. from graphstate import GraphState
  6. from websocket import create_connection
  7. class VisibleGraphState(GraphState):
  8. """ Overloads the graph state with methods for sending to the browser over a websocket """
  9. def __init__(self, *args, **kwargs):
  10. """ Constructor """
  11. GraphState.__init__(self, *args, **kwargs)
  12. self.ws = create_connection("ws://localhost:5000")
  13. atexit.register(self.shutdown)
  14. def shutdown(self):
  15. """ The client should shut down automatically on close """
  16. self.update()
  17. self.ws.close()
  18. def update(self, delay = 0.5):
  19. """ Call this function when you are ready to send data to the browser """
  20. data = json.dumps(self.to_json())
  21. self.ws.send(data)
  22. time.sleep(delay)