Monkey-patching is basically just pulling a switcheroo on Python. Since Python
functions are first-class objects, you can redefine them and their variable
names at will.
A simple example:
--------------------------------
# In a menu.py
import nukescripts
def monkeyPatchedCreateRead():
nuke.message('No Read for you!')
nukescripts.create_read = monkeyPatchedCreateRead
--------------------------------
This will basically "break" the 'R' hotkey without changing any actual menu
commands. Of course, in this situation, I would actually recommend writing your
own create_read function and re-binding the 'R' hotkey rather than using the
monkey-patch approach, but in some situations it can be very handy (especially
if you’re trying to debug something in a hurry).
I’ve actually monkey-patched all of Nuke’s script
save/open/load/new/import/export functions in our pipe so I can easily inject
our custom file browser into those calls. This allows me to avoid having to
edit any of Nuke’s shipped Python code, and also easily turn the whole
mechanism on and off (since all the patches are performed in one function). The
important thing in this case is I keep the originals around under different
names so they can still be called if necessary (and many of my patch functions
are eventually calling the originals under the hood).
Anyway, hope this all makes sense.
-Nathan
From: coreydrake
Sent: Wednesday, October 26, 2011 9:59 AM
To: [email protected]
Subject: [Nuke-python] Re: Setting stereo views within a callback
Thanks Nathan. I have a knobChanged callback working correctly. I'm not
familiar with the term monkey-patch though. Would you be able to explain what
that means?
--------------------------------------------------------------------------------
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python