feat (ui): right managment
This commit is contained in:
parent
494c732a39
commit
536a6e21b0
23
client.py
23
client.py
@ -71,18 +71,22 @@ class RCFClient(object):
|
|||||||
target=rcf_client_agent, args=(self.ctx, peer, self.queue), name="net-agent")
|
target=rcf_client_agent, args=(self.ctx, peer, self.queue), name="net-agent")
|
||||||
self.agent.daemon = True
|
self.agent.daemon = True
|
||||||
self.agent.start()
|
self.agent.start()
|
||||||
|
# self.sync_agent = threading.Thread(
|
||||||
|
# target=rcf_sync_agent, args=(self.ctx, self.pipe), name="sync-agent")
|
||||||
|
# self.sync_agent.daemon = True
|
||||||
|
# self.sync_agent.start()
|
||||||
|
|
||||||
def connect(self, id, address, port):
|
def connect(self, id, address, port):
|
||||||
self.pipe.send_multipart([b"CONNECT", (id.encode() if isinstance(
|
self.pipe.send_multipart([b"CONNECT", (id.encode() if isinstance(
|
||||||
id, str) else id), (address.encode() if isinstance(
|
id, str) else id), (address.encode() if isinstance(
|
||||||
address, str) else address), b'%d' % port])
|
address, str) else address), b'%d' % port])
|
||||||
|
|
||||||
def set(self, key, value=None):
|
def set(self, key, value=None, override=False):
|
||||||
"""Set new value in distributed hash table
|
"""Set new value in distributed hash table
|
||||||
Sends [SET][key][value] to the agent
|
Sends [SET][key][value] to the agent
|
||||||
"""
|
"""
|
||||||
self.pipe.send_multipart(
|
self.pipe.send_multipart(
|
||||||
[b"SET", umsgpack.packb(key), (umsgpack.packb(value) if value else umsgpack.packb('None'))])
|
[b"SET", umsgpack.packb(key), (umsgpack.packb(value) if value else umsgpack.packb('None')),umsgpack.packb(override)])
|
||||||
|
|
||||||
def add(self, key, value=None):
|
def add(self, key, value=None):
|
||||||
"""Set new value in distributed hash table
|
"""Set new value in distributed hash table
|
||||||
@ -200,6 +204,7 @@ class RCFClientAgent(object):
|
|||||||
elif command == b"SET":
|
elif command == b"SET":
|
||||||
key = umsgpack.unpackb(msg[0])
|
key = umsgpack.unpackb(msg[0])
|
||||||
value = umsgpack.unpackb(msg[1])
|
value = umsgpack.unpackb(msg[1])
|
||||||
|
override = umsgpack.unpackb(msg[2])
|
||||||
|
|
||||||
if key in self.property_map.keys():
|
if key in self.property_map.keys():
|
||||||
if self.property_map[key].id == self.id:
|
if self.property_map[key].id == self.id:
|
||||||
@ -207,8 +212,13 @@ class RCFClientAgent(object):
|
|||||||
value = helpers.dump(key)
|
value = helpers.dump(key)
|
||||||
value['id'] = self.id.decode()
|
value['id'] = self.id.decode()
|
||||||
if value:
|
if value:
|
||||||
|
key_id = self.id
|
||||||
|
|
||||||
|
if override:
|
||||||
|
key_id = value['id'].encode()
|
||||||
|
|
||||||
rcfmsg = message.RCFMessage(
|
rcfmsg = message.RCFMessage(
|
||||||
key=key, id=self.id, mtype="", body=value)
|
key=key, id=key_id, mtype="", body=value)
|
||||||
|
|
||||||
rcfmsg.store(self.property_map)
|
rcfmsg.store(self.property_map)
|
||||||
rcfmsg.send(self.publisher)
|
rcfmsg.send(self.publisher)
|
||||||
@ -217,6 +227,7 @@ class RCFClientAgent(object):
|
|||||||
else:
|
else:
|
||||||
helpers.load(key,self.property_map[key].body)
|
helpers.load(key,self.property_map[key].body)
|
||||||
|
|
||||||
|
|
||||||
elif command == b"ADD":
|
elif command == b"ADD":
|
||||||
key = umsgpack.unpackb(msg[0])
|
key = umsgpack.unpackb(msg[0])
|
||||||
value = umsgpack.unpackb(msg[1])
|
value = umsgpack.unpackb(msg[1])
|
||||||
@ -398,7 +409,7 @@ def serialization_agent(ctx, pipe):
|
|||||||
agent.control_message()
|
agent.control_message()
|
||||||
|
|
||||||
|
|
||||||
class SyncAgent(object):
|
class RCFSyncAgent(object):
|
||||||
ctx = None
|
ctx = None
|
||||||
pipe = None
|
pipe = None
|
||||||
|
|
||||||
@ -414,8 +425,8 @@ class SyncAgent(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def sync_agent(ctx, pipe):
|
def rcf_sync_agent(ctx, pipe):
|
||||||
agent = SyncAgent(ctx, pipe)
|
agent = RCFSyncAgent(ctx, pipe)
|
||||||
|
|
||||||
global stop
|
global stop
|
||||||
while True:
|
while True:
|
||||||
|
11
helpers.py
11
helpers.py
@ -23,9 +23,8 @@ def get_selected_objects(scene):
|
|||||||
|
|
||||||
return selected_objects
|
return selected_objects
|
||||||
|
|
||||||
|
|
||||||
# LOAD HELPERS
|
# LOAD HELPERS
|
||||||
|
|
||||||
|
|
||||||
def load(key, value):
|
def load(key, value):
|
||||||
target = resolve_bpy_path(key)
|
target = resolve_bpy_path(key)
|
||||||
target_type = key.split('/')[0]
|
target_type = key.split('/')[0]
|
||||||
@ -85,10 +84,14 @@ def load_client(client=None, data=None):
|
|||||||
client_data = data
|
client_data = data
|
||||||
# Load selected object
|
# Load selected object
|
||||||
for obj in C.scene.objects:
|
for obj in C.scene.objects:
|
||||||
if client_data['active_objects'] and obj.name in client_data['active_objects']:
|
if obj.id == client:
|
||||||
D.objects[obj.name].hide_select = True
|
D.objects[obj.name].hide_select = True
|
||||||
else:
|
else:
|
||||||
D.objects[obj.name].hide_select = False
|
D.objects[obj.name].hide_select = False
|
||||||
|
# if client_data['active_objects'] and obj.name in client_data['active_objects']:
|
||||||
|
# D.objects[obj.name].hide_select = True
|
||||||
|
# else:
|
||||||
|
# D.objects[obj.name].hide_select = False
|
||||||
|
|
||||||
|
|
||||||
def load_mesh(target=None, data=None, create=False):
|
def load_mesh(target=None, data=None, create=False):
|
||||||
|
101
operators.py
101
operators.py
@ -36,6 +36,18 @@ SUPPORTED_TYPES = ['Material',
|
|||||||
# UTILITY FUNCTIONS
|
# UTILITY FUNCTIONS
|
||||||
|
|
||||||
|
|
||||||
|
def client_list_callback(scene, context):
|
||||||
|
global client_keys
|
||||||
|
|
||||||
|
items = []
|
||||||
|
|
||||||
|
for k in client_keys:
|
||||||
|
if 'Client' in k[0]:
|
||||||
|
name = k[1].decode()
|
||||||
|
items.append((name, name, ""))
|
||||||
|
|
||||||
|
return items
|
||||||
|
|
||||||
def clean_scene(elements=SUPPORTED_DATABLOCKS):
|
def clean_scene(elements=SUPPORTED_DATABLOCKS):
|
||||||
for datablock in elements:
|
for datablock in elements:
|
||||||
datablock_ref = getattr(bpy.data, datablock)
|
datablock_ref = getattr(bpy.data, datablock)
|
||||||
@ -319,15 +331,18 @@ class session_create(bpy.types.Operator):
|
|||||||
global server
|
global server
|
||||||
global client_instance
|
global client_instance
|
||||||
|
|
||||||
|
net_settings = context.scene.session_settings
|
||||||
server = subprocess.Popen(
|
server = subprocess.Popen(
|
||||||
['python', 'server.py'], shell=False, stdout=subprocess.PIPE)
|
['python', 'server.py'], shell=False, stdout=subprocess.PIPE)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
bpy.ops.session.join()
|
bpy.ops.session.join()
|
||||||
|
|
||||||
if context.scene.session_settings.init_scene:
|
if net_settings.init_scene:
|
||||||
init_datablocks()
|
init_datablocks()
|
||||||
|
|
||||||
|
net_settings.is_admin = True
|
||||||
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
@ -358,7 +373,7 @@ class session_stop(bpy.types.Operator):
|
|||||||
del client_instance
|
del client_instance
|
||||||
client_instance = None
|
client_instance = None
|
||||||
client_keys = None
|
client_keys = None
|
||||||
net_settings.is_running = False
|
net_settings.is_admin = False
|
||||||
client_state = 1
|
client_state = 1
|
||||||
unregister_ticks()
|
unregister_ticks()
|
||||||
else:
|
else:
|
||||||
@ -367,6 +382,50 @@ class session_stop(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class session_rights(bpy.types.Operator):
|
||||||
|
bl_idname = "session.right"
|
||||||
|
bl_label = "close"
|
||||||
|
bl_description = "stop net service"
|
||||||
|
bl_options = {"REGISTER"}
|
||||||
|
|
||||||
|
key: bpy.props.StringProperty(default="None")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
wm = context.window_manager
|
||||||
|
return wm.invoke_props_dialog(self)
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
net_settings = context.scene.session_settings
|
||||||
|
|
||||||
|
col = layout.column()
|
||||||
|
col.prop(net_settings,"clients")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
global server
|
||||||
|
global client_instance, client_keys, client_state
|
||||||
|
|
||||||
|
net_settings = context.scene.session_settings
|
||||||
|
|
||||||
|
if net_settings.is_admin:
|
||||||
|
val = client_instance.get(self.key)
|
||||||
|
val[0][1]['id'] = net_settings.clients
|
||||||
|
|
||||||
|
client_instance.set(key=self.key, value=val[0][1],override=True)
|
||||||
|
|
||||||
|
print("Updating rights")
|
||||||
|
else:
|
||||||
|
print("Not admin")
|
||||||
|
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class session_settings(bpy.types.PropertyGroup):
|
class session_settings(bpy.types.PropertyGroup):
|
||||||
username = bpy.props.StringProperty(
|
username = bpy.props.StringProperty(
|
||||||
name="Username", default="user_{}".format(randomStringDigits()))
|
name="Username", default="user_{}".format(randomStringDigits()))
|
||||||
@ -378,7 +437,7 @@ class session_settings(bpy.types.PropertyGroup):
|
|||||||
add_property_depth = bpy.props.IntProperty(
|
add_property_depth = bpy.props.IntProperty(
|
||||||
name="add_property_depth", default=1)
|
name="add_property_depth", default=1)
|
||||||
buffer = bpy.props.StringProperty(name="None")
|
buffer = bpy.props.StringProperty(name="None")
|
||||||
is_running = bpy.props.BoolProperty(name="is_running", default=False)
|
is_admin = bpy.props.BoolProperty(name="is_admin", default=False)
|
||||||
load_data = bpy.props.BoolProperty(name="load_data", default=True)
|
load_data = bpy.props.BoolProperty(name="load_data", default=True)
|
||||||
init_scene = bpy.props.BoolProperty(name="load_data", default=True)
|
init_scene = bpy.props.BoolProperty(name="load_data", default=True)
|
||||||
clear_scene = bpy.props.BoolProperty(name="clear_scene", default=True)
|
clear_scene = bpy.props.BoolProperty(name="clear_scene", default=True)
|
||||||
@ -396,6 +455,11 @@ class session_settings(bpy.types.PropertyGroup):
|
|||||||
client_color = bpy.props.FloatVectorProperty(name="client_instance_color",
|
client_color = bpy.props.FloatVectorProperty(name="client_instance_color",
|
||||||
subtype='COLOR',
|
subtype='COLOR',
|
||||||
default=randomColor())
|
default=randomColor())
|
||||||
|
clients = bpy.props.EnumProperty(
|
||||||
|
name="clients",
|
||||||
|
description="client enum",
|
||||||
|
items=client_list_callback
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class session_snapview(bpy.types.Operator):
|
class session_snapview(bpy.types.Operator):
|
||||||
@ -438,6 +502,7 @@ classes = (
|
|||||||
session_settings,
|
session_settings,
|
||||||
session_remove_property,
|
session_remove_property,
|
||||||
session_snapview,
|
session_snapview,
|
||||||
|
session_rights,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -453,22 +518,20 @@ def ordered(updates):
|
|||||||
return uplist
|
return uplist
|
||||||
|
|
||||||
|
|
||||||
def is_dirty(updates):
|
def exist(update):
|
||||||
global client_keys
|
global client_keys
|
||||||
|
|
||||||
if client_keys:
|
key = "{}/{}".format(update.id.bl_rna.name, update.id.name)
|
||||||
if len(client_keys) > 0:
|
|
||||||
for u in updates:
|
|
||||||
key = "{}/{}".format(u.id.bl_rna.name, u.id.name)
|
|
||||||
|
|
||||||
if key not in client_keys:
|
if key in client_keys:
|
||||||
return True
|
return True
|
||||||
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def depsgraph_update(scene):
|
def depsgraph_update(scene):
|
||||||
global client_instance
|
global client_instance
|
||||||
|
global client_keys
|
||||||
|
|
||||||
if client_instance and client_instance.agent.is_alive():
|
if client_instance and client_instance.agent.is_alive():
|
||||||
updates = bpy.context.depsgraph.updates
|
updates = bpy.context.depsgraph.updates
|
||||||
@ -491,12 +554,22 @@ def depsgraph_update(scene):
|
|||||||
# else:
|
# else:
|
||||||
# print("{} applying update".format(username))
|
# print("{} applying update".format(username))
|
||||||
|
|
||||||
# if is_dirty(updates):
|
|
||||||
# for update in ordered(updates):
|
# for update in ordered(updates):
|
||||||
# if update[2] == "Master Collection":
|
# if update[2] == "Master Collection":
|
||||||
# pass
|
# pass
|
||||||
# elif update[1] in SUPPORTED_TYPES:
|
# elif update[1] in SUPPORTED_TYPES:
|
||||||
# client_instance.add("{}/{}".format(update[1], update[2]))
|
# key = "{}/{}".format(update[1], update[2])
|
||||||
|
|
||||||
|
# data = client_instance.get(key)
|
||||||
|
|
||||||
|
# if data:
|
||||||
|
# # Queue update
|
||||||
|
# client_instance.set(key)
|
||||||
|
# else:
|
||||||
|
# # Instance new object ?
|
||||||
|
# print("new")
|
||||||
|
# client_instance.add(key)
|
||||||
|
|
||||||
if hasattr(bpy.context, 'selected_objects'):
|
if hasattr(bpy.context, 'selected_objects'):
|
||||||
selected_objects = helpers.get_selected_objects(scene)
|
selected_objects = helpers.get_selected_objects(scene)
|
||||||
|
13
ui.py
13
ui.py
@ -3,6 +3,9 @@ import bpy
|
|||||||
from . import client, operators
|
from . import client, operators
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SessionSettingsPanel(bpy.types.Panel):
|
class SessionSettingsPanel(bpy.types.Panel):
|
||||||
"""Creates a Panel in the scene context of the properties editor"""
|
"""Creates a Panel in the scene context of the properties editor"""
|
||||||
bl_label = "NET settings"
|
bl_label = "NET settings"
|
||||||
@ -164,13 +167,19 @@ class SessionPropertiesPanel(bpy.types.Panel):
|
|||||||
|
|
||||||
detail_item_box.label(text="{} ".format(item[0]))
|
detail_item_box.label(text="{} ".format(item[0]))
|
||||||
|
|
||||||
|
# detail_item_box.prop(net_settings, "clients", text="")
|
||||||
|
|
||||||
detail_item_box.label(text="{} ".format(owner))
|
detail_item_box.label(text="{} ".format(owner))
|
||||||
|
|
||||||
|
right_icon = "DECORATE_UNLOCKED"
|
||||||
if owner == net_settings.username:
|
if owner == net_settings.username:
|
||||||
detail_item_box.label(text="",icon="DECORATE_UNLOCKED")
|
right_icon="DECORATE_UNLOCKED"
|
||||||
else:
|
else:
|
||||||
|
|
||||||
detail_item_box.label(text="",icon="DECORATE_LOCKED")
|
right_icon="DECORATE_LOCKED"
|
||||||
|
|
||||||
|
ro = detail_item_box.operator("session.right", text="", icon=right_icon)
|
||||||
|
ro.key = item[0]
|
||||||
# detail_item_box.operator(
|
# detail_item_box.operator(
|
||||||
# "session.remove_prop", text="", icon="X").property_path = key
|
# "session.remove_prop", text="", icon="X").property_path = key
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user