Issue commands to an Engine

I want to open WorkFiles2 via the engine_init.py hook post engine launch.

I can see the commands available to an Engine…

print engine.commands.keys()

But execute_command() is not available like it is for the Shotgun Engine.

If I try to just execute the callback function like…

callback = engine.commands['File Open...']['callback']
callback()

Or, if I try using the engine’s _handle_command() like…

uid = engine.commands['File Open...']['properties']['uid']
engine._handle_command(uid)

I get the same kind of errors.

QWidget: Must construct a QApplication before a QPaintDevice
Python exited unexpectedly.
Critical: The Shotgun integration has unexpectedly shut down. Specifically, the python process that handles the communication with Shotgun has been terminated.

All of this works great in the Shotgun Python Console.

I know this is executing as a hook, is there some other way I need to do this?

Daniel

3 Likes

I was just reading through a related post about core hooks, specifically the response from Phillip.

Seems this is not possible in a core hook?

I will move my logic to the engine’s post_app_init and see how that works. Wanted to avoid having to branch the engines and handle it all in one place.

1 Like

No better luck moving this to the engine. This is at the end of post_app_init().

if len(list(self.adobe.app.documents)) == 0:
	# check for the File Open command
	if 'File Open...' in self.commands :
		self.logger.info ('Opening WorkFiles2...')
		uid = self.commands['File Open...']['properties']['uid']
		self.logger.info ('   uid: %s' % uid)
		self._handle_command(uid)

…generates the same errors as in the hook. Help.

Opening WorkFiles2...
     uid: 4
QWidget: Must construct a QApplication before a QPaintDevice
Python exited unexpectedly.
Critical: The Shotgun integration has unexpectedly shut down. Specifically, the python process that handles the communication with Shotgun has been terminated.

Daniel

Same exact error for this…

if len(list(self.adobe.app.documents)) == 0:
    # check for the File Open command
    if 'File Open...' in self.commands :
	    self.logger.info ('Opening WorkFiles2...')
	    callback = self.commands['File Open...']['callback']
	    callback()

Hey Daniel!

I’m not sure which engines you’re hoping to set this up for, but I want to make sure that you’re aware of the launch_at_startup setting for tk-multi-workfiles2. It only works for the engines that support it, but if they do, then you just have to set the setting to True in your config to get the behavior you’re after.

Here’s the setting in tk-multi-workfiles's manifest, here’s the code that actually brings up the app if the setting is set to True, and here’s the value of SUPPORTED_ENGINES (currently set to ["tk-nuke", "tk-maya", "tk-3dsmax"]).

Do you think you’ll be able to go this route?

2 Likes

This is for all the Adobe stuff. Photoshop, Illustrator so that not an option.

Daniel

Hey Daniel,

Unfortunately, you’ve discovered that we’ve not implemented the launch_at_startup feature for the Photoshop engine. Unfortunately, as well, is that the core hook you were hoping to use to get the same result is executed too early in the process of bootstrapping Toolkit and there’s no Qt event loop up and running yet.

This is going to be tricky, because the process of getting the Adobe integration and its RPC connection up and running is much more complex than in integrations that are able to make use of fully embedded Python and Qt environments (like in Maya, as an example).

Off the top of my head, you could try one of two things, with the former being quicker to test:

  1. You can try doing exactly what you were doing in post_app_init, but do it in post_qt_init instead. However, I’m concerned this might also not work. At that point there is definitely a QApplication, but Qt’s event loop hasn’t yet been started. It’s worth a shot, though, to see if the app launch will work and pop up shortly after it’s called when the event loop is started.
  2. You could try instantiating a QTimer in post_qt_init and asking it to run your code as a single-shot event with a delay of 1ms, which should cause it to fire your code that launches Workfiles2 1ms after the Qt event loop starts. That’s obviously getting slightly more into depth with Qt, but hopefully my brief description there makes sense.

Very sorry there’s not an easier answer than that, but I hope that at least helps!

4 Likes

Moving this to post_app_init() works perfectly! No QTimer needed.

Works the same for AfterEffects and in my Illustrator and Premiere engines!

Daniel

5 Likes

Thanks for this question! Adding the callback to post_qt_init() helped open workfiles in (the unofficial?) tk-3de4 too!

4 Likes

Just now realized my typo.

Like Aparna said, post_qt_init() is where you want this code.

Thanks all,
Daniel

1 Like