|
@@ -18,32 +18,28 @@ from pkg_resources import resource_filename |
|
|
clients = [] |
|
|
clients = [] |
|
|
local_state = abp.GraphState() |
|
|
local_state = abp.GraphState() |
|
|
|
|
|
|
|
|
def process_edit(edit, server): |
|
|
|
|
|
|
|
|
def process_edit(edit, client, server): |
|
|
action = edit["action"] |
|
|
action = edit["action"] |
|
|
|
|
|
|
|
|
print edit |
|
|
print edit |
|
|
|
|
|
|
|
|
print local_state.node.keys() |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
if action == "create": |
|
|
|
|
|
print type(edit["name"]) |
|
|
|
|
|
local_state.add_qubit(edit["name"], position=edit["position"], vop=0) |
|
|
|
|
|
if action == "cz": |
|
|
|
|
|
local_state.act_cz(edit["start"], edit["end"]) |
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
print e |
|
|
|
|
|
|
|
|
|
|
|
server.send_message_to_all(json.dumps(local_state.to_json())) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if action == "create": |
|
|
|
|
|
local_state.add_qubit(edit["name"], position=edit["position"], vop=0) |
|
|
|
|
|
if action == "cz": |
|
|
|
|
|
local_state.act_cz(edit["start"], edit["end"]) |
|
|
|
|
|
if action == "hadamard": |
|
|
|
|
|
local_state.act_cz(edit["start"], edit["end"]) |
|
|
|
|
|
if action == "delete": |
|
|
|
|
|
local_state._del_node(edit["node"]) |
|
|
|
|
|
|
|
|
|
|
|
server.send_message(client, json.dumps(local_state.to_json())) |
|
|
|
|
|
|
|
|
def new_message(client, server, message): |
|
|
def new_message(client, server, message): |
|
|
if message.startswith("edit:"): |
|
|
if message.startswith("edit:"): |
|
|
print message[5:] |
|
|
print message[5:] |
|
|
edit = json.loads(message[5:]) |
|
|
edit = json.loads(message[5:]) |
|
|
print "Received update from javascript." |
|
|
print "Received update from javascript." |
|
|
process_edit(edit, server) |
|
|
|
|
|
|
|
|
process_edit(edit, client, server) |
|
|
else: |
|
|
else: |
|
|
print "Received update from python {}.".format(client["id"]) |
|
|
print "Received update from python {}.".format(client["id"]) |
|
|
print message |
|
|
print message |
|
@@ -54,6 +50,8 @@ def new_message(client, server, message): |
|
|
def new_client(client, server): |
|
|
def new_client(client, server): |
|
|
print "Client {} connected.".format(client["id"]) |
|
|
print "Client {} connected.".format(client["id"]) |
|
|
clients.append(client) |
|
|
clients.append(client) |
|
|
|
|
|
print "Sent state of {} nodes to client {}".format(local_state.order(), client["id"]) |
|
|
|
|
|
server.send_message(client, json.dumps(local_state.to_json())) |
|
|
|
|
|
|
|
|
def client_left(client, server): |
|
|
def client_left(client, server): |
|
|
print "Client {} disconnected.".format(client["id"]) |
|
|
print "Client {} disconnected.".format(client["id"]) |
|
|