feat(bevy_components): added progress indicators for from/to custom properties

This commit is contained in:
kaosat.dev 2024-03-05 18:05:49 +01:00
parent 7cf8007b18
commit 63bac03c7c
2 changed files with 100 additions and 12 deletions

View File

@ -42,11 +42,26 @@ class COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_ALL(Operator):
bl_label = "Apply Registry to all objects" bl_label = "Apply Registry to all objects"
bl_options = {"UNDO"} bl_options = {"UNDO"}
@classmethod
def register(cls):
bpy.types.WindowManager.custom_properties_from_components_progress_all = bpy.props.FloatProperty(default=-1.0) #bpy.props.PointerProperty(type=RenameHelper)
@classmethod
def unregister(cls):
del bpy.types.WindowManager.custom_properties_from_components_progress_all
def execute(self, context): def execute(self, context):
print("apply registry to all") print("apply registry to all")
#context.window_manager.components_registry.load_schema() #context.window_manager.components_registry.load_schema()
for object in bpy.data.objects: total = len(bpy.data.objects)
for index, object in enumerate(bpy.data.objects):
apply_propertyGroup_values_to_object_customProperties(object) apply_propertyGroup_values_to_object_customProperties(object)
progress = index / total
context.window_manager.custom_properties_from_components_progress_all = progress
# now force refresh the ui
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
context.window_manager.custom_properties_from_components_progress_all = -1.0
return {'FINISHED'} return {'FINISHED'}
@ -56,10 +71,23 @@ class COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_CURRENT(Operator):
bl_label = "Apply Registry to current object" bl_label = "Apply Registry to current object"
bl_options = {"UNDO"} bl_options = {"UNDO"}
@classmethod
def register(cls):
bpy.types.WindowManager.custom_properties_from_components_progress = bpy.props.FloatProperty(default=-1.0) #bpy.props.PointerProperty(type=RenameHelper)
@classmethod
def unregister(cls):
del bpy.types.WindowManager.custom_properties_from_components_progress
def execute(self, context): def execute(self, context):
print("apply registry to current object") print("apply registry to current object")
object = context.object object = context.object
context.window_manager.custom_properties_from_components_progress = 0.5
# now force refresh the ui
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
apply_propertyGroup_values_to_object_customProperties(object) apply_propertyGroup_values_to_object_customProperties(object)
context.window_manager.custom_properties_from_components_progress = -1.0
return {'FINISHED'} return {'FINISHED'}
@ -69,44 +97,77 @@ class COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT(Operator):
bl_label = "Apply custom_properties to current object" bl_label = "Apply custom_properties to current object"
bl_options = {"UNDO"} bl_options = {"UNDO"}
@classmethod
def register(cls):
bpy.types.WindowManager.components_from_custom_properties_progress = bpy.props.FloatProperty(default=-1.0) #bpy.props.PointerProperty(type=RenameHelper)
@classmethod
def unregister(cls):
del bpy.types.WindowManager.components_from_custom_properties_progress
def execute(self, context): def execute(self, context):
print("apply custom properties to current object") print("apply custom properties to current object")
object = context.object object = context.object
error = False error = False
try: try:
apply_customProperty_values_to_object_propertyGroups(object) apply_customProperty_values_to_object_propertyGroups(object)
progress = 0.5
context.window_manager.components_from_custom_properties_progress = progress
# now force refresh the ui
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
except Exception as error: except Exception as error:
del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure
error = True error = True
self.report({'ERROR'}, "Failed to update propertyGroup values from custom property: Error:" + str(error)) self.report({'ERROR'}, "Failed to update propertyGroup values from custom property: Error:" + str(error))
if not error: if not error:
self.report({'INFO'}, "Sucessfully generated UI values for custom properties for selected object") self.report({'INFO'}, "Sucessfully generated UI values for custom properties for selected object")
context.window_manager.components_from_custom_properties_progress = -1.0
return {'FINISHED'} return {'FINISHED'}
class COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL(Operator): class COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL(Operator):
"""Update UI values from custom properties to ALL object""" """Update UI values from custom properties to ALL object"""
bl_idname = "object.refresh_ui_from_custom_properties_all" bl_idname = "object.refresh_ui_from_custom_properties_all"
bl_label = "Apply custom_properties to all objects" bl_label = "Apply custom_properties to all objects"
bl_options = {"UNDO"} bl_options = {"UNDO"}
@classmethod
def register(cls):
bpy.types.WindowManager.components_from_custom_properties_progress_all = bpy.props.FloatProperty(default=-1.0) #bpy.props.PointerProperty(type=RenameHelper)
@classmethod
def unregister(cls):
del bpy.types.WindowManager.components_from_custom_properties_progress_all
def execute(self, context): def execute(self, context):
print("apply custom properties to all object") print("apply custom properties to all object")
bpy.context.window_manager.components_registry.disable_all_object_updates = True bpy.context.window_manager.components_registry.disable_all_object_updates = True
errors = [] errors = []
for object in bpy.data.objects: total = len(bpy.data.objects)
for index, object in enumerate(bpy.data.objects):
try: try:
apply_customProperty_values_to_object_propertyGroups(object) apply_customProperty_values_to_object_propertyGroups(object)
except Exception as error: except Exception as error:
del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure
errors.append( "object: '" + object.name + "', error: " + str(error)) errors.append( "object: '" + object.name + "', error: " + str(error))
progress = index / total
context.window_manager.components_from_custom_properties_progress_all = progress
# now force refresh the ui
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
if len(errors) > 0: if len(errors) > 0:
self.report({'ERROR'}, "Failed to update propertyGroup values from custom property: Errors:" + str(errors)) self.report({'ERROR'}, "Failed to update propertyGroup values from custom property: Errors:" + str(errors))
else: else:
self.report({'INFO'}, "Sucessfully generated UI values for custom properties for all objects") self.report({'INFO'}, "Sucessfully generated UI values for custom properties for all objects")
bpy.context.window_manager.components_registry.disable_all_object_updates = False bpy.context.window_manager.components_registry.disable_all_object_updates = False
context.window_manager.components_from_custom_properties_progress_all = -1.0
return {'FINISHED'} return {'FINISHED'}
class OT_OpenFilebrowser(Operator, ImportHelper): class OT_OpenFilebrowser(Operator, ImportHelper):

View File

@ -169,27 +169,54 @@ class BEVY_COMPONENTS_PT_AdvancedToolsPanel(bpy.types.Panel):
row.label(text="WARNING ! The following operations will overwrite your existing custom properties if they have matching types on the bevy side !") row.label(text="WARNING ! The following operations will overwrite your existing custom properties if they have matching types on the bevy side !")
row.alert = True row.alert = True
##
row = layout.row() row = layout.row()
row.operator(COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_CURRENT.bl_idname, text="update custom properties of current object" , icon="LOOP_FORWARDS") custom_properties_from_components_progress_current = context.window_manager.custom_properties_from_components_progress
row.enabled = registry_has_type_infos and selected_object is not None
if custom_properties_from_components_progress_current == -1.0:
row.operator(COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_CURRENT.bl_idname, text="update custom properties of current object" , icon="LOOP_FORWARDS")
row.enabled = registry_has_type_infos and selected_object is not None
else:
if hasattr(layout,"progress") : # only for Blender > 4.0
layout.progress(factor = custom_properties_from_components_progress_current, text=f"updating {custom_properties_from_components_progress_current * 100.0:.2f}%")
layout.separator() layout.separator()
row = layout.row() row = layout.row()
row.operator(COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_ALL.bl_idname, text="update custom properties of ALL objects" , icon="LOOP_FORWARDS") custom_properties_from_components_progress_all = context.window_manager.custom_properties_from_components_progress_all
row.enabled = registry_has_type_infos
if custom_properties_from_components_progress_all == -1.0:
row.operator(COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_ALL.bl_idname, text="update custom properties of ALL objects" , icon="LOOP_FORWARDS")
row.enabled = registry_has_type_infos
else:
if hasattr(layout,"progress") : # only for Blender > 4.0
layout.progress(factor = custom_properties_from_components_progress_all, text=f"updating {custom_properties_from_components_progress_all * 100.0:.2f}%")
########################
row = layout.row() row = layout.row()
row.label(text="WARNING ! The following operations will try to overwrite your existing ui values if they have matching types on the bevy side !") row.label(text="WARNING ! The following operations will try to overwrite your existing ui values if they have matching types on the bevy side !")
row.alert = True row.alert = True
components_from_custom_properties_progress_current = context.window_manager.components_from_custom_properties_progress
row = layout.row() row = layout.row()
row.operator(COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT.bl_idname, text="update UI FROM custom properties of current object" , icon="LOOP_BACK") if components_from_custom_properties_progress_current == -1.0:
row.enabled = registry_has_type_infos and selected_object is not None row.operator(COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT.bl_idname, text="update UI FROM custom properties of current object" , icon="LOOP_BACK")
row.enabled = registry_has_type_infos and selected_object is not None
else:
if hasattr(layout,"progress") : # only for Blender > 4.0
layout.progress(factor = components_from_custom_properties_progress_current, text=f"updating {components_from_custom_properties_progress_current * 100.0:.2f}%")
layout.separator() layout.separator()
row = layout.row() row = layout.row()
row.operator(COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL.bl_idname, text="update UI FROM custom properties of ALL objects" , icon="LOOP_BACK") components_from_custom_properties_progress_all = context.window_manager.components_from_custom_properties_progress_all
row.enabled = registry_has_type_infos
if components_from_custom_properties_progress_all == -1.0:
row.operator(COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL.bl_idname, text="update UI FROM custom properties of ALL objects" , icon="LOOP_BACK")
row.enabled = registry_has_type_infos
else:
if hasattr(layout,"progress") : # only for Blender > 4.0
layout.progress(factor = components_from_custom_properties_progress_all, text=f"updating {components_from_custom_properties_progress_all * 100.0:.2f}%")
class BEVY_COMPONENTS_PT_MissingTypesPanel(bpy.types.Panel): class BEVY_COMPONENTS_PT_MissingTypesPanel(bpy.types.Panel):