feat: get remove property operator back

This commit is contained in:
Swann Martinez 2019-08-12 10:32:25 +02:00
parent 1ee124e5b1
commit 91940837ee
No known key found for this signature in database
GPG Key ID: 414CCAFD8DA720E1
2 changed files with 44 additions and 99 deletions

View File

@ -41,36 +41,36 @@ context = None
# def update_client_selected_object(context):
# session = bpy.context.window_manager.session
# username = bpy.context.window_manager.session.username
# client_key = "Client/{}".format(username)
# client_data = client.get(client_key)
# session = bpy.context.window_manager.session
# username = bpy.context.window_manager.session.username
# client_key = "Client/{}".format(username)
# client_data = client.get(client_key)
# selected_objects = utils.get_selected_objects(context.scene)
# if len(selected_objects) > 0 and len(client_data) > 0:
# selected_objects = utils.get_selected_objects(context.scene)
# if len(selected_objects) > 0 and len(client_data) > 0:
# for obj in selected_objects:
# # if obj not in client_data[0][1]['active_objects']:
# client_data[0][1]['active_objects'] = selected_objects
# for obj in selected_objects:
# # if obj not in client_data[0][1]['active_objects']:
# client_data[0][1]['active_objects'] = selected_objects
# client.set(client_key, client_data[0][1])
# break
# client.set(client_key, client_data[0][1])
# break
# elif client_data and client_data[0][1]['active_objects']:
# client_data[0][1]['active_objects'] = []
# client.set(client_key, client_data[0][1])
# elif client_data and client_data[0][1]['active_objects']:
# client_data[0][1]['active_objects'] = []
# client.set(client_key, client_data[0][1])
def add_datablock(datablock):
global client
child=[]
child = []
if hasattr(datablock,"data"):
if hasattr(datablock, "data"):
child.append(add_datablock(datablock.data))
if datablock.uuid and client.exist(datablock.uuid) :
if datablock.uuid and client.exist(datablock.uuid):
return datablock.uuid
else:
new_uuid = client.add(datablock,childs=child)
new_uuid = client.add(datablock, childs=child)
datablock.uuid = new_uuid
return new_uuid
@ -80,12 +80,11 @@ def init_supported_datablocks(supported_types_id):
global client
for type_id in supported_types_id:
if hasattr(bpy.data,type_id):
for item in getattr(bpy.data,type_id):
if hasattr(bpy.data, type_id):
for item in getattr(bpy.data, type_id):
add_datablock(item)
# def default_tick():
# upload_client_instance_position()
@ -116,7 +115,6 @@ class SessionStartOperator(bpy.types.Operator):
host: bpy.props.BoolProperty(default=False)
@classmethod
def poll(cls, context):
return True
@ -136,13 +134,12 @@ class SessionStartOperator(bpy.types.Operator):
# init the factory with supported types
for type in bl_types.types_to_register():
_type = getattr(bl_types,type)
_type = getattr(bl_types, type)
supported_bl_types.append(_type.bl_id)
bpy_factory.register_type(_type.bl_class,_type.bl_rep_class)
bpy_factory.register_type(_type.bl_class, _type.bl_rep_class)
client = Client(factory=bpy_factory)
if self.host:
client.host(
id=settings.username,
@ -168,7 +165,7 @@ class SessionStartOperator(bpy.types.Operator):
# settings.is_running = True
# bpy.ops.session.refresh()
#register_ticks()
# register_ticks()
# Launch drawing module
if settings.enable_presence:
@ -196,34 +193,12 @@ class SessionStopOperator(bpy.types.Operator):
# del client_instance
# unregister_ticks()
# presence.renderer.stop()
return {"FINISHED"}
class SessionPropertyAddOperator(bpy.types.Operator):
bl_idname = "session.add_prop"
bl_label = "add"
bl_description = "broadcast a property to connected client_instances"
bl_options = {"REGISTER"}
property_path: bpy.props.StringProperty(default="None")
depth: bpy.props.IntProperty(default=1)
@classmethod
def poll(cls, context):
return True
def execute(self, context):
global client
client.add(self.property_path)
return {"FINISHED"}
class SessionPropertyRemoveOperator(bpy.types.Operator):
bl_idname = "session.remove_prop"
bl_label = "remove"
@ -239,7 +214,7 @@ class SessionPropertyRemoveOperator(bpy.types.Operator):
def execute(self, context):
global client
try:
del client.property_map[self.property_path]
client.remove(self.property_path)
return {"FINISHED"}
except:
@ -316,36 +291,6 @@ class SessionSnapUserOperator(bpy.types.Operator):
pass
class SessionDumpDatabase(bpy.types.Operator, ExportHelper):
bl_idname = "session.dump"
bl_label = "dump json data"
bl_description = "dump session stored data to a json file"
bl_options = {"REGISTER"}
# ExportHelper mixin class uses this
filename_ext = ".json"
filter_glob: bpy.props.StringProperty(
default="*.json",
options={'HIDDEN'},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
@classmethod
def poll(cls, context):
return True
def execute(self, context):
print(self.filepath)
if client and client.state() == 3:
client.dump(self.filepath)
return {"FINISHED"}
return {"CANCELLED"}
pass
class SessionSaveConfig(bpy.types.Operator):
bl_idname = "session.save"
bl_label = "Save session configuration"
@ -359,6 +304,7 @@ class SessionSaveConfig(bpy.types.Operator):
def execute(self, context):
context.window_manager.session.save()
class SessionApply(bpy.types.Operator):
bl_idname = "session.apply"
bl_label = "apply the target item into the blender data"
@ -371,7 +317,6 @@ class SessionApply(bpy.types.Operator):
def poll(cls, context):
return True
def execute(self, context):
global client
@ -379,18 +324,18 @@ class SessionApply(bpy.types.Operator):
return {"FINISHED"}
classes = (
SessionStartOperator,
SessionPropertyAddOperator,
SessionStopOperator,
SessionPropertyRemoveOperator,
SessionSnapUserOperator,
SessionPropertyRightOperator,
SessionDumpDatabase,
SessionSaveConfig,
SessionApply,
)
def register():
from bpy.utils import register_class
for cls in classes:

6
ui.py
View File

@ -60,7 +60,6 @@ class SESSION_PT_settings(bpy.types.Panel):
row.operator("session.stop", icon='QUIT', text="CANCEL")
class SESSION_PT_settings_network(bpy.types.Panel):
bl_idname = "MULTIUSER_SETTINGS_NETWORK_PT_panel"
bl_label = "Network"
@ -243,6 +242,8 @@ class SESSION_PT_outliner(bpy.types.Panel):
else:
detail_item_box.label(text="{} ".format(PROP_STATES[item.state]))
detail_item_box.operator(
"session.remove_prop", text="", icon="X").property_path = key
# right_icon = "DECORATE_UNLOCKED"
# if owner == settings.username:
@ -253,8 +254,7 @@ class SESSION_PT_outliner(bpy.types.Panel):
# ro = detail_item_box.operator("session.right", text="",emboss=settings.is_admin, icon=right_icon)
# ro.key = item[0]
# detail_item_box.operator(
# "session.remove_prop", text="", icon="X").property_path = key
else:
area_msg.label(text="Empty")