Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fusion: Implement callbacks to Fusion's event system thread #3928

Merged
merged 6 commits into from Oct 10, 2022

Conversation

BigRoy
Copy link
Collaborator

@BigRoy BigRoy commented Sep 28, 2022

Brief description

Implements "save", "open" and "new" OpenPype events based on Fusion notifications of certain events.

Description

Note that the Fusion events may not be 100% reliable. It could still be that a 'different action' might need to be listened to - but these events implemented now seemed reliable enough.

Additional info

This adds a background QThread with the OpenPype menu which will listen to the Fusion events for comp open, save and new comp. This has the downside that IF you were to ever open the OpenPype menu twice (or more times) that the Events will be heard multiple time and each running instance of the menu would then trigger the callbacks to happen.

As such - a next step likely would be to figure out a way for the menu to just get raised instead of re-requested to open if it was already opened for the current fusion session so that only ever a single OpenPype session/menu would be open for that Fusion session. This is difficult with Fusion because the scripts run in a separate background process each, disconnected from the Fusion app process itself.

Likely we'll need to keep a port open on the process that will highlight to fusion that the current process ID already has a menu open, or alike. However, at the same time - multiple Fusions might be open which do each want their own menu. So we'll still need to be able to identify per Fusion session too.

Testing notes:

  1. Start Fusion, Start OpenPype menu.
  2. You should get outdated containers reports on Comp open (if they have any outdated containers) and on Save it should also report if your current comp doesn't match the asset FPS, etc.

Comment on lines +45 to +51
class FusionLogHandler(logging.Handler):
# Keep a reference to fusion's Print function (Remote Object)
_print = getattr(sys.modules["__main__"], "fusion").Print

def emit(self, record):
entry = self.format(record)
comp = get_current_comp()
if comp:
comp.Print(entry)
self._print(entry)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly an optimization.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning: I've just found that this logic does not work in Fusion 17.2 (released around June 2021) but does work in Fusion 17.4 since the fusion instance does not have a Print method in the older Fusion.

We might need to introduce a fallback to support older fusion versions.

Comment on lines +22 to +27

# We don't need to call Test because PyRemoteObject of the app
# will actually fail to even resolve the Test function if it has
# gone down. So we can actually already just check by confirming
# the method is still getting resolved. (Optimization)
if app.Test is None:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As comment explains this will mostly result in less delays (since calling Test() actually called against the main fusion UI).

@BigRoy BigRoy self-assigned this Sep 28, 2022
Copy link
Member

@jakubjezek001 jakubjezek001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice one!
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants