45 lines
937 B
Python
45 lines
937 B
Python
from graphviz import Digraph
|
|
from pythonosc.dispatcher import Dispatcher
|
|
from pythonosc.osc_server import BlockingOSCUDPServer
|
|
|
|
g = Digraph('G', filename='graph.gv', format='pdf')
|
|
|
|
# last vertex received
|
|
v = -1
|
|
# last edge target received
|
|
w = -1
|
|
# last edge type received
|
|
t = ""
|
|
|
|
def print_vertex(address, *args):
|
|
global v
|
|
v = args[args.index('vertex') + 1]
|
|
if v == -1:
|
|
return
|
|
g.node(str(v))
|
|
g.render("Test")
|
|
print(v)
|
|
|
|
def print_edge(address, *args):
|
|
global v
|
|
global w
|
|
global t
|
|
w = args[args.index('w') + 1]
|
|
t = args[args.index('edge_type') + 1]
|
|
print((v,w,t))
|
|
if v == -1 or w == -1:
|
|
return
|
|
g.edge(str(v), str(w))
|
|
g.render("Test")
|
|
|
|
dispatcher = Dispatcher()
|
|
dispatcher.map("/edge", print_edge)
|
|
dispatcher.map("/vertex", print_vertex)
|
|
|
|
ip = "127.0.0.1"
|
|
port = 5050
|
|
|
|
server = BlockingOSCUDPServer((ip, port), dispatcher)
|
|
server.serve_forever() # Blocks forever
|
|
|