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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
""" The tree editor used in the application browser. """
# Enthought library imports.
from enthought.envisage.api import IApplication, IExtensionPoint, IPlugin
from enthought.traits.api import Any, HasTraits, List, Str, Undefined
from enthought.traits.ui.api import TreeEditor, TreeNode
# fixme: non-api imports.
from enthought.traits.ui.value_tree import value_tree_nodes
class Container(HasTraits):
""" A container. """
# The object that contains the container ;^)
parent = Any
# The contents of the container.
contents = List
# The label.
label = Str
class IApplicationTreeNode(TreeNode):
""" A tree node for an Envisage application. """
###########################################################################
# 'TreeNode' interface.
###########################################################################
def allows_children(self, obj):
""" Return True if this object allows children. """
return True
def get_children(self, obj):
""" Get the object's children. """
return [plugin for plugin in obj]
def is_node_for(self, obj):
""" Return whether this is the node that handles a specified object.
"""
return IApplication(obj, Undefined) is obj
class IPluginTreeNode(TreeNode):
""" A tree node for a Envisage plugins. """
###########################################################################
# 'TreeNode' interface.
###########################################################################
def allows_children(self, obj):
""" Return True if this object allows children. """
return False#True
def get_children(self, obj):
""" Get the object's children. """
extension_points = Container(
label = 'Extension Points',
parent = obj,
contents = obj.get_extension_points()
)
extensions = Container(
label = 'Extensions',
parent = obj,
contents = self._get_extensions(obj)
)
return [extension_points, extensions]
def is_node_for(self, obj):
""" Return whether this is the node that handles a specified object.
"""
return IPlugin(obj, Undefined) is obj
def _get_extensions(self, plugin):
from enthought.traits.ui.value_tree import ListNode, StringNode
class MyListNode(ListNode):
label = Str
def format_value(self, value):
return self.label
extensions = []
for trait_name, trait in plugin.traits().items():
if trait.extension_point is not None:
node = MyListNode(label=trait.extension_point, value=plugin.get_extensions(trait.extension_point))
extensions.append(node)
return extensions
class IExtensionPointTreeNode(TreeNode):
""" A tree node for an extension point. """
###########################################################################
# 'TreeNode' interface.
###########################################################################
def allows_children(self, obj):
""" Return True if this object allows children. """
return False
def get_children(self, obj):
""" Get the object's children. """
return []
def get_label(self, obj):
""" Get the object's label. """
return obj.id
def when_label_changed(self, obj, callback, remove):
return
def is_node_for(self, obj):
""" Return whether this is the node that handles a specified object.
"""
return IExtensionPoint(obj, Undefined) is obj
class ContainerTreeNode(TreeNode):
""" A tree node for a Envisage plugins. """
###########################################################################
# 'TreeNode' interface.
###########################################################################
def allows_children(self, obj):
""" Return True if this object allows children. """
return True
def get_children(self, obj):
""" Get the object's children. """
return obj.contents
def is_node_for(self, obj):
""" Return whether this is the node that handles a specified object.
"""
return isinstance(obj, Container)
application_browser_tree_nodes = [
IApplicationTreeNode(
auto_open = True,
label = 'id',
rename = False,
copy = False,
delete = False,
insert = False,
menu = None,
),
IExtensionPointTreeNode(
rename = False,
copy = False,
delete = False,
insert = False,
menu = None,
),
IPluginTreeNode(
label = 'name',
rename = False,
copy = False,
delete = False,
insert = False,
menu = None,
),
ContainerTreeNode(
label = 'label',
rename = False,
copy = False,
delete = False,
insert = False,
menu = None,
),
] + value_tree_nodes
#### EOF ######################################################################
|