1
0
mirror of https://github.com/DarklightGames/io_scene_psk_psa.git synced 2025-03-03 15:25:49 +01:00

The PSK and PSA import menu items will now be greyed out if in the wrong context, and a tooltip will be shown indicating what the issue is (e.g., having the wrong type of object selected)

This commit is contained in:
Colin Basnett 2022-05-05 20:56:52 -07:00
parent 19ff47cc83
commit d4a58caafe
2 changed files with 29 additions and 7 deletions

View File

@ -159,6 +159,15 @@ class PsaExportOperator(Operator, ExportHelper):
def __init__(self):
self.armature = None
@classmethod
def poll(cls, context):
try:
cls._check_context(context)
except RuntimeError as e:
cls.poll_message_set((str(e)))
return False
return True
def draw(self, context):
layout = self.layout
pg = context.scene.psa_export
@ -245,17 +254,21 @@ class PsaExportOperator(Operator, ExportHelper):
return True
return False
def invoke(self, context, event):
pg = context.scene.psa_export
@classmethod
def _check_context(cls, context):
if context.view_layer.objects.active is None:
self.report({'ERROR_INVALID_CONTEXT'}, 'An armature must be selected')
return {'CANCELLED'}
raise RuntimeError('An armature must be selected')
if context.view_layer.objects.active.type != 'ARMATURE':
self.report({'ERROR_INVALID_CONTEXT'}, 'The selected object must be an armature.')
return {'CANCELLED'}
raise RuntimeError('The selected object must be an armature')
def invoke(self, context, event):
try:
self._check_context(context)
except RuntimeError as e:
self.report({'ERROR_INVALID_CONTEXT'}, str(e))
pg = context.scene.psa_export
self.armature = context.view_layer.objects.active
# Populate actions list.

View File

@ -102,6 +102,15 @@ class PskExportOperator(Operator, ExportHelper):
return {'RUNNING_MODAL'}
@classmethod
def poll(cls, context):
try:
PskBuilder.get_input_objects(context)
except RuntimeError as e:
cls.poll_message_set(str(e))
return False
return True
def draw(self, context):
layout = self.layout
scene = context.scene