traitsui.editors.csv_list_editor module

This modules defines CSVListEditor.

A CSVListEditor provides an editor for lists of simple data types. It allows the user to edit the list in a text field, using commas (or optionally some other character) to separate the elements.

class traitsui.editors.csv_list_editor.CSVListEditor(*args, **traits)[source]

Bases: TextEditor

A text editor for a List.

This editor provides a single line of input text of comma separated values. (Actually, the default separator is a comma, but this can changed.) The editor can only be used with List traits whose inner trait is one of Int, Float, Str, Enum, or Range.

The ‘simple’, ‘text’, ‘custom’ and readonly styles are based on TextEditor. The ‘readonly’ style provides the same formatting in the text field as the other editors, but the user cannot change the value.

Like other Traits editors, the background of the text field will turn red if the user enters an incorrectly formatted list or if the values do not match the type of the inner trait. This validation only occurs while editing the text field. If, for example, the inner trait is Range(low=’lower’, high=’upper’), a change in ‘upper’ will not trigger the validation code of the editor.

The editor removes whitespace of entered items with strip(), so for Str types, the editor should not be used if whitespace at the beginning or end of the string must be preserved.

Parameters:
  • sep (str or None, optional) – The separator of the values in the list. If None, each contiguous sequence of whitespace is a separator. Default is ‘,’.

  • ignore_trailing_sep (bool, optional) – If this is False, a line containing a trailing separator is invalid. Default is True.

  • auto_set (bool) – If True, then every keystroke sets the value of the trait.

  • enter_set (bool) – If True, the user input sets the value when the Enter key is pressed.

Example

The following will display a window containing a single input field. Entering, say, ‘0, .5, 1’ in this field will result in the list x = [0.0, 0.5, 1.0].

auto_set = Bool(True)

Is user input set on every keystroke?

custom_editor(ui, object, name, description, parent)[source]

Generates an editor using the “custom” style.

enter_set = Bool(False)

Is user input set when the Enter key is pressed?

ignore_trailing_sep = Bool(True)

If False, it is an error to have a trailing separator.

readonly_editor(ui, object, name, description, parent)[source]

Generates an “editor” that is read-only.

sep = Union(None, Str, default_value=",")

The separator of the element in the list.

simple_editor(ui, object, name, description, parent)[source]

Generates an editor using the “simple” style.

text_editor(ui, object, name, description, parent)[source]

Generates an editor using the “text” style.