def test_text_editor_placeholder_text_and_readonly(self): # Placeholder can be set independently of read_only flag foo = Foo() editor = TextEditor( placeholder="Enter name", read_only=True, ) view = View(Item(name="name", editor=editor)) tester = UITester() with tester.create_ui(foo, dict(view=view)) as ui: name_editor, = ui.get_editors("name") self.assertEqual( name_editor.control.placeholderText(), "Enter name", )
def test_custom_auto_set_false_do_not_update_wx(self): foo = Foo(name="") view = View( Item("name", editor=TextEditor(auto_set=False), style="custom"), Item("nickname", editor=TextEditor(auto_set=False), style="custom") ) tester = UITester() with tester.create_ui(foo, dict(view=view)) as ui: name_field = tester.find_by_name(ui, "name") name_field.perform(command.KeySequence("NEW")) # with auto-set as False the displayed name should match what has # been typed not the trait itself, After moving to another textbox # it should match the name trait display_name = name_field.inspect(query.DisplayedText()) self.assertEqual(foo.name, "") self.assertEqual(display_name, "NEW") tester.find_by_name(ui, "nickname").perform(command.MouseClick()) display_name = name_field.inspect(query.DisplayedText()) self.assertEqual(foo.name, "NEW") self.assertEqual(display_name, foo.name)
def get_editor(self, trait): from traitsui.api import TextEditor, CompoundEditor the_editors = [x.get_editor(trait) for x in self.handlers] text_editor = TextEditor() count = 0 editors = [] for editor in the_editors: if isinstance(text_editor, editor.__class__): count += 1 if count > 1: continue editors.append(editor) return CompoundEditor(editors=editors)
def default_traits_view(self): base_view = BasePlotParams.default_traits_view(self) return View(Item('xlim', label = "X Limits", editor = TupleEditor(editors = [TextEditor(auto_set = False, evaluate = float, format_func = lambda x: "" if x == None else str(x)), TextEditor(auto_set = False, evaluate = float, format_func = lambda x: "" if x == None else str(x))], labels = ["Min", "Max"], cols = 1)), Item('ylim', label = "Y Limits", editor = TupleEditor(editors = [TextEditor(auto_set = False, evaluate = float, format_func = lambda x: "" if x == None else str(x)), TextEditor(auto_set = False, evaluate = float, format_func = lambda x: "" if x == None else str(x))], labels = ["Min", "Max"], cols = 1)), base_view.content)
class ApplyRevertDemo(HasTraits): # Trait definitions: input = Str() stack = List() queue = List() # Traits view definitions: traits_view = View( VGroup( VGroup( Item('input', show_label=False, editor=TextEditor(auto_set=True)), label='Input', show_border=True, ), HGroup( VGroup( Item( 'stack', show_label=False, height=50, width=100, style='readonly', ), label='Stack', show_border=True, ), VGroup( Item( 'queue', show_label=False, height=50, width=100, style='readonly', ), label='Queue', show_border=True, ), ), ), resizable=True, height=300, title='Apply/Revert example', buttons=['Apply', 'Revert'], handler=ApplyRevert_Handler, )
def traits_view(self): v = okcancel_view(HGroup( UItem('parameter', editor=EnumEditor(name='parameters')), Item( 'value', editor=TextEditor(enter_set=True, auto_set=False), tooltip= '''1. Enter a number to modify all values to entered number. e.g 10 2. Use +=N to add N to all values. e.g +=10 adds 10 to all values. -= and *= also valid''' )), title='Value Editor', buttons=[ 'OK', ], default_button=None) return v
def get_axes_group(self): editor = TextEditor(enter_set=True, auto_set=False) xgrp = VGroup( 'xtitle', Item('xmin', editor=editor), Item('xmax', editor=editor), # Item('xcolor_', editor = ColorEditor(current_color = 'red')) ) ygrp = VGroup( 'ytitle', Item('ymin', editor=editor), Item('ymax', editor=editor), # Item('ycolor_', editor = ColorEditor(current_color = 'blue')) ) return VGroup(xgrp, ygrp, show_border=True)
class ListItem(HasTraits): """ Class used to represent an item in a list with traits UI. """ column_number = Int name = Str my_name = Str parent = Instance(HasTraits) view = View( HGroup( Item('name', style='readonly', show_label=False, resizable=False), Item('my_name', style='simple', show_label=False, editor=TextEditor(auto_set=False, enter_set=True), springy=True), ))
class ShowUsage(HasTraits): usage_str = Str() traits_view = View(Item("usage_str", style='readonly', show_label=False, editor=TextEditor(), resizable=True), width=680, resizable=True, icon=icon, title='Swift Console Usage') def __init__(self, usage, error_str): if error_str != "": self.usage_str = "<pre>" + error_str + '<br><br><br>' + usage + "</pre>" else: self.usage_str = "<pre>" + usage + "</pre>"
def test_text_editor_custom_style_placeholder(self): # Test against CustomEditor using QTextEdit foo = Foo() view = View(Item( name="name", style="custom", editor=TextEditor(placeholder="Enter name"), )) with launch_ui(self, object=foo, view=view) as ui: name_editor, = ui.get_editors("name") try: placeholder = name_editor.control.placeholderText() except AttributeError: # placeholderText is introduced to QTextEdit since Qt 5.2 pass else: self.assertEqual(placeholder, "Enter name")
def default_traits_view(self): return View(Item('handler.import_event', show_label=False), Item('handler.samples', label='Samples', style='readonly'), Item('ret_events', label='Events', style='readonly'), Item('handler.coarse', label="Random subsample?", show_label = False, editor = ToggleButtonEditor()), Item('object.events', editor = TextEditor(auto_set = False), label="Events per\nsample", visible_when='handler.coarse == True'), shared_op_traits)
def traits_view(self): v = View(VGroup( UItem('helpstr', style='readonly'), Item('title'), HGroup( VGroup(UItem('labels', style='custom', editor=CheckListEditor(values=LABELS)), show_border=True, label='Labels (optional)'), VGroup(UItem('description', style='custom'), show_border=True, label='Description (optional)')), UItem('exctext', style='custom', editor=TextEditor(read_only=True))), title='Exception', buttons=[SubmitAction, 'Cancel']) return v
class EnumSetting(Setting): values = List() traits_view = View( VGroup( Item('full_name', label='Name', style='readonly'), Item('value', editor=EnumEditor(name='values')), Item('description', style='readonly'), Item('default_value', style='readonly'), UItem('notes', label="Notes", height=-1, editor=MultilineTextEditor(TextEditor(multi_line=True)), style='readonly', show_label=True, resizable=True), show_border=True, label='Setting', ), ) def __init__(self, name, section, value, ordering, values, **kwargs): self.values = values Setting.__init__(self, name, section, value, ordering, **kwargs)
def bytes_editor(auto_set=True, enter_set=False, encoding=None): """ Factory function that returns a text editor for bytes. """ from traitsui.api import TextEditor if encoding is None: format = bytes.hex evaluate = bytes.fromhex else: format = partial(bytes.decode, encoding=encoding) evaluate = partial(str.encode, encoding=encoding) return TextEditor( multi_line=True, format_func=format, evaluate=evaluate, auto_set=auto_set, enter_set=enter_set, )
def __init__(self, title, actions, callback=None): self.callback = callback self.handler_executed = False self.execute_callback = False self.closed = False self.close = 0 self.view = View( Item('text', style='readonly', editor=TextEditor(), show_label=False), buttons=actions, title=title, handler=CallbackHandler(actions), icon=icon, resizable=True, )
def datetime_editor(): """ Factory function that returns an editor with date & time for editing Datetime values. """ try: from traitsui.api import DatetimeEditor return DatetimeEditor() except ImportError: logger.warn(msg="Could not import DatetimeEditor from " "traitsui.api, using TextEditor instead") from traitsui.api import TextEditor return TextEditor(evaluate=_datetime_str_to_datetime, format_func=_datetime_to_datetime_str)
def default_traits_view(self): return View( Item('name', editor=TextEditor(auto_set=False)), Item('statistic', editor=EnumEditor(name='handler.previous_statistics_names'), label="Statistic"), Item('statistic_name', editor=EnumEditor(values=sorted(transform_functions.keys())), label="Function"), Item('by', editor=CheckListEditor(cols=2, name='handler.indices'), label='Group\nBy', style='custom'), VGroup(Item('subset_list', show_label=False, editor=SubsetListEditor(conditions="handler.levels")), label="Subset", show_border=False, show_labels=False), shared_op_traits)
def default_traits_view(self): return View(VGroup( VGroup(Item('channel', style = 'readonly'), Item('by', editor = TextEditor(), style = 'readonly', label = "Group\nBy"), label = "1D Mixture Model Default Plot", show_border = False)), Item('context.view_warning', resizable = True, visible_when = 'context.view_warning', editor = ColorTextEditor(foreground_color = "#000000", background_color = "#ffff99")), Item('context.view_error', resizable = True, visible_when = 'context.view_error', editor = ColorTextEditor(foreground_color = "#000000", background_color = "#ff9191")))
def default_traits_view(self): view = KromView( Item("model.name", tooltip=COMPONENT_NAME_TOOLTIP, editor=TextEditor(invalid='_invalid_name'), enabled_when='name_editable'), Item("model.target_product", enabled_when="target_product_editable"), Item("model.extinction_coefficient", editor=UnitScalarEditor(), width=200), Item("model.molecular_weight", editor=UnitScalarEditor(), tooltip="Molecular weight of the component in kilo-Daltons " "(1 kDa=1 kg/mol)"), # Relevant when used as standalone view: buttons=OKCancelButtons, title=self.title) return view
class GeometryNameHolder(NameHolder): geometry = Str color = Color previous_name = Str traits_view = View( HGroup( Item( 'name', show_label=False, editor=TextEditor(auto_set=False, enter_set=True), ), Item('geometry', style='readonly'), Item('color', style='readonly'), ), ) def __str__(self): return 'Grid: %s, col:%s, geom:%s' % (self.name, self.color, self.geometry) def __repr__(self): return str(self)
def traits_view(self): v = View( VGroup( HGroup( icon_button_editor( 'do_diff', 'edit_diff', tooltip='Make Diff between two commits'), Item('show_all_commits', label='Show All Commits')), VSplit( UItem('commits', editor=myTabularEditor( adapter=HistoryCommitAdapter(), multi_select=True, editable=False, selected='selected_commits'))), UItem('selected_message', style='custom', height=-200, editor=TextEditor(read_only=True)))) return v
def default_traits_view(self): return View(Item('name', editor = TextEditor(auto_set = False)), Item('channel', editor=EnumEditor(name='context.previous_wi.channels'), label = "Channel"), Item('statistic_name', editor = EnumEditor(values = list(summary_functions.keys())), label = "Function"), Item('by', editor = CheckListEditor(cols = 2, name = 'handler.previous_conditions_names'), label = 'Group\nBy', style = 'custom'), VGroup(Item('subset_list', show_label = False, editor = SubsetListEditor(conditions = "context.previous_wi.conditions")), label = "Subset", show_border = False, show_labels = False), shared_op_traits)
def traits_view(self): coarse_grp = Group( Item('reference_detector', editor=EnumEditor(name='detectors')), Item('start_dac', label='Start'), Item('stop_dac', label='Stop'), Item('step_dac', label='Step'), Item('period', label='Scan Period (ms)'), HGroup( spring, Item('execute_button', editor=ButtonEditor(label_value='execute_label'), show_label=False)), label='Coarse') peak_detection_grp = Group(Item('min_peak_height', label='Min. Height (fA)'), Item('min_peak_separation', label='Min. Separation (V)', editor=TextEditor(evaluate=float)), Item('delta', tooltip=DELTA_TOOLTIP), label='Peak Detection') fine_grp = Group( Item('fwindow', label='Window (V)', tooltip='+/- volts centered at peak_i'), Item('fperiod', label='Scan Period (ms)', tooltip='fine scan integration time'), HGroup( spring, Item('fexecute_button', editor=ButtonEditor(label_value='fexecute_label'), show_label=False)), label='Fine', enabled_when='fine_scan_enabled') v = View( Group(coarse_grp, peak_detection_grp, fine_grp, layout='tabbed')) return v
def get_axes_group(self): editor = TextEditor(enter_set=True, auto_set=False) xgrp = VGroup('xtitle', HGroup(spring, Label('Track')), HGroup(Item('xmin', editor=editor, format_str='%0.3f', enabled_when='not object.track_x_min'), spring, Item('track_x_min', show_label=False)), HGroup(Item('xmax', editor=editor, format_str='%0.3f', enabled_when='not object.track_x_max'), spring, Item('track_x_max', show_label=False)) ) ygrp = VGroup('ytitle', HGroup(Item('ymin', editor=editor, format_str='%0.3f', enabled_when='not object.track_y_min'), spring, Item('track_y_min', show_label=False)), HGroup(Item('ymax', editor=editor, format_str='%0.3f', enabled_when='not object.track_y_max'), spring, Item('track_y_max', show_label=False)), ) return VGroup(Item('data_limit'), xgrp, ygrp, show_border=True)
def default_traits_view(self): return View( VGroup(Label(label="Channels", visible_when='model.tubes'), Item('object.channels_list', editor=VerticalListEditor(editor=InstanceEditor(), style='custom', mutable=False, deletable=True), show_label=False), Item('handler.reset_channels', show_label=False), visible_when='object.channels_list'), Item('object.events', editor=TextEditor(auto_set=False, format_func=lambda x: "" if x == None else str(x)), label="Events per\nsample"), Item('handler.samples', label='Samples', style='readonly'), Item('ret_events', label='Events', style='readonly'), Item('handler.setup_event', show_label=False), Item('do_estimate', editor=ButtonEditor(value=True, label="Import!"), show_label=False), shared_op_traits)
def traits_view(self): dropdown_msg = "Replace an existing template by \nselecting it from " \ "the dropdown." error_message = "Name must contain only numbers and letters, <br>" \ "and cannot match an existing template." view = self.view_klass(HGroup( VGroup(Item( "new_name", editor=TextEditor(invalid="new_name_is_required_and_invalid"), enabled_when='not replace_old_template', label="New template name:"), HGroup(Label(error_message, color="red"), visible_when="new_name_is_required_and_invalid"), show_border=True), VGroup(Spring(), Label("OR", font_size=20), Spring(), visible_when="len(plot_types) > 0"), VGroup(HGroup(Item('replace_old_template', show_label=False), Label(dropdown_msg), Spring()), HGroup( Item("selected_string", editor=EnumEditor(name='plot_types'), enabled_when='replace_old_template', show_label=False), Spring(), ), visible_when="len(plot_types) > 0", show_border=True), ), buttons=[ self.ok_button, self.man_temp_button, CancelButton ], handler=ManageTemplatesHandler(), title=self.title, height=140) return view
def get_editor(self, trait): # Make the special case of a 'bool' type use the boolean editor: if self.aType is bool: if self.editor is None: from traitsui.api import BooleanEditor self.editor = BooleanEditor() return self.editor # Otherwise, map all other types to a text editor: auto_set = trait.auto_set if auto_set is None: auto_set = True from traitsui.api import TextEditor return TextEditor( auto_set=auto_set, enter_set=trait.enter_set or False, evaluate=self.fast_validate[1], )
def default_traits_view(self): visible_when_ph = "model.model_type == '{}'".format( PH_STERIC_BINDING_MODEL ) view = KromView( VGroup( HGroup( Item("model.name", editor=TextEditor(auto_set=True, enter_set=True)), Spring(), Item("model.model_type", style='readonly', label="Type"), Spring(), Item("model.target_product", style='readonly') ), VGroup( VGroup( Item("model.is_kinetic", label="Is Kinetic", editor=BooleanEditor()), Item("model.sma_lambda", label="SMA Lambda", editor=PositiveFloatEditor()), ), VGroup( Item('param_formula_str', visible_when=visible_when_ph, style="readonly", show_label=False), Item("component_array", label="Comp. Coeff.", show_label=False, editor=self._tabular_editor), ), label="Parameters", show_border=True, ), ), # Relevant when used as standalone view: resizable=True, buttons=OKCancelButtons, default_button=OKButton, title="Configure {} model".format(self.model.model_type) ) return view
def trait_view(self, name=None, view_elements=None): return View( VGroup( Item( 'SearchTerm', label='Search:', id='search', editor=TextEditor(), #style = 'custom', dock='horizontal', show_label=True), Item('Object', label='Debug', id='debug', editor=ValueEditor(), style='custom', dock='horizontal', show_label=False), ), title='Dictionary Editor', width=800, height=600, resizable=True, )
class Application ( HasStrictTraits ): compute_box = Float(0.0) temp = Float(0.0) count = Int(0) dot = Int(-1) nine_button = Button('9') eight_button = Button('8') seven_button = Button('7') six_button = Button('6') five_button = Button('5') four_button = Button('4') three_button = Button('3') two_button = Button('2') one_button = Button('1') equals_button = Button('=') add_button = Button('+') subtract_button = Button('-') mul_button = Button('*') div_button = Button('/') zero_button = Button('0') dot_button = Button('.') clr_button = Button('clr') def _nine_button_fired(self): if self.dot == -1: self.compute_box = self.compute_box*10 +9.0 else: self.compute_box = (self.compute_box*10**(self.dot) +9.0)/10**(self.dot) self.dot +=1 def _eight_button_fired(self): if self.dot == -1: self.compute_box = self.compute_box*10 +8.0 else: self.compute_box = (self.compute_box*10**(self.dot) +8.0)/10**(self.dot) self.dot +=1 def _seven_button_fired(self): if self.dot == -1: self.compute_box = self.compute_box*10 +7.0 else: self.compute_box = (self.compute_box*10**(self.dot) +7.0)/10**(self.dot) self.dot +=1 def _six_button_fired(self): if self.dot == -1: self.compute_box = self.compute_box*10 +6.0 else: self.compute_box = (self.compute_box*10**(self.dot) +6.0)/10**(self.dot) self.dot +=1 def _five_button_fired(self): if self.dot == -1: self.compute_box = self.compute_box*10 +5.0 else: self.compute_box = (self.compute_box*10**(self.dot) +5.0)/10**(self.dot) self.dot +=1 def _four_button_fired(self): if self.dot == -1: self.compute_box = self.compute_box*10 +4.0 else: self.compute_box = (self.compute_box*10**(self.dot) +4.0)/10**(self.dot) self.dot +=1 def _three_button_fired(self): if self.dot == -1: self.compute_box = self.compute_box*10 +3.0 else: self.compute_box = (self.compute_box*10**(self.dot) +3.0)/10**(self.dot) self.dot +=1 def _two_button_fired(self): if self.dot == -1: self.compute_box = self.compute_box*10 +2.0 else: self.compute_box = (self.compute_box*10**(self.dot) +2.0)/10**(self.dot) self.dot +=1 def _one_button_fired(self): if self.dot == -1: self.compute_box = self.compute_box*10 +1.0 else: self.compute_box = (self.compute_box*10**(self.dot) +1.0)/10**(self.dot) self.dot +=1 def _zero_button_fired(self): # does some weird shit! if self.dot == -1: self.compute_box = self.compute_box*10 # else: # dunno what to do when we want to add # after zero! def _dot_button_fired(self): self.dot = 1 @on_trait_change('equals_button') def eval_expr(self): if self.count == 1: self.compute_box += self.temp elif self.count == -1: self.compute_box -= self.temp elif self.count == 2: self.compute_box = self.compute_box*self.temp elif self.count == -2: self.compute_box = self.temp/self.compute_box def _add_button_fired(self): self.temp = self.compute_box self.compute_box = 0.0 self.count = 1 self.dot = -1 def _subtract_button_fired(self): self.temp = self.compute_box self.compute_box = 0.0 self.count = -1 self.dot = -1 def _mul_button_fired(self): self.temp = self.compute_box self.compute_box = 0.0 self.count = 2 self.dot = -1 def _div_button_fired(self): self.temp = self.compute_box self.compute_box = 0.0 self.count = -2 self.dot = -1 def _clr_button_fired(self): self.temp = 0.0 self.compute_box = 0.0 self.count = 0 self.dot =-1 traits_view = View( VGroup( HGroup(Item('compute_box', label=" ", editor=TextEditor()), Item('temp', label=" ", editor=TextEditor(), style="readonly") ), HGroup( Group( HGroup(Item('nine_button', label=" "), Item('eight_button', label=" "), Item('seven_button', label=" "), ), HGroup(Item('six_button', label=" "), Item('five_button', label=" "), Item('four_button', label=" "), ), HGroup(Item('three_button', label=" "), Item('two_button', label=" "), Item('one_button', label=" "), ) ), VGroup(Item('zero_button', label=" "), Item('clr_button', label=" "), ), ), HGroup(Item('mul_button', label=" "), Item('dot_button', label=" "), Item('div_button', label=" "), ), HGroup(Item('add_button', label=" "), Item('equals_button', label=" "), Item('subtract_button', label=" "), ) ), resizable = True, buttons = [ 'OK' ], kind = 'live', )