def check_checklist_mappings_tuple_value_change(self, style): check_list_editor_factory = CheckListEditor( values=[(1, "one"), (2, "two")], format_func=lambda t: t[1].upper(), ) formatted_view = View( UItem( "value", editor=check_list_editor_factory, style=style, )) model = ListModel() with reraise_exceptions(), \ self.setup_ui(model, formatted_view) as editor: # FIXME issue enthought/traitsui#841 with self.assertRaises(AssertionError): self.assertEqual(editor.names, ["ONE", "TWO"]) self.assertEqual(editor.names, ["one", "two"]) check_list_editor_factory.values = [(2, "two"), (1, "one")] # FIXME issue enthought/traitsui#841 with self.assertRaises(AssertionError): self.assertEqual(editor.names, ["TWO", "ONE"]) self.assertEqual(editor.names, ["two", "one"])
def traits_view(self): hgrp = VGroup(HGroup(Item('hpost_pad', label='Pad')), UItem('hpost_date', style='custom'), HGroup(UItem('hpost_time')), show_border=True, label='High') lgrp = VGroup(HGroup(Item('lpost_pad', label='Pad')), UItem('lpost_date', style='custom'), HGroup(UItem('lpost_time')), show_border=True, label='Low') atype_grp = HGroup(UItem('atypes', style='custom', editor=CheckListEditor( name='available_atypes', cols=3)), show_border=True, label='Analysis Types') mgrp = HGroup(UItem('mass_spectrometers', style='custom', editor=CheckListEditor( name='available_mass_spectrometers', cols=3)), show_border=True, label='Mass Spectrometers') v = View(VGroup(HGroup(lgrp, hgrp), atype_grp, mgrp), title='Find Associated Parameters', buttons=['OK', 'Cancel']) return v
def default_traits_view(self): view = KromView( HGroup( VGroup( Group( Item("select_all_collections", label="All"), UItem('displayed_log_collection_names', editor=CheckListEditor( values=self._all_log_collection_names), style='custom'), HGroup( UItem("color_editor"), ), label='Experiments/Simulations', show_border=True, ), Group( UItem('displayed_log_family_names', editor=CheckListEditor( values=self._all_log_family_names, format_func=lambda a: a), style='custom'), label='Plot Grouping', show_border=True, ), visible_when='_show_control' ), VGroup( UItem('_container', editor=ComponentEditor(), show_label=False), show_border=True, ), ), title="Chromatogram Plot", ) return view
class CheckListEditorDemo(HasTraits): """ Define the main CheckListEditor demo class. """ # Define a trait for each of three formations: checklist_4col = List( editor=CheckListEditor(values=['one', 'two', 'three', 'four'], cols=4)) checklist_2col = List( editor=CheckListEditor(values=['one', 'two', 'three', 'four'], cols=2)) checklist_1col = List( editor=CheckListEditor(values=['one', 'two', 'three', 'four'], cols=1)) # CheckListEditor display with four columns: cl_4_group = Group(Item('checklist_4col', style='simple', label='Simple'), Item('_'), Item('checklist_4col', style='custom', label='Custom'), Item('_'), Item('checklist_4col', style='text', label='Text'), Item('_'), Item('checklist_4col', style='readonly', label='ReadOnly'), label='4-column') # CheckListEditor display with two columns: cl_2_group = Group(Item('checklist_2col', style='simple', label='Simple'), Item('_'), Item('checklist_2col', style='custom', label='Custom'), Item('_'), Item('checklist_2col', style='text', label='Text'), Item('_'), Item('checklist_2col', style='readonly', label='ReadOnly'), label='2-column') # CheckListEditor display with one column: cl_1_group = Group(Item('checklist_1col', style='simple', label='Simple'), Item('_'), Item('checklist_1col', style='custom', label='Custom'), Item('_'), Item('checklist_1col', style='text', label='Text'), Item('_'), Item('checklist_1col', style='readonly', label='ReadOnly'), label='1-column') # The view includes one group per column formation. These will be displayed # on separate tabbed panels. view1 = View(cl_4_group, cl_2_group, cl_1_group, title='CheckListEditor', buttons=['OK'], resizable=True)
class PrefmapPicker(HasTraits): # Consumer liking ds row_set = List(Tuple()) # Descriptive analysis / sensory profiling ds col_set = List(Tuple()) sel_row = List() sel_col = List() combinations = List(Tuple()) combination_updated = Event() @on_trait_change('sel_row,sel_col') def _new_selection(self, obj, name, old_value, new_value): if not (self.sel_row and self.sel_col): return sel = (self.sel_row[0], self.sel_col[0]) self.combinations = [] self.combinations.append(sel) self.combination_updated = True def get_selected_combinations(self): return self.combinations traits_view = View( Group( Group( Label('Consumer likings'), Item('sel_row', editor=CheckListEditor(name='row_set'), style='simple', show_label=False), orientation='vertical', ), Group( Label('Sensory profiling'), Item('sel_col', editor=CheckListEditor(name='col_set'), style='simple', show_label=False), orientation='vertical', ), orientation='horizontal', ), resizable=True, ) test_view = View( resizable=True, width=300, height=200, )
def traits_view(self): ctrl_grp = VGroup( HGroup(UItem('use_project_exclusion'), Item('exclusion_pad', enabled_when='use_project_exclusion')), HGroup(Item('use_offset_analyses', label='Use Offset')), VGroup(HGroup(Item('toggle_analysis_types', label='Toggle')), UItem('analysis_types', style='custom', editor=CheckListEditor( cols=1, name='available_analysis_types')), label='Analysis Types', show_border=True)) v = View(HSplit(ctrl_grp, UItem('graph', style='custom', width=0.80)), buttons=[ 'Cancel', Action(name='Replace', on_perform=self.replace_action), Action(name='Append', on_perform=self.append_action), Action(name='Replace All', on_perform=self.replace_all_action), Action(name='Append All', on_perform=self.append_all_action) ], title='Graphical Filter', kind='livemodal', resizable=True) return v
class PCAHandler(OpHandler): add_channel = Event remove_channel = Event channels = Property(List(Str), observe='context.channels') operation_traits_view = \ View(Item('name', editor = TextEditor(auto_set = False, placeholder = "None")), VGroup(Item('channels_list', editor = VerticalListEditor(editor = InstanceHandlerEditor(view = 'channel_view', handler_factory = ChannelHandler), style = 'custom', mutable = False), style = 'custom'), Item('handler.add_channel', editor = ButtonEditor(value = True, label = "Add a channel"), show_label = False), Item('handler.remove_channel', editor = ButtonEditor(value = True, label = "Remove a channel")), show_labels = False), VGroup(Item('num_components', editor = TextEditor(auto_set = False), label = "Num\nComponents"), Item('whiten'), Item('by', editor = CheckListEditor(cols = 2, name = 'context_handler.previous_conditions_names'), label = 'Group\nEstimates\nBy', style = 'custom'), label = "Estimate parameters"), VGroup(Item('subset_list', show_label = False, editor = SubsetListEditor(conditions = "context_handler.previous_conditions", editor = InstanceHandlerEditor(view = 'subset_view', handler_factory = subset_handler_factory))), label = "Subset", show_border = False, show_labels = False), Item('do_estimate', editor = ButtonEditor(value = True, label = "Estimate!"), show_label = False), shared_op_traits_view) # MAGIC: called when add_channel is set def _add_channel_fired(self): self.model.channels_list.append(PCAChannel()) def _remove_channel_fired(self): if self.model.channels_list: self.model.channels_list.pop() def _get_channels(self): if self.context and self.context.channels: return natsorted(self.context.channels) else: return []
def view_data_control_group_builder(self, force_visible=False): """ Build view element for the Data column control. Parameters ---------- force_visible : bool Controls visibility of the created group. Don't force for the group embedded in the global view, but force it when opened as a popup. """ num_cols = 1 + len(self.model.column_list) // self.max_names_per_column column_controls_group = VGroup( make_window_title_group(self.column_list_section_title, title_size=3, include_blank_spaces=False), Item("visible_columns", show_label=False, editor=CheckListEditor(values=self.model.column_list, cols=num_cols), # The custom style allows to control a list of options rather # than having a checklist editor for a single value: style='custom'), show_border=True ) if force_visible: column_controls_group.visible_when = "" else: column_controls_group.visible_when = "show_column_controls" return column_controls_group
def traits_view(self): top = HGroup( NItem( 'parameter', editor=EnumEditor(name='parameters'), # width= -100 ), # Spring(springy=False, # width= -5), NItem( 'comparator', editor=EnumEditor(name='comparisons'), ), # NItem('add'), # Spring(springy=False, # width=50, visible_when='not removable'), show_labels=False, ) bottom = HGroup(NItem('add', ), NItem('remove', visible_when='removable'), NItem('criterion', ), NItem('criterion', width=-30, editor=CheckListEditor(name='criteria')), show_labels=False) v = View(VGroup(top, bottom, show_border=True)) return v
def get_view(style): return View(UItem( "value", editor=CheckListEditor(values=["one", "two", "three", "four"], ), style=style, ), resizable=True)
def check_checklist_mappings_name_change(self, style): class ListModel(HasTraits): value = List() possible_values = List(["one", "two"]) check_list_editor_factory = CheckListEditor( name="object.possible_values", format_func=lambda v: v.upper(), ) formatted_view = View( UItem( "value", editor=check_list_editor_factory, style=style, )) model = ListModel() with reraise_exceptions(), \ self.setup_ui(model, formatted_view) as editor: self.assertEqual(editor.names, ["ONE", "TWO"]) model.possible_values = ["two", "one"] self.assertEqual(editor.names, ["TWO", "ONE"])
def check_checklist_mappings_tuple_name_change(self, style): class ListModel(HasTraits): value = List() possible_values = List([(1, "one"), (2, "two")]) check_list_editor_factory = CheckListEditor( name="object.possible_values", format_func=lambda t: t[1].upper(), ) formatted_view = View( UItem( "value", editor=check_list_editor_factory, style=style, )) model = ListModel() with store_exceptions_on_all_threads(): editor = self.setup_ui(model, formatted_view) # FIXME issue enthought/traitsui#841 with self.assertRaises(AssertionError): self.assertEqual(editor.names, ["ONE", "TWO"]) self.assertEqual(editor.names, ["one", "two"]) model.possible_values = [(2, "two"), (1, "one")] # FIXME issue enthought/traitsui#841 with self.assertRaises(AssertionError): self.assertEqual(editor.names, ["TWO", "ONE"]) self.assertEqual(editor.names, ["two", "one"])
def default_traits_view(self): return View(Item('object.name'), Item('object.channels', editor = CheckListEditor(name='handler.previous_channels', cols = 2), style = 'custom'), shared_op_traits)
def traits_view(self): v = okcancel_view( Item( 'mode', tooltip= 'Normal: get analyses between now and start of pipeline - hours\n' 'Window: get analyses between now and now - hours'), Item('hours'), Item('period', label='Update Period (s)', tooltip= 'Default time (s) to delay between "check for new analyses"'), Item('mass_spectrometer', label='Mass Spectrometer', editor=EnumEditor(name='available_spectrometers')), Item('analysis_types', style='custom', editor=CheckListEditor(name='available_analysis_types', cols=len( self.available_analysis_types))), Item('post_analysis_delay', label='Post Analysis Found Delay', tooltip= 'Time (min) to delay before next "check for new analyses"'), Item('verbose'), title='Configure', ) return v
class PCPlotControl(PCBaseControl): show_labels = Bool(True) plot_controllers = Group( Item('x_down', show_label=False), Item('x_up', show_label=False), Item('reset_xy', show_label=False), Item('y_up', show_label=False), Item('y_down', show_label=False), Item('eq_axis', label="Equal scale axis"), Item('show_labels', label="Show labels"), Item('subset_groups', label="Color subset groups", editor=CheckListEditor(name='model.data.group_names')), orientation="horizontal", ) @on_trait_change('subset_groups') def sel_subset(self, obj, name, new): if not new: obj.model.color_subsets_group() else: obj.model.color_subsets_group(new[0]) @on_trait_change('show_labels') def switch_labels(self, obj, name, new): obj.model.show_labels(set_id=1, show=new)
class CheckListTest(Handler): #------------------------------------------------------------------------- # Trait definitions: #------------------------------------------------------------------------- value = List(editor=CheckListEditor(name='values', cols=5)) values = List(Str) values_text = Str('red orange yellow green blue indigo violet') #------------------------------------------------------------------------- # Traits view definitions: #------------------------------------------------------------------------- simple_view = View('value', 'values_text@') custom_view = View('value@', 'values_text@') #------------------------------------------------------------------------- # 'Initializes the object: #------------------------------------------------------------------------- def __init__(self, **traits): super().__init__(**traits) self._values_text_changed() #------------------------------------------------------------------------- # Event handlers: #------------------------------------------------------------------------- def _values_text_changed(self): self.values = self.values_text.split()
class OrderMenu(HasPrivateTraits): # The person's entree order: entree = Str # Reference to the restaurant's current entree capabilities: capabilities = Constant(kitchen_capabilities) # The user interface view: view = View( HSplit( VGroup(Item( 'entree', editor=EnumEditor(name='object.capabilities.available')), label='Order', show_border=True, dock='tab'), VGroup(Item('object.capabilities.available', show_label=False, style='custom', editor=CheckListEditor(values=possible_entrees)), label='Kitchen', show_border=True, dock='tab')), title='Dynamic EnumEditor Demo', )
def default_traits_view(self): return View( Item('name', editor=TextEditor(auto_set=False)), Item('xchannel', editor=EnumEditor(name='context.previous_wi.channels'), label="X Channel"), Item('ychannel', editor=EnumEditor(name='context.previous_wi.channels'), label="Y Channel"), Item('xscale', label="X Scale"), Item('yscale', label="Y Scale"), VGroup(Item('num_clusters', editor=TextEditor(auto_set=False)), Item('by', editor=CheckListEditor( cols=2, name='handler.previous_conditions_names'), label='Group\nEstimates\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), Item('do_estimate', editor=ButtonEditor(value=True, label="Estimate!"), show_label=False), label="Estimation parameters", show_border=False), shared_op_traits)
def traits_view(self): v = okcancel_view(UItem('attributes', style='custom', editor=CheckListEditor( name='available_attributes', cols=3)), title='Select Attributes') return v
def traits_view(self): v = View(VGroup(VGroup(UItem('columns', style='custom', editor=CheckListEditor(name='available_columns', cols=3)), label='Columns', show_border=True), # Group( # VGroup(HGroup(Heading('Lower Bound'), UItem('use_low_post')), # UItem('low_post', style='custom', enabled_when='use_low_post')), # VGroup(HGroup(Heading('Upper Bound'), UItem('use_high_post')), # UItem('high_post', style='custom', enabled_when='use_high_post')), # VGroup(HGroup(Heading('Named Range'), UItem('use_named_date_range')), # UItem('named_date_range', enabled_when='use_named_date_range'))), Item('omit_invalid'), Item('limit', tooltip='Limit number of displayed analyses', label='Limit'), show_border=True, label='Limiting'), buttons=['OK', 'Cancel', 'Revert'], # kind='modal', title=self.title, handler=TableConfigurerHandler, resizable=True, width=300) return v
class CheckListEditorDemo(HasTraits): """ Define the main CheckListEditor simple demo class. """ # Specify the strings to be displayed in the checklist: checklist = List( editor=CheckListEditor( values=['one', 'two', 'three', 'four', 'five', 'six'], cols=2 ) ) # CheckListEditor display with two columns: checklist_group = Group( '10', # insert vertical space (10 empty pixels) Label('The custom style lets you select items from a checklist:'), UItem('checklist', style='custom', id="custom"), '10', '_', '10', # horizontal line with vertical space above and below Label('The readonly style shows you which items are selected, ' 'as a Python list:'), UItem('checklist', style='readonly', id="readonly"), ) traits_view = View( checklist_group, title='CheckListEditor', buttons=['OK'], resizable=True )
def default_traits_view(self): return View( Item('name', editor=TextEditor(auto_set=False)), Item('channel', editor=EnumEditor(name='context.previous.channels'), label="Channel"), Item('scale'), VGroup(Item('num_components', editor=TextEditor(auto_set=False), label="Num\nComponents"), Item('sigma', editor=TextEditor(auto_set=False)), Item('by', editor=CheckListEditor( cols=2, name='context.previous.conditions_names'), label='Group\nEstimates\nBy', style='custom'), VGroup(Item('subset_dict', show_label=False, editor=SubsetEditor( conditions="context.previous.conditions")), label="Subset", show_border=False, show_labels=False), Item('context.do_estimate', editor=ButtonEditor(value=True, label="Estimate!"), show_label=False), label="Estimation parameters", show_border=False), shared_op_traits)
class ToolChooserExample(HasTraits): plot = Instance(Plot) tools = List(editor=CheckListEditor( values=["PanTool", "ZoomTool", "DragZoom"])) traits_view = View(Item("tools", label="Tools", style="custom"), Item('plot', editor=ComponentEditor(), show_label=False), width=800, height=600, resizable=True, title="Tool Chooser") def __init__(self): # Create the data and the PlotData object x = linspace(-14, 14, 500) y = sin(x) * x**3 plotdata = ArrayPlotData(x=x, y=y) # Create a Plot and associate it with the PlotData plot = Plot(plotdata) # Create a line plot in the Plot plot.plot(("x", "y"), type="line", color="blue") self.plot = plot def _tools_changed(self): classes = [eval(class_name) for class_name in self.tools] # Remove all tools from the plot plot_tools = self.plot.tools for tool in plot_tools: plot_tools.remove(tool) # Create new instances for the selected tool classes for cls in classes: self.plot.tools.append(cls(self.plot))
def default_traits_view(self): return View(Item("channels", editor = CheckListEditor(cols = 2, name = 'context.previous_wi.channels'), style = 'custom'), VGroup( Item('blank_file'), label = "Autofluorescence"), VGroup( Item('bleedthrough_list', editor = VerticalListEditor(editor = InstanceEditor(view = self.bleedthrough_traits_view()), style = 'custom', mutable = False), style = 'custom'), label = "Bleedthrough Correction", show_border = False, show_labels = False), VGroup( Item('beads_name', editor = EnumEditor(name = 'handler.beads_name_choices'), label = "Beads", width = -125), Item('beads_file'), Item('beads_unit', editor = EnumEditor(name = 'handler.beads_units')), Item('bead_peak_quantile', label = "Peak\nQuantile"), Item('bead_brightness_threshold', label = "Peak\nThreshold "), Item('bead_brightness_cutoff', label = "Peak\nCutoff"), label = "Bead Calibration", show_border = False), VGroup( Item('to_channel', editor = EnumEditor(name = 'channels')), Item('mixture_model', label = "Use mixture\nmodel?"), label = "Color Translation"), VGroup( Item('translation_list', editor = VerticalListEditor(editor = InstanceEditor(view = self.translation_traits_view()), style = 'custom', mutable = False), style = 'custom'), show_labels = False), VGroup(Item('subset_list', show_label = False, editor = SubsetListEditor(conditions = "context.previous_wi.conditions", metadata = "context.previous_wi.metadata", when = "'experiment' not in vars() or not experiment")), label = "Subset", show_border = False, show_labels = False), Item('do_estimate', editor = ButtonEditor(value = True, label = "Estimate!"), show_label = False), shared_op_traits)
def get_mapped_view(style): return View(UItem( "value", editor=CheckListEditor(values=[(1, "one"), (2, "two"), (3, "three"), (4, "four")], ), style=style, ), resizable=True)
def get_columns_group(): col_grp = VGroup(UItem('columns', style='custom', editor=CheckListEditor(name='available_columns', cols=3)), label='Columns', show_border=True) return col_grp
def traits_view(self): v = View(VGroup(UItem('columns', style='custom', editor=CheckListEditor(name='available_columns', cols=3)), Item('font', enabled_when='fontsize_enabled'), show_border=True, label='Isotopes')) return v
def traits_view(self): v = View(UItem('attributes', style='custom', editor=CheckListEditor(name='available_attributes', cols=3)), buttons=['OK', 'Cancel'], kind='livemodal') return v
def traits_view(self): g = VGroup( Item('user', style=self.user_style), Item('email'), Item('affiliation'), Item('categories', style='custom', editor=CheckListEditor(name='available_categories', cols=3))) v = self._new_view(g, title='Edit User') return v
class SelGType(HasTraits): check_list = List('for1', editor=CheckListEditor(values=['for1', 'for2', 'plain'], cols=1)) trait_view = View(Item('check_list', label='Group/Loop', height=40), title='Group/Loop type selection', buttons=['OK'])