class Registry: (source)
A priority sorted registry. A `Registry` instance provides two public methods to alter the data of the registry: `register` and `deregister`. Use `register` to add items and `deregister` to remove items. See each method for specifics. When registering an item, a "name" and a "priority" must be provided. All items are automatically sorted by "priority" from highest to lowest. The "name" is used to remove ("deregister") and get items. A `Registry` instance it like a list (which maintains order) when reading data. You may iterate over the items, get an item and get a count (length) of all items. You may also check that the registry contains an item. When getting an item you may use either the index of the item or the string-based "name". For example: registry = Registry() registry.register(SomeItem(), 'itemname', 20) # Get the item by index item = registry[0] # Get the item by name item = registry['itemname'] When checking that the registry contains an item, you may use either the string-based "name", or a reference to the actual item. For example: someitem = SomeItem() registry.register(someitem, 'itemname', 20) # Contains the name assert 'itemname' in registry # Contains the item instance assert someitem in registry The method `get_index_for_name` is also available to obtain the index of an item using that item's assigned "name".
Method | __contains__ |
Undocumented |
Method | __getitem__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | __iter__ |
Undocumented |
Method | __len__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | deregister |
Remove an item from the registry. |
Method | get |
Return the index of the given name. |
Method | register |
Add an item to the registry with the given name and priority. |
Method | _sort |
Sort the registry by priority from highest to lowest. |
Instance Variable | _data |
Undocumented |
Instance Variable | _is |
Undocumented |
Instance Variable | _priority |
Undocumented |
Add an item to the registry with the given name and priority. Parameters: * `item`: The item being registered. * `name`: A string used to reference the item. * `priority`: An integer or float used to sort against all items. If an item is registered with a "name" which already exists, the existing item is replaced with the new item. Treat carefully as the old item is lost with no way to recover it. The new item will be sorted according to its priority and will **not** retain the position of the old item.