Parcourir la source

Closed the loop - JS -> Python -> JS

master
Pete Shadbolt il y a 8 ans
Parent
révision
899b202810
2 fichiers modifiés avec 10 ajouts et 3 suppressions
  1. +2
    -2
      abp/static/scripts/editor.js
  2. +8
    -1
      bin/abpserver

+ 2
- 2
abp/static/scripts/editor.js Voir le fichier

@@ -47,8 +47,8 @@ editor.addQubitAtPoint = function(point) {
return;
}
point.round();
websocket.edit({test:"test"});
var new_node = Math.floor(point.x*1000000 + point.y*1000 + point.z);
websocket.edit({action:"create", name:new_node, position: point});
gui.serverMessage("Created node " + new_node +".");
};



+ 8
- 1
bin/abpserver Voir le fichier

@@ -18,12 +18,19 @@ from pkg_resources import resource_filename
clients = []
local_state = abp.GraphState()

def process_edit(edit, server):
action = edit["action"]
if action == "create":
local_state.add_qubit(edit["name"], position=edit["position"])
server.send_message_to_all(json.dumps(local_state.to_json()))


def new_message(client, server, message):
if message.startswith("edit:"):
print message[5:]
edit = json.loads(message[5:])
print "Received update from javascript."
print edit
process_edit(edit, server)
else:
print "Received update from python {}.".format(client["id"])
print message


Chargement…
Annuler
Enregistrer