enaml.core.looper

Classes

Looper

A pattern object that repeats its children over an iterable.

class enaml.core.looper.Looper(parent=None, **kwargs)[source]

Bases: Pattern

A pattern object that repeats its children over an iterable.

The children of a Looper are used as a template when creating new objects for each item in the given iterable. Each iteration of the loop will be given an independent scope which is the union of the outer scope and any identifiers created during the iteration. This scope will also contain a loop variable which has item and index members to access the index and value of the iterable, respectively.

All items created by the looper will be added as children of the parent of the Looper. The Looper keeps ownership of all items it creates. When the iterable for the looper is changed, the looper will only create and destroy children for the items in the iterable which have changed. When an item in the iterable is moved the loop.index will be updated to reflect the new index.

The Looper works under the assumption that the values stored in the iterable are unique.

The loop_item and loop_index scope variables are depreciated in favor of loop.item and loop.index respectively. This is because the old loop_index variable may become invalid when items are moved.

iterable

The iterable to use when creating the items for the looper. The items in the iterable must be unique. This allows the Looper to optimize the creation and destruction of widgets. If the iterable is an Iterator it is first coerced to a tuple.

items

The list of items created by the conditional. Each item in the list represents one iteration of the loop and is a list of the items generated during that iteration. This list should not be manipulated directly by user code.

destroy()[source]

A reimplemented destructor.

The looper will release the owned items on destruction.

pattern_items()[source]

Get a list of items created by the pattern.

refresh_items()[source]

Refresh the items of the pattern.

This method destroys the old items and creates and initializes the new items.