How to use traitsui - 10 common examples

To help you get started, we’ve selected a few traitsui examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enthought / traitsui / integrationtests / ui / test_ui5.py View on Github external
integer_text = Int(1)
    enumeration = Trait('one', 'two', 'three', 'four', 'five', 'six',
                        cols=3)
    float_range = Range(0.0, 10.0, 10.0)
    int_range = Range(1, 5)
    boolean = Bool(True)

    view = View('integer_text', 'enumeration', 'float_range',
                'int_range', 'boolean')

#-------------------------------------------------------------------------
#  'TraitsTestHandler' class:
#-------------------------------------------------------------------------


class TraitsTestHandler(Handler):

    def object_enabled_changed(self, info):
        enabled = info.object.enabled
        for i in range(1, 63):
            getattr(info, 'f%d' % i).enabled = enabled

#-------------------------------------------------------------------------
#  'TraitsTest' class
#-------------------------------------------------------------------------


class TraitsTest(HasTraits):

    #-------------------------------------------------------------------------
    #  Trait definitions:
    #-------------------------------------------------------------------------
github enthought / traitsui / integrationtests / ui / table_editor_focus_bug.py View on Github external
def _input_changed(self):
        words = self.input.split()

        for word in self.parsed[:]:
            if word.word in words:
                words.remove(word.word)
            else:
                self.parsed.remove(word)

        for word in words:
            self.parsed.append(Word(word=word))

        return

    table_editor = TableEditor(
        columns=[ObjectColumn(name='word')],
        editable=True)

    help = Str("""Type in the 'input' box before clicking the Parsed tab.
The first non-whitespace character will cause changes to the parsed trait
and therefore changes to the table rows.  That is expected.

BUG: the table grabs the focus from 'input' and thus subsequent typing goes
into one of the table cells.

If you click the 'Parsed' tab, to view the table, and then the 'Inputs' tab
the focus will stay with the 'input' box.
""")

    traits_view = View(
        Group(Item('help', style='readonly'),
github enthought / traitsui / integrationtests / ui / test_ui2.py View on Github external
info.city.enabled = enabled
        info.state.enabled = enabled
        if obj.zip == 78664:
            obj.street = '901 Morning View Place'
            obj.city = 'Round Rock'
            obj.state = 'Texas'

    def object_call_changed(self, info):
        print 'You called?'

#-------------------------------------------------------------------------
#  'WizardHandler' class:
#-------------------------------------------------------------------------


class WizardHandler(Handler):

    def object_sex_changed(self, info):
        if info.object.sex == 'Female':
            info.p1.next = 'p3'
        else:
            info.p1.next = 'p2'
            info.p2.next = None

    def object_name_changed(self, info):
        info.p2.enabled = info.p3.enabled = (info.object.name != '')
        if not info.p2.enabled:
            info.p2.msg = info.p3.msg = 'You must enter a valid name.'

#-------------------------------------------------------------------------
#  'Employer' class:
#-------------------------------------------------------------------------
github enthought / enable / enable / savage / compliance / comparator.py View on Github external
traits_view = tui.View(
        tui.Tabbed(
            tui.VGroup(
                tui.HGroup(
                    tui.Item('current_file', editor=tui.EnumEditor(name='svg_files'),
                        style='simple', width=1.0, show_label=False),
                    tui.Item('move_backward', show_label=False,
                        enabled_when="svg_files.index(current_file) != 0"),
                    tui.Item('move_forward', show_label=False,
                        enabled_when="svg_files.index(current_file) != len(svg_files)-1"),
                ),
                tui.VSplit(
                    tui.HSplit(
                        tui.Item('description', label='Description', show_label=False),
                        tui.Item('current_xml_view', editor=xml_tree_editor, show_label=False),
                    ),
                    tui.HSplit(
                        tui.Item('document', editor=SVGEditor(), show_label=False),
                        tui.Item('kiva_component', show_label=False),
                        tui.Item('ref_component', show_label=False),
                        # TODO: tui.Item('agg_component', show_label=False),
                    ),
                ),
                label='SVG',
            ),
            tui.Item('parsing_sike', style='custom', show_label=False,
                label='Parsing Profile'),
            tui.Item('drawing_sike', style='custom', show_label=False,
                label='Kiva Drawing Profile'),
            tui.Item('wx_doc_sike', style='custom', show_label=False,
                label='Creating WX document'),
github NMGRL / pychron / pychron / dvc / tasks / panes.py View on Github external
def traits_view(self):
        commit_grp = VGroup(Item('ncommits', label='Limit'),
                            VGroup(UItem('commits',
                                         editor=TabularEditor(adapter=CommitAdapter(),
                                                              selected='selected_commit')),
                                   show_border=True, label='Commits'))
        bookmark_grp = VGroup(VGroup(UItem('git_tags', editor=TabularEditor(adapter=GitTagAdapter()),
                                           height=200),
                                     show_border=True, label='Bookmarks'))

        v = View(VGroup(UItem('branch',
                              editor=EnumEditor(name='branches')),
                        VSplit(commit_grp, bookmark_grp)))
        return v
github enthought / traitsui / examples / demo / Advanced / Table_editor_with_live_search_and_cell_editor.py View on Github external
),
                Item('case_sensitive')
            ),
            VSplit(
                VGroup(
                    Item('summary',
                         editor=TitleEditor()
                         ),
                    Item('source_files',
                         id='source_files',
                         editor=table_editor
                         ),
                    dock='horizontal',
                    show_labels=False
                ),
                VGroup(
                    HGroup(
                        Item('selected_full_name',
                             editor=TitleEditor(),
                             springy=True
                             ),
                        Item('selected_full_name',
                             editor=DNDEditor(),
                             tooltip='Drag this file'
                             ),
                        show_labels=False
                    ),
                    Item('selected_contents',
                         style='readonly',
                         editor=CodeEditor(mark_lines='mark_lines',
                                           line='selected_line',
                                           selected_line='selected_line')
github NMGRL / pychron / pychron / pipeline / csv_dataset_factory.py View on Github external
format='%0.6f', ),
                 ObjectColumn(name='weighted_mean_err',
                              format='%0.6f',
                              label=PLUSMINUS_ONE_SIGMA),
                 ObjectColumn(name='mswd',
                              format='%0.3f',
                              label='MSWD'),
                 ObjectColumn(name='displayn', label='N'),
                 ObjectColumn(name='mean', format='%0.6f', label='Mean'),
                 ObjectColumn(name='std', format='%0.6f', label='Std'),
                 ObjectColumn(name='min', format='%0.6f', label='Min'),
                 ObjectColumn(name='max', format='%0.6f', label='Max'),
                 ObjectColumn(name='dev', format='%0.6f', label='Dev.'),
                 ObjectColumn(name='percent_dev', format='%0.2f', label='% Dev.')]

        button_grp = HGroup(UItem('save_button'), UItem('save_as_button'),
                            UItem('clear_button'), UItem('open_via_finder_button'),
                            UItem('add_record_button'),
                            UItem('calculate_button')),

        repo_grp = VGroup(BorderVGroup(UItem('repo_filter'),
                                       UItem('repositories',
                                             width=200,
                                             editor=ListStrEditor(selected='repository')),
                                       label='Repositories'),
                          BorderVGroup(UItem('name_filter'),
                                       UItem('names', editor=ListStrEditor(selected='name')),
                                       label='DataSets'))

        record_grp = VSplit(UItem('records', editor=TableEditor(columns=cols,
                                                                selected='selected',
                                                                sortable=False,
github chrisdembia / yeadon / yeadon / gui.py View on Github external
Item('PJ1extension', label='PJ1 extension'),
            Item('PJ1adduction', label='PJ1 adduction'),
            Item('PK1extension', label='PK1 extension'),
            Item('PK1abduction', label='PK1 abduction'),
            Item('J1J2flexion', label='J1J2 flexion'),
            Item('K1K2flexion', label='K1K2 flexion'),
            label='Lower limbs',
            dock='tab',
            )
    config_group = VGroup(
            Label('Configuration'),
            Group(config_first_group, config_upper_group, config_lower_group,
                layout='tabbed',
                ),
            Item('reset_configuration', show_label=False),
            Label('P: pelvis (red); T: thorax (orange); C: chest-head (yellow)'),
            Label('A1/A2: left upper arm/forearm-hand; B1/B2: right arm'),
            Label('J1/J2: left thigh/shank-foot; K1/K2: right leg'),
            show_border=True,
            )

    inertia_prop = VGroup(
            Label('Mass center (from origin of coord. sys.) (m):'),
            HGroup(
                Item('x', style='readonly', format_func=format_func),
                Item('y', style='readonly', format_func=format_func),
                Item('z', style='readonly', format_func=format_func)
                ),
            Label('Inertia tensor (about origin, in basis shown) (kg-m^2):'),
            HSplit( # HSplit 2
                Group(
                    Item('Ixx', style='readonly', format_func=format_func),
github enthought / traitsui / traitsui / wx / table_editor.py View on Github external
def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """

        factory = self.factory
        self.filter = factory.filter
        self.auto_add = (
            factory.auto_add and (
                factory.row_factory is not None))

        columns = factory.columns[:]
        if (len(columns) == 0) and (len(self.value) > 0):
            columns = [ObjectColumn(name=name)
                       for name in self.value[0].editable_traits()]
        self.columns = columns

        self.model = model = TableModel(
            editor=self,
            reverse=factory.reverse)
        model.on_trait_change(self._model_sorted, 'sorted', dispatch='ui')
        mode = factory.selection_mode
        row_mode = mode in ('row', 'rows')
        selected = None
        items = model.get_filtered_items()
        if factory.editable and (len(items) > 0):
            selected = items[0]
        if (factory.edit_view == ' ') or (not row_mode):
            self.control = panel = TraitsUIPanel(parent, -1)
            sizer = wx.BoxSizer(wx.VERTICAL)
github enthought / traitsui / examples / demo / Advanced / Tabular_editor_demo.py View on Github external
address = Str
    age     = Int
    
    # surname is displayed in qt-only row label:
    surname = Property(fget=lambda self: self.name.split()[-1], 
                       depends_on='name')

#-- MarriedPerson Class Definition ---------------------------------------------

class MarriedPerson(Person):

    partner = Instance(Person)

#-- Tabular Adapter Definition -------------------------------------------------

class ReportAdapter(TabularAdapter):

    columns = [ ('Name',    'name'),
                ('Age',     'age'),
                ('Address', 'address'),
                ('Spouse',  'spouse') ]

    row_label_name = 'surname'

    # Font fails with wx in OSX; see traitsui issue #13:
    # font                      = 'Courier 10'
    age_alignment             = Constant('right')
    MarriedPerson_age_image   = Property
    MarriedPerson_bg_color    = Color(0xE0E0FF)
    MarriedPerson_spouse_text = Property
    Person_spouse_text        = Constant('')