Build/publish: add poll() function to prevent exception when executing from outside of UI

If there was no exporter, calling `bpy.ops.arm.publish_project()` would result in an exception before. Now the call is simply ignored and a "poll failed" message is emitted instead.
This commit is contained in:
Moritz Brückner 2021-06-23 20:19:08 +02:00
parent cbcc3e4e04
commit 66856e7ecc

View file

@ -626,7 +626,6 @@ class ARM_PT_ArmoryExporterPanel(bpy.types.Panel):
row = layout.row(align=True)
row.alignment = 'EXPAND'
row.scale_y = 1.3
row.enabled = wrd.arm_exporterlist_index >= 0 and len(wrd.arm_exporterlist) > 0
row.operator("arm.build_project", icon="MOD_BUILD")
# row.operator("arm.patch_project")
row.operator("arm.publish_project", icon="EXPORT")
@ -1053,10 +1052,15 @@ class ArmoryStopButton(bpy.types.Operator):
return{'FINISHED'}
class ArmoryBuildProjectButton(bpy.types.Operator):
'''Build and compile project'''
"""Build and compile project"""
bl_idname = 'arm.build_project'
bl_label = 'Build'
@classmethod
def poll(cls, context):
wrd = bpy.data.worlds['Arm']
return wrd.arm_exporterlist_index >= 0 and len(wrd.arm_exporterlist) > 0
def execute(self, context):
# Compare version Blender and Armory (major, minor)
if not arm.utils.compare_version_blender_arm():
@ -1093,10 +1097,15 @@ class ArmoryBuildProjectButton(bpy.types.Operator):
return{'FINISHED'}
class ArmoryPublishProjectButton(bpy.types.Operator):
'''Build project ready for publishing'''
"""Build project ready for publishing."""
bl_idname = 'arm.publish_project'
bl_label = 'Publish'
@classmethod
def poll(cls, context):
wrd = bpy.data.worlds['Arm']
return wrd.arm_exporterlist_index >= 0 and len(wrd.arm_exporterlist) > 0
def execute(self, context):
# Compare version Blender and Armory (major, minor)
if not arm.utils.compare_version_blender_arm():