1""" 2Implementation of a ButtonEditor demo plugin for Traits UI demo program. 3 4This demo shows each of the two styles of the ButtonEditor. 5(As of this writing, they are identical.) 6""" 7 8from traits.api import HasTraits, Button 9from traitsui.api import Item, View, Group, message 10 11 12# ------------------------------------------------------------------------- 13# Demo Class 14# ------------------------------------------------------------------------- 15 16class ButtonEditorDemo(HasTraits): 17 """ This class specifies the details of the ButtonEditor demo. 18 """ 19 20 # To demonstrate any given Trait editor, an appropriate Trait is required. 21 fire_event = Button('Click Me') 22 23 def _fire_event_fired(): 24 message("Button clicked!") 25 26 # ButtonEditor display 27 # (Note that Text and ReadOnly versions are not applicable) 28 event_group = Group( 29 Item('fire_event', style='simple', label='Simple', id="simple"), 30 Item('_'), 31 Item('fire_event', style='custom', label='Custom', id="custom"), 32 Item('_'), 33 Item(label='[text style unavailable]'), 34 Item('_'), 35 Item(label='[readonly style unavailable]') 36 ) 37 38 # Demo view 39 traits_view = View( 40 event_group, 41 title='ButtonEditor', 42 buttons=['OK'], 43 width=250 44 ) 45 46 47# Create the demo: 48demo = ButtonEditorDemo() 49 50# Run the demo (if invoked from the command line): 51if __name__ == '__main__': 52 demo.configure_traits() 53