feat(rcf): relatively agnostic property transfert is working !
This commit is contained in:
parent
2cd1f604ec
commit
886befeb14
@ -15,17 +15,17 @@ class RCFMessage(object):
|
|||||||
"""
|
"""
|
||||||
Message is formatted on wire as 2 frames:
|
Message is formatted on wire as 2 frames:
|
||||||
frame 0: key (0MQ string) // property path
|
frame 0: key (0MQ string) // property path
|
||||||
frame 1: type (0MQ string) // property path
|
frame 1: mtype (0MQ string) // property path
|
||||||
frame 2: body (blob) // Could be any data
|
frame 2: body (blob) // Could be any data
|
||||||
|
|
||||||
"""
|
"""
|
||||||
key = None # key (string)
|
key = None # key (string)
|
||||||
type = None # data type (string)
|
mtype = None # data mtype (string)
|
||||||
body = None # data blob
|
body = None # data blob
|
||||||
|
|
||||||
def __init__(self, key=None, type=None, body=None):
|
def __init__(self, key=None, mtype=None, body=None):
|
||||||
self.key = key
|
self.key = key
|
||||||
self.type = type
|
self.mtype = mtype
|
||||||
self.body = body
|
self.body = body
|
||||||
|
|
||||||
def store(self, dikt):
|
def store(self, dikt):
|
||||||
@ -38,19 +38,19 @@ class RCFMessage(object):
|
|||||||
def send(self, socket):
|
def send(self, socket):
|
||||||
"""Send key-value message to socket; any empty frames are sent as such."""
|
"""Send key-value message to socket; any empty frames are sent as such."""
|
||||||
key = '' if self.key is None else self.key.encode()
|
key = '' if self.key is None else self.key.encode()
|
||||||
type = '' if self.type is None else self.type.encode()
|
mtype = '' if self.mtype is None else self.mtype.encode()
|
||||||
body = '' if self.body is None else umsgpack.packb(self.body)
|
body = '' if self.body is None else umsgpack.packb(self.body)
|
||||||
socket.send_multipart([key, body])
|
socket.send_multipart([key,mtype, body])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def recv(cls, socket):
|
def recv(cls, socket):
|
||||||
"""Reads key-value message from socket, returns new kvmsg instance."""
|
"""Reads key-value message from socket, returns new kvmsg instance."""
|
||||||
key,type, body = socket.recv_multipart(zmq.NOBLOCK)
|
key,mtype, body = socket.recv_multipart(zmq.NOBLOCK)
|
||||||
key = key.decode() if key else None
|
key = key.decode() if key else None
|
||||||
body = body.decode() if body else None
|
mtype = mtype.decode() if body else None
|
||||||
body = umsgpack.unpackb(body) if body else None
|
body = umsgpack.unpackb(body) if body else None
|
||||||
|
|
||||||
return cls(key=key, body=body)
|
return cls(key=key,mtype=mtype, body=body)
|
||||||
|
|
||||||
def dump(self):
|
def dump(self):
|
||||||
if self.body is None:
|
if self.body is None:
|
||||||
@ -59,10 +59,10 @@ class RCFMessage(object):
|
|||||||
else:
|
else:
|
||||||
size = len(self.body)
|
size = len(self.body)
|
||||||
data = repr(self.body)
|
data = repr(self.body)
|
||||||
print("[key:{key}][size:{size}][type:{type}] {data}".format(
|
print("[key:{key}][size:{size}][mtype:{mtype}] {data}".format(
|
||||||
key=self.key,
|
key=self.key,
|
||||||
size=size,
|
size=size,
|
||||||
type=self.type,
|
mtype=self.mtype,
|
||||||
data=data,
|
data=data,
|
||||||
))
|
))
|
||||||
|
|
||||||
@ -128,8 +128,8 @@ class Client():
|
|||||||
for f in self.recv_callback:
|
for f in self.recv_callback:
|
||||||
f(rcfmsg)
|
f(rcfmsg)
|
||||||
|
|
||||||
def push_update(self, key,type,body):
|
def push_update(self, key,mtype,body):
|
||||||
rcfmsg = RCFMessage(key,body)
|
rcfmsg = RCFMessage(key,mtype,body)
|
||||||
rcfmsg.send(self.push_sock)
|
rcfmsg.send(self.push_sock)
|
||||||
# self.push_sock.send_multipart()
|
# self.push_sock.send_multipart()
|
||||||
|
|
||||||
|
@ -36,13 +36,13 @@ def from_bpy(value):
|
|||||||
elif value_type is NATIVE_TYPES:
|
elif value_type is NATIVE_TYPES:
|
||||||
value_casted = value
|
value_casted = value
|
||||||
|
|
||||||
return value_casted.__class__.__name__,value_casted
|
return str(value.__class__.__name__),value_casted
|
||||||
|
|
||||||
def to_bpy(store_item):
|
def to_bpy(store_item):
|
||||||
"""
|
"""
|
||||||
Get bpy value from store
|
Get bpy value from store
|
||||||
"""
|
"""
|
||||||
value_type = store_item.type
|
value_type = store_item.mtype
|
||||||
value_casted = None
|
value_casted = None
|
||||||
store_value = store_item.body
|
store_value = store_item.body
|
||||||
|
|
||||||
@ -58,8 +58,9 @@ def resolve_bpy_path(path):
|
|||||||
path = path.split('/')
|
path = path.split('/')
|
||||||
|
|
||||||
obj = None
|
obj = None
|
||||||
attribute = None
|
attribute = path[2]
|
||||||
logger.info("resolving {}".format(path))
|
logger.info("resolving {}".format(path))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj = getattr(bpy.data,path[0])[path[1]]
|
obj = getattr(bpy.data,path[0])[path[1]]
|
||||||
attribute = getattr(obj,path[2])
|
attribute = getattr(obj,path[2])
|
||||||
@ -69,8 +70,6 @@ def resolve_bpy_path(path):
|
|||||||
|
|
||||||
return obj, attribute
|
return obj, attribute
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# CLIENT-SERVER
|
# CLIENT-SERVER
|
||||||
def refresh_window(msg):
|
def refresh_window(msg):
|
||||||
import bpy
|
import bpy
|
||||||
@ -78,15 +77,16 @@ def refresh_window(msg):
|
|||||||
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
||||||
|
|
||||||
def patch_scene(msg):
|
def patch_scene(msg):
|
||||||
|
|
||||||
value = None
|
value = None
|
||||||
|
|
||||||
obj, attr = resolve_bpy_path(msg.key)
|
obj, attr = resolve_bpy_path(msg.key)
|
||||||
value = to_bpy(attr)
|
attr_name = msg.key.split('/')[2]
|
||||||
print("attribute: {} , value: {}".format(attr, value))
|
|
||||||
|
value = to_bpy(msg)
|
||||||
|
print("Updating scene:\n object: {} attribute: {} , value: {}".format(obj, attr_name, value))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
setattr(obj,attr,value)
|
setattr(obj,attr_name,value)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -33,9 +33,9 @@ class SessionPanel(bpy.types.Panel):
|
|||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
area_msg = row.box()
|
area_msg = row.box()
|
||||||
if len(net_operators.client.property_map) > 0:
|
if len(net_operators.client.property_map) > 0:
|
||||||
for key,value in net_operators.client.property_map.items():
|
for key,values in net_operators.client.property_map.items():
|
||||||
area_msg.label(text="{}".format(key))
|
area_msg.label(text="{} ({})".format(key, values.mtype))
|
||||||
else:
|
else:
|
||||||
area_msg.label(text="Empty")
|
area_msg.label(text="Empty")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user