<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from traits . trait_base import SequenceTypes <EOL> from traits . api import Bool , HasTraits , List , Tuple , Unicode , Int , Any , TraitType <EOL> from . . view import View <EOL> from . . group import Group <EOL> from . . item import Item <EOL> from . . editor_factory import EditorFactory <EOL> from . . editor import Editor <EOL> class ToolkitEditorFactory ( EditorFactory ) : <EOL> """<STR_LIT>""" <EOL> types = Any <EOL> labels = List ( Unicode ) <EOL> editors = List ( EditorFactory ) <EOL> cols = Int ( <NUM_LIT:1> ) <EOL> auto_set = Bool ( True ) <EOL> enter_set = Bool ( False ) <EOL> class SimpleEditor ( Editor ) : <EOL> """<STR_LIT>""" <EOL> def init ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> self . _ts = ts = TupleStructure ( self ) <EOL> self . _ui = ui = ts . view . ui ( ts , parent , kind = '<STR_LIT>' ) . set ( <EOL> parent = self . ui ) <EOL> self . control = ui . control <EOL> self . set_tooltip ( ) <EOL> def update_editor ( self ) : <EOL> """<STR_LIT>""" <EOL> ts = self . _ts <EOL> for i , value in enumerate ( self . value ) : <EOL> setattr ( ts , '<STR_LIT>' % i , value ) <EOL> def get_error_control ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _ui . get_error_controls ( ) <EOL> class TupleStructure ( HasTraits ) : <EOL> """<STR_LIT>""" <EOL> editor = Any <EOL> view = Any <EOL> fields = Int <EOL> def __init__ ( self , editor ) : <EOL> """<STR_LIT>""" <EOL> factory = editor . factory <EOL> types = factory . types <EOL> labels = factory . labels <EOL> editors = factory . editors <EOL> cols = factory . cols <EOL> self . editor = editor <EOL> object = editor . value <EOL> content = [ ] <EOL> self . fields = len ( object ) <EOL> len_labels = len ( labels ) <EOL> len_editors = len ( editors ) <EOL> if types is None : <EOL> type = editor . value_trait . handler <EOL> if isinstance ( type , Tuple ) : <EOL> types = type . types <EOL> if not isinstance ( types , SequenceTypes ) : <EOL> types = [ types ] <EOL> len_types = len ( types ) <EOL> if len_types == <NUM_LIT:0> : <EOL> types = [ Any ] <EOL> len_types = <NUM_LIT:1> <EOL> for i , value in enumerate ( object ) : <EOL> type = types [ i % len_types ] <EOL> auto_set = enter_set = None <EOL> if isinstance ( type , TraitType ) : <EOL> auto_set = type . auto_set <EOL> enter_set = type . enter_set <EOL> if auto_set is None : <EOL> auto_set = editor . factory . auto_set <EOL> if enter_set is None : <EOL> enter_set = editor . factory . enter_set <EOL> label = '<STR_LIT>' <EOL> if i < len_labels : <EOL> label = labels [ i ] <EOL> field_editor = None <EOL> if i < len_editors : <EOL> field_editor = editors [ i ] <EOL> name = '<STR_LIT>' % i <EOL> self . add_trait ( name , type ( value , event = '<STR_LIT>' , <EOL> auto_set = auto_set , <EOL> enter_set = enter_set ) ) <EOL> item = Item ( name = name , label = label , editor = field_editor ) <EOL> if cols <= <NUM_LIT:1> : <EOL> content . append ( item ) <EOL> else : <EOL> if ( i % cols ) == <NUM_LIT:0> : <EOL> group = Group ( orientation = '<STR_LIT>' ) <EOL> content . append ( group ) <EOL> group . content . append ( item ) <EOL> self . view = View ( Group ( show_labels = ( len_labels != <NUM_LIT:0> ) , * content ) ) <EOL> def _field_changed ( self , name , old , new ) : <EOL> """<STR_LIT>""" <EOL> index = int ( name [ <NUM_LIT:1> : ] ) <EOL> value = self . editor . value <EOL> if new != value [ index ] : <EOL> self . editor . value = tuple ( <EOL> [ getattr ( self , '<STR_LIT>' % i ) for i in range ( self . fields ) ] ) <EOL> TupleEditor = ToolkitEditorFactory </s>
