base_classes module

Contains the common base class defining the interface shared by all modules.

class ModuleBase(*args, **kwargs)

Bases: YamlLoadable

Base class defining the interface all modules in the framework must implement.

A module is implemented either as a tab or as a window (modal). The implementation can be set with the as_type argument when the module is instantiated, or be inferred by main_layout from whether the module is passed in tab_list or in window_list. layout returns the layout matching the chosen implementation.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Self

label

The label shown in the tab or on the sidebar button of the window.

Type:

str

module_name

The name of the module, defaults to the class name.

Type:

str

module_number

The value of the class-wide instance counter at the time the module was instantiated.

Type:

int

module_id

Unique id for the module, combining module_name and module_number.

Type:

str

module_layout

The layout of the module itself, without tab/window wrapping.

Type:

Div | Tab

implemented_as

Either “Tab”, “Window” or None if it has not been decided yet.

Type:

Optional[Literal['Tab', 'Window']]

icon

Optional icon shown next to the label.

Type:

str | Component

Note

Subclasses must set label, and any other attribute needed by _create_layout and module_callbacks, before calling ModuleBase.__init__. Ids used inside the module layout and its callbacks should be prefixed with self.module_id to keep them unique across modules.

icon: str | Component
implemented_as: Optional[Literal['Tab', 'Window']]
label: str
abstractmethod layout()

Create the layout of the module itself, without tab/window wrapping.

Return type:

Div

abstractmethod module_callbacks()

Define the callbacks belonging to the module itself.

Return type:

None

module_id: str
module_layout: Div | Tab
module_name: str
module_number: int
set_implementation(as_type)

Decide whether the module is implemented as a tab or as a window.

Called by main_layout for modules that were instantiated without as_type.

Parameters:

as_type (Literal['Tab', 'Window']) – Whether the module is implemented as a “Tab” or as a “Window”.

Raises:

ValueError – If as_type is not “Tab” or “Window”, or if the module is already implemented as the other type.

Return type:

None