Exemple #1
0
class SettableCachedProperty(HasTraits):

    a = Range(1, 10)
    b = Range(1, 10)
    c = Property(Int)
    d = Property

    view = View(
        Item('a'),
        Item('b'),
        '_',
        Item('c',
             editor=RangeEditor(low=1, high=100, mode='slider')),
        Item('c'),
        '_',
        Item('d',
             editor=RangeEditor(low=1, high=400, mode='slider')),
        Item('d'),
        width=0.3
    )

    @property_depends_on('a,b', settable=True)
    def _get_c(self):
        return (self.a * self.b)

    @property_depends_on('c')
    def _get_d(self):
        return (self.c + self.c)
Exemple #2
0
 def control_view(self):
     v = View(
         #                 Group(
         Item('discrete_position',
              show_label=False,
              editor=EnumEditor(name='discrete_positions'),
              defined_when='discrete_positions'),
         Item('data_position',
              show_label=False,
              editor=RangeEditor(mode='slider',
                                 low_name='min',
                                 high_name='max')),
         Item(
             'update_position',
             show_label=False,
             editor=RangeEditor(mode='slider',
                                low_name='min',
                                high_name='max',
                                enabled=False),
         ),
         #                       label=self.display_name,
         #                       show_border=True
         #                       )
     )
     return v
Exemple #3
0
class TestRangeEditor(HasTraits):
    x = Float()
    low = Float(123.123)
    high = Float(1123.123)
    list = List(
        Float(editor=RangeEditor(
            low_name='low',
            high_name='high',
            # These force the large range
            # slider to be used.
            low=100.0,
            high=10000.123,
        )))
    view = View(
        Item(
            name='x',
            editor=RangeEditor(
                low_name='low',
                high_name='high',
                # These force the large range
                # slider to be used.
                low=100.0,
                high=10000.123,
            ),
        ),
        Item('list'),
        resizable=True,
    )
Exemple #4
0
    def default_traits_view(self):
        v = super(MultiframeSavesFigure, self).default_traits_view()
        vsplit = v.content.content[0]

        if self._has_ffmpeg:
            vpanel = HGroup(
                Item('video_file', editor=FileEditor(dialog_style='save')),
                Item('video_fps',
                     label='FPS',
                     editor=RangeEditor(low=1, high=100, mode='spinner')),
                UItem('make_video'))
            vsplit.content.insert(1, vpanel)
        panel = HGroup(
            Item('mode',
                 label='Scroll frames',
                 editor=RangeEditor(low=self._mn, high=self._mx)),
            UItem('mode',
                  visible_when='_mx > 101',
                  editor=RangeEditor(low=self._mn,
                                     high=self._mx,
                                     mode='slider')),
            Item('mode_value',
                 style='readonly',
                 label='Current frame: {0}'.format(self.mode_name)))
        vsplit.content.insert(1, panel)
        return v
class SettableCachedProperty(HasTraits):

    a = Range(1, 10)
    b = Range(1, 10)
    c = Property(Int, depends_on=['a', 'b'])
    d = Property(depends_on='c')

    view = View(
        Item('a'),
        Item('b'),
        '_',
        Item('c',
             editor=RangeEditor(low=1, high=100, mode='slider')),
        Item('c'),
        '_',
        Item('d',
             editor=RangeEditor(low=1, high=400, mode='slider')),
        Item('d'),
        width=0.3
    )

    @cached_property
    def _get_c(self):
        return (self.a * self.b)

    def _set_c(self, value):
        self.a = int(sqrt(value))
        self.b = int(sqrt(value))

    @cached_property
    def _get_d(self):
        return (self.c + self.c)
Exemple #6
0
 def control_view(self):
     return View(
         #                    CustomLabel('display_name', font_color=self.display_name_color),
         #                    Group(
         Item('data_position',
              show_label=False,
              editor=RangeEditor(mode='slider',
                                 format='%0.3f',
                                 low_name='min',
                                 high_name='max')),
         Item(
             'update_position',
             show_label=False,
             editor=RangeEditor(mode='slider',
                                format='%0.3f',
                                low_name='min',
                                high_name='max',
                                enabled=False),
         ),
         HGroup(
             Item('home_status',
                  show_label=False,
                  editor=ProgressEditor(
                      min=0,
                      max=2,
                  )),
             Item('home_position',
                  style='readonly',
                  width=150,
                  label='Steps'), Item('home_button', show_label=False),
             spring)
         #                          show_border=True,
         #                          label=self.display_name,
         #                          )
     )
Exemple #7
0
class Demo(HasTraits):

    vu = Instance(VUMeter)

    traits_view = View(
        VGroup(
            Group(
                UItem("vu",
                      editor=ComponentEditor(size=(60, 60)),
                      style="custom")),
            Item(
                "object.vu.percent",
                editor=RangeEditor(low=0.0, high=200.0, mode="slider"),
            ),
        ),
        "_",
        VGroup(
            Item(
                "object.vu.angle",
                label="angle",
                editor=RangeEditor(low=0.0, high=89.0, mode="slider"),
            ),
            Item(
                "object.vu._beta",
                editor=RangeEditor(low=0.0, high=1.0, mode="slider"),
            ),
        ),
        width=450,
        height=380,
        title="VU Meter",
        resizable=True,
    )
class CustomOverlay(AbstractOverlay):
    x = Float(10, editor=RangeEditor(low=1.0, high=600, mode="slider"))
    y = Float(10, editor=RangeEditor(low=1.0, high=500, mode="slider"))
    width = Range(10.0,
                  300,
                  editor=RangeEditor(low=10.0, high=300, mode="slider"))
    height = Range(10.0,
                   300,
                   editor=RangeEditor(low=10.0, high=300, mode="slider"))
    color = ColorTrait("red")

    traits_view = View(
        Group(Item("x"),
              Item("y"),
              Item("width"),
              Item("height"),
              Item("color"),
              orientation="vertical"))

    def overlay(self, component, gc, view_bounds=None, mode="normal"):
        gc.set_fill_color(self.color_)
        x = self.x + component.x
        y = self.y + component.y
        gc.rect(x, y, self.width, self.height)
        gc.fill_path()

    def _anytrait_changed(self):
        self.component.request_redraw()
class CustomOverlay(AbstractOverlay):
    x = Float(10, editor=RangeEditor(low=1.0, high=600, mode="slider"))
    y = Float(10, editor=RangeEditor(low=1.0, high=500, mode="slider"))
    width = Range(10.0, 300, editor=RangeEditor(low=10.0, high=300, mode="slider"))
    height = Range(10.0, 300, editor=RangeEditor(low=10.0, high=300, mode="slider"))
    color = ColorTrait("red")
    dataspace = Bool(False)

    _anchor = CArray

    traits_view = View(Group(
                        Item("x"), Item("y"), Item("width"), Item("height"),
                        Item("color"),
                        Item("dataspace", label="Data space?"),
                        orientation = "vertical"
                        ))

    def overlay(self, component, gc, view_bounds=None, mode="normal"):
        if self.dataspace:
            self.x, self.y = component.map_screen(self._anchor)
        gc.set_fill_color(self.color_)
        x = self.x + component.x
        y = self.y + component.y
        gc.rect(x, y, self.width, self.height)
        gc.fill_path()

    def _anytrait_changed(self):
        self.component.request_redraw()

    def _dataspace_changed(self):
        if self.dataspace:
            # Map our current x,y point into data space
            self._anchor = self.component.map_data((self.x, self.y))
Exemple #10
0
class ImageAdjustView(HasTraits):
    # brightness contrast controls
    freq_choices = List
    frequency = Str
    brightness = Float(0.0)
    contrast = Float(1.0)
    contrast_brightness = Property(depends_on=['brightness', 'contrast'])
    invert = Bool

    traits_view = View(Label('Frequency to Edit'),
                       UItem('frequency',
                             editor=EnumEditor(name='freq_choices')),
                       Label('Brightness and Contrast'),
                       Item('brightness',
                            editor=RangeEditor(low=0.0, high=1.0),
                            label='B'),
                       Item('contrast',
                            editor=RangeEditor(low=1.0, high=CONTRAST_MAX),
                            label='C'),
                       Item('invert'),
                       resizable=True,
                       kind='livemodal')

    def _get_contrast_brightness(self):
        return (self.contrast, self.brightness)
Exemple #11
0
    def traits_view(self):
        pos_grp = VGroup(
            UItem('move_enabled_button'),
            VGroup(HGroup(
                Item('position'),
                UItem('object.stage_manager.stage_map_name',
                      editor=EnumEditor(
                          name='object.stage_manager.stage_map_names')),
                UItem('stage_stop_button')),
                   Item('x', editor=RangeEditor(low=-25.0, high=25.0)),
                   Item('y', editor=RangeEditor(low=-25.0, high=25.0)),
                   Item('z', editor=RangeEditor(low=-25.0, high=25.0)),
                   enabled_when='_move_enabled'),
            label='Positioning')

        calibration_grp = VGroup(
            UItem('tray_calibration.style',
                  enabled_when='not tray_calibration.isCalibrating()'),
            UItem('tray_calibration.calibrate',
                  editor=ButtonEditor(
                      label_value='tray_calibration.calibration_step')),
            HGroup(
                Item('tray_calibration.x',
                     format_str='%0.3f',
                     style='readonly'),
                Item('tray_calibration.y',
                     format_str='%0.3f',
                     style='readonly')),
            Item('tray_calibration.rotation',
                 format_str='%0.3f',
                 style='readonly'),
            Item('tray_calibration.scale',
                 format_str='%0.4f',
                 style='readonly'),
            Item('tray_calibration.error',
                 format_str='%0.2f',
                 style='readonly'),
            UItem('tray_calibration.calibrator',
                  style='custom',
                  editor=InstanceEditor()),
            CustomLabel('tray_calibration.calibration_help',
                        color='green',
                        height=75,
                        width=300),
            label='Tray Calibration')

        tgrp = Group(pos_grp, calibration_grp, layout='tabbed')

        egrp = HGroup(
            UItem('enabled_led', editor=LEDEditor()),
            UItem('enable', editor=ButtonEditor(label_value='enable_label')),
            UItem('fire_laser_button', enabled_when='enabled'),
            Item('output_power', label='Power'), UItem('units'), spring,
            icon_button_editor('snapshot_button', 'camera'),
            icon_button_editor('test_connection_button',
                               'connect',
                               tooltip='Test Connection'))
        v = View(VGroup(egrp, tgrp))
        return v
class Example(HasTraits):
    radius = Float
    angle = Float
    traits_view = View(Item('radius', editor=RangeEditor(low=0, high=10.0)),
                       Item('angle',
                            editor=RangeEditor(low=-pi,
                                               high=pi,
                                               low_label='-pi',
                                               high_label='pi')),
                       title="RangeEditor Example")
Exemple #13
0
 def traits_view(self):
     v = View(
         Item('nominal_hv'), Item('current_hv', style='readonly'),
         Item('y_symmetry',
              editor=RangeEditor(low_name='y_symmetry_low',
                                 high_name='y_symmetry_high',
                                 mode='slider')),
         Item('z_symmetry',
              editor=RangeEditor(low_name='z_symmetry_low',
                                 high_name='z_symmetry_high',
                                 mode='slider')), Item('extraction_lens'))
     return v
Exemple #14
0
class EmulatorPreferencesPane(PreferencesPane):
    """ The preferences pane for the Framework application.
    """

    #### 'PreferencesPane' interface ##########################################

    # The factory to use for creating the preferences model object.
    model_factory = EmulatorPreferences

    category = Str('Editors')

    #### 'FrameworkPreferencesPane' interface ################################

    # Note the quirk in the RangeEditor: specifying a custom editor is
    # supposed to take the defaults from the item name specified, but I
    # can't get it to work with only the "mode" parameter.  I have to specify
    # all the other params, and the low/high values have to be attributes
    # in EmulatorPreferences, not the values in the trait itself.  See
    # traitsui/editors/range_editor.py
    view = View(
        VGroup(HGroup(Item('map_width', editor=RangeEditor(mode="spinner", is_float=False, low_name='map_width_low', high_name='map_width_high')),
                      Label('Default Character Map Width (in bytes)'),
                      show_labels = False),
               HGroup(Item('bitmap_width', editor=RangeEditor(mode="spinner", is_float=False, low_name='bitmap_width_low', high_name='bitmap_width_high')),
                      Label('Default Bitmap Width (in bytes)'),
                      show_labels = False),
               HGroup(Item('hex_grid_width', editor=RangeEditor(mode="spinner", is_float=False, low_name='hex_grid_width_low', high_name='hex_grid_width_high')),
                      Label('Default Hex Grid Width (in bytes)'),
                      show_labels = False),
               HGroup(Item('text_font'),
                      Label('Hex Display Font'),
                      show_labels = False),
               HGroup(Item('header_font'),
                      Label('Column Header Font'),
                      show_labels = False),
               HGroup(Item('int_display_format'),
                      Label('Number Display Format'),
                      show_labels=False),
               HGroup(Item('hex_display_format'),
                      Label('Hex Display Format'),
                      show_labels=False),
               HGroup(Item('hex_grid_lower_case'),
                      Label('Use Lower Case for Hex Digits'),
                      show_labels = False),
               HGroup(Item('assembly_lower_case'),
                      Label('Use Lower Case for Assembler Mnemonics'),
                      show_labels = False),
               HGroup(Item('highlight_background_color', editor=ColorEditor(), style='custom'),
                      Label('Highlight Color'),
                      show_labels = False),
               label='Hex Editor'),
        resizable=True)
Exemple #15
0
 def traits_view(self):
     v = View(
         Item('test_connection_button', show_label=False),
         HGroup(
             UItem('enabled_led', editor=LEDEditor()),
             UItem('enable',
                   editor=ButtonEditor(label_value='enable_label'))),
         Item('position'),
         Item('x', editor=RangeEditor(low=-25.0, high=25.0)),
         Item('y', editor=RangeEditor(low=-25.0, high=25.0)),
         Item('z', editor=RangeEditor(low=-25.0, high=25.0)),
     )
     return v
class Oscillator(HasTraits):

    amp = Float(1.0)
    freq = Float(5.0)
    phase = Float(0.0)
    damping = Float(0.01)
    
    traits_view = View(
            Item('amp', editor=RangeEditor(low=1.0, high=5.0, low_label='', high_label='', mode='slider'), show_label=False),
            Item('freq', editor=RangeEditor(low=10.0, high=10.5, low_label='', high_label='', mode='slider'), show_label=False),
            Item('phase', editor=RangeEditor(low=0.0, high=2. * np.pi, low_label='', high_label='', mode='slider'), show_label=False),
            Item('damping', editor=RangeEditor(low=0.0, high=0.1, low_label='', high_label='', mode='slider'), show_label=False),
            )
Exemple #17
0
class DampedOscView(HasTraits):
    """
    Access the model traits using DelegatesTo().
    """

    model = Instance(DampedOsc)

    x = DelegatesTo('model')
    y = DelegatesTo('model')
    a = DelegatesTo('model')
    b = DelegatesTo('model')
    omega = DelegatesTo('model')
    phase = DelegatesTo('model')

    plot = Instance(Plot)

    traits_view = \
        View(
            Group(
                UItem('plot', editor=ComponentEditor(), style='custom'),
            ),
            Item('a', label='a', editor=RangeEditor(low=0.0, high=10.0)),
            Item('b', label='b', editor=RangeEditor(low=0.0, high=2.0)),
            Item('omega', label='omega',
                 editor=RangeEditor(low=0.0, high=10.0)),
            Item('phase', label='phase',
                 editor=RangeEditor(low=-pi, high=pi,
                                    low_label='-pi', high_label="pi")),
            resizable=True,
            width=600,
            height=550,
            title="a * exp(-b*x) * cos(omega*x + phase)",
        )

    def _plot_default(self):
        data = ArrayPlotData(x=self.x, y=self.y)
        plot = Plot(data)
        plot.plot(('x', 'y'), style='line', color='green')
        plot.value_range.set_bounds(-self.a, self.a)
        return plot

    def _y_changed(self):
        # Get the plot's ArrayPlotData object.
        data = self.plot.data
        # Update the value of y in the ArrayPlotData.
        data.set_data('y', self.y)

    def _a_changed(self):
        self.plot.value_range.set_bounds(-self.a, self.a)
Exemple #18
0
class Demo(HasTraits):
    plot = Instance(Component)

    scatter_renderer = Instance(Component)

    alpha = DelegatesTo('scatter_renderer')

    traits_view = View(Group(Item('plot',
                                  editor=ComponentEditor(size=size,
                                                         bgcolor=bg_color),
                                  show_label=False),
                             Group(
                                 Item('alpha',
                                      editor=RangeEditor(low=0.0,
                                                         high=1.0)), ),
                             orientation="vertical"),
                       resizable=True,
                       title=title)

    def _plot_default(self):
        return _create_plot_component()

    def _scatter_renderer_default(self):
        renderer = _create_scatter_renderer(self.plot)
        return renderer
Exemple #19
0
    def traits_view(self):
        agrp = VGroup(
            HGroup(
                Item('power', tooltip='Hit Enter for change to take effect'),
                Item('units', style='readonly', show_label=False), spring,
                Item('duration',
                     label='Duration (s)',
                     tooltip='Set the laser pulse duration in seconds'),
                Item('pulse_button',
                     editor=ButtonEditor(label_value='pulse_label'),
                     show_label=False,
                     enabled_when='enabled')))
        mgrp = VGroup(
            HGroup(Spring(width=-5, springy=False),
                   Item('object.wait_control.high', label='Set Max. Seconds'),
                   spring, UItem('object.wait_control.continue_button')),
            HGroup(
                Spring(width=-5, springy=False),
                Item(
                    'object.wait_control.current_time',
                    show_label=False,
                    editor=RangeEditor(
                        mode='slider',
                        low=1,
                        # low_name='low_name',
                        high_name='object.wait_control.duration')),
                CustomLabel('object.wait_control.current_time',
                            size=14,
                            weight='bold')),
            show_border=True)

        v = View(VGroup(agrp, mgrp, show_border=True),
                 id='pulse',
                 handler=PulseHandler())
        return v
    def default_traits_view(self):
        prod_comp_names = self.model.all_data.keys()
        time_slice_max = self.model.active_anim_data.columnliqZ.shape[2] - 1

        return View(
            VGroup(
                HGroup(
                    Item('model.product_component',
                         label='Component',
                         editor=EnumEditor(values=prod_comp_names)),
                    Spring(),
                    Item("time_description",
                         style="readonly",
                         show_label=False),
                    Spring(),
                    Item("model.simulation_name",
                         style="readonly",
                         label="Simulation"),
                ),
                Item('model.time_slice',
                     label='Time slice',
                     editor=RangeEditor(low=0,
                                        high=time_slice_max,
                                        mode='slider')),
                HGroup(
                    UItem('model.plot',
                          editor=ComponentEditor(),
                          show_label=False), ),
                show_border=True,
            ),
            resizable=True,
            title="Animation Plot",
            width=1000,
            height=800,
        )
Exemple #21
0
    def traits_view(self):
        cview = View(
            VGroup(
                CustomLabel('message',
                            size=14,
                            weight='bold',
                            color_name='message_color'),
                HGroup(Spring(width=-5, springy=False),
                       Item('high', label='Set Max. Seconds'), spring,
                       CustomLabel('current_time', size=14, weight='bold'),
                       UItem('continue_button')),
                HGroup(
                    Spring(width=-5, springy=False),
                    Item('current_time',
                         show_label=False,
                         editor=RangeEditor(mode='slider',
                                            low=1,
                                            high_name='duration')))))

        v = View(
            UItem('active_control',
                  style='custom',
                  visible_when='single',
                  editor=InstanceEditor(view=cview)),
            UItem('controls',
                  editor=ListEditor(use_notebook=True,
                                    selected='active_control',
                                    page_name='.page_name',
                                    view=cview),
                  style='custom',
                  visible_when='not single'))
        return v
Exemple #22
0
 def default_traits_view(self):
     return View(
         Item(
             "lower_bound",
             editor=TextEditor(auto_set=False,
                               enter_set=True,
                               evaluate=float),
         ),
         Item(
             "upper_bound",
             editor=TextEditor(auto_set=False,
                               enter_set=True,
                               evaluate=float),
         ),
         Item(
             "initial_value",
             editor=RangeEditor(
                 low_name="lower_bound",
                 high_name="upper_bound",
                 format="%.3f",
                 label_width=28,
             ),
         ),
         Item("n_samples"),
     )
Exemple #23
0
 def _get_additional_tabs(self):
     controls = VGroup(
         HGroup(
             Item('play', show_label=False),
             Item('stop', show_label=False, enabled_when='_playing'),
             Item('pause', show_label=False, enabled_when='_playing'),
             Item('bstep',
                  show_label=False,
                  enabled_when=
                  '_stepping or not _playing and frame>=1+step_len'),
             Item('fstep',
                  show_label=False,
                  enabled_when='_stepping or not _playing'),
             Item('step_len', show_label=False),
         ),
         Item('frame',
              enabled_when='0',
              editor=RangeEditor(low=1, high_name='nframes',
                                 mode='slider')))
     vtab = VGroup(
         controls,
         Item(
             'video_image',
             style='custom',
             show_label=False,
             width=150,
             height=170,
             #                    width=640, height=480,
             editor=ImageEditor()))
     return [vtab]
 def get_control_group(self):
     cg = Group(
         HGroup(
             UItem('pointer',
                   editor=ButtonEditor(label_value='pointer_label')),
             Item('time_constant',
                  editor=EnumEditor(values=TIME_CONSTANTS)),
             spring,
         ),
         HGroup(
             Item('temperature',
                  width=50,
                  format_str='%0.1f',
                  style='readonly'),
             Item('temperature',
                  width=-150,
                  show_label=False,
                  editor=BarGaugeEditor(low=300,
                                        high=1500,
                                        colormap='hot',
                                        scale='linear',
                                        width=100))),
         Item('emissivity',
              editor=RangeEditor(format='%0.1f',
                                 mode='slider',
                                 low_name='emmin',
                                 high_name='emmax')))
     return cg
 def test_modify_slider_log_range_slider(self):
     model = RangeModel()
     view = View(
         Item(
             "float_value",
             editor=RangeEditor(low=.1, high=1000000000, mode='logslider')
         )
     )
     tester = UITester()
     with tester.create_ui(model, dict(view=view)) as ui:
         number_field = tester.find_by_name(ui, "float_value")
         slider = number_field.locate(Slider())
         text = number_field.locate(Textbox())
         # 10 steps is equivalent to 1 page step
         # on this scale either of those is equivalent to increasing the
         # trait's value from 10^n to 10^(n+1)
         for _ in range(10):
             slider.perform(KeyClick("Right"))
         displayed = text.inspect(DisplayedText())
         self.assertEqual(model.float_value, 1.0)
         self.assertEqual(displayed, str(model.float_value))
         slider.perform(KeyClick("Page Up"))
         displayed = text.inspect(DisplayedText())
         self.assertEqual(model.float_value, 10.0)
         self.assertEqual(displayed, str(model.float_value))
 def default_traits_view(self):
     return View(
         HGroup(VGroup(
             Label('Select the variables to be displayed'
                   'in the salt-curve plot'),
             UItem("curve_plot", style='custom')),
                VGroup(
                    Group(UItem("base_table",
                                style='custom',
                                resizable=False),
                          scrollable=True,
                          show_border=True),
                    Label("Select a formulation base to view in the"
                          " salt-curve plot"),
                    HGroup(
                        Item('conc_rounding',
                             editor=RangeEditor(
                                 low=0,
                                 high=10,
                                 high_label='No. of decimal places'),
                             label="Concentration rounding",
                             tooltip="Number of decimal places to round"
                             " concentration values")),
                    UItem("curve_data_table", style='custom'),
                ),
                scrollable=True))
Exemple #27
0
 def test_simple_spin_editor_auto_set_false(self):
     model = RangeModel()
     view = View(
         Item("value",
              editor=RangeEditor(
                  low=1,
                  high=12,
                  mode="spinner",
                  auto_set=False,
              )))
     LOCAL_REGISTRY = TargetRegistry()
     _register_simple_spin(LOCAL_REGISTRY)
     tester = UITester(registries=[LOCAL_REGISTRY])
     with tester.create_ui(model, dict(view=view)) as ui:
         # sanity check
         self.assertEqual(model.value, 1)
         number_field = tester.find_by_name(ui, "value")
         # For whatever reason, "End" was not working here
         number_field.perform(KeyClick("Right"))
         with self.assertTraitDoesNotChange(model, "value"):
             number_field.perform(KeyClick("0"))
         displayed = number_field.inspect(DisplayedText())
         self.assertEqual(displayed, "10")
         with self.assertTraitChanges(model, "value"):
             number_field.perform(KeyClick("Enter"))
         self.assertEqual(model.value, 10)
    def check_range_enum_editor_format_func(self, style):
        # RangeEditor with enum mode doesn't support format_func
        obj = RangeModel()
        view = View(
            UItem(
                "value",
                editor=RangeEditor(
                    low=1, high=3,
                    format_func=lambda v: "{:02d}".format(v),
                    mode="enum"
                ),
                style=style,
            )
        )

        tester = UITester()
        with tester.create_ui(obj, dict(view=view)) as ui:
            editor = ui.get_editors("value")[0]

            # No formatting - simple strings
            self.assertEqual(editor.names[:3], ["1", "2", "3"])
            self.assertEqual(editor.mapping, {"1": 1, "2": 2, "3": 3})
            self.assertEqual(
                editor.inverse_mapping, {1: "1", 2: "2", 3: "3"}
            )
Exemple #29
0
 def traits_view(self):
     return self.view_klass(VGroup(
         HGroup(Item("range_low", label=self.axis_name + "-axis range"),
                Item("range_high", show_label=False),
                Item("reset_range", show_label=False),
                Item("scaling", label="Scaling"),
                show_border=True,
                label="Range"),
         HGroup(Item("title_style",
                     editor=InstanceEditor(),
                     style="custom",
                     show_label=False),
                show_border=True,
                label="Title"),
         HGroup(Item('label_rotation',
                     editor=RangeEditor(low=0, high=360),
                     tooltip="(String labels only)"),
                Item('show_all_labels',
                     label="Show all ticks/labels",
                     tooltip="(String labels only)"),
                show_border=True,
                label="Labels",
                visible_when="support_text_labels"),
     ),
                            resizable=True)
 def check_modify_slider(self, mode):
     model = RangeModel(value=0)
     view = View(
         Item(
             "value",
             editor=RangeEditor(low=0, high=10, mode=mode)
         )
     )
     tester = UITester()
     with tester.create_ui(model, dict(view=view)) as ui:
         number_field = tester.find_by_name(ui, "value")
         slider = number_field.locate(Slider())
         text = number_field.locate(Textbox())
         # slider values are converted to a [0, 10000] scale.  A single
         # step is a change of 100 on that scale and a page step is 1000.
         # Our range in [0, 10] so these correspond to changes of .1 and 1.
         # Note: when tested manually, the step size seen on OSX and Wx is
         # different.
         for _ in range(10):
             slider.perform(KeyClick("Right"))
         displayed = text.inspect(DisplayedText())
         self.assertEqual(model.value, 1)
         self.assertEqual(displayed, str(model.value))
         slider.perform(KeyClick("Page Up"))
         displayed = text.inspect(DisplayedText())
         self.assertEqual(model.value, 2)
         self.assertEqual(displayed, str(model.value))