User interfacing
Utility classes for light user interfacing.
FancyLogger and FancyPrinter provide the same API, only difference is that FancyLogger will output to the logging system and FancyPrinter uses standard print function to print the output to sys.stdout. FancyStringifier can be used in general case when output is need in string form.
FancyLogger
dcase_util.ui.FancyLogger
This class provides extra formatting when using logging. If Python logging is not yet initialized when calling
FancyLogger, dcase_util.utils.setup_logging
is first called.
Usage examples:
1ui = dcase_util.ui.FancyLogger()
2ui.title('title')
3ui.section_header('section_header')
4ui.sub_header('sub_header')
5ui.foot('foot')
6ui.line('line', indent=2)
7ui.line('line', indent=4)
8ui.line('line', indent=6)
9
10# Data row with field and value
11ui.data('data field', 'value', 'unit')
12
13# Horizontal separator
14ui.sep()
15
16# Table
17ui.table(cell_data=[[1, 2, 3], [1, 2, 3]])
18
19# Faster way to create output tables without collecting data into one data structure.
20ui.row('Header1', 'Header2', widths=[10,20], types=['float2','str20'])
21ui.row('-','-')
22ui.row(10.21231, 'String text')
Output:
[I] title
[I] section_header
[I] ========================================
[I] === sub_header ===
[I] foot
[I]
[I] line
[I] line
[I] line
[I] data field : value unit
[I] ========================================
[I] Col #0 Col #1
[I] ------ ------
[I] 1 1
[I] 2 2
[I] 3 3
[I]
[I] Header1 | Header2 |
[I] ------- | ----------------- |
[I] 10.21 | String text |
Logger class |
|
|
Generic line logger Multiple lines are split and logged separately |
|
Table row |
Reset table row formatting |
|
|
Table separator row |
|
Table row showing internally accumulated sum of previous row values per column |
|
Table row showing internally accumulated average of previous row values per column |
|
Title, logged at info level |
|
Section header, logged at info level |
|
Sub header |
|
Footer, logged at info level |
|
Data line logger |
|
Horizontal separator, logged at info level |
|
Data table |
|
Info line logger |
|
Debug line logger |
|
Error line logger |
FancyPrinter
dcase_util.processors.FancyPrinter
This class provides uniformly formatted status printing to the console.
Usage examples:
1ui = dcase_util.ui.FancyPrinter()
2ui.title('title')
3ui.section_header('section_header')
4ui.sub_header('sub_header')
5ui.foot('foot')
6ui.line('line', indent=2)
7ui.line('line', indent=4)
8ui.line('line', indent=6)
9
10# Data row with field and value
11ui.data('data field', 'value', 'unit')
12
13# Horizontal separator
14ui.sep()
15
16# Table
17ui.table(cell_data=[[1, 2, 3], [1, 2, 3]])
18
19# Faster way to create output tables without collecting data into one data structure.
20ui.row('Name', 'Value', widths=[10,20], types=['str20','float2','float2'])
21ui.row_sep()
22ui.row('A', 8.89)
23ui.row('B', 3.23)
24ui.row('C', 2.57)
25ui.row_sep()
26ui.row_sum()
27ui.row_average()
Output:
title
section_header
========================================
=== sub_header ===
foot
line
line
line
data field : value unit
========================================
Col #0 Col #1
------ ------
1 1
2 2
3 3
Name Value
------- -----------------
A 8.89
B 3.23
C 2.57
------- -----------------
Sum 14.69
Avg 4.90
|
Printer class |
|
Generic line logger Multiple lines are split and logged separately |
|
Table row |
Reset table row formatting |
|
|
Table separator row |
|
Title, logged at info level |
|
Section header, logged at info level |
|
Sub header |
|
Footer, logged at info level |
|
Data line logger |
|
Horizontal separator, logged at info level |
|
Data table |
|
Info line logger |
|
Debug line logger |
|
Error line logger |
FancyHTMLPrinter
dcase_util.processors.FancyHTMLPrinter
This class provides rich HTML formatted output printing in IPython/Jupyter.
|
Printer class for rich HTML formatted output in IPython/Jupyter |
|
Generic line logger Multiple lines are split and logged separately |
|
Table row |
Reset table row formatting |
|
|
Table separator row |
|
Table row showing internally accumulated sum of previous row values per column |
|
Table row showing internally accumulated average of previous row values per column |
|
Title, logged at info level |
|
Section header, logged at info level |
|
Sub header |
|
Footer, logged at info level |
|
Data line logger |
|
Horizontal separator, logged at info level |
|
Data table |
|
Info line logger |
|
Debug line logger |
|
Error line logger |
FancyStringifier
dcase_util.processors.FancyStringifier
This class can be used to produce uniformly formatted output strings.
Fancy UI |
|
|
Title |
|
Section header |
|
Sub header |
|
Footer |
|
Line |
|
Format value into string. |
|
Data line |
|
Horizontal separator |
|
Data table |
|
Table row |
Reset table row formatting |
|
|
Table separator row |
|
Table row showing internally accumulated sum of previous row values per column |
|
Table row showing internally accumulated average of previous row values per column |
|
Class name |
FancyHTMLStringifier
dcase_util.processors.FancyHTMLStringifier
This class can be used to produce HTML formatted output strings.
Fancy UI to produce HTML output |
|
|
Title |
|
Section header |
|
Sub header |
|
Footer |
|
Line |
Format value into string. |
|
|
Data line |
|
Horizontal separator |
|
Data table |
|
Table row |
Reset table row formatting |
|
|
Table separator row |
|
Table row showing internally accumulated sum of previous row values per column |
|
Table row showing internally accumulated average of previous row values per column |
|
Class name |