Skip to content

Commit

Permalink
Fix poll errors during migration.
Browse files Browse the repository at this point in the history
Refactor the component poll methods to receive
the component host, and optionally the object,
as an argument and use them directly, rather than
receiving the context, which isn't correct during
migrations, and using that to get the host/object.

Remove the warning message in the video-texture-source
component ui for no camera being found in the object
hierarchy.
  • Loading branch information
Exairnous committed Dec 16, 2022
1 parent 3fe86ac commit 48c39cd
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class MorphAudioFeedback(HubsComponent):
default=1.0)

@classmethod
def poll(cls, context, panel_type):
return context.object.type == 'MESH'
def poll(cls, panel_type, host, ob=None):
return host.type == 'MESH'

def migrate(self, migration_type, panel_type, instance_version, host, migration_report, ob=None):
migration_occurred = False
Expand Down
4 changes: 2 additions & 2 deletions addons/io_hubs_addon/components/definitions/nav_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class NavMesh(HubsComponent):
}

@classmethod
def poll(cls, context, panel_type):
return context.object.type == 'MESH'
def poll(cls, panel_type, host, ob=None):
return host.type == 'MESH'
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,8 @@ def draw_global(cls, context, layout, panel):
icon='ERROR')

@ classmethod
def poll(cls, context, panel_type):
return context.object.type == 'LIGHT_PROBE'
def poll(cls, panel_type, host, ob=None):
return host.type == 'LIGHT_PROBE'

@ staticmethod
def register():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ class VideoTextureSource(HubsComponent):
name="FPS", description="FPS", default=15)

@classmethod
def poll(cls, context, panel_type):
ob = context.object
def poll(cls, panel_type, host, ob=None):
if panel_type == PanelType.OBJECT:
return hasattr(
ob, 'type') and (
ob.type == 'CAMERA' or [x for x in children_recursive(ob) if x.type == "CAMERA" and not x.parent_bone])
host, 'type') and (
host.type == 'CAMERA' or
[x for x in children_recursive(host) if x.type == "CAMERA" and not x.parent_bone])
elif panel_type == PanelType.BONE:
bone = context.active_bone
return [x for x in children_recursive(ob) if x.type == "CAMERA" and x.parent_bone == bone.name]
return [x for x in children_recursive(ob) if x.type == "CAMERA" and x.parent_bone == host.name]
return False

@classmethod
Expand All @@ -48,11 +47,3 @@ def get_unsupported_host_message(cls, panel_type, host):
message = f"Warning: Unsupported component on {host_type} {host_reference}, {host_type}s that{object_message} don't have a camera somewhere in their child hierarchy don't support {cls.get_display_name()} components"

return message

def draw(self, context, layout, panel):
super().draw(context, layout, panel)
if not VideoTextureSource.poll(context, PanelType(panel.bl_context)):
col = layout.column()
col.alert = True
col.label(text='No camera found in the object hierarchy',
icon='ERROR')
2 changes: 1 addition & 1 deletion addons/io_hubs_addon/components/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def migrate(component, migration_type, panel_type, host, migration_report, ob=No

component.instance_version = definition_version

if panel_type not in component.__class__.get_panel_type() or not component.__class__.poll(bpy.context, panel_type):
if panel_type not in component.__class__.get_panel_type() or not component.__class__.poll(panel_type, host, ob=ob):
message = component.__class__.get_unsupported_host_message(panel_type, host)
migration_report.append(message)

Expand Down
5 changes: 3 additions & 2 deletions addons/io_hubs_addon/components/hubs_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ def get_properties(cls):
return {}

@classmethod
def poll(cls, context, panel_type):
def poll(cls, panel_type, host, ob=None):
'''This method will return true if this component's shown be shown or run.
This is currently called when checking if the component should be added to the components pop-up, when the components properties panel is drawn, and during migrations to warn about unsupported hosts.'''
This is currently called when checking if the component should be added to the components pop-up, when the components properties panel is drawn, and during migrations to warn about unsupported hosts.
The ob argument is guaranteed to be present only for objects/bones.'''
return True

@classmethod
Expand Down
3 changes: 2 additions & 1 deletion addons/io_hubs_addon/components/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def invoke(self, context, event):
# Filter components that are not targeted to this object type or their poll method call returns False
def filter_source_type(cmp):
(_, component_class) = cmp
return not component_class.is_dep_only() and PanelType(panel_type) in component_class.get_panel_type() and component_class.poll(context, PanelType(panel_type))
host = get_object_source(context, panel_type)
return not component_class.is_dep_only() and PanelType(panel_type) in component_class.get_panel_type() and component_class.poll(PanelType(panel_type), host, ob=context.object)

components_registry = get_components_registry()
components_icons = get_components_icons()
Expand Down
2 changes: 1 addition & 1 deletion addons/io_hubs_addon/components/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def draw_component(panel, context, obj, row, component_item):
component_class = get_component_by_name(component_name)
if component_class:
panel_type = PanelType(panel.bl_context)
if panel_type not in component_class.get_panel_type() or not component_class.poll(context, panel_type):
if panel_type not in component_class.get_panel_type() or not component_class.poll(panel_type, obj, ob=context.object):
col = row.box().column()
top_row = col.row()
top_row.label(
Expand Down

0 comments on commit 48c39cd

Please sign in to comment.