#NEWLINE# def display( self , format = 'png' ) : #NEWLINE# #INDENT# '\n        Return an object that can be used to display this sequence.\n        This is used for IPython Notebook.\n\n        :param format: "png" or "svg"\n        ' #NEWLINE# from sebastian.core.transforms import lilypond #NEWLINE# seq = ( HSeq ( self ) | lilypond ( ) ) #NEWLINE# lily_output = write_lilypond . lily_format ( seq ) #NEWLINE# if ( not lily_output . strip ( ) ) : #NEWLINE# #INDENT# return self #NEWLINE# #UNINDENT# if ( format == 'png' ) : #NEWLINE# #INDENT# suffix = '.preview.png' #NEWLINE# args = [ 'lilypond' , '--png' , '-dno-print-pages' , '-dpreview' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( format == 'svg' ) : #NEWLINE# #INDENT# suffix = '.preview.svg' #NEWLINE# args = [ 'lilypond' , '-dbackend=svg' , '-dno-print-pages' , '-dpreview' ] #NEWLINE# #UNINDENT# #UNINDENT# f = tempfile . NamedTemporaryFile ( suffix = suffix ) #NEWLINE# basename = f . name [ : ( - len ( suffix ) ) ] #NEWLINE# args . extend ( [ ( '-o' + basename ) , '-' ] ) #NEWLINE# p = sp . Popen ( ' ' . join ( args ) , stdin = sp . PIPE , shell = True ) #NEWLINE# ( stdout , stderr ) = p . communicate ( ( '{ %s }' % lily_output ) ) #NEWLINE# if ( p . returncode != 0 ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# if ( not ipython ) : #NEWLINE# #INDENT# return f . read ( ) #NEWLINE# #UNINDENT# if ( format == 'png' ) : #NEWLINE# #INDENT# return Image ( data = f . read ( ) , filename = f . name , format = 'png' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return SVG ( data = f . read ( ) , filename = f . name )