Ejemplo n.º 1
0
def list_editor(trait, handler):
    """ Factory that constructs an appropriate editor for a list.
    """
    item_handler = handler.item_trait.handler
    if _expects_hastraits_instance(item_handler):
        from traitsui.table_column import ObjectColumn
        from traitsui.table_filter import (EvalFilterTemplate,
                                           RuleFilterTemplate,
                                           MenuFilterTemplate, EvalTableFilter)
        from traitsui.api import TableEditor

        return TableEditor(filters=[
            RuleFilterTemplate, MenuFilterTemplate, EvalFilterTemplate
        ],
                           edit_view='',
                           orientation='vertical',
                           search=EvalTableFilter(),
                           deletable=True,
                           show_toolbar=True,
                           reorderable=True,
                           row_factory=_instance_handler_factory(item_handler))
    else:
        from traitsui.api import ListEditor

        return ListEditor(trait_handler=handler,
                          rows=trait.rows if trait.rows else 5,
                          use_notebook=bool(trait.use_notebook),
                          page_name=trait.page_name if trait.page_name else '')
Ejemplo n.º 2
0
 def default_traits_view(self):
     return View(
         Item('stats',
              show_label=False,
              editor=TableEditor(columns=columns + [
                  ObjectColumn(name='cumulative_calls',
                               label='C. Calls',
                               format='%.0f',
                               editable=False,
                               maximum=TraitValue(
                                   delegate=self,
                                   name='max_cumulative_calls')),
                  ObjectColumn(name='n_calls',
                               label='# Calls',
                               format='%.0f',
                               editable=False,
                               maximum=TraitValue(delegate=self,
                                                  name='max_n_calls')),
                  ObjectColumn(name='total_time',
                               label='T. Time',
                               format='%.5f',
                               editable=False,
                               maximum=TraitValue(delegate=self,
                                                  name='max_total_time')),
                  ObjectColumn(name='total_time_per_call',
                               label='T. Time/Call',
                               format='%.5f',
                               editable=False,
                               maximum=TraitValue(
                                   delegate=self,
                                   name='max_total_time_per_call')),
                  ObjectColumn(name='cumulative_time',
                               label='C. Time',
                               format='%.5f',
                               editable=False,
                               maximum=TraitValue(
                                   delegate=self,
                                   name='max_cumulative_time')),
                  ObjectColumn(name='cumulative_time_per_call',
                               label='C. Time/Call',
                               format='%.5f',
                               editable=False,
                               maximum=TraitValue(
                                   delegate=self,
                                   name='max_cumulative_time_per_call'))
              ],
                                 other_columns=other_columns,
                                 filters=[
                                     EvalFilterTemplate, RuleFilterTemplate,
                                     MenuFilterTemplate
                                 ],
                                 search=EvalTableFilter(),
                                 auto_size=False,
                                 selection_bg_color=0xFBD391,
                                 selection_color='black',
                                 selected='selected')))
Ejemplo n.º 3
0
        "object.last_name )"),
        ObjectColumn(name='age', width=0.10,
                     horizontal_alignment='center'),
        ObjectColumn(name='phone', width=0.20)],
    deletable=True,
    sort_model=True,
    auto_size=False,
    orientation='vertical',
    edit_view=View(
        Group('first_name', 'last_name', 'age', 'phone',
                            show_border=True
              ),
        resizable=True
    ),
    filters=[EvalFilterTemplate, MenuFilterTemplate, RuleFilterTemplate],
    search=EvalTableFilter(),
    show_toolbar=True,
    row_factory=Employee)

# The class to be edited with the TableEditor:


class Department(HasStrictTraits):

    employees = List(Employee)

    traits_view = View(
        Group(
            Item('employees',
                 show_label=False,
                 editor=table_editor