Actions to implement custom additional functionality for Plug-ins

Yeah, that would totally make sense.

Maybe something to have by default even? There’s been talk about making something like this available before, but nothing ever came up to provide the interface for it. This could be it.

It would be awesome if you could share what you come up with, and maybe even pull request to add a default.

1 Like

Will have a look shortly.

Would it be possible to only show up if some development environment variable was set? Or a way to keep regular artists from seeing it?

How about this?

if os.environ.get("DEBUG"):

Perfect. Only other thing… can I get the plug-in instance that it is running on from within the Action’s process?

Yeah, it’s available via dependency injection alongside context.

def process(self, context, plugin):
  # do things

Added a line about that on the release page, under “Dependency Injected”.

1 Like

Actually as I expected! This should be all that’s necessary. Will have a look later today.

1 Like

This seems to be a bit harder because of how Pyblish loads the plug-ins dynamically.
An issue has been opened on the Pyblish repository to discuss the possible workarounds.

And @marcus already fixed the issue and with the new version in the repository all should be well doing a inspect.getfile() on the plug-in. As such creating an Action to show the plug-in in explorer should be roughly similar to

import pyblish.api
import subprocess
import os
import inspect

class ShowPluginInExplorerAction(pyblish.api.Action):
    def process(self, plugin):
        # Ensure it's not a registry loaded plug-in
        module = plugin.__module__
        if module == '__main__':
            self.log.error("Action: Can't show file for in-memory plug-in")
        path = inspect.getfile(plugin)
    def show_in_explorer(self, path):
        path = os.path.abspath(str(path))
        subprocess.Popen(r'explorer /select, "{0}"'.format(path))

Note that this is untested code!

Hope to have some more time on my hands soon to get this tested and added.

+1 for adding this by default when there is a working version in place:)

Looks good!

Two thoughts.

  1. What can we do about cross-platform compatibility?
  2. Should we show the Action when it doesn’t have a file to open?

You could send the file link to the browser;

import webbrowser

url = "file://X:/MiscDev/language_links.html",new=2)

Wow, did not know about that one! +1

Was this also recommended as a way to perform Repair? What I like about the old implementation where one defines a repair() method on the plug-in is that it would show up as a “wrench” icon on the plug-in when it failed.

How does one implement that same behavior with Actions?

Currently I don’t think Actions are visually represented in the Overview (@marcus?). Would be an interesting feature to add the actions icons to the plugin when appropriate.

Mm, that’s right.

Have a look at the announcement thread for examples.

They’re in the right-click menu, you can assign custom icons to each item as well.

But you can’t see whether a plugin has actions associated, without right-clicking on it. If you added the icons of an action to the plugin visually, similar to how the wrench looks now, the user would know whether there are actions on a plugin without knowing in advanced or right-clicking.

I’d imagine that the user still needs to right-click to execute the action, but they can see in the overview that a certain action is present for a plugin.

I was planning on adding permanent/default actions to all items, such as opening the folder of a particular plug-in and such.

I was specifically looking for a way to have an “icon” be added to the plug-in in the overview just like the Repair icon did before. So that one doesn’t need to right click?

Could the Actions have something like that?

class MyAction(Action):
    icon_in_overview = True

No. Just, no.