Code Monkey home page Code Monkey logo

pyvfx-boilerplate's Introduction

pyvfx-boilerplate

Tests PyPI

A boilerplate for creating PyQt4/PySide and PyQt5/PySide2 applications running in Maya, Nuke, Blender, 3DS Max, Houdini, Unreal Engine or completely standalone.

Documentation

Version 3.x

  • The entire boilerplate was re-written so it could be packaged and distributed with PyPi.
  • Adding Blender, 3DS Max, Houdini, and Unreal Engine support.

For details, see CHANGELOG.md.

Noteworthy known issues

  • Does not work with Nuke 10.0v1 on OS X: #7
  • Maya palette glitchy in standalone mode with PySide/PyQt4 on OS X (disabled by default): #9
  • Window will not stay on top of Nuke (OS X) without Qt.Tool or Qt.WindowStaysOnTopHint: #12

Installation

Easy way:

pip install pyvfx-boilerplate

Long way:

git clone https://github.com/fredrikaverpil/pyvfx-boilerplate.git
cd pyvfx-boilerplate
python setup.py sdist bdist_wheel
pip install dist/*

Example usage

Pip installs a program named pyvfx-boilerplate as an example Run as standalone: (you may need to additionally install PyQt4, PyQt5, PySide or PySide2 for standalone to work depending on your system configuration)

pyvfx-boilerplate

Run in script editor of Maya or Nuke:

import sys
sys.path.append('/path/to/pyvfx-boilerplate')
from pyvfx_boilerplate import boilerplate_ui
bpr = boilerplate_ui.BoilerplateRunner()
bpr.run_main()

Modifying the boilerplate

  • See inheritance example above

Development guidelines

Since the boilerplate relies on Qt.py, you should design your application as if you were designing it for PyQt5/PySide2. This means creating widgets using QtWidgets rather than QtGui. The Qt.py module takes care of the remapping and makes for compatibility with PyQt4/PySide. Read more over at the Qt.py repository.

Tip: when you cannot rely on Qt.py, create an issue (probably over at Qt.py) and/or detect which binding is being used and write some custom code:

from Qt import QtCompat

if QtCompat.__binding__ in ('PyQt4', 'PySide'):
    # Do something if PyQt4 or PySide is used

if QtCompat__binding.startswith('PySide'):
    # Do something if PySide or PySide2 is used

if QtCompat__binding == 'PySide2':
    # Do something if PySide2 is used

Issues

Something wrong, have a question or wish to file a feature request?

Open up an issue here!

Contribute

If you wish to contribute, pull requests are more than welcome!

pyvfx-boilerplate's People

Contributors

fredrikaverpil avatar nzanepro avatar sanfx 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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

pyvfx-boilerplate's Issues

Incompatible with Nuke 10 on OS X

Due to the fact that Nuke 10.0v1 for OS X is missing PySide.QtUiTools, the boilerplate won't work in that environment if you load .ui files via convenience function Qt.load_ui.

I've requested that The Foundry include PySide.QtUiTools with Nuke 10 on OS X, as it is included in Nuke 10.0v1 for Windows and Linux.

I will keep this issue open until this has been resolved in a future Nuke version.

Latest version checked which exhibits this issue: 10.5v1

launch as panel in nuke crop the window

Hi,
thanks a lot for the boilerplate, it has been very useful !
I got an issue though. My panel is over 500px high and when i launch it as a panel in nuke half of is hidden. Meaning only the top half is visible, even if my nuke panel is big enough.
It is a strange bug and i don't know where it's coming from. When i use the pyside example from nuke the panel looks fine and display all the way down.
Did you experienced something similar ?

Window will not stay on top of Nuke (OS X) without Qt.Tool or Qt.WindowStaysOnTopHint

On Mac OS X, I was unable to get the floating window to always stay on top of Nuke. If you click in the main Nuke window, the floating window would disappear behind the main Nuke window.

I reached out to the Foundry:

I'm creating a simple window with PySide and I parent it to the main Nuke application. In Windows this window will always stay on top of Nuke even if I click the main Nuke window.

In OS X however (and I assume perhaps also on Linux), if I click the Nuke window, my PySide window disappears behind Nuke. Why is that and can that be fixed?

Please note, I wish to keep the fullscreen/maximize/minimize window controls, so I'm not interested in setting the window flags to either Qt.Tool or Qt.WindowStaysOnTopHint.

Regards,
Fredrik

from PySide import QtGui, QtCore


class Boilerplate(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(Boilerplate, self).__init__(parent)

        # Set object name and window title
        self.setObjectName('hello')
        self.setWindowTitle('hello world!')

        # Window type (I don't want Qt.Tool)
        self.setWindowFlags(QtCore.Qt.Window)

        # Set the main widget
        self.main_widget = QtGui.QLabel('Hello world!')
        self.setCentralWidget(self.main_widget)


def _nuke_main_window():
    """Returns Nuke's main window"""
    for obj in QtGui.qApp.topLevelWidgets():
        if (obj.inherits('QMainWindow') and
                obj.metaObject().className() == 'Foundry::UI::DockMainWindow'):
            return obj
    else:
        raise RuntimeError('Could not find DockMainWindow instance')


my_window = Boilerplate(parent=_nuke_main_window())
my_window.show()  # Show the UI

This was the response from The Foundry:

This is really difficult to solve unfortunately. The Qt documentation for QWidget says that parenting a window to another will make it float above the other window, but the documentation is wrong and the behaviour is dependent on the window management policy for your platform. Having a floating window which doesn't get hidden when the application goes to the background is deemed un-Mac-like behaviour and not allowed. The only ways to get windows to float are to use Qt.Tool or Qt.WindowStaysOnTopHint which both have problems. In particular, Qt.WindowStaysOnTopHint makes the window stay on top of all windows even when the application is in the background. Nuke gets round this problem by manipulating the Qt.WindowStaysOnTopHint during application activation and deactivation, but to do this correctly requires writing Objective-C code and can't be done from Python (the equivalent Qt events don't get delivered at the correct time for this).

Possible solutions are:

Use Qt.Tool (I know this has already been dismissed, but it's here for completeness. Nuke does make sure that Qt.Tool windows don't get hidden when the application is deactivated, but you do lose the maximize/minimize buttons
Use the Nuke APIs to register the window as a panel, This will allow the window to be docked but also make it float correctly. I'm not sure if it solves the maximize/minimize buttons though.

So, as a workaround, the boilerplate is now setting the windows flag Qt.Tool, as I believe this a bit better than setting Qt.WindowStaysOnTopHint.

Unfortunately, there seems to be no way around this as for now.

Provide maya palette as separate file

In v1.0, the maya palette was implemented inside of the boilerplate which caused the file to gain ~100 rows of code. For v2.x, it would be better to put this code outside of the boilerplate.

PySide.QUiTools ?

You're writing in your readme about this but I can't find any of that in your repo?
Quiet possibly I'm confused..

Escape key doesn't close window

When pressing the escape key, one would expect the window to close. Currently however, it causes the contents of the window to close, but the window remains open.

I have tried both defining the eventFilter, which picks up keypresses, but not escape, and overriding keyPressEvent, which has the same behaviour as eventFilter.

class Boilerplate(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        ...
        self.installEventFilter(self)

    def eventFilter(self, widget, event):
        if event.type() == QtCore.QEvent.KeyPress:
            print 'press'
            if event.key() == QtCore.Qt.Key_Escape:
                print 'escape'
        return super(Boilerplate, self).eventFilter(widget, event)
class Boilerplate(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        ...
        self.keyPressEvent = self.newKeyPressEvent

    def newKeyPressEvent(self, event):
        print 'press'
        if event.key() == QtCore.Qt.Key_Escape:
            print 'escape'
            self.close()

Have a look

Hi,

I've made a cookiecutter version, check it out:
cookiecutter-pyvfx-boilerplate

This is really a copy paste of yours with minor updates and cookiecutterized.
I'll try to ehance it further but the workflow to code cookiecutters is not ideal, at least I haven't found an efficient workflow yet.

Thanks for the base.

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.