瀏覽代碼

Add stuff

master
Pete Shadbolt 8 年之前
父節點
當前提交
7785d264c9
共有 7 個檔案被更改,包括 36 行新增61 行删除
  1. +0
    -1
      abp/__init__.py
  2. +0
    -48
      abp/client.py
  3. +2
    -2
      abp/server.py
  4. +3
    -6
      abp/viz.py
  5. +11
    -3
      client/api.js
  6. +4
    -0
      client/index.html
  7. +16
    -1
      client/main.css

+ 0
- 1
abp/__init__.py 查看文件

@@ -1,4 +1,3 @@
# Alias some stuff to make imports cleaner
from abp.graphstate import GraphState
from abp.qi import CircuitModel
from abp.visiblegraphstate import VisibleGraphState

+ 0
- 48
abp/client.py 查看文件

@@ -1,48 +0,0 @@
import requests
import abp, json

class ClientError(Exception):
def __init__(self, message):
self.message = message

class Client(object):
def __init__(self, host="localhost", port=5000, clear=False):
self.session = requests.Session()
self.root = "http://{}:{}".format(host, port)
if clear:
self.clear()

def get(self, endpoint):
url =self.root+endpoint
response = self.session.get(url)
if response.status_code == 404:
message = "404. Check that the server is running!".format(self.root, endpoint)
raise ClientError(message)
return response.content

def get_state(self):
response = self.get("/state")
output = abp.GraphState()
output.from_json(json.loads(response))
return output

def set_state(self, state):
response = self.session.post(self.root+"/state", data=state.to_json())
if not response.status_code == 200:
print response.status_code
return response.content

def add_node(self, node):
return self.get("/add_node/{}".format(node))

def act_local_rotation(self, node, operation):
return self.get("/act_local_rotation/{}/{}".format(node, operation))

def act_cz(self, a, b):
return self.get("/act_cz/{}/{}".format(a, b))

def clear(self):
return self.get("/clear")

def kill(self):
self.session.close()

+ 2
- 2
abp/server.py 查看文件

@@ -1,7 +1,7 @@
import json
from websocket_server import WebsocketServer
import threading
import abp
import json

clients = []



abp/visiblegraphstate.py → abp/viz.py 查看文件

@@ -2,13 +2,9 @@
Allows us to visualize the state in a browser
"""

import atexit
import threading
import time
from websocket import create_connection
import atexit, json
from graphstate import GraphState
import json

from websocket import create_connection

class VisibleGraphState(GraphState):

@@ -35,3 +31,4 @@ class VisibleGraphState(GraphState):
""" Call this function when you are ready to send data to the browser """
data = json.dumps(self.to_json())
self.ws.send(data)


+ 11
- 3
client/api.js 查看文件

@@ -1,10 +1,17 @@
var ws;

function connect_to_server() {
ws = new WebSocket("ws://localhost:5001");
ws = new WebSocket("ws://localhost:5000");
ws.onopen = function()
{
console.log("Connected to server.");
message.innerHTML = "Connected to server.";
message.className = "visible";
};

ws.onerror = function(err)
{
message.innerHTML = "Could not connect to server.";
message.className = "visible";
};
ws.onmessage = function (evt)
@@ -18,7 +25,8 @@ function connect_to_server() {
ws.onclose = function()
{
console.log("Connection was closed.");
message.innerHTML = "Connection to server lost. <a href='#' onclick='javascript:connect_to_server()'>Reconnect</a>.";
message.className = "visible";
};
}



+ 4
- 0
client/index.html 查看文件

@@ -35,5 +35,9 @@
</ul>
</div>

<div id=message class=hidden>
hello
</div>

</body>
</html>

+ 16
- 1
client/main.css 查看文件

@@ -16,7 +16,6 @@ html, body { margin: 0; padding: 0; overflow: hidden; font-size: 10pt; font-fam

#pallette {
background-color: black;
/*border-radius:3px;*/
color:white;
padding: 10px;
font-family:"courier new";
@@ -26,6 +25,18 @@ html, body { margin: 0; padding: 0; overflow: hidden; font-size: 10pt; font-fam
font-size: 9pt;
}

#message {
background-color: black;
color:white;
padding: 10px;
font-family:"courier new";
position: absolute;
bottom: 10px;
right: 10px;
font-size: 9pt;
}


ul {
list-style-type: none;
padding: 0px;
@@ -45,3 +56,7 @@ ul {
transform: scale(.5);
transition: visibility .08s, opacity .08s linear, transform .08s linear;
}

a {
color: yellow;
}

Loading…
取消
儲存