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       |

FancyLogger()

Logger class

FancyLogger.line([field, indent, level, data])

Generic line logger Multiple lines are split and logged separately

FancyLogger.row(*args, **kwargs)

Table row

FancyLogger.row_reset()

Reset table row formatting

FancyLogger.row_sep([separator_char])

Table separator row

FancyLogger.row_sum([label])

Table row showing internally accumulated sum of previous row values per column

FancyLogger.row_average([label])

Table row showing internally accumulated average of previous row values per column

FancyLogger.title(text[, level])

Title, logged at info level

FancyLogger.section_header(text[, indent, level])

Section header, logged at info level

FancyLogger.sub_header([text, indent, level])

Sub header

FancyLogger.foot([text, time, item_count, ...])

Footer, logged at info level

FancyLogger.data([field, value, unit, ...])

Data line logger

FancyLogger.sep([level, length, indent])

Horizontal separator, logged at info level

FancyLogger.table([cell_data, ...])

Data table

FancyLogger.info([text, indent])

Info line logger

FancyLogger.debug([text, indent])

Debug line logger

FancyLogger.error([text, indent])

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

FancyPrinter([colors])

Printer class

FancyPrinter.line([field, indent, level])

Generic line logger Multiple lines are split and logged separately

FancyPrinter.row(*args, **kwargs)

Table row

FancyPrinter.row_reset()

Reset table row formatting

FancyPrinter.row_sep([separator_char])

Table separator row

FancyPrinter.title(text[, level])

Title, logged at info level

FancyPrinter.section_header(text[, indent, ...])

Section header, logged at info level

FancyPrinter.sub_header([text, indent, level])

Sub header

FancyPrinter.foot([text, time, item_count, ...])

Footer, logged at info level

FancyPrinter.data([field, value, unit, ...])

Data line logger

FancyPrinter.sep([level, length, indent])

Horizontal separator, logged at info level

FancyPrinter.table([cell_data, ...])

Data table

FancyPrinter.info([text, indent])

Info line logger

FancyPrinter.debug([text, indent])

Debug line logger

FancyPrinter.error([text, indent])

Error line logger

FancyHTMLPrinter

dcase_util.processors.FancyHTMLPrinter

This class provides rich HTML formatted output printing in IPython/Jupyter.

FancyHTMLPrinter([colors])

Printer class for rich HTML formatted output in IPython/Jupyter

FancyHTMLPrinter.line([field, indent, level])

Generic line logger Multiple lines are split and logged separately

FancyHTMLPrinter.row(*args, **kwargs)

Table row

FancyHTMLPrinter.row_reset()

Reset table row formatting

FancyHTMLPrinter.row_sep([separator_char])

Table separator row

FancyHTMLPrinter.row_sum([label])

Table row showing internally accumulated sum of previous row values per column

FancyHTMLPrinter.row_average([label])

Table row showing internally accumulated average of previous row values per column

FancyHTMLPrinter.title(text[, level])

Title, logged at info level

FancyHTMLPrinter.section_header(text[, ...])

Section header, logged at info level

FancyHTMLPrinter.sub_header([text, indent, ...])

Sub header

FancyHTMLPrinter.foot([text, time, ...])

Footer, logged at info level

FancyHTMLPrinter.data([field, value, unit, ...])

Data line logger

FancyHTMLPrinter.sep([level, length, indent])

Horizontal separator, logged at info level

FancyHTMLPrinter.table([cell_data, ...])

Data table

FancyHTMLPrinter.info([text, indent])

Info line logger

FancyHTMLPrinter.debug([text, indent])

Debug line logger

FancyHTMLPrinter.error([text, indent])

Error line logger

FancyStringifier

dcase_util.processors.FancyStringifier

This class can be used to produce uniformly formatted output strings.

FancyStringifier()

Fancy UI

FancyStringifier.title(text)

Title

FancyStringifier.section_header(text[, indent])

Section header

FancyStringifier.sub_header([text, indent])

Sub header

FancyStringifier.foot([text, time, ...])

Footer

FancyStringifier.line([field, indent, data])

Line

FancyStringifier.formatted_value(value[, ...])

Format value into string.

FancyStringifier.data([field, value, unit, ...])

Data line

FancyStringifier.sep([length, indent])

Horizontal separator

FancyStringifier.table([cell_data, ...])

Data table

FancyStringifier.row(*args, **kwargs)

Table row

FancyStringifier.row_reset()

Reset table row formatting

FancyStringifier.row_sep([separator_char])

Table separator row

FancyStringifier.row_sum([label])

Table row showing internally accumulated sum of previous row values per column

FancyStringifier.row_average([label])

Table row showing internally accumulated average of previous row values per column

FancyStringifier.class_name(class_name[, indent])

Class name

FancyHTMLStringifier

dcase_util.processors.FancyHTMLStringifier

This class can be used to produce HTML formatted output strings.

FancyHTMLStringifier()

Fancy UI to produce HTML output

FancyHTMLStringifier.title(text[, tag])

Title

FancyHTMLStringifier.section_header(text[, ...])

Section header

FancyHTMLStringifier.sub_header([text, ...])

Sub header

FancyHTMLStringifier.foot([text, time, ...])

Footer

FancyHTMLStringifier.line([field, indent, data])

Line

FancyHTMLStringifier.formatted_value(value)

Format value into string.

FancyHTMLStringifier.data([field, value, ...])

Data line

FancyHTMLStringifier.sep([length, indent, ...])

Horizontal separator

FancyHTMLStringifier.table([cell_data, ...])

Data table

FancyHTMLStringifier.row(*args, **kwargs)

Table row

FancyHTMLStringifier.row_reset()

Reset table row formatting

FancyHTMLStringifier.row_sep(**kwargs)

Table separator row

FancyHTMLStringifier.row_sum([label])

Table row showing internally accumulated sum of previous row values per column

FancyHTMLStringifier.row_average([label])

Table row showing internally accumulated average of previous row values per column

FancyHTMLStringifier.class_name(class_name)

Class name