1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#------------------------------------------------------------------------------
# Copyright (c) 2013-2025, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
from __future__ import unicode_literals
from atom.api import Callable, Int, Str
from enaml.core.declarative import Declarative, d_
class Extension(Declarative):
""" A declarative class which represents a plugin extension.
An Extension must be declared as a child of a PluginManifest.
"""
#: The globally unique identifier for the extension.
id = d_(Str())
#: The fully qualified id of the target extension point.
point = d_(Str())
#: An optional rank to use for order the extension among others.
rank = d_(Int())
#: A callable which will create the implementation object for the
#: extension point. The call signature and return type are defined
#: by the extension point plugin which invokes the factory.
factory = d_(Callable())
#: An optional description of the extension.
description = d_(Str())
@property
def plugin_id(self):
""" Get the plugin id from the parent plugin manifest.
"""
return self.parent.id
@property
def qualified_id(self):
""" Get the fully qualified extension identifer.
"""
this_id = self.id
if '.' in this_id:
return this_id
return '%s.%s' % (self.plugin_id, this_id)
def get_child(self, kind, reverse=False):
""" Find a child by the given type.
Parameters
----------
kind : type
The declarative type of the child of interest.
reverse : bool, optional
Whether to search in reversed order. The default is False.
Returns
-------
result : child or None
The first child found of the requested type.
"""
it = reversed if reverse else iter
for child in it(self.children):
if isinstance(child, kind):
return child
return None
def get_children(self, kind):
""" Get all the children of the given type.
Parameters
----------
kind : type
The declarative type of the children of interest.
Returns
-------
result : list
The list of children of the request type.
"""
return [c for c in self.children if isinstance(c, kind)]
|