use threading
parent
690e81cea3
commit
dcd1633bd9
41
osc/main.py
41
osc/main.py
|
|
@ -1,43 +1,46 @@
|
||||||
from graphviz import Digraph
|
from graphviz import Digraph
|
||||||
from pythonosc.dispatcher import Dispatcher
|
from pythonosc.dispatcher import Dispatcher
|
||||||
from pythonosc.osc_server import BlockingOSCUDPServer
|
from pythonosc.osc_server import BlockingOSCUDPServer
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
edge_attrs = {
|
edge_attrs = {
|
||||||
'arrowhead': 'vee',
|
'arrowhead': 'vee',
|
||||||
}
|
}
|
||||||
|
|
||||||
g = Digraph('G', filename='graph.gv', format='pdf', engine='circo', strict=True, edge_attr = edge_attrs)
|
g = Digraph('G', filename='graph.gv', format='png', engine='circo', strict=True, edge_attr = edge_attrs)
|
||||||
|
|
||||||
# last vertex received
|
g_lock = threading.Lock()
|
||||||
v = -1
|
|
||||||
# last edge target received
|
|
||||||
w = -1
|
|
||||||
# last edge type received
|
|
||||||
t = ""
|
|
||||||
|
|
||||||
def print_vertex(address, *args):
|
def print_vertex(address, *args):
|
||||||
global v
|
|
||||||
global g
|
global g
|
||||||
v = args[args.index('vertex') + 1]
|
v = args[args.index('vertex') + 1]
|
||||||
if v == -1:
|
if v == -1:
|
||||||
g = Digraph('G', filename='graph.gv', format='pdf', engine='circo', strict=True, edge_attr = edge_attrs)
|
with g_lock:
|
||||||
|
g = Digraph('G', filename='graph.gv', format='pdf', engine='circo', strict=True, edge_attr = edge_attrs)
|
||||||
return
|
return
|
||||||
g.node(str(v))
|
with g_lock:
|
||||||
g.render("Test")
|
g.node(str(v))
|
||||||
print(args)
|
print(args)
|
||||||
|
|
||||||
def print_edge(address, *args):
|
def print_edge(address, *args):
|
||||||
global v
|
v = args[args.index('v') + 1]
|
||||||
global w
|
|
||||||
global t
|
|
||||||
w = args[args.index('w') + 1]
|
w = args[args.index('w') + 1]
|
||||||
t = args[args.index('edge_type') + 1]
|
t = args[args.index('edge_type') + 1]
|
||||||
print(args)
|
if v == -1:
|
||||||
# print((v,w,t))
|
|
||||||
if v == -1 or w == -1:
|
|
||||||
return
|
return
|
||||||
g.edge(str(v), str(w))
|
with g_lock:
|
||||||
g.render("Test")
|
g.edge(str(v), str(w))
|
||||||
|
print(args)
|
||||||
|
|
||||||
|
def update_loop():
|
||||||
|
while True:
|
||||||
|
g.render("Test")
|
||||||
|
time.sleep(0.4)
|
||||||
|
|
||||||
|
ul_thread = threading.Thread(target=update_loop)
|
||||||
|
|
||||||
|
ul_thread.start()
|
||||||
|
|
||||||
dispatcher = Dispatcher()
|
dispatcher = Dispatcher()
|
||||||
dispatcher.map("/edge", print_edge)
|
dispatcher.map("/edge", print_edge)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue