GithubHelp home page GithubHelp logo

huntfx / vfxwindow Goto Github PK

View Code? Open in Web Editor NEW
94.0 13.0 14.0 349 KB

Python Qt Window class for compatibility between VFX programs

License: MIT License

Python 99.94% Batchfile 0.06%
qt python maya nuke houdini substance-designer substance-painter blender pypi pypi-package

vfxwindow's Introduction

VFXWindow

Qt Window class for designing tools to be compatible between multiple VFX programs.

The main purpose of the class is to integrate into the program UI, but it also contains helpful features such as safely dealing with callbacks and automatically saving the window position.

The intended usage is to make your window class inherit VFXWindow - which is an instance of QMainWindow. By calling cls.show(), it will launch the correct window type based on what program is loaded, and what settings were previously saved.

This is perfectly stable, but there is still plenty that needs improvement. Maya, Nuke, 3DS Max, Houdini, Blender, Substance Designer, Unreal and Fusion are currently supported, though any help to extend those would be appreciated, as well as support for any other applications.

Installation

pip install vfxwindow

Basic Example:

class MyWindow(VFXWindow):
    WindowID = 'unique_window_id'
    WindowName = 'My Window'

    def __init__(self, parent=None, **kwargs):
        super(MyWindow, self).__init__(parent, **kwargs)
        # Setup window here

        # Setup callbacks, but wait until the program is ready
        self.deferred(self.newScene)

    def newScene(self, *args):
        """Example: Delete and reapply callbacks after loading a new scene."""
        self.removeCallbacks('sceneNewCallbacks')
        if self.application == 'Maya':
            self.addCallbackScene('kAfterNew', self.newScene, group='sceneNewCallbacks')
        elif self.application == 'Nuke':
            self.addCallbackOnCreate(self.newScene, nodeClass='Root', group='sceneNewCallbacks')

if __name__ == '__main__':
    MyWindow.show()

Support / Compatibility

✔️ Working / ❔ Untested / ❌ Not Working

Standard Window Docked Window Callbacks Tested Versions Linux Windows MacOs
Maya ✔️ ✔️ ✔️ 2011-2016, 2017+ ✔️ ✔️
Maya (Standalone) ✔️ ✔️ ✔️
Nuke ✔️ ✔️ ✔️ 9-12 ✔️
Nuke (Terminal) ✔️ ✔️ ✔️
Houdini ✔️ 16-19 ✔️ ✔️
Unreal Engine ✔️ 4.19-4.23, 5.0-5.3 ✔️
Blender ✔️ ✔️ 2.8-3.4 ✔️
3ds Max ✔️ 2018-2020 ✔️
Substance Painter ✔️ ✔️ 8.3 ✔️ ✔️
Substance Designer ✔️ ✔️ 2019.3, 7.1, 12.3 ✔️ ✔️
Blackmagic Fusion ✔️ 9 ✔️
CryEngine Sandbox ✔️ 5.7 ✔️
Standalone Python ✔️ 2.7 (Qt4), 3.7-3.9 (Qt5) ✔️

Features

  • Automatically save/restore window position
  • Move window to screen if out of bounds (windows only)
  • Keep track of callbacks to remove groups if required, and clean up on window close
  • Keep track of signals to remove groups if required
  • Display a popup message that forces control
  • Set palette to that of another program
  • Auto close if opening a duplicate window
  • Close down all windows at once
  • Create dialog windows automatically attached to the application (and return data)

Running with Non-Python Applications

Certain Windows applications have dispatch based COM interface, which will allow a link between Python and the application. See photoshop-scripting-python for an example on how to connect to an application.

Currently there is no way of launching VFXWindow from inside these applications.

Special Thanks

vfxwindow's People

Contributors

gpijat avatar huntfx avatar peter92 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vfxwindow's Issues

Is this supposed to address the Blender window freeze when the Qt window is open?

I'm just starting out on some PySide2 pipeline dev with Blender and I'm running into the issue where Blender's window freezes or doesn't update when the Qt window is open.

Does vfxwindow address that or do we still need to handle that on our own?

I've found a few workarounds, but they're not perfect- for example I can get Blender to not freeze by following this method, but if I try to move the main Blender window the whole program freezes. Same result with this method.

Seems like a cool package though, I'll look into implementing it into my project.

Latest release (1.6.4) is missing a lot of the latest improvements

Hello @huntfx,

The latest release who's the default one installed with pip is missing a lot of the latest improvements.
One I have for instance (Linux Mint - Maya 2022.4) is here:

if VERSION < 2017:

Error: # Error: TypeError: file /home/gpij/Workspace/vfxwindow/vfxwindow/maya.py line 488: '<' not supported between instances of 'str' and 'int' #

I think this is a really specific issue to Maya 2022 but It's a good example for this current issue as it's addressed on the master branch.

PS: To run on linux I changed https://github.com/huntfx/vfxwindow/blob/679c4348ff3956e4be47994135888544d57409dc/vfxwindow/__init__.py#L64 to use maya.bin instead of maya.exe. As a temporary workaround to test the rest of the library.
For Linux, I'm working on some changes that I would like to submit to your approval, I'm talking about it here: #3 (comment)

Thank you.

Integrate some of bqt

A coworker came across this for Blender, will have a look at some point to see if it's worth integrating any of it.

Maya issue - AttributeError: 'NoneType' object has no attribute 'layout'

Hi Peter,

I am trying to make a cross application plugin to be run on Maya, Blender, 3DSMax, Unreal, Unity3D, and Standalone Python and it seems your package is the perfect fit (that sounds dirty some how). I am currently using Qt.py on top of PySide2 and have a functioning version for the most part.

As a test I have tried incorporating VFXWindow to ease the management required to handle the window management, but I am unable to get it to display a window properly due to the following error in Maya:

# Error: 'NoneType' object has no attribute 'layout'
# Traceback (most recent call last):
#   File "<maya console>", line 2, in <module>
#   File "C:\Users\gary\Projects\Area28\Area28Module\vendor\area28\ui\__init__.py", line 88, in create
#     ui_window = met(*args, **kwargs)
#   File "C:\Users\gary\Projects\Area28\Area28Module\vendor\area28\ui\about.py", line 54, in __init__
#     self.setCentralWidget(self.container)
#   File "C:\Users\gary\Projects\Area28\Area28Module\vendor\vfxwindow\maya.py", line 548, in setCentralWidget
#     self.parent().layout().takeAt(0)
# AttributeError: 'NoneType' object has no attribute 'layout'

And within Blender I get an error due to no QApplication defined.

QWidget: Must construct a QApplication before a QWidget

Questions

  1. Does VFXWindow manage parenting the QMainWindow within the application as it looks like the parent is not defined in Maya (2020.3) and in Blender (2.82) the QApplication is not defined.

  2. Should I still pass in the parent window (created by myself in Blender, and returned from omui.MQtUtil.mainWindow() in Maya) and do I still need to wrapInstance() as I noticed you have an implementation of wrapInstance?

  3. What would be the best way to approach multiple windows, as an example I have an about, chat, login. For my current solution I have built a ui manager that stores a reference to the window and replaces it each time a new ui is shown.

  4. Is there somewhere I can find a slightly more complete example. I have looked at the wiki page and the tests but both seem very minimal?

Code Snippets

Below is the manager used to create the ui using a string to load the module eg ui.create('account.LoginUI'):

def create(interface, *args, **kwargs):
    """Create a window using the provided UI class. A check is made to ensure
    that only one window is open at any point in time.
    """
    log.debug('creating window: {}'.format(interface))
    global ui_window

    # delete the current interface before creating a new one
    delete()

    if ui_window is None:
        p, m = interface.rsplit('.', 1)
        mod = import_module(__name__ + '.' + p)
        met = getattr(mod, m)
        # ui_window = met(parent=get_main_window(), *args, **kwargs)
        ui_window = met(*args, **kwargs)

        log.debug('created window {} ({})'.format(ui_window.objectName(), ui_window.windowType()))

    result = ui_window.show()

and below is an example of using the ui to create an about window:

from area28 import PREFIX, PATH
from area28.utils import logger
from vfxwindow import VFXWindow
from PySide2 import QtWidgets, QtSvg, QtGui

# setup the logger for this module
log = logger.getLogger(__name__)


class AboutUI(VFXWindow):
    WindowID = PREFIX + 'AboutUI'
    WindowName = PREFIX + 'AboutUI'
    WindowDockable = True

    def __init__(self, parent=None, **kwargs):
        super(VFXWindow, self).__init__(parent, **kwargs)

        # add the window icon
        self.icon = QtGui.QIcon(area28.PATH + '/../../icons/logo.svg')
        self.setWindowIcon(self.icon)

        # build the interface for the window
        self.container = QtWidgets.QWidget()
        self.main_layout = QtWidgets.QVBoxLayout()
        self.container.setLayout(self.main_layout)
        self.setCentralWidget(self.container)

        # initialize the interface
        self.init_ui()

    def init_ui(self):

        # add the banner
        self.banner = QtSvg.QSvgWidget(area28.PATH + '/../../icons/banner.svg')
        self.banner.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)

        # add our widgets to the layout
        self.main_layout.addWidget(self.banner)

Fork error on MacOS

When running in standalone mode on MacOS, having a window open another window causes the following error:

The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.

This seems to be related to the _MultiAppLaunch class within standalone.py

Support for other operating systems

In the init.py checks are getting made on sys.executable that restrict proper functionality to windows only (checking if maya.exe is the executable for example).

Would you like me to provide a pull request for a more generic way of doing the checks? From what I see, the reason for these is to make sure its not a module with the same name not within the program, and to differentiate between maya and mayapy?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.