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'])
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): l = VGroup(UItem('low_post_time'), UItem('low_post_date', style='custom')) h = VGroup(UItem('high_post_time'), UItem('high_post_date', style='custom')) v = okcancel_view(Item('pad', label='Pad (hrs)'), HGroup(l, h), width=500) return v
class ShowRightLabelsDialog(HasTraits): """Dialog with labels on the left/right to test the label text.""" bool_item = Bool(True) traits_view = View( VGroup( VGroup(Item("bool_item"), show_left=False), VGroup(Item("bool_item"), show_left=True), ))
def traits_view(self): l = VGroup(UItem('low_post_time'), UItem('low_post_date', style='custom')) h = VGroup(UItem('high_post_time'), UItem('high_post_date', style='custom')) v = View(UItem('pad'), HGroup(l, h), kind='livemodal', width=500, resizable=True, buttons=['OK', 'Cancel']) return v
class VResizeTestDialog(HasTraits): """ Dialog with checkbox and text elements and labels on the right. We test the separation between element and label in VGroups. """ bool_item = Bool(True) txt_item = Str traits_view = View(VGroup( VGroup(Item('bool_item', resizable=True), show_left=False), VGroup(Item('txt_item', resizable=True), show_left=False), ), width=_DIALOG_WIDTH, height=100, resizable=True)
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
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 PyannoModelView(ModelView): """Superclass for all pyAnno model views""" #### Class attributes (*not* traits) # subclass of NewModelDialog new_model_dialog_class = None #### Model traits # name of the model model_name = Str('pyAnno model') # raised when model is updated model_updated = Event #### Class methods @classmethod def _create_model_from_dialog(cls, dialog): raise NotImplementedError() @classmethod def create_model_dialog(cls, parent, **kwargs): """Open a dialog to create a new model. All keyword arguments are passed to the model dialog class constructor. """ dialog = cls.new_model_dialog_class(**kwargs) dialog_ui = dialog.edit_traits(kind="livemodal", parent=parent) if dialog_ui.result: # user pressed 'Ok' # create model and update view model = cls._create_model_from_dialog(dialog) return model else: return None info_group = VGroup( Item('model_name', label='Model name:', style='readonly'), VGrid( Item('model.nclasses', label='Number of classes:', style='readonly'), Label(' '), Item('model.nannotators', label='Number of annotators:', style='readonly'), Label(' '), padding=0 ), padding=0 )
class NewModelBDialog(NewModelDialog): """Create a dialog requesting the parameters to create Model B.""" model_name = Str(MODEL_B_NAME) nclasses = Int(5) nannotators = Int(8) # prior strength multiplies the dirichlet parameters alpha prior_strength = Float(1.0) parameters_group = VGroup( Item(name='nclasses', editor=RangeEditor(mode='spinner', low=2, high=1000), label='Number of annotation classes:', width=100), Item(name='nannotators', editor=RangeEditor(mode='spinner', low=2, high=1000), label='Number of annotators:', width=100), Item(name='prior_strength', editor=RangeEditor(mode='slider', low=0.0, low_label='null ', high=3.0, high_label=' high', label_width=50), label='Informativeness of prior:') )
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_vertical_layout(self): view = View(VGroup( Item("txt1"), Item("txt2"), )) with reraise_exceptions(), \ create_ui(MultipleTrait(), ui_kwargs=dict(view=view)): pass
class VResizeDialog(HasTraits): txt = Str('hallo') traits_view = View(VGroup(Item('txt', width=_TXT_WIDTH, resizable=True), ), width=_DIALOG_WIDTH, height=_DIALOG_HEIGHT, resizable=True)
def traits_view(self): height = 760 if is_display_small() else 900 traits_view = View(VGroup(VGroup( Item('show_maximum', label='Show MAP estimate (circle)'), Item('show_majority_vote', label='Show majority vote (triangle)'), ), VGroup( Item('posterior_plot', editor=InstanceEditor(), style='custom', show_label=False), ), padding=0), height=height, scrollable=True, resizable=True) return traits_view
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 VResizeDialog(HasTraits): txt = Str("hallo") traits_view = View( VGroup(Item("txt", width=_TXT_WIDTH, resizable=True)), width=_DIALOG_WIDTH, height=_DIALOG_HEIGHT, resizable=True, )
def default_traits_view(self): return View( VGroup( UItem( "resizable_readonly_item", resizable=True, style="readonly", ), ), height=_DIALOG_HEIGHT, width=_DIALOG_WIDTH, )
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)
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), )
def traits_view(self): ctrl_grp = VGroup( # HGroup(UItem('add_band')), UItem('highlight_bands', height=115,editor=ListEditor(mutable=False, style='custom', editor=InstanceEditor()))) v = View( VSplit( ctrl_grp, UItem('container', editor=ComponentEditor(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
class SaveFileDialog(HasTraits): save_file = File(exists=False) dpi = Int(300) traits_view = View(VGroup( Item('save_file', label='Save to:', editor=FileEditor(allow_dir=False, dialog_style='save', entries=0), style='simple'), Item('dpi', label='Resolution (dpi):')), title='Save plot', width=400, resizable=True, buttons=OKCancelButtons)
def traits_view(self): db_table_editor = TableEditor( columns=[ ObjectColumn(name='data_id', label='Annotations ID', editable=False, width=0.65), ObjectColumn(name='model_name', editable=False, width=0.20), ObjectColumn(name='value', label='Log likelihood', editable=False, width=0.15) ], search=SearchIDFilter(), editable=True, deletable=True, configurable=False, sortable=True, sort_model=False, auto_size=False, orientation='vertical', show_toolbar=True, selection_mode='row', on_dclick=self.forward_to_model_data_view, on_select=self.track_selection) traits_view = View( VGroup( Item( 'results_table', editor=db_table_editor, show_label=False, ), HGroup( Item('open_to_main', show_label=False, width=100), Item('delete_action', show_label=False, enabled_when='current_selection is not None', width=100), Spring(), Item('close_view', show_label=False, width=100)), ), title='pyAnno results database', width=800, height=400, resizable=True, #buttons = [ 'OK' ], kind='live') return traits_view
class EnableWhenDialog(HasTraits): """ Test labels for enable when. """ bool_item = Bool(True) labelled_item = Str('test') unlabelled_item = Str('test') traits_view = View(VGroup( Item('bool_item', ), Item('labelled_item', enabled_when='bool_item'), Item('unlabelled_item', enabled_when='bool_item', show_label=False), ), 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 EnableWhenDialog(HasTraits): """ Test labels for enable when. """ bool_item = Bool(True) labelled_item = Str("test") unlabelled_item = Str("test") traits_view = View( VGroup( Item("bool_item"), Item("labelled_item", enabled_when="bool_item"), Item("unlabelled_item", enabled_when="bool_item", show_label=False), ), resizable=True, )
class TestShowArray(HasTraits): data = Array view = View(Item('data', editor=TabularEditor(adapter=Array2DAdapter( ncolumns=2, format='%s', show_index=False)), show_label=False), title='Array2D editor', width=0.3, height=0.8, resizable=True, buttons=NoButtons) VGroup( Item('data', editor=TabularEditor(adapter=Array2DAdapter( ncolumns=2, format='%d', show_index=False)), show_label=False)),
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
def traits_view(self): nclasses = self.beta.shape[1] w_table = WIDTH_CELL * nclasses h_table = HEIGHT_CELL * nclasses w_view = min(MAX_WIDTH, w_table + W_MARGIN) h_view = min(MAX_HEIGHT, h_table + HEIGHT_CELL + H_MARGIN) view = View( VGroup( Label('Beta parameters (prior over pi):'), UItem('beta', editor=TabularEditor( adapter=Array2DAdapter(ncolumns=nclasses, format='%.4f', show_index=True, count_from_one=False), ), width = w_table, height = HEIGHT_CELL, padding = 10 ), Label('Alpha parameters (prior over theta):'), UItem('alpha', editor=TabularEditor( adapter=Array2DAdapter(ncolumns=nclasses, format='%.4f', show_index=True, count_from_one=False), ), width = w_table, height = h_table, padding = 10 ), ), width = w_view, height = h_view, scrollable = True, resizable = True, buttons = ['OK', 'Cancel'] ) return view
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'))))