def _hdf5_tree_editor(selected=''): """Return a TreeEditor specifically for HDF5 file trees.""" return TreeEditor( nodes = [ TreeNode( node_for = [ Hdf5FileNode ], auto_open = True, children = 'groups_and_arrays', label = 'name', view = no_view, ), TreeNode( node_for = [ Hdf5GroupNode ], auto_open = False, children = 'groups_and_arrays', label = 'name', view = no_view, ), TreeNode( node_for = [ Hdf5ArrayNode ], auto_open = False, children = '', label = 'name', view = no_view, ), ], editable = False, selected = selected, )
def traits_view(self): """ Default traits view for this class. """ help_action = Action(name='Info', action='preferences_help') buttons = ['OK', 'Cancel'] if self.show_apply: buttons = ['Apply'] + buttons if self.show_help: buttons = [help_action] + buttons # A tree editor for preferences nodes. tree_editor = TreeEditor(nodes=[ TreeNode( node_for=[PreferencesNode], auto_open=False, children='children', label='name', rename=False, copy=False, delete=False, insert=False, menu=None, ), ], on_select=self._selection_changed, editable=False, hide_root=True, selected='selected_node', show_icons=False) view = View( HSplit( Item( name='root', editor=tree_editor, show_label=False, width=250, ), Item( name='selected_page', #editor = WidgetEditor(), show_label=False, width=450, style='custom', ), ), buttons=buttons, handler=PreferencesManagerHandler(model=self), resizable=True, title='Preferences', width=.3, height=.3, kind='modal') self.selected_page = self.pages[0] return view
class CfgFileManager(HasTraits): session = Instance(Session) directory = Str name = Str files = Dict def _session_default(self): return Session(name=self.name, directory=self.directory, files=self.files) tree_editor = TreeEditor(nodes=[ TreeNode(node_for=[Session], children='descendents', label='name', rename=False, delete=False, view=View()), TreeNode(node_for=[SubSession], children='descendents', label='name', rename=False, delete=False, view=View()), TreeNode(node_for=[CfgFile], children='descendents', label='name', on_dclick=openFile, rename=False, delete=False, view=View()) ], hide_root=True, editable=False) view = View(Item(name='directory', show_label=False, style='readonly'), Item(editor=tree_editor, name='session', id='session', resizable=True, show_label=False), resizable=True)
def default_traits_view(self): nodes = [ TreeNode( node_for=[AdderNode], label='name', copy=False, delete=False, rename=False, children='items_list', ), TreeNode( node_for=[DocumentedItem], label='name', copy=False, delete=False, rename=False, icon_item=self.icon_name, ), ] tree_editor = TreeEditor( editable=False, hide_root=True, orientation='vertical', selected='object.selected_item', nodes=nodes, on_dclick='object._on_tree_dclick', ) view = View(Item('self', show_label=False, editor=tree_editor, resizable=True, springy=True, height=0.5), Item('selected_item', style='custom', show_label=False, height=0.5), resizable=True) return view
def _nodes_default(self): """ The default value of the cached nodes list. """ # Now setup the view. nodes = [ TreeNode( node_for=[Engine], children='children_ui_list', label='=Mayavi', auto_open=False, copy=False, delete=False, rename=True, ), ObjectTreeNode( node_for=[Base], children='children_ui_list', label='name', auto_open=True, copy=True, delete=True, rename=True, tooltip='=Right click for more options', ), AdderTreeNode( node_for=[SceneAdderNode], icon_item='add_scene.png', ), AdderTreeNode( node_for=[SourceAdderNode], icon_item='add_source.png', ), AdderTreeNode( node_for=[ModuleFilterAdderNode], icon_item='add_module.png', ), ] return nodes
class PlotOMatic(HasTraits): io_driver_list = Instance(IODriverList) variables = Instance(Variables) viewers = Instance(Viewers) selected_viewer = Instance(Viewer) handler = PlotOMaticHandler() viewer_node = TreeNode(node_for=[Viewer], auto_open=True, label='name', menu=Menu(handler.remove_viewer_action), icon_path='icons/', icon_item='plot.png') tree_editor = TreeEditor(nodes=[ TreeNode( node_for=[IODriverList], auto_open=True, children='io_drivers', label='=Input Drivers', menu=Menu(handler.refresh_tree_action, handler.add_io_driver_actions_menu), view=View(), ), TreeNode(node_for=[IODriver], auto_open=True, children='_decoders', label='name', add=[DataDecoder], menu=Menu(handler.remove_io_driver_action, handler.refresh_tree_action, handler.add_decoder_actions_menu), icon_path='icons/', icon_open='input.png', icon_group='input.png'), TreeNode(node_for=[DataDecoder], auto_open=True, children='', label='name', menu=Menu(handler.refresh_tree_action, handler.remove_decoder_action), icon_path='icons/', icon_item='decoder.png'), TreeNode(node_for=[IODriverList], auto_open=True, children='viewers', label='=Viewers', menu=Menu(handler.refresh_tree_action, handler.add_viewer_actions_menu), view=View()), viewer_node ], hide_root=True, orientation='vertical') view = View(HSplit( Item(name='io_driver_list', editor=tree_editor, resizable=True, show_label=False, width=.32), VSplit( Item(name='selected_viewer', style='custom', resizable=True, show_label=False, editor=InstanceEditor(view='view')), Item(name='variables', show_label=False, style='custom', height=.3))), menubar=MenuBar(handler.file_menu, handler.data_menu), title='Plot-o-matic', resizable=True, width=1000, height=600, handler=PlotOMaticHandler()) def __init__(self, **kwargs): HasTraits.__init__(self, **kwargs) self.viewer_node.on_select = self.click_viewer def click_viewer(self, viewer): self.selected_viewer = viewer self.viewers.select_viewer(viewer) def start(self): self.io_driver_list.start_all() self.viewers.start() def stop(self): self.viewers.stop() self.io_driver_list.stop_all() def get_config(self): config = {} config['io_drivers'] = self.io_driver_list.get_config() config['viewers'] = self.viewers.get_config() return config def set_config(self, config): if 'io_drivers' in config: self.io_driver_list.set_config(config['io_drivers']) if 'viewers' in config: self.viewers.set_config(config['viewers']) self.variables.clear()
# Local imports. from preferences_node import PreferencesNode from preferences_page import PreferencesPage # fixme: This is part of the attempt to allow developers to use non-Traits UI # preferences pages. It doesn't work yet! ##from widget_editor import WidgetEditor # A tree editor for preferences nodes. tree_editor = TreeEditor(nodes=[ TreeNode( node_for=[PreferencesNode], auto_open=False, children='children', label='name', rename=False, copy=False, delete=False, insert=False, menu=None, ), ], editable=False, hide_root=True, selected='selected_node', show_icons=False) class PreferencesHelpWindow(HasTraits): """ Container class to present a view with string info. """ def traits_view(self):
employees = [ dave, martin, mike, duncan, jason ] ) ) #------------------------------------------------------------------------------- # Define the tree trait editor: #------------------------------------------------------------------------------- no_view = View() tree_editor = TreeEditor( editable = False, nodes = [ TreeNode( node_for = [ Company ], auto_open = True, children = '', label = 'name', view = View( [ 'name', '|<' ] ) ), TreeNode( node_for = [ Company ], auto_open = True, children = 'departments', label = '=Departments', view = no_view, add = [ Department ] ), TreeNode( node_for = [ Company ], auto_open = True, children = 'employees', label = '=Employees', view = no_view, add = [ Employee ] ), TreeNode( node_for = [ Department ],
root.selection.patient = None print( root.selection.control_point, root.selection.beam, root.selection.plan, root.selection.series, root.selection.study, root.selection.patient, ) # Tree editor tree_editor = TreeEditor(nodes=[ TreeNode(node_for=[PatientList], auto_open=True, children='patients', label='=Patients', view=no_view), TreeNode(node_for=[Patient], auto_open=True, children='studies', label='label', view=no_view), TreeNode(node_for=[Study], auto_open=True, children='series', label='label', view=no_view), TreeNode(node_for=[Series], auto_open=False, children='sopinstances',
hide_root=True, editable=False, nodes=value_tree_nodes) # Editor for a value tree with a root value_tree_editor_with_root = TreeEditor( auto_open=3, editable=False, nodes=[ ObjectTreeNode(node_for=[ NoneNode, StringNode, BoolNode, IntNode, FloatNode, ComplexNode, OtherNode, TupleNode, ListNode, ArrayNode, DictNode, ObjectNode, TraitsNode, RootNode ]), TreeNode(node_for=[_ValueTree], auto_open=True, children='values', move=[SingleValueTreeNodeObject], copy=False, label='=Values', icon_group='traits_node', icon_open='traits_node') ]) #------------------------------------------------------------------------------- # Defines a 'ValueTree' trait: #------------------------------------------------------------------------------- # Trait for a value tree ValueTree = Instance(_ValueTree, (), editor=value_tree_editor_with_root)
class ShapeList(HasTraits): """ Just a container for DisplayShapes. This exists mostly because the TreeEditor expects child nodes on a single sub-object. A simple list doesn't work. """ shapes = List(DisplayShape) occ_tree = TreeEditor(nodes=[ TreeNode(node_for=[ShapeList], auto_open=True, children='shapes', label="=Shapes", view=View()), TreeNode(node_for=[DisplayShape], auto_open=True, children='_input', label='name'), TreeNode(node_for=[ProcessObject], auto_open=True, children='_inputs', label='name')], orientation="vertical" ) class OCCModel(HasTraits):
class DomainEdge(HasTraits): name = Str("graphedge") source = Instance(DomainNode) target = Instance(DomainNode) class DomainModel(HasTraits): nodes = List(Instance(DomainNode)) edges = List(Instance(DomainEdge)) other_nodes = List(Instance(OtherNode)) tree_editor = TreeEditor(nodes=[ TreeNode(node_for=[DomainModel], label="=Model"), TreeNode(node_for=[DomainModel], label="=Nodes", children="nodes", add=[DomainNode]), TreeNode(node_for=[DomainModel], label="=Edges", children="edges", add=[DomainEdge]), TreeNode(node_for=[DomainModel], label="=Other Nodes", children="other_nodes", add=[OtherNode]), TreeNode(node_for=[DomainNode], label="name"), TreeNode(node_for=[DomainEdge], label="name"), TreeNode(node_for=[OtherNode], label="name")
self.attributes = attrs def _get_sublabels(self): itr = TDF.TDF_ChildIterator(self.TDF_Label, False) result = [] while itr.More(): val = itr.Value() result.append(Label(TDF_Label=val)) itr.Next() return result tree_ed = TreeEditor(nodes=[ TreeNode(node_for=[Label], auto_open=False, children='children', label='repr', view=View()), TreeNode( node_for=[Attribute], auto_open=False, children='', label='cls_name', ) ], orientation='horizontal') class Doc(HasTraits): filename = File TDocStd = Instance(TDocStd.TDocStd_Document)
class ViewChooser(HasTraits): """ Allow the user to choose a view. This implementation shows views in a tree grouped by category. """ # The window that contains the views to choose from. window = Instance('enthought.pyface.workbench.api.WorkbenchWindow') # The currently selected tree item (at any point in time this might be # either None, a view category, or a view). selected = Any # The selected view (None if the selected item is not a view). view = Instance(IView) #### Traits UI views ###################################################### traits_ui_view = View( Item(name='window', editor=TreeEditor(nodes=[ WorkbenchWindowTreeNode( auto_open=True, label='=Views', rename=False, copy=False, delete=False, insert=False, menu=None, ), TreeNode( node_for=[Category], auto_open=True, children='views', label='name', rename=False, copy=False, delete=False, insert=False, menu=None, ), IViewTreeNode( auto_open=False, label='name', rename=False, copy=False, delete=False, insert=False, menu=None, ) ], editable=False, hide_root=True, selected='selected', show_icons=True), show_label=False), buttons=[Action(name='OK', enabled_when='view is not None'), 'Cancel'], resizable=True, style='custom', title='Show View', width=.2, height=.4) ########################################################################### # 'ViewChooser' interface. ########################################################################### def _selected_changed(self, old, new): """ Static trait change handler. """ # If the assignment fails then the selected object does *not* implement # the 'IView' interface. try: self.view = new except TraitError: self.view = None return
Department(name='Business', employees=[jason, mike]), Department(name='Scientific', employees=[dave, martin, duncan]) ], employees=[dave, martin, mike, duncan, jason])) #------------------------------------------------------------------------------- # Define the tree trait editor: #------------------------------------------------------------------------------- no_view = View() tree_editor = TreeEditor(nodes=[ TreeNode(node_for=[Company], auto_open=True, children='', label='name', view=View(['name', '|<'])), TreeNode(node_for=[Company], auto_open=True, children='departments', label='=Departments', view=no_view, add=[Department]), TreeNode(node_for=[Company], auto_open=True, children='employees', label='=Employees', view=no_view, add=[Employee]), TreeNode(node_for=[Department],
from enthought.traits.api import HasTraits, Instance, List from enthought.traits.trait_handlers import TraitListObject from enthought.traits.ui.api import TreeEditor, TreeNode, TreeNodeObject, Item, View, \ ListEditor, ObjectTreeNode, MultiTreeNode from enthought.traits.ui.value_tree import ObjectNode, TraitsNode no_view = View() def selection_changed(selection): print selection AVL_tree_editor = TreeEditor( nodes = [ TreeNode( node_for = [ AVL ], auto_open = True, children = '', label = '=pyAVL', view = no_view ), TreeNode( node_for = [ AVL ], auto_open = True, children = 'run_cases', label = '=runcases', view = View( [ 'selected_runcase'] ) ), TreeNode( node_for = [ AVL ], auto_open = True, children = '', label = '=cases', view = View( [ 'case'] ) ), TreeNode( node_for = [ RunCase ],
# TreeNode(node_for=[Graph], auto_open=True, children="edges", # label="=Edges"), # # TreeNode(node_for=[Subgraph], label="ID", icon_item="subgraph"), # TreeNode(node_for=[Subgraph], auto_open=False, children="subgraphs", # label="=Subgraphs", add=[Subgraph]), # TreeNode(node_for=[Subgraph], auto_open=False, children="clusters", # label="=Clusters", add=[Cluster]), # TreeNode(node_for=[Subgraph], auto_open=False, children="nodes", # label="=Nodes", add=[Node]), # TreeNode(node_for=[Subgraph], children="edges", label="=Edges"), # # TreeNode(node_for=[Cluster], label="ID", icon_item="cluster"), # TreeNode(node_for=[Cluster], auto_open=False, children="subgraphs", # label="=Subgraphs", add=[Subgraph]), # TreeNode(node_for=[Cluster], auto_open=False, children="clusters", # label="=Clusters", add=[Cluster]), # TreeNode(node_for=[Cluster], auto_open=False, children="nodes", # label="=Nodes", add=[Node]), # TreeNode(node_for=[Cluster], children="edges", label="=Edges"), TreeNode(node_for=[Node], label="ID", icon_item="node"), TreeNode(node_for=[Edge], label="name", icon_item="edge") ], orientation="vertical", editable=False,# hide_root=True, on_dclick=lambda obj: obj.edit_traits(kind="livemodal"), # selected="selected_graph" ) # EOF -------------------------------------------------------------------------
class Company(HasTraits): """ Defines a company with departments and employees. """ name = Str('<unknown>') departments = List(Department) employees = List(Employee) # Create an empty view for objects that have no data to display: no_view = View() # Define the TreeEditor used to display the hierarchy: tree_editor = TreeEditor(nodes=[ TreeNode(node_for=[Company], auto_open=True, children='', label='name', view=View(['name'])), TreeNode( node_for=[Company], auto_open=True, children='departments', label='=Departments', view=no_view, add=[Department], ), TreeNode(node_for=[Company], auto_open=True, children='employees', label='=Employees', view=no_view,
class MainWindow(HasTraits): parameter_file_collections = Instance(ParameterFileCollectionList) parameter_files = Instance(ParameterFileCollection) plot_frame_tabs = List(Instance(DataObject)) open_parameterfile = Button shell = PythonValue def _shell_default(self): return globals() notebook_editor = ListEditor(editor=InstanceEditor(editable=True), use_notebook=True) traits_view = View( VSplit( HSplit( VGroup( Item( 'parameter_file_collections', width=120.0, height=500.0, show_label=False, editor=TreeEditor( editable=False, nodes=[ TreeNode( node_for=[ParameterFileCollectionList], children='parameter_file_collections', label="=Data Collections"), TreeNode(node_for=[ParameterFileCollection], children='parameter_files', label="name", view=View()), TreeNode(node_for=[ParameterFile], children='data_objects', label="name", menu=Menu( Action(name='Slice', action='object.do_slice'), Action(name='Project', action='object.do_proj'), Action(name='VTK', action='object.do_vtk')), view=View()), TreeNode(node_for=[DataObject], children='', label="name"), ], show_icons=False), ), Item('open_parameterfile', show_label=False)), Item('plot_frame_tabs', style='custom', editor=notebook_editor, show_label=False, height=500.0, width=500.0), ), HGroup( #Item('shell', editor=ShellEditor(share=True), #show_label=False, height=120.0), ), ), resizable=True, width=800.0, height=660.0, title="reason v2 [prototype]") def _open_parameterfile_fired(self): print "OPENING" def _parameter_file_collections_default(self): return ParameterFileCollectionList()
id='enthought.traits.doc.example.treeeditor', dock='vertical') class TreeHandler(Handler): def employee_department(self, editor, object): dept = editor.get_parent(object) print '%s works in the %s department.' %\ ( object.name, dept.name ) # Tree editor tree_editor = TreeEditor(nodes=[ TreeNode(node_for=[Company], auto_open=True, children='', label='name', view=View(Group('name', orientation='vertical', show_left=True))), TreeNode(node_for=[Company], auto_open=True, children='departments', label='=Departments', view=no_view, add=[Department]), TreeNode(node_for=[Company], auto_open=True, children='employees', label='=Employees', view=no_view, add=[Employee]), TreeNode(node_for=[Department],