[Tutor] how to temporarily disable a function

Dave Angel d at davea.name
Thu Jul 28 10:44:22 CEST 2011


On 07/27/2011 09:58 PM, Pete O'Connell wrote:
> Hi I was wondering if there is a way to disable a function.
> Hi have a GUI grid snapping function that I use in a program called Nuke
> (the film compositing software)
>
> Here is the function (which loads when Nuke loads):
> #######################
> def theAutoplaceSnap():
>      try:
>          nuke.thisNode().autoplace()
>          n = nuke.allNodes();
>          for i in n:
>            nuke.autoplaceSnap(i)
>      except:
>          pass
>
> nuke.addOnUserCreate(theAutoplaceSnap)
> ###################################
>
> I have many functions which get loaded, but this particular one needs to be
> disabled when I am viewing another compositors script in the gui.
>
> I have a python script editor in Nuke in which I can run code if need be to
> run code on the fly.
>
> Help
>
>
Presumably that function is defined in a different module than the one 
you're going to "disable" it from.  So, what you're attempting is 
commonly called "monkeypatching."

Let's say the module is   snapper  (in a file snapper.py).

All you probably need is to substitute another do-nothing function in 
its place.

import snapper

def donothing():
     return

snapper.theAutoplaceSnap = donothing

If it will need to be restored later, you can copy it to a variable in 
your own module, and then copy it back later.

-- 

DaveA

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110728/cb86d7f6/attachment.html>


More information about the Tutor mailing list