def get_view(**kwargs): return View( Item( "value", editor=ListStrEditor(**kwargs), ) )
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'])
def traits_view(self): v = View( UItem('a', editor=VideoEditor()), # UItem('state'), width=1200, height=700) return v
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
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
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"], )
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
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
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)
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))
class DataFrameViewer(HasTraits): data = Instance('pandas.core.frame.DataFrame') view = View( Item('data', editor=DataFrameEditor(), width=400) )
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)
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"])
class DisallowNewTraits(HasStrictTraits): """ Make sure no extra traits are added. """ x = Int(10) traits_view = View(Item("x"), spring)
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
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)
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()
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'])
class _ComponentDialog(HasTraits): """ View containing an item with ComponentEditor. """ thing = Any traits_view = View( Item( 'thing', editor=ComponentEditor(), show_label=False), resizable=True)
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)
def test_vertical_layout(self): view = View(VGroup( Item("txt1"), Item("txt2"), )) with reraise_exceptions(), \ create_ui(MultipleTrait(), ui_kwargs=dict(view=view)): pass
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")))
class ListOfFloatsWithCSVEditor(ModelView): model = Instance(ListOfFloats) traits_view = View( Item(label="Close the window to append data"), Item("model.data", editor=CSVListEditor()), buttons=["OK"], )
def traits_view(self): traits_view = View( Include('parameters_group'), buttons=OKCancelButtons, title='Create new ' + self.model_name, #kind='modal' ) return traits_view
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'])
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
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"] )
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, )
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'])