idmtools.utils.display.displays module

Tools around displays and formatting.

Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.

class idmtools.utils.display.displays.IDisplaySetting(header: str | None = None, field: str | None = None)[source]

Bases: object

Base class for a display setting.

The child class needs to implement the display() method.

Includes:

  • header: Optional header for the display.

  • field: If specified, the get_object() will call getattr for this field on the object.

__init__(header: str | None = None, field: str | None = None)[source]

Initialize our IDisplaySetting.

Parameters:
  • header – Header for display

  • field – Optional field to display instead of object

get_object(obj: Any) Any[source]

Get object or field depending if field is set.

Parameters:

obj – Object to get

Returns:

Either obj.field or obj depending if self.field is set

abstract display(obj: Any) str[source]

Display the object.

Note that the attribute (identified by self.field) should be handled with get_object().

Parameters:

obj – The object to consider for display.

Returns:

A string representing what to show.

class idmtools.utils.display.displays.StringDisplaySetting(header: str | None = None, field: str | None = None)[source]

Bases: IDisplaySetting

Class that displays the object as string.

display(obj)[source]

Display object.

Parameters:

obj – Object to display

Returns:

String of object

class idmtools.utils.display.displays.DictDisplaySetting(header: str | None = None, field: str | None = None, max_items: int = 10, flat: bool = False)[source]

Bases: IDisplaySetting

Class that displays a dictionary.

__init__(header: str | None = None, field: str | None = None, max_items: int = 10, flat: bool = False)[source]

DictDisplay.

Parameters:
  • header – Optional field header.

  • field – The field in the object to consider.

  • max_items – The maximum number of items to display.

  • flat – If False, display as a list; if True, display as a comma-separated list.

display(obj: Any) str[source]

Display a dictionary.

Parameters:

obj – Object to display

Returns:

String display of object

class idmtools.utils.display.displays.TableDisplay(columns, max_rows=5, field=None)[source]

Bases: IDisplaySetting

Class that displays the object as a table.

__init__(columns, max_rows=5, field=None)[source]

Initialize our TableDisplay.

Parameters:
  • columns – A list of display settings.

  • max_rows – The maximum number of rows to display.

  • field – The field of the object to consider.

display(obj) str[source]

Display our object as a table.

Parameters:

obj – Object to display

Returns:

Table represented as a string of the object