Ejemplo n.º 1
0
class Person(HasTraits):
    """ Demo class for demonstrating enabling/disabling of trait editors
    """

    first_name = Str
    last_name = Str
    age = Range(0, 120)
    marital_status = Enum('single', 'married', 'divorced', 'widowed')
    registered_voter = Bool
    legal_guardian = Str

    # Interface for attributes that are always enabled:
    gen_group = Group(Item(name='first_name'),
                      Item(name='last_name'),
                      Item(name='age'),
                      label='General Info',
                      show_border=True)

    # Interface for adult-only attributes:
    adult_group = Group(Item(name='marital_status'),
                        Item(name='registered_voter'),
                        enabled_when='age >= 18',
                        label='Adults',
                        show_border=True)

    # Interface for child-only attribute:
    child_group = Group(Item(name='legal_guardian', enabled_when='age < 18'),
                        label='Minors',
                        show_border=True)

    # The view specification is simple, as the group specs have done the work:
    view = View(Group(gen_group, adult_group, child_group),
                resizable=True,
                buttons=['OK'])
Ejemplo n.º 2
0
class RecorderWithUI(Recorder):
    """
    This class represents a Recorder but with a simple user interface.
    """

    # The code to display
    code = Code(editor=CodeEditor(line='current_line'))

    # Button to save script to file.
    save_script = Button('Save Script')

    # The current line to show, used by the editor.
    current_line = Int

    # The root object which is being recorded.
    root = Any

    ########################################
    # Traits View.
    view = View(Group(
        HGroup(
            Item('recording', show_label=True),
            spring,
            Item('save_script', show_label=False),
        ),
        Group(Item('code', show_label=False)),
    ),
                width=600,
                height=360,
                id='enthought.scripting.recorder_with_ui',
                buttons=['Cancel'],
                resizable=True,
                handler=CloseHandler())

    ######################################################################
    # RecorderWithUI interface.
    ######################################################################
    def on_ui_close(self):
        """Called from the CloseHandler when the UI is closed. This
        method basically stops the recording.
        """
        from util import stop_recording
        from package_globals import get_recorder

        if get_recorder() is self:
            stop_recording(self.root, save=False)
        else:
            self.recording = False
            self.unregister(self.root)

    ######################################################################
    # Non-public interface.
    ######################################################################
    @on_trait_change('lines[]')
    def _update_code(self):
        self.code = self.get_code()
        self.current_line = len(self.lines) + 1

    def _save_script_fired(self):
        self.ui_save()
Ejemplo n.º 3
0
class Person(HasTraits):
    """ Demo class for demonstrating dynamic interface restructuring.
    """
    first_name = Str
    last_name = Str
    age = Range(0, 120)
    misc = Instance(Spec)

    # Interface for attributes that are always visible in interface:
    gen_group = Group(Item(name='first_name'),
                      Item(name='last_name'),
                      Item(name='age'),
                      label='General Info',
                      show_border=True)

    # Interface for attributes that depend on the value of 'age':
    spec_group = Group(Group(Item(name='misc', style='custom'),
                             show_labels=False),
                       label='Additional Info',
                       show_border=True)

    # A simple View is enough as long as the right handler is specified:
    view = View(Group(gen_group, spec_group),
                title='Personal Information',
                buttons=['OK'],
                resizable=True,
                handler=PersonHandler())
Ejemplo n.º 4
0
class Probe(HasTraits):
    HT = Range(low=40, high=3000.0, value=200.0)
    alpha = Range(low=0.0, high=80.0, value=15.0)
    wl = Property(Float, depends_on=['HT'])
    nomenclature = Enum('Krivanek', 'Rose', 'Number3')
    ab = Instance(Aberrations)

    def _get_wl(self):
        h = 6.626 * 10**-34
        m0 = 9.109 * 10**-31
        eV = 1.602 * 10**-19 * self.HT * 1000
        C = 2.998 * 10**8
        return h / np.sqrt(2 * m0 * eV * (1 + eV / (2 * m0 * C**2))) * 10**12

    gen_group = Group(
        HGroup(
            Item(name='nomenclature', label='Nomenclature'), spring,
            Item(name='HT',
                 label="High Tension, kV",
                 help='The microscope accelerating voltage'),
            Item('wl',
                 label="Wavelength, pm ",
                 style='readonly',
                 editor=TextEditor(format_str='%3.2f')), spring,
            Item('alpha', label="Conv. Angle")), )
    ab_group = Group(Group(Item(name='ab', style='custom'), show_labels=False),
                     show_border=True)

    view = View(Group(gen_group, ab_group),
                title='Higher-order Aberrations',
                buttons=['OK', 'Cancel'],
                resizable=True,
                handler=ProbeHandler())
Ejemplo n.º 5
0
    def default_traits_view(self):
        if self.model is None:
            g = Group()
            g.content.append(Label('No Model Selected'))
        else:
            #g = Group(label=self.modelname,show_border=False,orientation='horizontal',layout='flow')
            g = Group(label=self.modelname,show_border=True,orientation='vertical')
            hg = HGroup(Item('fittype',label='Fit Technique',
                             editor=EnumEditor(name='fittypes')))
            g.content.append(hg)
            gp = HGroup(scrollable=True)
            for p in self.model.params:
                gi = Group(orientation='horizontal',label=p)
                self.add_trait(p,Float)
                setattr(self,p,getattr(self.model,p))
                self.on_trait_change(self._param_change_handler,p)
                gi.content.append(Item(p,show_label=False))

                ffp = 'fixfit_'+p
                self.add_trait(ffp,Bool)
                #default to fixed if the paramtere is a class-level fixed model
                setattr(self,ffp,p in self.model.__class__.fixedpars)
                self.on_trait_change(self._param_change_handler,ffp)
                gi.content.append(Item(ffp,label='Fix?'))

                gp.content.append(gi)
            g.content.append(gp)

        return View(g,buttons=['Apply','Revert','OK','Cancel'])
Ejemplo n.º 6
0
class CheckListEditorDemo(HasTraits):
    """ Define the main CheckListEditor demo class. """

    # Define a trait for each of three formations:
    checklist_4col = List(
        editor=CheckListEditor(values=['one', 'two', 'three', 'four'], cols=4))

    checklist_2col = List(
        editor=CheckListEditor(values=['one', 'two', 'three', 'four'], cols=2))

    checklist_1col = List(
        editor=CheckListEditor(values=['one', 'two', 'three', 'four'], cols=1))

    # CheckListEditor display with four columns:
    cl_4_group = Group(Item('checklist_4col', style='simple', label='Simple'),
                       Item('_'),
                       Item('checklist_4col', style='custom', label='Custom'),
                       Item('_'),
                       Item('checklist_4col', style='text', label='Text'),
                       Item('_'),
                       Item('checklist_4col',
                            style='readonly',
                            label='ReadOnly'),
                       label='4-column')

    # CheckListEditor display with two columns:
    cl_2_group = Group(Item('checklist_2col', style='simple', label='Simple'),
                       Item('_'),
                       Item('checklist_2col', style='custom', label='Custom'),
                       Item('_'),
                       Item('checklist_2col', style='text', label='Text'),
                       Item('_'),
                       Item('checklist_2col',
                            style='readonly',
                            label='ReadOnly'),
                       label='2-column')

    # CheckListEditor display with one column:
    cl_1_group = Group(Item('checklist_1col', style='simple', label='Simple'),
                       Item('_'),
                       Item('checklist_1col', style='custom', label='Custom'),
                       Item('_'),
                       Item('checklist_1col', style='text', label='Text'),
                       Item('_'),
                       Item('checklist_1col',
                            style='readonly',
                            label='ReadOnly'),
                       label='1-column')

    # The view includes one group per column formation.  These will be displayed
    # on separate tabbed panels.
    view1 = View(cl_4_group,
                 cl_2_group,
                 cl_1_group,
                 title='CheckListEditor',
                 buttons=['OK'],
                 resizable=True)
Ejemplo n.º 7
0
class SetEditorDemo(HasTraits):
    """ Defines the SetEditor demo class.
    """

    # Define a trait each for four SetEditor variants:
    unord_nma_set = List(
        editor=SetEditor(values=['kumquats', 'pomegranates', 'kiwi'],
                         can_move_all=False,
                         left_column_title='Available Fruit',
                         right_column_title='Exotic Fruit Bowl'))

    unord_ma_set = List(
        editor=SetEditor(values=['kumquats', 'pomegranates', 'kiwi'],
                         left_column_title='Available Fruit',
                         right_column_title='Exotic Fruit Bowl'))

    ord_nma_set = List(
        editor=SetEditor(values=['apples', 'berries', 'cantaloupe'],
                         ordered=True,
                         can_move_all=False,
                         left_column_title='Available Fruit',
                         right_column_title='Fruit Bowl'))

    ord_ma_set = List(
        editor=SetEditor(values=['apples', 'berries', 'cantaloupe'],
                         ordered=True,
                         left_column_title='Available Fruit',
                         right_column_title='Fruit Bowl'))

    # SetEditor display, unordered, no move-all buttons:
    no_nma_group = Group(Item('unord_nma_set', style='simple'),
                         label='Unord I',
                         show_labels=False)

    # SetEditor display, unordered, move-all buttons:
    no_ma_group = Group(Item('unord_ma_set', style='simple'),
                        label='Unord II',
                        show_labels=False)

    # SetEditor display, ordered, no move-all buttons:
    o_nma_group = Group(Item('ord_nma_set', style='simple'),
                        label='Ord I',
                        show_labels=False)

    # SetEditor display, ordered, move-all buttons:
    o_ma_group = Group(Item('ord_ma_set', style='simple'),
                       label='Ord II',
                       show_labels=False)

    # The view includes one group per data type. These will be displayed
    # on separate tabbed panels:
    view = View(no_nma_group,
                no_ma_group,
                o_nma_group,
                o_ma_group,
                title='SetEditor',
                buttons=['OK'])
class NBSNetworkParameter(HasTraits):

    choices1 = List(Str)
    selected1 = List(Str)

    choices2 = List(Str)
    selected2 = List(Str)

    view = View(
        HGroup(
            Group(HGroup(
                Item('choices1',
                     show_label=False,
                     editor=TabularEditor(show_titles=False,
                                          selected='selected1',
                                          editable=False,
                                          multi_select=True,
                                          adapter=MultiSelectAdapter())),
                Item('selected1',
                     show_label=False,
                     editor=TabularEditor(show_titles=False,
                                          editable=False,
                                          adapter=MultiSelectAdapter())),
            ),
                  label="First group"),
            Group(HGroup(
                Item('choices2',
                     show_label=False,
                     editor=TabularEditor(show_titles=False,
                                          selected='selected2',
                                          editable=False,
                                          multi_select=True,
                                          adapter=MultiSelectAdapter())),
                Item('selected2',
                     show_label=False,
                     editor=TabularEditor(show_titles=False,
                                          editable=False,
                                          adapter=MultiSelectAdapter())),
            ),
                  label="Second group"),
        ),
        title='Select networks',
        width=0.5,
        height=0.5,
        buttons=['OK'],
        resizable=True,
    )

    def __init__(self, cfile, **traits):
        super(NBSNetworkParameter, self).__init__(**traits)

        li = []
        for cobj in cfile.connectome_network:
            li.append(cobj.obj.name)

        self.choices1 = li
        self.choices2 = li
Ejemplo n.º 9
0
class DerivedFoo(BaseFoo):
    """ A derived class that puts additional content in the 'foo' dynamic view.
        Note that the additional content could also have been added via a traits 
        category contribution, or even dynamic manipulation of metadata on a UI
        subelement.  The key is what the metadata represents when the view is
        *created*
    """

    knows_mother = Bool(False)
    mother_first_name = Str("My mother's first name")
    mother_last_name = Str("My mother's last name")

    knows_father = Bool(True)
    father_first_name = Str("My father's first name")
    father_last_name = Str("My father's last name")
    father_derived = Str

    ui_parents = Group(
        'knows_mother',
        'knows_father',
        label='Parents?',
        _foo_order=7,
        _foo_priority=1,
    )

    ui_mother = Group(
        'mother_first_name',
        'mother_last_name',
        label="Mother's Info",
        _foo_priority=1,
    )

    ui_father = Group(
        'father_first_name',
        'father_last_name',
        spring,
        'father_derived',
        label="Father's Info",
        _foo_order=15,
        _foo_priority=1,
        _foo_handler=FatherInfoHandler(),
    )

    def _knows_mother_changed(self, old, new):
        ui_mother = self.trait_view('ui_mother')
        if new:
            ui_mother._foo_order = 10
        elif hasattr(ui_mother, '_foo_order'):
            del ui_mother._foo_order

    def _knows_father_changed(self, old, new):
        ui_father = self.trait_view('ui_father')
        if new:
            ui_father._foo_order = 15
        elif hasattr(ui_father, '_foo_order'):
            del ui_father._foo_order
Ejemplo n.º 10
0
class TextEditorDemo ( HasTraits ): 
    """ This class specifies the details of the TextEditor demo.
    """

    # Define a trait for each of three variants
    string_trait     = Str( "sample string" ) 
    int_trait        = Int( 1 ) 
    password         = Password 


    # TextEditor display without multi-line capability (for various traits):
    text_int_group = Group( Item('int_trait', style='simple', label='Simple'), 
                            Item('_'),
                            Item('int_trait', style='custom', label='Custom'), 
                            Item('_'),
                            Item('int_trait', style='text', label='Text'), 
                            Item('_'),
                            Item('int_trait', style='readonly', label='ReadOnly'), 
                            label='Integer' ) 

    # TextEditor display with multi-line capability (for various traits):
    text_str_group = Group( Item('string_trait',
                                  style='simple', 
                                  label='Simple'), 
                            Item('_'),
                            Item('string_trait',
                                  style='custom', 
                                  label='Custom'), 
                            Item('_'),
                            Item('string_trait',
                                  style='text', 
                                  label='Text'), 
                            Item('_'),
                            Item('string_trait',
                                  style='readonly', 
                                  label='ReadOnly'), 
                            label='String' ) 

    # TextEditor display with secret typing capability (for Password traits):
    text_pass_group = Group( Item('password', style='simple', label='Simple'), 
                             Item('_'),
                             Item('password', style='custom', label='Custom'), 
                             Item('_'),
                             Item('password', style='text', label='Text'), 
                             Item('_'),
                             Item('password', style='readonly', label='ReadOnly'), 
                             label='Password' ) 


    # The view includes one group per data type.  These will be displayed
    # on separate tabbed panels.
    view1 = View(text_int_group, 
                 text_str_group, 
                 text_pass_group, 
                 title = 'TextEditor',
                 buttons = ['OK']) 
Ejemplo n.º 11
0
 def default_traits_view(self):
     return View(
         Group(Group(Item('open_file', style='custom'),
                     show_labels=False,
                     show_border=False),
               Item('items_list',
                    style='readonly',
                    editor=ListEditor(style='custom')),
               show_labels=False,
               label='Add a data source'))
Ejemplo n.º 12
0
class Employee(HasTraits):
    name = Str
    department = Str
    salary = Int
    bonus = Int

    traits_view = View(Group(*g1, label='个人信息', show_border=True),
                       Group(*g2, label='收入', show_border=True),
                       title="缺省内部视图")

    another_view = View(Group(*g1, label='个人信息', show_border=True),
                        Group(*g2, label='收入', show_border=True),
                        title="另一个内部视图")
Ejemplo n.º 13
0
 def default_traits_view(self):
     view = View(
         Group(
             Group(Item(
                 name='enabled',
                 label='Compute Vorticity',
             )),
             Group(
                 Item(name='vorticity_component',
                      style='custom',
                      resizable=True,
                      show_label=False), )))
     return view
Ejemplo n.º 14
0
class DateEditorDemo(HasTraits):
    """ Demo class to show Date editors. """
    single_date = Date
    multi_date = List(Date)
    info_string = Str('The editors for Traits Date objects.  Showing both '\
                      'the defaults, and one with alternate options.')

    multi_select_editor = DateEditor(multi_select=True,
                                     months=2,
                                     allow_future=False,
                                     padding=30,
                                     on_mixed_select='max_change',
                                     shift_to_select=False)

    view = View(Item('info_string',
                     show_label=False,
                     style='readonly'),

                Group(Item('single_date',
                           label='Simple date editor'),
                      Item('single_date',
                           style='custom',
                           label='Default custom editor'),
                      Item('single_date',
                           style='readonly',
                           editor=DateEditor(strftime='You picked %B %d %Y',
                                             message='Click a date above.'),
                           label='ReadOnly editor'),
                      label='Default settings for editors'),

                Group(Item('multi_date',
                           editor=multi_select_editor,
                           style='custom',
                           label='Multi-select custom editor'),
                      label='More customized editor: multi-select; disallow '\
                            'future; two months; padding; selection '\
                            'style; etc.'),

                resizable=True)

    def _multi_date_changed(self):
        """ Print each time the date value is changed in the editor. """
        print self.multi_date

    def _simple_date_changed(self):
        """ Print each time the date value is changed in the editor. """
        print self.simple_date, self.single_date

    def _single_date_changed(self):
        """ Print each time the date value is changed in the editor. """
        print self.single_date
Ejemplo n.º 15
0
    def _createView(self):
        """Set up a view for the traits."""

        # Figure out the ticks and ticklabels for the TAM. We want to put a tick on every
        #  coincidence. The dimensions of the TAM image we're showing are N*numCoincidences
        #  wide and tall.
        dim = self.subTAM.shape[0]
        tickWidth = dim / self._numCoincidences
        ticks = numpy.arange(tickWidth / 2, dim, tickWidth, dtype='float')
        tickLabels = [str(x) for x in range(self._numCoincidences)]

        self._plotEditor = PlotEditor(colorbar=True,
                                      xTicks=ticks,
                                      xTickLabels=tickLabels,
                                      yTicks=ticks,
                                      yTickLabels=tickLabels)
        self.traits_view = View(HGroup(
            Group(
                Group(Item(
                    'topology',
                    show_label=False,
                    label="Topology",
                ),
                      Item('normalized', show_label=True),
                      Item('magnifyActivity', show_label=True),
                      Item('threshold', show_label=True),
                      orientation='horizontal',
                      show_left=False),
                Group(
                    Item(
                        'subTAM',
                        style='custom',
                        show_label=False,
                        editor=PlotEditor(colorbar=True,
                                          xTicks=ticks,
                                          xTickLabels=tickLabels,
                                          yTicks=ticks,
                                          yTickLabels=tickLabels),
                        width=-self.plotSize[0],
                        height=-self.plotSize[0] + self.toolbarSize,
                    ),
                    Item(
                        'output',
                        style='readonly',
                        show_label=False,
                        editor=CodeEditor(),
                    ),
                ),
            ), ),
                                title='LocalTAM')
Ejemplo n.º 16
0
class MixedStyles(HasTraits):
    first_name = Str
    last_name = Str

    department = Enum("Business", "Research", "Admin")
    position_type = Enum("Full-Time", "Part-Time", "Contract")

    traits_view = View(Group(
        Item(name='first_name'), Item(name='last_name'),
        Group(Item(name='department'),
              Item(name='position_type', style='custom'),
              style='simple')),
                       title='Mixed Styles',
                       style='readonly')
Ejemplo n.º 17
0
class CubeAxesActor2D(tvtk.CubeAxesActor2D):
    """ Just has a different view than the tvtk.CubesAxesActor2D, with an 
        additional tick box.
    """

    # Automaticaly fit the bounds of the axes to the data
    use_data_bounds = true

    input_info = PipelineInfo(datasets=['any'],
                              attribute_types=['any'],
                              attributes=['any'])

    ########################################
    # The view of this object.

    traits_view = View(
        Group(
            Group(Item('visibility'),
                  HGroup(
                      Item('x_axis_visibility', label='X axis'),
                      Item('y_axis_visibility', label='Y axis'),
                      Item('z_axis_visibility', label='Z axis'),
                  ),
                  show_border=True,
                  label='Visibity'),
            Group(Item('use_ranges'),
                  HGroup(Item('ranges', enabled_when='use_ranges'), ),
                  show_border=True),
            Group(Item('use_data_bounds'),
                  HGroup(Item('bounds', enabled_when='not use_data_bounds'), ),
                  show_border=True),
            Group(Item('x_label'),
                  Item('y_label'),
                  Item('z_label'),
                  Item('label_format'),
                  Item('number_of_labels'),
                  Item('font_factor'),
                  show_border=True),
            HGroup(
                Item('show_actual_bounds',
                     label='Use size bigger than screen',
                     editor=BooleanEditor())),
            Item('fly_mode'),
            Item('corner_offset'),
            Item('layer_number'),
            springy=True,
        ),
        scrollable=True,
        resizable=True,
    )
Ejemplo n.º 18
0
 def default_traits_view(self):
     view = View(VSplit(
         HGroup(
             Group(
                 spring,
                 Item('delimiter', label='Column delimiter character'),
                 Item('comments', label='Comment character'),
                 Item('skiprows',
                      label='Number of lines to skip at the '
                      'beginning of the file'),
                 spring,
                 Item('handler.update_preview', show_label=False),
             ),
             Group(
                 Item(
                     'columns',
                     show_label=False,
                     style='readonly',
                     editor=ListEditor(style='custom'),
                     springy=True,
                 ),
                 label="Column names",
                 show_border=True,
             ),
         ),
         Group(Group(
             Item(
                 'data',
                 show_label=False,
                 editor=self.tabular_editor,
             ),
             label="Preview table",
         ),
               Group(
                   Item('handler.file_content',
                        style='readonly',
                        show_label=False,
                        springy=True),
                   label="%s" % self.model.filename,
               ),
               layout='tab'),
     ),
                 buttons=['OK', 'Cancel', 'Help'],
                 id='csv_load_editor',
                 resizable=True,
                 width=640,
                 height=580,
                 title='CSV import - [%s]' % self.model.filename)
     return view
Ejemplo n.º 19
0
class ComponentViewer(HasTraits):
    """ A viewer of components for testing purposes """

    # The component being viewed
    component = Instance(Component)

    # The canvas to which the component is added
    canvas = Instance(Canvas)

    # A view into a subsection of the canvas
    viewport = Instance(Viewport)

    # Default view
    traits_view = View(HSplit(
        Group(Item("viewport", editor=ComponentEditor(), show_label=False)),
        Group(Item(name="component", style="custom", show_label=False),
              scrollable=True)),
                       resizable=True,
                       id="canvas_viewer",
                       width=.6,
                       height=.4,
                       title="Viewer")

    def _canvas_default(self):
        """ Trait initialiser """

        canvas = Canvas(draw_axes=True, bgcolor="honeydew")
        return canvas

    def _viewport_default(self):
        """ Trait initialiser """

        viewport = Viewport(component=self.canvas, enable_zoom=True)
        viewport.tools.append(ViewportPanTool(viewport))
        return viewport

    def _component_changed(self, old, new):
        """ Handles the component being changed.
        """
        canvas = self.canvas
        if old is not None:
            canvas.remove(old)
        if new is not None:
            canvas.add(new)

    def _anytrait_changed_for_component(self, new):
        """ Handles redrawing of the canvas. """

        self.canvas.request_redraw()
Ejemplo n.º 20
0
class Plot_i(HasTraits):

    plot = Instance(Plot)
    color = ColorTrait('blue')
    marker = marker_trait
    marker_size = Int(4)
    line_width = Int(4)
    traits_view = View(Group(Tabbed(Group( \
        Group(Item('color', label="Color"), \
            Item('marker', label="Marker"), \
            orientation = 'vertical'), \
        Group( \
            Item('marker_size', label= "Size"), \
            Item('line_width', label = 'Linewidth'), \
            orientation = 'vertical'), \
        dock = 'tab', orientation = 'vertical')), \
        Item('plot', editor=ComponentEditor(), show_label=False), orientation = 'horizontal'), \
        width=800, height=600, resizable=True, title="Chaco Plot")

    def __init__(self,X,Y):
        super(Plot_i, self).__init__()
        self.load_data(X,Y)
        self.start()

    def load_data(self,X,Y) :
        self.X = X
        self.Y = Y
        plotdata = ArrayPlotData(x = X, y = Y)
        plot = Plot(plotdata)
        self.renderer_line = plot.plot(('x','y'),type = 'line', color = "blue")[0]
        self.renderer_scat = plot.plot(('x','y'),type = 'scatter', color = "blue")[0]
        self.plot = plot

    def start(self):
        self.configure_traits()

    def _color_changed(self):
        self.renderer_line.color = self.color
        self.renderer_scat.color = self.color

    def _marker_changed(self):
        self.renderer_scat.marker = self.marker

    def _marker_size_changed(self):
        self.renderer_scat.marker_size = self.marker_size

    def _line_width_changed(self):
        self.renderer_line.line_width = self.line_width
Ejemplo n.º 21
0
class ButtonEditorDemo ( HasTraits ): 
    """ Defines the main ButtonEditor demo class. """

    # Define a Button trait:
    fire_event = Button( 'Click Me' )

    def _fire_event_fired ( self ):
        print 'Button clicked!'

    # ButtonEditor display:
    # (Note that Text and ReadOnly versions are not applicable)
    event_group = Group(
        Item( 'fire_event', style = 'simple', label = 'Simple' ),
        Item( '_' ),
        Item( 'fire_event', style = 'custom', label = 'Custom' ),
        Item( '_' ),
        Item( label = '[text style unavailable]' ),
        Item( '_' ),
        Item( label = '[read only style unavailable]' )
    )

    # Demo view:
    view = View( 
        event_group,
        title     = 'ButtonEditor',
        buttons   = [ 'OK' ],
        resizable = True
    )
Ejemplo n.º 22
0
 def default_traits_view(self):
     view = View(
         HSplit(
             VSplit(
                 Item("object_class", editor=self.tree_editor, show_label=False, 
                     visible_when="object.show_tree"),
                 Group(
                     Item("search", label="搜索"),
                     Item("search_result_str", show_label=False,
                         editor=ListStrEditor(editable=False, selected_index="search_result_index")),
                     label="Search"),
             ),
             Item("current_document", style="custom", show_label=False,
                 editor=CodeEditor(lexer="null", search="top", line = "current_line", 
                     mark_lines="mark_lines", mark_color=0xff7777)),
             id = "tvtkdoc.hsplit"
         ),
         width = 700,
         height = 500,
         resizable = True,
         title = "TVTK文档浏览器",
         id = "tvtkdoc", 
         handler = TVTKDocumentHandler(),
     )
     return view
Ejemplo n.º 23
0
class StripeClass(remote_traits.MaybeRemoteHasTraits):
    gain = traits.Float(-40.0)  # in (degrees per second) / degrees
    offset = traits.Float(0.0)  # in degrees per second

    traits_view = View(
        Group((Item(name='gain', label='gain [ (deg/sec) / deg ]'),
               Item(name='offset', label='offset [ deg/sec ]'))), )
Ejemplo n.º 24
0
class StopShow(HasTraits):

    ########################################
    # Traits

    stop = Button('Stop interaction',
                  desc='if the UI interaction is to be stopped')

    # Private traits.
    # Stores a reference to the UI object so it can be disposed when the
    # interaction is stopped.
    _ui = Any

    view = View(Group(Item('stop'), show_labels=False),
                buttons=[],
                title='Control Show')

    ######################################################################
    # `object` interface.
    ######################################################################
    def __init__(self, **traits):
        super(StopShow, self).__init__(**traits)
        self._ui = self.edit_traits()

    ######################################################################
    # Non-public interface.
    ######################################################################
    def _stop_fired(self):
        _gui.stop_event_loop()
        self._ui.dispose()
Ejemplo n.º 25
0
class PointLoad(Source):
    # The version of this class.  Used for persistence.
    __version__ = 0

    point_load = Instance(tvtk.PointLoad,
                          args=(),
                          allow_none=False,
                          record=True)

    # Information about what this object can produce.
    output_info = PipelineInfo(datasets=['image_data'],
                               attribute_types=['any'],
                               attributes=['any'])

    # Create the UI for the traits.
    view = View(Group(Item(name='point_load', style='custom', resizable=True),
                      label='PointLoad',
                      show_labels=False),
                resizable=True)

    ######################################################################
    # `object` interface
    ######################################################################
    def __init__(self, **traits):
        # Call parent class' init.
        super(PointLoad, self).__init__(**traits)

        # Call render everytime source traits change.
        self.point_load.on_trait_change(self.render)

        # Setup the outputs.
        self.outputs = [self.point_load.output]
Ejemplo n.º 26
0
class LocatedPerson(Person):
    street = Str
    city = Str
    state = Str
    zip = Int(78663)

    extra = Group('street', 'city', 'state', 'zip')
Ejemplo n.º 27
0
class DataFitterPanel(DataFitter):
    """Fitter panel object, for data fitting with gui for fit function selection
    
    >>> import numpy
    >>> x = numpy.linspace(0,100)
    >>> y = numpy.linspace(0,100) + numpy.random.randn(50)
    >>> data = FitData(x = x, y = y)
    >>> t = DataFitter(data = data)
    
    >>> p,c =  t.fit()
    """
    category = Enum(list(CATEGORIES.keys()))
    function_names = Property(List(Str), depends_on='category')
    function_name = Str
    description = DelegatesTo('function')

    view = View(Group('category',
                      Item(name='function_name',
                           editor=EnumEditor(name='function_names'),
                           id='function_name_edit'),
                      Item('description', style='custom'),
                      label='Fit Function'),
                data_fitter_group,
                resizable=False)

    def _function_name_changed(self, name):
        self.function.function = getattr(CATEGORIES[self.category], name)

    def _get_function_names(self):
        function_names = CATEGORIES[self.category].FUNCTIONS
        self.function_name = function_names[0]
        return function_names
Ejemplo n.º 28
0
class ImageEnumEditorDemo ( HasTraits ): 
    """ Defines the ImageEnumEditor demo class.
    """

    # Define a trait to view:
    image_from_list = Trait( editor = ImageEnumEditor( values = image_list, 
                                                       prefix = '@icons:',
                                                       suffix = '_origin', 
                                                       cols   = 4, 
                                                       klass  = Dummy ), 
                             *image_list ) 

    # Items are used to define the demo display, one Item per editor style:
    img_group = Group(
        Item( 'image_from_list', style = 'simple',   label = 'Simple' ), 
        Item( '_' ),
        Item( 'image_from_list', style = 'custom',   label = 'Custom' ), 
        Item( '_' ),
        Item( 'image_from_list', style = 'text',     label = 'Text' ), 
        Item( '_' ),
        Item( 'image_from_list', style = 'readonly', label = 'ReadOnly' )
    ) 

    # Demo view:
    view = View( 
        img_group,
        title     = 'ImageEnumEditor',
        buttons   = [ 'OK' ],
        resizable = True
    ) 
Ejemplo n.º 29
0
    def _create_traits_ui_view(self):
        """ Create the traits UI view used by the editor.

        fixme: We create the view dynamically to allow the key bindings to be
        created dynamically (we don't use this just yet, but obviously plugins
        need to be able to contribute new bindings).

        """

        view = View(
            Group(Item('text',
                       editor=CodeEditor(key_bindings=self.key_bindings)),
                  Item('runbut', label='Run script...', show_label=False),
                  show_labels=False),
            id='enthought.envisage.editor.text_editor',
            handler=TextEditorHandler(),
            kind='live',
            resizable=True,
            width=1.0,
            height=1.0,
            #buttons   = NoButtons,
            buttons=['OK'],
        )

        return view
Ejemplo n.º 30
0
class ScatterPlotTraits(HasTraits):
    plot = Instance(Plot)
    data = Instance(ArrayPlotData)
    color = Color("blue")
    marker = marker_trait

    traits_view = View(Group(Item('color', label="Color"),
                             Item('marker', label="Marker"),
                             Item('object.line.marker_size', label="Size"),
                             Item('plot',
                                  editor=ComponentEditor(),
                                  show_label=False),
                             orientation="vertical"),
                       width=800,
                       height=600,
                       resizable=True,
                       title="Chaco Plot")

    def __init__(self, **traits):
        super(ScatterPlotTraits, self).__init__(**traits)
        x = np.linspace(-14, 14, 100)
        y = np.sin(x) * x**3
        data = ArrayPlotData(x=x, y=y)
        plot = Plot(data)

        self.line = plot.plot(("x", "y"), type="scatter", color="blue")[0]
        self.plot = plot
        self.data = data

    def _color_changed(self):
        self.line.color = self.color

    def _marker_changed(self):
        self.line.marker = self.marker