Extensions#

extendable#

tkclasswiz.extensions.extendable(obj: T | list) T#

Decorator that makes the obj extendable.

It wraps the obj, which is a class or a function, into an extension object. The extension object will adds 3 methods to the original class or function:

  • register_pre_extension

  • register_post_extension

  • get_extensions

The get_extensions method just returns the list of registered extensions (tkclasswiz.extensions.Extension).

The register_pre_extension and register_post_extension methods allow users to extend the functionality of original tkclass wiz classes or functions. They accept the extension (tkclasswiz.extensions.Extension) parameter.

Pre-extensions (register_pre_extension) get activated / called before the original __init__ method / before the original function and accept the loader of the extension must accept the same arguments as the original __init__ method / original function.

Post-extensions differ a bit if the thing being extended is a class or a function. They both have in common that they get activated after the original __init__ method call / original function call, but they differ in the arguments they receive:

  • In the case of the extended is a class, the extension loader accepts the same arguments as the __init__ method receives.

  • In the case of the extended is a function, the extension loader accepts the same arguments as the original function and an additional parameter, which is the result of the original function call. The result parameter is passed to the loader as the last positional argument.

Parameters:

obj (T) – Function or a class that can be extended.