enthoughttraitsui

Does TreeEditor support multiple selection?


I am using a TreeEditor to represent model objects in my traitsui application. I would like the ability select multiple objects in the tree editor by holding down Shift or Ctrl and performing selections. My ultimate goal is to provide a quick way for the user to delete multiple objects in one go rather than right-clicking each item individually.

From reading the source code for tree editor I noticed,

selection_mode = Enum('single', 'extended')

which appears to define an extended selection mode. But I cannot find any example code which uses nor is it mentioned in the documentation of TreeEditor.

Is this supported by traitsui?


Solution

  • FWIW, here's some relevant code snipped from a working application and sanitized. I have not tried to run it, so there could be some copy/paste/sanitize typos.

    def default_traits_view(self):
        return View(
            UItem(
                'my_run_tree',
                editor=TreeEditor(
                    nodes=[
                        TestRunTreeNode(
                            node_for=[Node0],
                            children='children',
                            label='label',
                        ),
                        TestRunTreeNode(
                            node_for=[Node1],
                            children='',
                            label='mylabel',
                        ),
                    ],
                    editable=False,
                    selected='selected_nodes',
                    selection_mode='extended',
                )
            ),
            resizable=True,
        )