def readonly(name, checkbox=False, format_func=None, format_str=None, **kwargs): if checkbox: return Item(name=name, editor=BooleanEditor(), enabled_when='0', **kwargs ) else: item = Item(name=name, # editor=TextEditor(format_func=format_func), style='readonly', **kwargs ) if format_func or format_str: item.editor = TextEditor(format_func=format_func, format_str=format_str) return item
def config_model_view(self): menubar_config = MenuBar( Menu(Action(name='New Model', action='new_model', tooltip='Create a new model from scratch'), Action( name='Copy Model', action='copy_model', tooltip='Create a new model by copying an existing one'), name='Create Model')) view_config = View(Group(Item(name='model_list', style='custom'), show_border=True), Item(label="Lots of stuff should go here"), menubar=menubar_config, buttons=NoButtons, title='BiKiPy Modeler') return (view_config)
class DialogWithToolbar(HasTraits): """Test dialog with toolbar and menu.""" action_successful = Bool(False) def test_clicked(self): self.action_successful = True menubar = MenuBar(Menu(ActionGroup(TestAction), name="&Test menu")) toolbar = ToolBar(ActionGroup(TestAction)) traits_view = View( Item(label="Click the button on the toolbar or the menu item.\n" "The 'Action successful' element should turn to True."), Item("action_successful", style="readonly"), menubar=menubar, toolbar=toolbar, buttons=[TestAction, "OK"], )
class DatetimeInitDailog(HasTraits): date = Datetime() def _date_default(self): return DATE traits_view = View( Item('date', editor=DatetimeEditor(maximum_datetime=MAX_DATE, minimum_datetime=MIN_DATE)))
class NewModelADialog(NewModelDialog): """Create a dialog requesting the parameters to create Model A.""" model_name = Str(MODEL_A_NAME) nclasses = Int(5) parameters_group = VGroup( Item(name='nclasses', editor=RangeEditor(mode='spinner', low=3, high=1000), label='Number of annotation classes:', width=100), )
class _SingleStatView(HasTraits): value = Float name = Str txt = Str @on_trait_change('value') def _update_txt(self): txt = "{name} = {val:.4}".format(name=self.name, val=self.value) self.txt = txt traits_view = View(Item('txt', style='readonly', show_label=False))
def popup_view(self): """ Returns the popup View. """ factory = self.factory item = Item( self.name, show_label=False, padding=-4, style=factory.style, height=factory.height, width=factory.width, ) editor = factory.editor if editor is not None: if not isinstance(editor, EditorFactory): editor = editor() item.editor = editor return View(item, kind=factory.kind)
def slider(name, low=0, high=100, is_float=True): return Item( name=name, editor=RangeEditor( mode='slider', low=low, high=high, is_float=is_float, ), style='custom', )
def table(name, **kwargs): return Item( name=name, editor=TableEditor( auto_size=False, editable=False, configurable=False, # selection_mode='row', ), style='readonly', **kwargs)
class DialogWithToolbar(HasTraits): """Test dialog with toolbar and menu.""" action_successful = Bool(False) def test_clicked(self): print('perform action') self.action_successful = True menubar = MenuBar(Menu(ActionGroup(TestAction), name='&Test menu'), ) toolbar = ToolBar(ActionGroup(TestAction), ) traits_view = View( Item(label="Click the button on the toolbar or the menu item.\n" "The 'Action successful' element should turn to True."), Item('action_successful', style='readonly'), menubar=menubar, toolbar=toolbar, buttons=[TestAction, 'OK'])
def readonly(name, checkbox=False, format_func=None, format_str=None, **kwargs): if checkbox: return Item(name=name, editor=BooleanEditor(), enabled_when='0', **kwargs) else: item = Item( name=name, # editor=TextEditor(format_func=format_func), style='readonly', **kwargs) if format_func or format_str: item.editor = TextEditor(format_func=format_func, format_str=format_str) return item
def traits_view(self): traits_view = View( VGroup( Item('annotator_idx', label='Annotator index', editor=RangeEditor(mode='spinner', low=0, high=self.theta.shape[0]-1, ), ), HGroup( Item('theta_j_view', style='custom', show_label=False), ), ), width = 500, height = 400, resizable = True ) return traits_view
class NoLabelResizeTestDialog(HasTraits): """ Test the combination show_label=False, show_left=False. """ bool_item = Bool(True) traits_view = View(VGroup(Item('bool_item', resizable=True, show_label=False), show_left=False), resizable=True)
def base_view(self): """Returns the View that allows the popup view to be displayed.""" return View( Item( self.name, show_label=False, style="readonly", editor=TextEditor(view=self.popup_view()), padding=-4, ), kind="subpanel", )
class InputBox(HasPrivateTraits): message = Str input = Str view = View( [ Item( name='message', show_label=False, style='readonly', ), Item( name='input', show_label=False, ), ], buttons=['OK', 'Cancel'], kind='modal', width=400, # height=600, resizable=True, )
class _ComponentDialogWithSize(HasTraits): """ View containing an item with ComponentEditor and given size. """ thing = Any traits_view = View( Item( 'thing', editor=ComponentEditor(), show_label=False, width=ITEM_WIDTH, height=ITEM_HEIGHT), resizable=True)
def test_data_frame_editor_alternate_adapter(): class AlternateAdapter(DataFrameAdapter): pass alternate_adapter_view = View( Item('data', editor=DataFrameEditor(adapter=AlternateAdapter()), width=400)) viewer = sample_data() with store_exceptions_on_all_threads(): ui = viewer.edit_traits(view=alternate_adapter_view) ui.dispose()
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 tabs(name, **kwargs): ''' page_name ''' return Item( name=name, editor=ListEditor( use_notebook=True, dock_style='fixed', # view=view, **kwargs), show_label=False, style='custom', )
def test_data_frame_editor_alternate_adapter(self): class AlternateAdapter(DataFrameAdapter): pass alternate_adapter_view = View( Item( "data", editor=DataFrameEditor(adapter=AlternateAdapter()), width=400, )) viewer = sample_data() with reraise_exceptions(), \ create_ui(viewer, dict(view=alternate_adapter_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, multi_select=self.factory.multi_select, activated=self._target_name(self.factory.activated), activated_row=self._target_name( self.factory.activated_row ), # noqa clicked=self._target_name(self.factory.clicked), dclicked=self._target_name(self.factory.dclicked), scroll_to_row=self._target_name( self.factory.scroll_to_row ), # noqa scroll_to_row_hint=self.factory.scroll_to_row_hint, scroll_to_column=self._target_name( self.factory.scroll_to_column ), # noqa 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 traits_view(self): self.statistics_name = "Cohen's Kappa" traits_view = View( VGroup( HGroup( Item("statistics_name", show_label=False), Item("info_button", show_label=False) ), Spring(), HGroup( Spring(), Item("stats_view", style="custom", show_label=False, width=300, resizable=False), Spring() ), ), width=400, resizable = True ) return traits_view
class DialogWithSchema(HasTraits): """Test dialog with toolbar and menu schemas.""" action_successful = Bool(False) def test_clicked(self): self.action_successful = True menubar = SMenuBar( SMenu( SGroup( ActionSchema( action_factory=lambda **traits: TestAction, ), ), name="&Test menu", ), ) toolbar = SToolBar( SGroup( ActionSchema( action_factory=lambda **traits: TestAction, ), ), ) traits_view = View( Item( label="Click the button on the toolbar or the menu item.\n" "The 'Action successful' element should turn to True." ), Item("action_successful", style="readonly"), menubar=menubar, toolbar=toolbar, buttons=[TestAction, "OK"], )
def _get_auto_group(self): return HGroup( icon_button_editor( 'plot_button', 'chart_curve_go', tooltip='Replot the isotope evolutions. ' 'This may take awhile if many analyses are selected'), icon_button_editor('save_event', 'database_save', tooltip='Save fits to database'), spring, Item( 'auto_update', label='Auto Plot', tooltip= 'Should the plot refresh after each change ie. "fit" or "show". ' 'It is not advisable to use this option with many analyses'))
def traits_view(self): ncolumns = len(self.data[0]) w_table = min(WIDTH_CELL * ncolumns, MAX_WIDTH) w_view = min(w_table + W_MARGIN, MAX_WIDTH) return View(Group( Item('data', editor=TabularEditor(adapter=Array2DAdapter( ncolumns=ncolumns, format='%s', show_index=True)), show_label=False, width=w_table, padding=10), ), title='Annotations', width=w_view, height=800, resizable=True, buttons=OKCancelButtons)
class TextBox (HasPrivateTraits): message = Str view = View([ Item(name='message', show_label=False, style='readonly', editor=CodeEditor(), ), ], buttons=['OK'], # kind='modal', width=800, height=600, resizable=True, )
def init(self, parent): """Finishes initializing the editor by creating the underlying toolkit widget. """ self.update_editor() editor = TreeEditor( auto_open=self.factory.auto_open, hide_root=True, editable=False, nodes=value_tree_nodes, ) self._ui = self.edit_traits( parent=parent, view=View(Item("root", show_label=False, editor=editor), kind="subpanel"), ) self._ui.parent = self.ui self.control = self._ui.control
def icon_button_editor(trait, name, label=None, editor_kw=None, **kw): if editor_kw is None: editor_kw = {} name = add_extension(name, '.png') # name = '{}.png'.format(name) kw['show_label'] = label is not None kw['label'] = label or '' image = icon(name) return Item( trait, style='custom', editor=ButtonEditor( image=image, # style='toolbar', **editor_kw), **kw)
def _get_auto_group(self): return VGroup( HGroup( icon_button_editor( 'plot_button', 'refresh', tooltip='Replot the isotope evolutions. ' 'This may take awhile if many analyses are selected'), icon_button_editor('save_event', 'database_save', tooltip='Save fits to database'), Item( 'auto_update', label='Auto Plot', tooltip= 'Should the plot refresh after each change ie. "fit" or "show". ' 'It is not advisable to use this option with many analyses' )), HGroup( UItem('global_fit', editor=EnumEditor(name='fit_types')), UItem('global_error_type', editor=EnumEditor(name='error_types'))))
def traits_view(self): contour_grp = VGroup(Item('color_map_name', label='Color Map', editor=EnumEditor(values=sorted(color_map_name_dict.keys()))), Item('levels'), 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('group_positions'), Item('object.monitor.sample', style='readonly',label='Sample')), 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 ScopeWnd(AbstractWnd): pin = PinTrait('analog') interval = Time() @property def conf(self): return dict(pin=self.pin, interval=self.interval) def plot(self, data, fig): time_plot(data, fig) def measure(self, conf, stop_condition): return measure(self.conf, stop_condition) view = View( HGroup( 'start', 'stop', 'auto_update', readonly('alive', checkbox=True), ), # instance('tester', view=View( slider('interval', 0.1, 10), 'pin', # ), # ), Group( Item('figure', editor=MPLFigureEditor(), show_label=False ), ), width=600, height=300, resizable=True)