ironflow.gui.draws_widgets module

ipywidgets holds each instantiated widget independently, and they aren’t released to the garbage collector until their close method has been called and there are no further references to their instance.

If we’re not careful, this can lead to a massive bloat of the registered widgets and memory strain. Here, we introduce a abstract class to help manage the closure of the widgets we create.

class ironflow.gui.draws_widgets.AbstractPostCaller(name, bases, namespace, /, **kwargs)[source]

Bases: PostCaller, ABCMeta

class ironflow.gui.draws_widgets.DrawsWidgets(*args, **kwargs)[source]

Bases: ABC

A mixin for classes that instantiate at least one ipywidgets widget during their __init__ and _only_ instantiate other widgets in methods decorated with the draws_widgets decorator.

All instantiated widgets are logged and can then be destroyed with the clear or close methods for those widgets instantiated since the last clear call or all instantiated widgets, respectively.

Children will instantiate one widget attribute, which will be of type main_widget_class, which must be of type ipywidgets.Box (i.e. it takes a list of children as its first argument.)

Note: Child classes will need to additionally define __new__ to pull out all args

and kwargs that are explicitly passed into the init, and pass on only super().__new__(cls, *args, **kwargs) upstream.

clear()[source]

Delete all widgets instantiated between the end of init and the last clear call.

close()[source]

Call clear, then delete all widgets instantiated in init.

main_widget_class

alias of Box

class ironflow.gui.draws_widgets.PostCaller[source]

Bases: type

Inspired by [@Cam.Davidson.Pilon](https://stackoverflow.com/questions/795190/how-to-perform-common-post-initialization-tasks-in-inherited-classes)

ironflow.gui.draws_widgets.draws_widgets(fnc: Callable) Callable[source]

A decorator for any class methods that instantiate new widgets outside init.