TextFormatter: Common text formatter

This package provides a class sharred by widget from the data module to format data as text in the same way.

class TextFormatter(parent=None, formatter=None)[source]

Formatter to convert data to string.

The method toString() returns a formatted string from an input data using parameters set to this object.

It support most python and numpy data, expecting dictionary. Unsupported data are displayed using the string representation of the object (str).

It provides a set of parameters to custom the formatting of integer and float values (setIntegerFormat(), setFloatFormat()).

It also allows to custom the use of quotes to display text data (setUseQuoteForText()), and custom unit used to display imaginary numbers (setImaginaryUnit()).

The object emit an event formatChanged every time a parametter is changed.

formatChanged

Emitted when properties of the formatter change.

integerFormat()[source]

Returns the format string controlling how the integer data are formated by this object.

This is the C-style format string used by python when formatting strings with the modulus operator.

Return type

str

setIntegerFormat(value)[source]

Set format string controlling how the integer data are formated by this object.

Parameters

value (str) – Format string (e.g. “%d”, “%i”, “%08i”). This is the C-style format string used by python when formatting strings with the modulus operator.

floatFormat()[source]

Returns the format string controlling how the floating-point data are formated by this object.

This is the C-style format string used by python when formatting strings with the modulus operator.

Return type

str

setFloatFormat(value)[source]

Set format string controlling how the floating-point data are formated by this object.

Parameters

value (str) – Format string (e.g. “%.3f”, “%d”, “%-10.2f”, “%10.3e”). This is the C-style format string used by python when formatting strings with the modulus operator.

useQuoteForText()[source]

Returns true if the string data are formatted using double quotes.

Else, no quotes are used.

setUseQuoteForText(useQuote)[source]

Set the use of quotes to delimit string data.

Parameters

useQuote (bool) – True to use quotes.

imaginaryUnit()[source]

Returns the unit display for imaginary numbers.

Return type

str

setImaginaryUnit(imaginaryUnit)[source]

Set the unit display for imaginary numbers.

Parameters

imaginaryUnit (str) – Unit displayed after imaginary numbers

setEnumFormat(value)[source]

Set format string controlling how the enum data are formated by this object.

Parameters

value (str) – Format string (e.g. “%(name)s(%(value)d)”). This is the C-style format string used by python when formatting strings with the modulus operator.

enumFormat()[source]

Returns the format string controlling how the enum data are formated by this object.

This is the C-style format string used by python when formatting strings with the modulus operator.

Return type

str

toString(data, dtype=None)[source]

Format a data into a string using formatter options

Parameters
  • data (object) – Data to render

  • dtype – enforce a dtype (mostly used to remember the h5py dtype, special h5py dtypes are not propagated from array to items)

Return type

str