enenra / space-engineers-utilities

A Blender 4.0+ addon to streamline working on assets for Space Engineers.
https://spaceengineers.wiki.gg/wiki/Modding/Tools/Space_Engineers_Utilities
GNU General Public License v3.0
47 stars 12 forks source link

Evaluate transition to operator.poll_messages() #303

Closed enenra closed 2 years ago

enenra commented 2 years ago

https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Python_API

Added Operator.poll_message_set(message, ...) Operators can now set a message for why an operators poll function fails (ebe04bd3ca).

This means I can prevent pressing of buttons with a message, instead of having to allow pressing but then show an error in order to inform of the issues.

Implement poll function to prevent running things like export / the 3 modes without being in the right context.

    @classmethod
    def poll(cls, context):
        if not SpaceAssetInfo.is_asset_browser_poll(context) or not context.asset_file_handle:
            return False

        if not context.asset_file_handle.local_id:
            Operator.poll_message_set(
                "Asset metadata from external asset libraries can't be "
                "edited, only assets stored in the current file can"
            )
            return False
        return True