baseObject module

Contains the base classes that many of NVDA’s classes such as NVDAObjects, virtualBuffers, appModules, synthDrivers inherit from. These base classes provide such things as auto properties, and methods and properties for scripting and key binding.

class baseObject.Getter(fget, abstract=False)

Bases: object

setter(func)
deleter(func)
class baseObject.CachingGetter(fget, abstract=False)

Bases: Getter

class baseObject.AutoPropertyType(name, bases, namespace, /, **kwargs)

Bases: ABCMeta

class baseObject.AutoPropertyObject(*args, **kwargs)

Bases: TrackedObject

A class that dynamically supports properties, by looking up _get_*, _set_*, and _del_* methods at runtime. _get_x will make property x with a getter (you can get its value). _set_x will make a property x with a setter (you can set its value). _del_x will make a property x with a deleter that is executed when deleting its value. If there is a _get_x but no _set_x then setting x will override the property completely. Properties can also be cached for the duration of one core pump cycle. This is useful if the same property is likely to be fetched multiple times in one cycle. For example, several NVDAObject properties are fetched by both braille and speech. Setting _cache_x to C{True} specifies that x should be cached. Setting it to C{False} specifies that it should not be cached. If _cache_x is not set, L{cachePropertiesByDefault} is used. Properties can also be made abstract. Setting _abstract_x to C{True} specifies that x should be abstract. Setting it to C{False} specifies that it should not be abstract.

__instances = <WeakKeyDictionary at 0x508fd50>

Tracks the instances of this class; used by L{invalidateCaches}. @type: weakref.WeakKeyDictionary

cachePropertiesByDefault = False

Specifies whether properties are cached by default; can be overridden for individual properties by setting _cache_propertyName. @type: bool

_propertyCache: Set[Callable[[AutoPropertyObject], Any]]
_getPropertyViaCache(getterMethod: Callable[[AutoPropertyObject], Any] | None = None) Any
invalidateCache()
classmethod invalidateCaches()

Invalidate the caches for all current instances.

_abc_impl = <_abc._abc_data object>
class baseObject.ScriptableType(name, bases, dict)

Bases: AutoPropertyType

A metaclass used for collecting and caching gestures on a ScriptableObject

class baseObject.ScriptableObject(*args, **kwargs)

Bases: AutoPropertyObject

A class that implements NVDA’s scripting interface. Input gestures are bound to scripts such that the script will be executed when the appropriate input gesture is received. Scripts are methods named with a prefix of C{script_}; e.g. C{script_foo}. They accept an L{inputCore.InputGesture} as their single argument. Gesture bindings can be specified on the class by creating a C{__gestures} dict which maps gesture identifiers to script names. They can also be bound on an instance using the L{bindGesture} method. @cvar scriptCategory: If present, a translatable string displayed to the user

as the category for scripts in this class; e.g. in the Input Gestures dialog. This can be overridden for individual scripts by setting a C{category} attribute on the script method.

@type scriptCategory: str

_gestureMap

Maps input gestures to script functions. @type: dict

bindGesture(gestureIdentifier, scriptName)

Bind an input gesture to a script. @param gestureIdentifier: The identifier of the input gesture. @type gestureIdentifier: str @param scriptName: The name of the script, which is the name of the method excluding the C{script_} prefix. @type scriptName: str @raise LookupError: If there is no script with the provided name.

removeGestureBinding(gestureIdentifier)

Removes the binding for the given gesture identifier if a binding exists. @param gestureIdentifier: The identifier of the input gesture. @type gestureIdentifier: str @raise LookupError: If there is no binding for this gesture

clearGestureBindings()

Remove all input gesture bindings from this object.

bindGestures(gestureMap)

Bind or unbind multiple input gestures. This is a convenience method which simply calls L{bindGesture} for each gesture and script pair, logging any errors. For the case where script is None, L{removeGestureBinding} is called instead. @param gestureMap: A mapping of gesture identifiers to script names. @type gestureMap: dict of str to str

getScript(gesture)

Retrieve the script bound to a given gesture. @param gesture: The input gesture in question. @type gesture: L{inputCore.InputGesture} @return: The script function or C{None} if none was found. @rtype: script function

SLEEP_FULL = 'full'

A value for sleepMode which indicates that NVDA should fully sleep for this object; i.e. braille and speech via NVDA controller client is disabled and the user cannot disable sleep mode.

_abc_impl = <_abc._abc_data object>
_propertyCache: Set[Callable[[AutoPropertyObject], Any]]