MFunc:
Filter:
adclib/Classes (extension) | Modality

MFunc
ExtensionExtension

MFunc is a proxy for multiple, modal functions.

Description

MFunc is a proxy for multiple, modal functions which can replace a single function with easily configurable flexible behavior.

It contains a dictionary of named functions (i.e. a behavior repertoire), an ordered list of the function names, lists of combinations of functions, and lists of the currently active functions and names.

The MFunc's behavior can be reconfigured at any time:

MFunc is intended for use in modal interfaces, so for example, when a single slider has an MFunc as its action, it can have functions that

This is intended to replace complicated cascades of if-statements (which easily accumulate when coding modal user interface functions). Instead of setting flags for modes and reading them in control structure logic, one can use MFuncs to switch between modes by a. enabling the functions desired in the new mode, b. disabling the ones that should be off in the new mode, and c. keeping all other functions independent by leaving them untouched.

Class Methods

.new

make a new MFunc, like this:

Instance Methods

.activeNames

the names of the currently active funcs

.mode

get name of the currently active mode, set currently active mode by name.

.modes

the available modes

.modeLists

the modeLists

.funcDict

the repertoire of all functions

.orderedNames

the ordered names of all available functions

.activeFuncs

the currently active functions

.value

calls .value on the activeFuncs, returns a list of the return values.

.enable

.disable

enable and disable functions by name(s)

.add

add or replace a function by name, optionally relative to another name.

Arguments:

name

name by which to store func

func

the func to store

active

flag whether the func should become active

addAction

optional addAction, default is \addLast

otherName

addActions \addBefore, \addAfter need a name relative to which to add.

.remove

fully remove functions by name or names

.addFirst

.addLast

.replace

short methods indicating where to add or replace

.addBefore

.addAfter

short methods for adding relative to another name

Arguments:

name

the name for the new func

func

the new func to add

active

flag whether active

otherName

the name relative to which to add

.useTry

get and set flag whether to use .tryValue istead of .value

.tryValue

wrap all function evaluations in try { }, so that if one fails, it posts good info, and all later functions in the list will still be evaluated.

Examples