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: Optional[str] = None, field: Optional[str] = None)¶
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 callgetattr
for this field on the object.
- __init__(header: Optional[str] = None, field: Optional[str] = None)¶
Initialize our IDisplaySetting.
- Parameters:
header – Header for display
field – Optional field to display instead of object
- get_object(obj: Any) Any ¶
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 ¶
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: Optional[str] = None, field: Optional[str] = None)¶
Bases:
idmtools.utils.display.displays.IDisplaySetting
Class that displays the object as string.
- display(obj)¶
Display object.
- Parameters:
obj – Object to display
- Returns:
String of object
- class idmtools.utils.display.displays.DictDisplaySetting(header: Optional[str] = None, field: Optional[str] = None, max_items: int = 10, flat: bool = False)¶
Bases:
idmtools.utils.display.displays.IDisplaySetting
Class that displays a dictionary.
- __init__(header: Optional[str] = None, field: Optional[str] = None, max_items: int = 10, flat: bool = False)¶
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.
- class idmtools.utils.display.displays.TableDisplay(columns, max_rows=5, field=None)¶
Bases:
idmtools.utils.display.displays.IDisplaySetting
Class that displays the object as a table.
- __init__(columns, max_rows=5, field=None)¶
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.