mgear.core.callbackManager module

API for creating, deleting, debuging callbacks

# examples ——————————————————————– # module cb.selectionChangedCB(“testingSessssslection”, cb.testFunc) cb.RECORDED_CALLBACKS cb.removeAllSessionCB()

# manager A e = cb.CallbackManager() e.namespace e.debug = False e.selectionChangedCB(“synopticUI1”, cb.testFunc) e.newSceneCB(“synopticNewScene”, cb.testFunc) e.removeManagedCB(“synopticUI1”) e.removeManagedCB(“synopticNewScene”)

e.attributeChangedCB(“attrChanged”, cb.testFunc, “pSphere1”, [“tx”]) e.removeManagedCB(“attrChanged”)

e.MANAGER_CALLBACKS e.removeAllManagedCB()

# manager b r = cb.CallbackManager() r.selectionChangedCB(“synopticUI1”, cb.testFunc) r.MANAGER_CALLBACKS r.removeAllManagedCB()

__author__ = “Rafael Villar” __email__ = “rav@ravrigs.com

class mgear.core.callbackManager.AttributeChangedManager(m_node, attributes, func)

Bases: object

mini class that will be called upon when attrChanged callback is run this will check the plugs passed in to see if it is an attr of desired name

attributes

[tx, ty] of SHORT NAMED attrs to monitor

Type:

list

func

to call when criteria met

Type:

function

m_node

mobject

Type:

om.MOBJECT

attributeChanged(id, plug1, plug2, payload)

actual function that will be called when attrChanged callback is created

Parameters:
  • id (int) – 2056 is the desired, attr changed id

  • plug1 (om.MPlug) – MPlug attr to query

Returns:

n/a

Return type:

n/a

class mgear.core.callbackManager.CallbackManager

Bases: object

Convenience to manage callbacks

debug

should callbacks created by manager produce print outs

Type:

bool

MANAGER_CALLBACKS

record of all created callbacks

Type:

dict

namespace

namespace to put callbacks under

Type:

str

addNamespace(callback_name)

used in the decorator, add namespace to any name provided

Parameters:

callback_name (str) – name of callback

Returns:

provided name with namespace

Return type:

str

attributeChangedCB(callback_name, func, node, attributes)
checkDebug(debugInfo, *args)

safely check if manager is in debug mode

Parameters:
  • debugInfo (list) – callback name, function being called with args

  • *args – args to pass to the function associated with callback

newSceneCB(callback_name, func)
registerManagerCB()

decorator, adds debug and namespace to every callback created

Parameters:

func (function) – function to wrap

Returns:

wrapped function

Return type:

function

removeAllManagedCB()

remove all the callbacks created my this manager

removeManagedCB(callback_name)

remove specific callback under this manager

Parameters:

callback_name (str) – name

selectionChangedCB(callback_name, func)
setNamespace(namespace)

set the namespace to put callbacks under

Parameters:

namespace (str) – desired namespace

timeChangedCB(callback_name, func)
userTimeChangedCB(callback_name, func)
wrapWithDebug(debugInfo, func)

so every function that is associated with a callback is swapped out for this one, so it will check for debugging

Parameters:
  • debugInfo (list) – callback name, mayacallback id, functions to call

  • func (function) – to wrap with this debug checker

Returns:

partial function that will check for debug

Return type:

function

class mgear.core.callbackManager.UserTimeChangedManager(func)

Bases: object

mini class that will be called upon when timeChanged callback is run this will check to see if playback is active, if so BREAK

attributes

[tx, ty] of SHORT NAMED attrs to monitor

Type:

list

func

to call when criteria met

Type:

function

m_node

mobject

Type:

om.MOBJECT

userTimeChanged(*args)

Check if playback is active, if so return without calling func

mgear.core.callbackManager.attributeChangedCB(callback_name, func, node, attributes)

call the provided function any of the provided attributes are changed

Parameters:
  • callback_name (str) – name of the callback

  • func (function) – to be called upon

  • node (str) – name of node to montior for attr changes

  • attributes (list) – of SHORTNAMED attributes to monitor

Returns:

maya id to created callback

Return type:

long

mgear.core.callbackManager.checkAndRecordCB(callback_name, callback_id, callback_info={})

will remove any callbacks of the same name prior to creating a new one

Parameters:
  • callback_name (str) – desired name of the callback, readable

  • callback_id (long) – api method of identifying callbacks

mgear.core.callbackManager.getMObject(node)

get the mobject of any name provided, so it can have cb’s assined to it

Parameters:

node (str) – of node

Returns:

MOBJECT

Return type:

om.MObject

mgear.core.callbackManager.newSceneCB(callback_name, func)

When a new scene is opened, call the provided function

Parameters:
  • callback_name (str) – name you want to assign cb

  • func (function) – will be called upon

Returns:

maya id to created callback

Return type:

long

mgear.core.callbackManager.registerSessionCB(func)

decorator to ensure that every callback created is recorded

Parameters:

func (function) – function that will create the callback

Returns:

function

Return type:

function

mgear.core.callbackManager.removeAllCBFromNode(node)

remove all callbacks from the provided node

Parameters:

node (str) – name of node to remove callbacks from

mgear.core.callbackManager.removeAllSessionCB()

Remove all the callbacks created in this session, provided they are in the RECORDED_CALLBACKS dict

mgear.core.callbackManager.removeCB(callback_identifier, callback_info={})

Remove callback from scene and RECORDED_CALLBACKS(or provided dict)

Parameters:
  • callback_identifier (str) – name of callback

  • callback_info (dict, optional) – dict to remove callback from

mgear.core.callbackManager.removeCBviaMayaID(mayaID, callback_info={})

This if have the maya pointer only, this will remove it from the recorded_callbacks as well

Parameters:
  • mayaID (long) – maya point to a callback

  • callback_info (dict, optional) – remove it from desired cb recorder

mgear.core.callbackManager.removeNamespaceCB(namespace)

Remove all callbacks under the provided namespace

Parameters:

namespace (str) – uuid or other type of namespace

mgear.core.callbackManager.sampleCallback(callback_name, func)

argument order is important. Callback_name and func must always be first must always return the mayaID to the callback :param callback_name: name you want to assign cb :type callback_name: str :param func: will be called upon :type func: function

Returns:

maya id to created callback

Return type:

long

mgear.core.callbackManager.selectionChangedCB(callback_name, func)

When the selection is changed call the provided function

Parameters:
  • callback_name (str) – name you want to assign cb

  • func (function) – will be called upon

Returns:

maya id to created callback

Return type:

long

mgear.core.callbackManager.testFunc(*args)

test function used for debugging/dev

Parameters:

*args – things that will printed

mgear.core.callbackManager.timeChangedCB(callback_name, func)

ANYTIME the time is changed, call the provided function

Parameters:
  • callback_name (str) – name you want to assign cb

  • func (function) – will be called upon

Returns:

maya id to created callback

Return type:

long

mgear.core.callbackManager.userTimeChangedCB(callback_name, func)

Callback triggers during user timeChange, skips PLAYBACK

Parameters:
  • callback_name (str) – name you want to assign cb

  • func (function) – will be called upon

Returns:

maya id to created callback

Return type:

long