callbacksExt Extension

From TouchDesigner Documentation
Jump to: navigation, search


Python Callback System[edit]

The CallbackExt extension provides Python callback functionality to custom components. All callbacks will be passed a single argument containing an info dictionary. Callbacks can be defined in the DAT named in the Callback DAT parameter. To report all callbacks to the textport, turn on the Print Callbacks toggle parameter. The Callback DAT and Print Callbacks parameters are often found on the Callbacks parameter page, but their location can be customized.

The info dictionary always contains an "ownerComp" key. It will also have a "callbackName" key holding the callback name. It will sometimes contain an "about" key, describing the callback, and should always contain this key if a return value is expected. Generally, callbacks are called AFTER the internal method they are associated with, to allow over-riding of whatever that method does.

See also: CallbacksExt Extension

Adding CallbackExt to a Component[edit]

The standard way to add CallbackExt to a component is to add a Select DAT inside that component and rename it "CallbacksExt". Change the DAT parameter of CallbacksExt to expression mode and enter the expression:

op.TDModules.op('TDCallbacksExt')

Next, set one of the component's Extension Object parameters to:

op('./CallbacksExt').module.CallbacksExt(me)

If you want to access the callback functionality directly via the component, toggle the "Promote Extension" parameter for that extension.

To implement a system allowing a user callback DAT, you will want to add a custom "Callbackdat" DAT parameter. For testing you will usually want a custom "Printcallbacks" toggle parameter. Adding these parameters is generally done with the Component Editor.

Methods[edit]

DoCallback(callbackName, callbackInfo=None, callbackOrDat=None) → callbackInfo

If it exists, call the named callback in ownerComp.par.Callbackdat and return callbackInfo with the callback's return value placed in callbackInfo['returnValue']. If no callback is found, returns None.
If ownerComp has a parameter called Printcallbacks, and that parameter is True, callback debug info will be printed to textport.
  • callbackName - Name of callback to be called
  • callbackInfo - (Optional) Dictionary of info to be passed to callback. callbackInfo['ownerComp'] is automatically set to ownerComp. If callback needs special instructions, put them in callbackInfo['about'].
  • callbackOrDat - (Optional) Used to redirect callback to a DAT or specific function.


SetAssignedCallback(self, callbackName, callback, details=None)

An assigned callback is a python function assigned to a particlar callback name. When doCallback is called with callbackName, callback will be invoked instead of searching CallbackDat
  • callbackName - Name of callback to be called
  • callback - The callback or None to remove the assigned callback
  • details - Optional extra info to be passed in the ['details'] key of infoDict when callback is called.

PassCallbacksTo(self, passTarget)

Set a target DAT or function for passing on unfound callbacks to.
  • passTarget - a DAT or function

PassOnCallback(self, info)

Pass this callback (as named in info) to the callback stored in extension's PassTarget member. Use PassCallbacksTo to set target
  • info - the callback's info dict

-->

Members[edit]

CallbackDat

Get or set the dat containing user callbacks. This will set the value of the Callbackdat parameter as well, if it exists.

PrintCallbacks

Get or set whether to print callback info to the Textport

Some operators have a DAT docked to them that contains some python functions. These functions, called "callbacks", get called when something in the operator changes.

An Operator Family that manipulates text strings: multi-line text or tables. Multi-line text is often a command Script, but can be any multi-line text. Tables are rows and columns of cells, each containing a text string.

An Operator Family that contains its own Network inside. There are twelve 3D Object Component and eight 2D Panel Component types. See also Network Path.

The component types that are used to render 3D scenes: Geometry Component contain the 3D shapes to render, plus Camera, Light, Ambient Light, Null, Bone, Handle and other component types.

A dialog box in which commands and scripts can entered manually. Script errors and python print() messages are also output to the textport.