From 42f896b38963fbe905975f62f636f592175d79e6 Mon Sep 17 00:00:00 2001 From: Swann Martinez Date: Wed, 28 Aug 2019 18:58:18 +0200 Subject: [PATCH] feat: expose bl_implementations settings --- __init__.py | 52 ++++++++++++++++++++------- bl_types/bl_camera.py | 3 +- bl_types/bl_collection.py | 6 +--- bl_types/bl_curve.py | 8 ++--- bl_types/bl_gpencil.py | 8 ++--- bl_types/bl_image.py | 8 ++--- bl_types/bl_light.py | 8 ++--- bl_types/bl_material.py | 8 ++--- bl_types/bl_mesh.py | 6 +--- bl_types/bl_object.py | 8 ++--- bl_types/bl_scene.py | 8 ++--- bl_types/bl_user.py | 6 ++-- environment.py | 48 +------------------------ operators.py | 8 ++--- ui.py | 74 ++++++++++++++++++++++++++------------- 15 files changed, 115 insertions(+), 144 deletions(-) diff --git a/__init__.py b/__init__.py index 1674e3a..6610cbe 100644 --- a/__init__.py +++ b/__init__.py @@ -18,6 +18,7 @@ import bpy from bpy.app.handlers import persistent from . import environment, utils +# from . import bl_types DEPENDENCIES = { ("zmq","zmq"), @@ -31,6 +32,20 @@ logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) # UTILITY FUNCTIONS +def generate_supported_types(): + stype_dict = {'supported_types':{}} + for type in bl_types.types_to_register(): + _type = getattr(bl_types, type) + props = {} + props['bl_delay_refresh']=_type.bl_delay_refresh + props['bl_delay_apply']=_type.bl_delay_apply + props['use_as_filter'] = False + props['icon'] = _type.bl_icon + # stype_dict[type]['bl_delay_apply']=_type.bl_delay_apply + stype_dict['supported_types'][_type.bl_rep_class.__name__] = props + + return stype_dict + def client_list_callback(scene, context): from . import operators from .bl_types.bl_user import BlUser @@ -62,7 +77,8 @@ def randomColor(): def save_session_config(self,context): config = environment.load_config() - + if "supported_types" not in config: + config = generate_supported_types() config["username"] = self.username config["ip"] = self.ip config["port"] = self.port @@ -72,10 +88,11 @@ def save_session_config(self,context): rep_type = {} for bloc in self.supported_datablock: - config["replicated_types"][bloc.type_name] = bloc.is_replicated + config["supported_types"][bloc.type_name]['bl_delay_refresh'] = bloc.bl_delay_refresh + config["supported_types"][bloc.type_name]['bl_delay_apply'] = bloc.bl_delay_apply + config["supported_types"][bloc.type_name]['use_as_filter'] = bloc.use_as_filter + config["supported_types"][bloc.type_name]['icon'] = bloc.icon - # Generate ordered replicate types - environment.genererate_replicated_types() # Save out the configuration file environment.save_config(config) @@ -84,8 +101,10 @@ def save_session_config(self,context): class ReplicatedDatablock(bpy.types.PropertyGroup): '''name = StringProperty() ''' type_name: bpy.props.StringProperty() - is_replicated: bpy.props.BoolProperty() - + bl_delay_refresh: bpy.props.FloatProperty() + bl_delay_apply: bpy.props.FloatProperty() + use_as_filter: bpy.props.BoolProperty(default=False) + icon: bpy.props.StringProperty() class SessionProps(bpy.types.PropertyGroup): username: bpy.props.StringProperty( @@ -147,11 +166,14 @@ class SessionProps(bpy.types.PropertyGroup): supported_datablock: bpy.props.CollectionProperty( type=ReplicatedDatablock, ) + session_filter: bpy.props.CollectionProperty( + type=ReplicatedDatablock, + ) def load(self): config = environment.load_config() logger.info(config) - if "username" in config: + if "username" in config.keys(): self.username = config["username"] self.ip = config["ip"] self.port = config["port"] @@ -163,13 +185,15 @@ class SessionProps(bpy.types.PropertyGroup): if len(self.supported_datablock)>0: self.supported_datablock.clear() - - for datablock,enabled in config["replicated_types"].items(): + if "supported_types" not in config: + config = generate_supported_types() + for datablock in config["supported_types"].keys(): rep_value = self.supported_datablock.add() rep_value.name = datablock rep_value.type_name = datablock - rep_value.is_replicated = enabled - + rep_value.bl_delay_refresh = config["supported_types"][datablock]['bl_delay_refresh'] + rep_value.bl_delay_apply = config["supported_types"][datablock]['bl_delay_apply'] + rep_value.icon = config["supported_types"][datablock]['icon'] def save(self,context): config = environment.load_config() @@ -182,8 +206,10 @@ class SessionProps(bpy.types.PropertyGroup): for bloc in self.supported_datablock: - config["replicated_types"][bloc.type_name] = bloc.is_replicated - + config["supported_types"][bloc.type_name]['bl_delay_refresh'] = bloc.bl_delay_refresh + config["supported_types"][bloc.type_name]['bl_delay_apply'] = bloc.bl_delay_apply + config["supported_types"][bloc.type_name]['use_as_filter'] = bloc.use_as_filter + config["supported_types"][bloc.type_name]['icon'] = bloc.icon environment.save_config(config) diff --git a/bl_types/bl_camera.py b/bl_types/bl_camera.py index b867503..7bfad54 100644 --- a/bl_types/bl_camera.py +++ b/bl_types/bl_camera.py @@ -36,4 +36,5 @@ bl_class = bpy.types.Camera bl_rep_class = BlCamera bl_delay_refresh = 1 bl_delay_apply = 1 -bl_automatic_push = True \ No newline at end of file +bl_automatic_push = True +bl_icon = 'CAMERA_DATA' \ No newline at end of file diff --git a/bl_types/bl_collection.py b/bl_types/bl_collection.py index d833942..1419876 100644 --- a/bl_types/bl_collection.py +++ b/bl_types/bl_collection.py @@ -6,11 +6,6 @@ from .bl_datablock import BlDatablock class BlCollection(BlDatablock): - def __init__(self, *args, **kwargs): - self.icon = 'FILE_FOLDER' - - super().__init__(*args, **kwargs) - def construct(self,data): return bpy.data.collections.new(data["name"]) @@ -65,6 +60,7 @@ class BlCollection(BlDatablock): return deps bl_id = "collections" +bl_icon = 'FILE_FOLDER' bl_class = bpy.types.Collection bl_rep_class = BlCollection bl_delay_refresh = 1 diff --git a/bl_types/bl_curve.py b/bl_types/bl_curve.py index 58d7fe0..cb52ac3 100644 --- a/bl_types/bl_curve.py +++ b/bl_types/bl_curve.py @@ -6,11 +6,6 @@ from .. import utils from .bl_datablock import BlDatablock class BlCurve(BlDatablock): - def __init__(self, *args, **kwargs): - self.icon = 'CURVE_DATA' - - super().__init__( *args, **kwargs) - def construct(self, data): return bpy.data.curves.new(data["name"], 'CURVE') @@ -57,4 +52,5 @@ bl_class = bpy.types.Curve bl_rep_class = BlCurve bl_delay_refresh = 1 bl_delay_apply = 1 -bl_automatic_push = True \ No newline at end of file +bl_automatic_push = True +bl_icon = 'CURVE_DATA' \ No newline at end of file diff --git a/bl_types/bl_gpencil.py b/bl_types/bl_gpencil.py index 1a28d5a..bd5f777 100644 --- a/bl_types/bl_gpencil.py +++ b/bl_types/bl_gpencil.py @@ -34,11 +34,6 @@ def load_gpencil_layer(target=None, data=None, create=False): class BlGpencil(BlDatablock): - def __init__(self, *args, **kwargs): - self.icon = 'GREASEPENCIL' - - super().__init__(*args, **kwargs) - def construct(self, data): return bpy.data.grease_pencils.new(data["name"]) @@ -91,4 +86,5 @@ bl_class = bpy.types.GreasePencil bl_rep_class = BlGpencil bl_delay_refresh = 5 bl_delay_apply = 5 -bl_automatic_push = True \ No newline at end of file +bl_automatic_push = True +bl_icon = 'GREASEPENCIL' \ No newline at end of file diff --git a/bl_types/bl_image.py b/bl_types/bl_image.py index 5cfac0b..691db7a 100644 --- a/bl_types/bl_image.py +++ b/bl_types/bl_image.py @@ -23,11 +23,6 @@ def dump_image(image): return pixels class BlImage(BlDatablock): - def __init__(self, *args, **kwargs): - self.icon = 'IMAGE_DATA' - - super().__init__( *args, **kwargs) - def construct(self, data): return bpy.data.images.new( name=data['name'], @@ -73,4 +68,5 @@ bl_class = bpy.types.Image bl_rep_class = BlImage bl_delay_refresh = 0 bl_delay_apply = 0 -bl_automatic_push = False \ No newline at end of file +bl_automatic_push = False +bl_icon = 'IMAGE_DATA' \ No newline at end of file diff --git a/bl_types/bl_light.py b/bl_types/bl_light.py index 11c2ebc..ab69ce2 100644 --- a/bl_types/bl_light.py +++ b/bl_types/bl_light.py @@ -7,11 +7,6 @@ from .bl_datablock import BlDatablock class BlLight(BlDatablock): - def __init__(self, *args, **kwargs): - self.icon = 'LIGHT_DATA' - - super().__init__(*args, **kwargs) - def construct(self, data): return bpy.data.lights.new(data["name"], data["type"]) @@ -37,4 +32,5 @@ bl_class = bpy.types.Light bl_rep_class = BlLight bl_delay_refresh = 1 bl_delay_apply = 1 -bl_automatic_push = True \ No newline at end of file +bl_automatic_push = True +bl_icon = 'LIGHT_DATA' \ No newline at end of file diff --git a/bl_types/bl_material.py b/bl_types/bl_material.py index 5b6ef71..354a43f 100644 --- a/bl_types/bl_material.py +++ b/bl_types/bl_material.py @@ -7,11 +7,6 @@ from .bl_datablock import BlDatablock class BlMaterial(BlDatablock): - def __init__(self, *args, **kwargs): - self.icon = 'MATERIAL_DATA' - - super().__init__(*args, **kwargs) - def construct(self, data): return bpy.data.materials.new(data["name"]) @@ -104,4 +99,5 @@ bl_class = bpy.types.Material bl_rep_class = BlMaterial bl_delay_refresh = 5 bl_delay_apply = 5 -bl_automatic_push = True \ No newline at end of file +bl_automatic_push = True +bl_icon = 'MATERIAL_DATA' \ No newline at end of file diff --git a/bl_types/bl_mesh.py b/bl_types/bl_mesh.py index caee402..3662d3c 100644 --- a/bl_types/bl_mesh.py +++ b/bl_types/bl_mesh.py @@ -71,11 +71,6 @@ def dump_mesh(mesh, data={}): return mesh_data class BlMesh(BlDatablock): - def __init__(self, *args, **kwargs): - self.icon = 'MESH_DATA' - - super().__init__( *args, **kwargs) - def construct(self, data): return bpy.data.meshes.new(data["name"]) @@ -181,3 +176,4 @@ bl_rep_class = BlMesh bl_delay_refresh = 10 bl_delay_apply = 10 bl_automatic_push = False +bl_icon = 'MESH_DATA' diff --git a/bl_types/bl_object.py b/bl_types/bl_object.py index fbd31c1..cca22c9 100644 --- a/bl_types/bl_object.py +++ b/bl_types/bl_object.py @@ -6,11 +6,6 @@ from .bl_datablock import BlDatablock class BlObject(BlDatablock): - def __init__(self, *args, **kwargs): - self.icon = 'OBJECT_DATA' - - super().__init__(*args, **kwargs) - def construct(self, data): pointer = None @@ -85,4 +80,5 @@ bl_class = bpy.types.Object bl_rep_class = BlObject bl_delay_refresh = 1 bl_delay_apply = 1 -bl_automatic_push = True \ No newline at end of file +bl_automatic_push = True +bl_icon = 'OBJECT_DATA' \ No newline at end of file diff --git a/bl_types/bl_scene.py b/bl_types/bl_scene.py index ad98628..192c351 100644 --- a/bl_types/bl_scene.py +++ b/bl_types/bl_scene.py @@ -6,11 +6,6 @@ from .. import utils from .bl_datablock import BlDatablock class BlScene(BlDatablock): - def __init__(self, *args, **kwargs): - self.icon = 'SCENE_DATA' - - super().__init__( *args, **kwargs) - def construct(self, data): return bpy.data.scenes.new(data["name"]) @@ -76,4 +71,5 @@ bl_class = bpy.types.Scene bl_rep_class = BlScene bl_delay_refresh = 1 bl_delay_apply = 1 -bl_automatic_push = True \ No newline at end of file +bl_automatic_push = True +bl_icon = 'SCENE_DATA' \ No newline at end of file diff --git a/bl_types/bl_user.py b/bl_types/bl_user.py index a5230eb..b97af55 100644 --- a/bl_types/bl_user.py +++ b/bl_types/bl_user.py @@ -12,11 +12,10 @@ from ..libs.debug import draw_point class BlUser(BlDatablock): def __init__(self, *args, **kwargs): super().__init__( *args, **kwargs) - - self.icon = 'CON_ARMATURE' if self.buffer: self.load(self.buffer, self.pointer) + def construct(self, name): return presence.User() @@ -59,4 +58,5 @@ bl_class = presence.User bl_rep_class = BlUser bl_delay_refresh = 1 bl_delay_apply = 1 -bl_automatic_push = True \ No newline at end of file +bl_automatic_push = True +bl_icon = 'CON_ARMATURE' \ No newline at end of file diff --git a/environment.py b/environment.py index 5833c54..bb5f89e 100644 --- a/environment.py +++ b/environment.py @@ -15,28 +15,6 @@ THIRD_PARTY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs") CACHE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "cache") PYTHON_PATH = None SUBPROCESS_DIR = None -DEFAULT_CONFIG = { - "replicated_types": { - 'Client': True, - 'Image': True, - 'Texture': True, - 'Curve': True, - 'Material': True, - 'Light': True, - 'SunLight': True, - 'SpotLight': True, - 'AreaLight': True, - 'PointLight': True, - 'Camera': True, - 'Mesh': True, - 'Armature': True, - 'GreasePencil': True, - 'Object': True, - 'Action': True, - 'Collection': True, - 'Scene': True - } -} ORDERED_TYPES = [ 'Image', @@ -69,31 +47,7 @@ def load_config(): return yaml.safe_load(config_file) except FileNotFoundError: logger.info("no config") - - return DEFAULT_CONFIG - - -def get_replicated_types(): - config = load_config() - rtpyes = config["replicated_types"] - tlist = [] - - for t in ORDERED_TYPES: - if rtpyes[t]: - tlist.append(t) - - return tlist - - -def genererate_replicated_types(): - rtypes.clear() - - cfg = load_config() - replicated_types = cfg['replicated_types'] - for t in ORDERED_TYPES: - if replicated_types[t]: - rtypes.append(t) - + return {} def save_config(config): import yaml diff --git a/operators.py b/operators.py index 2cf5fee..d8d71a2 100644 --- a/operators.py +++ b/operators.py @@ -74,16 +74,16 @@ class SessionStartOperator(bpy.types.Operator): for type in bl_types.types_to_register(): _type = getattr(bl_types, type) supported_bl_types.append(_type.bl_id) - + type_local_config = settings.supported_datablock[_type.bl_rep_class.__name__] bpy_factory.register_type( _type.bl_class, _type.bl_rep_class, - timer=_type.bl_delay_refresh, + timer=type_local_config.bl_delay_refresh, automatic=_type.bl_automatic_push) - if _type.bl_delay_apply > 0: + if type_local_config.bl_delay_apply > 0: delayables.append(delayable.ApplyTimer( - timout=_type.bl_delay_apply, + timout=type_local_config.bl_delay_apply, target_type=_type.bl_rep_class)) client = Session(factory=bpy_factory) diff --git a/ui.py b/ui.py index 5677b38..aca63ec 100644 --- a/ui.py +++ b/ui.py @@ -4,12 +4,12 @@ from .libs.replication.replication.constants import FETCHED, ERROR, MODIFIED, UP from .bl_types.bl_user import BlUser -PROP_STATES = ['FILE_REFRESH', # ADDED - 'TRIA_UP', # COMMITED - 'KEYTYPE_KEYFRAME_VEC', # PUSHED - 'TRIA_DOWN', # FETCHED - 'FILE_REFRESH', # UP - 'TRIA_UP'] # CHANGED +ICONS_PROP_STATES = ['FILE_REFRESH', # ADDED + 'TRIA_UP', # COMMITED + 'KEYTYPE_KEYFRAME_VEC', # PUSHED + 'TRIA_DOWN', # FETCHED + 'FILE_REFRESH', # UP + 'TRIA_UP'] # CHANGED class SESSION_PT_settings(bpy.types.Panel): @@ -33,17 +33,6 @@ class SESSION_PT_settings(bpy.types.Panel): if not operators.client \ or (operators.client and operators.client.state == 0): pass - # REPLICATION SETTINGS - # row = layout.row() - # box = row.box() - # row = box.row() - # row.label(text="REPLICATION", icon='TRIA_RIGHT') - # row = box.row() - - # for item in window_manager.session.supported_datablock: - # row.label(text=item.type_name,icon=ICONS[item.type_name]) - # row.prop(item, "is_replicated", text="") - # row = box.row() else: # STATE ACTIVE if operators.client.state == 2: @@ -138,6 +127,34 @@ class SESSION_PT_settings_user(bpy.types.Panel): row = layout.row() +class SESSION_PT_settings_replication(bpy.types.Panel): + bl_idname = "MULTIUSER_SETTINGS_REPLICATION_PT_panel" + bl_label = "Replication" + bl_space_type = 'VIEW_3D' + bl_region_type = 'UI' + bl_category = "Multiuser" + bl_parent_id = 'MULTIUSER_SETTINGS_PT_panel' + + @classmethod + def poll(cls, context): + return not operators.client \ + or (operators.client and operators.client.state == 0) + + def draw(self, context): + layout = self.layout + + settings = context.window_manager.session + + + flow = layout.grid_flow( + row_major=True, columns=0, even_columns=True, even_rows=False, align=True) + for item in settings.supported_datablock: + line = flow.column(align=True) + line.label(text=item.type_name,icon=item.icon) + line.prop(item, "bl_delay_refresh", text="refresh time") + line.prop(item, "bl_delay_apply", text="apply timer") + + class SESSION_PT_user(bpy.types.Panel): bl_idname = "MULTIUSER_USER_PT_panel" bl_label = "Users" @@ -208,7 +225,8 @@ def draw_property(context, parent, property_uuid, level=0): detail_item_box = line.row(align=True) - detail_item_box.label(text="", icon=item.icon) + detail_item_box.label(text="", + icon=settings.supported_datablock[item.str_type].icon) detail_item_box.label(text="{} ".format(name)) # Operations @@ -219,14 +237,14 @@ def draw_property(context, parent, property_uuid, level=0): detail_item_box.operator( "session.apply", text="", - icon=PROP_STATES[item.state]).target = item.uuid + icon=ICONS_PROP_STATES[item.state]).target = item.uuid elif item.state == MODIFIED: detail_item_box.operator( "session.commit", text="", - icon=PROP_STATES[item.state]).target = item.uuid + icon=ICONS_PROP_STATES[item.state]).target = item.uuid else: - detail_item_box.label(text="", icon=PROP_STATES[item.state]) + detail_item_box.label(text="", icon=ICONS_PROP_STATES[item.state]) right_icon = "DECORATE_UNLOCKED" if item.owner != settings.username: @@ -240,7 +258,8 @@ def draw_property(context, parent, property_uuid, level=0): detail_item_box.operator( "session.remove_prop", text="", icon="X").property_path = property_uuid else: - detail_item_box.label( text="", icon="DECORATE_LOCKED") + detail_item_box.label(text="", icon="DECORATE_LOCKED") + class SESSION_PT_outliner(bpy.types.Panel): bl_idname = "MULTIUSER_PROPERTIES_PT_panel" @@ -262,8 +281,14 @@ class SESSION_PT_outliner(bpy.types.Panel): if hasattr(context.window_manager, 'session'): settings = context.window_manager.session - row = layout.row() - row.prop(settings, 'outliner_filter', text="") + # row.prop(settings, 'outliner_filter', text="") + flow = layout.grid_flow( + row_major=True, columns=0, even_columns=True, even_rows=False, align=True) + + for item in settings.supported_datablock: + col = flow.column() + col.prop(item,"use_as_filter",text="", icon=item.icon) + # row.prop(item, "is_replicated", text="") row = layout.row(align=True) # Property area @@ -283,6 +308,7 @@ classes = ( SESSION_PT_settings, SESSION_PT_settings_user, SESSION_PT_settings_network, + SESSION_PT_settings_replication, SESSION_PT_user, SESSION_PT_outliner,