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")
|
||||
self.agent.daemon = True
|
||||
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):
|
||||
self.pipe.send_multipart([b"CONNECT", (id.encode() if isinstance(
|
||||
id, str) else id), (address.encode() if isinstance(
|
||||
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
|
||||
Sends [SET][key][value] to the agent
|
||||
"""
|
||||
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):
|
||||
"""Set new value in distributed hash table
|
||||
@ -200,6 +204,7 @@ class RCFClientAgent(object):
|
||||
elif command == b"SET":
|
||||
key = umsgpack.unpackb(msg[0])
|
||||
value = umsgpack.unpackb(msg[1])
|
||||
override = umsgpack.unpackb(msg[2])
|
||||
|
||||
if key in self.property_map.keys():
|
||||
if self.property_map[key].id == self.id:
|
||||
@ -207,8 +212,13 @@ class RCFClientAgent(object):
|
||||
value = helpers.dump(key)
|
||||
value['id'] = self.id.decode()
|
||||
if value:
|
||||
key_id = self.id
|
||||
|
||||
if override:
|
||||
key_id = value['id'].encode()
|
||||
|
||||
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.send(self.publisher)
|
||||
@ -216,6 +226,7 @@ class RCFClientAgent(object):
|
||||
logger.error("Fail to dump ")
|
||||
else:
|
||||
helpers.load(key,self.property_map[key].body)
|
||||
|
||||
|
||||
elif command == b"ADD":
|
||||
key = umsgpack.unpackb(msg[0])
|
||||
@ -398,7 +409,7 @@ def serialization_agent(ctx, pipe):
|
||||
agent.control_message()
|
||||
|
||||
|
||||
class SyncAgent(object):
|
||||
class RCFSyncAgent(object):
|
||||
ctx = None
|
||||
pipe = None
|
||||
|
||||
@ -414,8 +425,8 @@ class SyncAgent(object):
|
||||
pass
|
||||
|
||||
|
||||
def sync_agent(ctx, pipe):
|
||||
agent = SyncAgent(ctx, pipe)
|
||||
def rcf_sync_agent(ctx, pipe):
|
||||
agent = RCFSyncAgent(ctx, pipe)
|
||||
|
||||
global stop
|
||||
while True:
|
||||
|
13
helpers.py
13
helpers.py
@ -23,9 +23,8 @@ def get_selected_objects(scene):
|
||||
|
||||
return selected_objects
|
||||
|
||||
|
||||
# LOAD HELPERS
|
||||
|
||||
|
||||
def load(key, value):
|
||||
target = resolve_bpy_path(key)
|
||||
target_type = key.split('/')[0]
|
||||
@ -85,10 +84,14 @@ def load_client(client=None, data=None):
|
||||
client_data = data
|
||||
# Load selected object
|
||||
for obj in C.scene.objects:
|
||||
if client_data['active_objects'] and obj.name in client_data['active_objects']:
|
||||
D.objects[obj.name].hide_select = True
|
||||
if obj.id == client:
|
||||
D.objects[obj.name].hide_select = True
|
||||
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):
|
||||
|
101
operators.py
101
operators.py
@ -36,6 +36,18 @@ SUPPORTED_TYPES = ['Material',
|
||||
# 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):
|
||||
for datablock in elements:
|
||||
datablock_ref = getattr(bpy.data, datablock)
|
||||
@ -319,15 +331,18 @@ class session_create(bpy.types.Operator):
|
||||
global server
|
||||
global client_instance
|
||||
|
||||
net_settings = context.scene.session_settings
|
||||
server = subprocess.Popen(
|
||||
['python', 'server.py'], shell=False, stdout=subprocess.PIPE)
|
||||
time.sleep(0.1)
|
||||
|
||||
bpy.ops.session.join()
|
||||
|
||||
if context.scene.session_settings.init_scene:
|
||||
if net_settings.init_scene:
|
||||
init_datablocks()
|
||||
|
||||
net_settings.is_admin = True
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
@ -358,7 +373,7 @@ class session_stop(bpy.types.Operator):
|
||||
del client_instance
|
||||
client_instance = None
|
||||
client_keys = None
|
||||
net_settings.is_running = False
|
||||
net_settings.is_admin = False
|
||||
client_state = 1
|
||||
unregister_ticks()
|
||||
else:
|
||||
@ -367,6 +382,50 @@ class session_stop(bpy.types.Operator):
|
||||
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):
|
||||
username = bpy.props.StringProperty(
|
||||
name="Username", default="user_{}".format(randomStringDigits()))
|
||||
@ -378,7 +437,7 @@ class session_settings(bpy.types.PropertyGroup):
|
||||
add_property_depth = bpy.props.IntProperty(
|
||||
name="add_property_depth", default=1)
|
||||
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)
|
||||
init_scene = bpy.props.BoolProperty(name="load_data", 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",
|
||||
subtype='COLOR',
|
||||
default=randomColor())
|
||||
clients = bpy.props.EnumProperty(
|
||||
name="clients",
|
||||
description="client enum",
|
||||
items=client_list_callback
|
||||
)
|
||||
|
||||
|
||||
class session_snapview(bpy.types.Operator):
|
||||
@ -438,6 +502,7 @@ classes = (
|
||||
session_settings,
|
||||
session_remove_property,
|
||||
session_snapview,
|
||||
session_rights,
|
||||
)
|
||||
|
||||
|
||||
@ -453,22 +518,20 @@ def ordered(updates):
|
||||
return uplist
|
||||
|
||||
|
||||
def is_dirty(updates):
|
||||
def exist(update):
|
||||
global client_keys
|
||||
|
||||
if client_keys:
|
||||
if len(client_keys) > 0:
|
||||
for u in updates:
|
||||
key = "{}/{}".format(u.id.bl_rna.name, u.id.name)
|
||||
key = "{}/{}".format(update.id.bl_rna.name, update.id.name)
|
||||
|
||||
if key not in client_keys:
|
||||
return True
|
||||
|
||||
return False
|
||||
if key in client_keys:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def depsgraph_update(scene):
|
||||
global client_instance
|
||||
global client_keys
|
||||
|
||||
if client_instance and client_instance.agent.is_alive():
|
||||
updates = bpy.context.depsgraph.updates
|
||||
@ -491,12 +554,22 @@ def depsgraph_update(scene):
|
||||
# else:
|
||||
# print("{} applying update".format(username))
|
||||
|
||||
# if is_dirty(updates):
|
||||
|
||||
# for update in ordered(updates):
|
||||
# if update[2] == "Master Collection":
|
||||
# pass
|
||||
# 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'):
|
||||
selected_objects = helpers.get_selected_objects(scene)
|
||||
|
13
ui.py
13
ui.py
@ -3,6 +3,9 @@ import bpy
|
||||
from . import client, operators
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class SessionSettingsPanel(bpy.types.Panel):
|
||||
"""Creates a Panel in the scene context of the properties editor"""
|
||||
bl_label = "NET settings"
|
||||
@ -164,13 +167,19 @@ class SessionPropertiesPanel(bpy.types.Panel):
|
||||
|
||||
detail_item_box.label(text="{} ".format(item[0]))
|
||||
|
||||
# detail_item_box.prop(net_settings, "clients", text="")
|
||||
|
||||
detail_item_box.label(text="{} ".format(owner))
|
||||
|
||||
right_icon = "DECORATE_UNLOCKED"
|
||||
if owner == net_settings.username:
|
||||
detail_item_box.label(text="",icon="DECORATE_UNLOCKED")
|
||||
right_icon="DECORATE_UNLOCKED"
|
||||
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(
|
||||
# "session.remove_prop", text="", icon="X").property_path = key
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user