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.

34 lignes
813B

  1. """
  2. Allows us to visualize the state in a browser
  3. """
  4. import atexit
  5. import threading
  6. import time
  7. from websocket import create_connection
  8. from graphstate import GraphState
  9. import json
  10. class VisibleGraphState(GraphState):
  11. def __init__(self, *args, **kwargs):
  12. GraphState.__init__(self, *args, **kwargs)
  13. self.ws = create_connection("ws://localhost:5001")
  14. atexit.register(self.shutdown)
  15. #self.ws.send(json.dumps({"method":"clear"}))
  16. def shutdown(self):
  17. self.update()
  18. self.ws.close()
  19. def to_json(self):
  20. ngbh = {a: {b : True for b in self.ngbh[a]}
  21. for a in self.ngbh}
  22. return {"vops": self.vops, "ngbh": ngbh, "meta": self.meta}
  23. def update(self):
  24. data = json.dumps(self.to_json())
  25. self.ws.send(data)