<s> """<STR_LIT>""" <EOL> import os , glob , sys <EOL> from traitsui . api import Editor <EOL> from traitsui . editor_factory import EditorFactory <EOL> def gen_editor_definitions ( target_filename ) : <EOL> """<STR_LIT>""" <EOL> target_file = open ( target_filename , '<STR_LIT:w>' ) <EOL> dirpath = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> editor_files = [ ] <EOL> for ( root , dirs , files ) in os . walk ( dirpath ) : <EOL> if '<STR_LIT>' in dirs : <EOL> dirs . remove ( '<STR_LIT>' ) <EOL> editor_files . extend ( glob . glob ( os . path . join ( root , '<STR_LIT>' ) ) ) <EOL> for absfilename in editor_files : <EOL> ( dirname , filename ) = ( os . path . dirname ( absfilename ) , <EOL> os . path . basename ( absfilename ) . rstrip ( '<STR_LIT>' ) ) <EOL> import_path = '<STR_LIT>' + dirname . replace ( dirpath , '<STR_LIT>' ) . replace ( os . sep , '<STR_LIT:.>' ) + '<STR_LIT:.>' + filename <EOL> __import__ ( import_path ) <EOL> module = sys . modules [ import_path ] <EOL> class_names = [ ] <EOL> for name in dir ( module ) : <EOL> try : <EOL> if issubclass ( getattr ( module , name ) , EditorFactory ) and name not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> class_names . append ( name ) <EOL> elif issubclass ( getattr ( module , name ) , Editor ) and name != '<STR_LIT>' : <EOL> class_names . append ( name ) <EOL> except : <EOL> try : <EOL> if isinstance ( getattr ( module , name ) , EditorFactory ) or isinstance ( getattr ( module , name ) , Editor ) : <EOL> class_names . insert ( <NUM_LIT:0> , name ) <EOL> except : <EOL> pass <EOL> if len ( class_names ) > <NUM_LIT:0> : <EOL> if '<STR_LIT>' in class_names : <EOL> class_name = '<STR_LIT>' <EOL> else : <EOL> class_name = '<STR_LIT>' . join ( [ name . capitalize ( ) for name in <EOL> filename . split ( '<STR_LIT:_>' ) ] ) <EOL> if class_name not in class_names : <EOL> class_name = class_names [ <NUM_LIT:0> ] <EOL> function = "<STR_LIT>" % locals ( ) <EOL> target_file . write ( function ) <EOL> target_file . write ( '<STR_LIT:\n>' ) <EOL> func_code = '<STR_LIT:U+0020>' * <NUM_LIT:4> + "<STR_LIT>" % locals ( ) + '<STR_LIT:\n>' <EOL> func_code += '<STR_LIT:U+0020>' * <NUM_LIT:4> + "<STR_LIT>" % locals ( ) <EOL> target_file . write ( func_code ) <EOL> target_file . write ( '<STR_LIT>' ) <EOL> target_file . close ( ) </s>
