Ejemplo n.º 1
0
def get_view(**kwargs):
    return View(
        Item(
            "value",
            editor=ListStrEditor(**kwargs),
        )
    )
Ejemplo n.º 2
0
class BooleanEditor(TextEditor):
    """ Editor factory for Boolean editors.
    """

    # -------------------------------------------------------------------------
    #  Trait definitions:
    # -------------------------------------------------------------------------

    #: Dictionary mapping user input to other values.
    #: These definitions override definitions in the 'text_editor' version
    mapping = mapping_trait

    # -------------------------------------------------------------------------
    #  Traits view definition:
    # -------------------------------------------------------------------------

    traits_view = View()

    # -------------------------------------------------------------------------
    #  EditorFactory methods
    # -------------------------------------------------------------------------

    def _get_custom_editor_class(self):
        """ Returns the editor class to use for "custom" style views.
        Overridden to return the simple_editor_class (instead of the
        CustomEditor class for the text editor's factory, which this class
        inherits from).

        """
        return self.simple_editor_class
class VisibleWhenProblem(HasTraits):

    which = Enum('one', 'two')

    on = Bool
    txt = Str

    onoff_group = HGroup(
        VGroup(Item('on', resizable=False, width=-100, height=-70),
               show_left=False,
               show_border=True,
               visible_when='which == "one"'), )

    text_group = VGroup(
        Item('txt', width=-_TEXT_WIDTH, height=-_TEXT_HEIGHT),
        visible_when='which == "two"',
        show_border=True,
    )

    traits_view = View(Item('which'),
                       VGroup(
                           Include('onoff_group'),
                           Include('text_group'),
                       ),
                       resizable=True,
                       buttons=['OK', 'Cancel'])
Ejemplo n.º 4
0
 def traits_view(self):
     v = View(
         UItem('a', editor=VideoEditor()),
         # UItem('state'),
         width=1200,
         height=700)
     return v
Ejemplo n.º 5
0
    def traits_view(self):
        w_view = 350 if is_display_small() else 480

        parameters_group = VGroup(
            Item('_'),
            HGroup(
                VGroup(
                    Spring(),
                    Item('handler.omega_hinton_diagram',
                         style='custom',
                         resizable=False,
                         show_label=False,
                         width=w_view), Spring()), Spring(),
                VGroup(Spring(), Item('handler.view_omega', show_label=False),
                       Spring())), Spring(), Item('_'), Spring(),
            HGroup(
                VGroup(
                    UItem('handler.theta_views'),
                    UItem('handler.theta_view',
                          style='custom',
                          resizable=False,
                          width=w_view), Spring()), Spring(),
                VGroup(Spring(), UItem('handler.view_theta'), Spring())))

        body = VGroup(Include('info_group'), parameters_group)

        traits_view = View(body, buttons=[OKButton], resizable=True)
        return traits_view
Ejemplo n.º 6
0
 def traits_view(self):
     contour_grp = HGroup(Item('color_map_name',
                               label='Color Map',
                               editor=EnumEditor(values=sorted(color_map_name_dict.keys()))),
                          Item('levels'),
                          Item('marker_size'),
                          visible_when='plot_kind=="Contour"')
     monitor_grp = Item('monitor', editor=EnumEditor(name='monitors'))
     v = View(
         VGroup(HGroup(UItem('calculate_button'),
                       UItem('data_source', editor=EnumEditor(values=['database', 'file'])),
                       monitor_grp),
                HGroup(Item('save_mean_j', label='Save Mean J'),
                       Item('auto_clear_cache', label='Auto Clear Cache')),
                Item('mean_j_error_type', label='Mean J Error'),
                HGroup(Item('use_weighted_fit'),
                       Item('use_monte_carlo'),
                       Item('monte_carlo_ntrials',
                            enabled_when='object.use_monte_carlo')),
                Item('predicted_j_error_type', label='Predicted J Error',
                     enabled_when='not (object.use_weighted_fit or object.use_monte_carlo)'),
                HGroup(Item('group_positions'),
                       Item('object.monitor.sample',
                            style='readonly', label='Sample')),
                Item('show_labels',
                     label='Display Labels',
                     tooltip='Display hole labels on plot'),
                HGroup(UItem('plot_kind'),
                       Item('model_kind', label='Fit Model',
                            editor=EnumEditor(values=['Bowl', 'Plane']))),
                # UItem('plot_kind', editor=EnumEditor(values=['Contour', 'Hole vs J']))),
                contour_grp))
     return v
Ejemplo n.º 7
0
class VisibleWhenProblem(HasTraits):

    which = Enum("one", "two")

    on = Bool()
    txt = Str()

    onoff_group = HGroup(
        VGroup(
            Item("on", resizable=False, width=-100, height=-70),
            show_left=False,
            show_border=True,
            visible_when='which == "one"',
        )
    )

    text_group = VGroup(
        Item("txt", width=-_TEXT_WIDTH, height=-_TEXT_HEIGHT),
        visible_when='which == "two"',
        show_border=True,
    )

    traits_view = View(
        Item("which"),
        VGroup(Include("onoff_group"), Include("text_group")),
        resizable=True,
        buttons=["OK", "Cancel"],
    )
Ejemplo n.º 8
0
 def default_traits_view(self):
     traits_view = View(
         Item('model.code',
              editor=CodeEditor(show_line_numbers=self.show_line_numbers),
              style=self.style)
     )
     return traits_view
Ejemplo n.º 9
0
 def test_data_frame_editor_multi_select(self):
     view = View(
         Item("data", editor=DataFrameEditor(multi_select=True), width=400))
     viewer = sample_data()
     with reraise_exceptions(), \
             create_ui(viewer, dict(view=view)):
         pass
Ejemplo n.º 10
0
    def _data_frame_view(self):
        """ Return the view used by the editor.
        """

        return View(
            Item(
                self._target_name(self.name),
                id='tabular_editor',
                show_label=False,
                editor=TabularEditor(
                    show_titles=self.factory.show_titles,
                    editable=self.factory.editable,
                    adapter=self.adapter,
                    selected=self._target_name(self.factory.selected),
                    selected_row=self._target_name(self.factory.selected_row),
                    selectable=self.factory.selectable,
                    activated=self._target_name(self.factory.selected),
                    activated_row=self._target_name(
                        self.factory.activated_row),  # noqa
                    clicked=self._target_name(self.factory.clicked),
                    dclicked=self._target_name(self.factory.dclicked),
                    right_clicked=self._target_name(
                        self.factory.right_clicked),  # noqa
                    right_dclicked=self._target_name(
                        self.factory.right_dclicked),  # noqa
                    column_clicked=self._target_name(
                        self.factory.column_clicked),  # noqa
                    column_right_clicked=self._target_name(
                        self.factory.column_right_clicked),  # noqa
                    operations=self.factory.operations,
                    update=self._target_name(self.factory.update),
                    refresh=self._target_name(self.factory.refresh),
                )),
            id='data_frame_editor',
            resizable=True)
Ejemplo n.º 11
0
    def _one_dim_view(self, object, style, width, trait):
        content = []
        shape = object.shape
        items = []
        format_func = self.editor.factory.format_func
        format_str = self.editor.factory.format_str
        for i in range(shape[0]):
            name = "f%d" % i
            self.add_trait(
                name,
                trait(
                    object[i],
                    event="field",
                    auto_set=self.editor.factory.auto_set,
                    enter_set=self.editor.factory.enter_set,
                ),
            )
            items.append(
                Item(
                    name=name,
                    style=style,
                    width=width,
                    format_func=format_func,
                    format_str=format_str,
                    padding=-3,
                ))

        group = Group(orientation="horizontal", show_labels=False, *items)
        content.append(group)

        return View(Group(show_labels=False, *content))
Ejemplo n.º 12
0
class DataFrameViewer(HasTraits):

    data = Instance('pandas.core.frame.DataFrame')

    view = View(
        Item('data', editor=DataFrameEditor(), width=400)
    )
Ejemplo n.º 13
0
    class Example(HasTraits):
        shapes = List()
        selection = List()
        add_random_cylinder = Button()
        remove_cylinder = Button()
        view = View(Item('shapes',
                         editor=OCCEditorFactory(selection='selection'),
                         show_label=False),
                    Item('add_random_cylinder', show_label=False),
                    Item('remove_cylinder', show_label=False),
                    width=0.8,
                    height=0.8,
                    resizable=True)

        def _selection_items_changed(self, name, undefined, list_change):
            print("selection trait changed", list_change.added)

        def _add_random_cylinder_fired(self, old, new):
            brep = BRepPrimAPI_MakeCylinder(random.random() * 50,
                                            random.random() * 50).Shape()
            trsf = gp_Trsf()
            trsf.SetTranslation(
                gp_Vec(random.random() * 100,
                       random.random() * 100,
                       random.random() * 100))
            brep.Move(TopLoc_Location(trsf))
            self.shapes.append(brep)

        def _remove_cylinder_fired(self, old, new):
            for s in self.selection:
                if s is None:
                    continue

                self.shapes.remove(s)
Ejemplo n.º 14
0
class FooDialog(HasTraits):
    """Test dialog that does nothing useful."""

    my_int = Int(2)
    my_str = Str("hallo")

    traits_view = View(Item("my_int"), Item("my_str"), buttons=["OK"])
Ejemplo n.º 15
0
class DisallowNewTraits(HasStrictTraits):
    """ Make sure no extra traits are added.
    """

    x = Int(10)

    traits_view = View(Item("x"), spring)
Ejemplo n.º 16
0
    def _create_resizable_view(self):
        # resizable_view factory, as I need to compute the height of the plot
        # from the number of annotations, and I couldn't find any other way to
        # do that

        # "touch" posterior_plot to have it initialize
        self.plot_container

        if is_display_small():
            height = 760
        else:
            height = 800

        resizable_plot_item = (Item(
            'plot_container',
            editor=ComponentEditor(),
            resizable=True,
            show_label=False,
            width=self.plot_width,
            height=self.plot_height,
        ))

        resizable_view = View(VGroup(
            Include('instructions_group'),
            resizable_plot_item,
        ),
                              width=450,
                              height=height,
                              resizable=True)

        return resizable_view
Ejemplo n.º 17
0
class _SamplingParamsDialog(HasTraits):
    nsamples = Int(200)
    burn_in_samples = Int(100)
    thin_samples = Int(1)

    traits_view = View(VGroup(
        Item('nsamples',
             label='Number of samples',
             editor=RangeEditor(mode='spinner',
                                low=100,
                                high=50000,
                                is_float=False),
             width=100),
        Item('burn_in_samples',
             label='Number of samples in burn-in phase',
             editor=RangeEditor(mode='spinner',
                                low=1,
                                high=50000,
                                is_float=False),
             width=100),
        Item('thin_samples',
             label='Thinning (keep 1 samples every N)',
             editor=RangeEditor(mode='spinner',
                                low=1,
                                high=50000,
                                is_float=False),
             width=100),
    ),
                       buttons=OKCancelButtons)
Ejemplo n.º 18
0
def test_data_frame_editor_multi_select():
    view = View(
        Item('data', editor=DataFrameEditor(multi_select=True), width=400))
    viewer = sample_data()
    with store_exceptions_on_all_threads():
        ui = viewer.edit_traits(view=view)
        ui.dispose()
Ejemplo n.º 19
0
class FooDialog(HasTraits):
    """Test dialog that does nothing useful."""

    my_int = Int(2)
    my_str = Str('hallo')

    traits_view = View(Item('my_int'), Item('my_str'), buttons=['OK'])
Ejemplo n.º 20
0
class _ComponentDialog(HasTraits):
    """ View containing an item with ComponentEditor. """
    thing = Any

    traits_view = View(
        Item(
            'thing', editor=ComponentEditor(), show_label=False),
        resizable=True)
Ejemplo n.º 21
0
class HResizeDialog(HasTraits):

    txt = Str('hallo')

    traits_view = View(HGroup(Item('txt', width=_TXT_WIDTH, resizable=True), ),
                       width=_DIALOG_WIDTH,
                       height=_DIALOG_HEIGHT,
                       resizable=True)
Ejemplo n.º 22
0
 def test_vertical_layout(self):
     view = View(VGroup(
         Item("txt1"),
         Item("txt2"),
     ))
     with reraise_exceptions(), \
             create_ui(MultipleTrait(), ui_kwargs=dict(view=view)):
         pass
Ejemplo n.º 23
0
 class TestClass(HasTraits):
     b = Bool(True)
     b_str = String("teststring")
     
     traits_view = View(Item(name = 'b',
                             label = "boooool",
                             show_label = False,
                             editor = ToggleButtonEditor(label_value = "b_str")))
Ejemplo n.º 24
0
class ListOfFloatsWithCSVEditor(ModelView):
    model = Instance(ListOfFloats)

    traits_view = View(
        Item(label="Close the window to append data"),
        Item("model.data", editor=CSVListEditor()),
        buttons=["OK"],
    )
Ejemplo n.º 25
0
 def traits_view(self):
     traits_view = View(
         Include('parameters_group'),
         buttons=OKCancelButtons,
         title='Create new ' + self.model_name,
         #kind='modal'
     )
     return traits_view
Ejemplo n.º 26
0
class FloatWithRangeEditor(HasTraits):
    """Dialog containing a RangeEditor in 'spinner' mode for an Int.
    """

    number = Float(5.0)

    traits_view = View(Item('number', editor=RangeEditor(low=0.0, high=12.0)),
                       buttons=['OK'])
Ejemplo n.º 27
0
 def test_horizontal_layout(self):
     # layout
     view = View(HGroup(
         Item("txt1"),
         Item("txt2"),
     ))
     with reraise_exceptions(), create_ui(MultipleTrait(),
                                          ui_kwargs=dict(view=view)):
         pass
Ejemplo n.º 28
0
class TupleEditor(HasTraits):
    """Dialog containing a Tuple of two Int's.
    """

    tup = Tuple(Int, Int)

    traits_view = View(
        Item(label="Enter 4 and 6, then press OK"), Item("tup"), buttons=["OK"]
    )
Ejemplo n.º 29
0
class HResizeDialog(HasTraits):

    txt = Str("hallo")

    traits_view = View(
        HGroup(Item("txt", width=_TXT_WIDTH, resizable=True)),
        width=_DIALOG_WIDTH,
        height=_DIALOG_HEIGHT,
        resizable=True,
    )
Ejemplo n.º 30
0
class NumberWithRangeEditor(HasTraits):
    """Dialog containing a RangeEditor in 'spinner' mode for an Int.
    """

    number = Int

    traits_view = View(
        Item(label="Range should be 3 to 8. Enter 1, then press OK"),
        Item('number', editor=RangeEditor(low=3, high=8, mode='text')),
        buttons=['OK'])