<s> """<STR_LIT>""" <EOL> from __future__ import division , print_function , unicode_literals <EOL> __docformat__ = '<STR_LIT>' <EOL> __all__ = [ '<STR_LIT>' ] <EOL> import cocos <EOL> from cocos . director import director <EOL> import cocos . cocosnode as cocosnode <EOL> try : <EOL> import cocos . audio . music <EOL> except Exception : <EOL> pass <EOL> class EventHandlerMixin ( object ) : <EOL> def add ( self , child , * args , ** kwargs ) : <EOL> super ( EventHandlerMixin , self ) . add ( child , * args , ** kwargs ) <EOL> scene = self . get ( Scene ) <EOL> if not scene : <EOL> return <EOL> if scene . _handlers_enabled and scene . is_running and isinstance ( child , cocos . layer . Layer ) : <EOL> child . push_all_handlers ( ) <EOL> def remove ( self , child ) : <EOL> super ( EventHandlerMixin , self ) . remove ( child ) <EOL> scene = self . get ( Scene ) <EOL> if not scene : <EOL> return <EOL> if scene . _handlers_enabled and scene . is_running and isinstance ( child , cocos . layer . Layer ) : <EOL> child . remove_all_handlers ( ) <EOL> class Scene ( cocosnode . CocosNode , EventHandlerMixin ) : <EOL> """<STR_LIT:U+0020>""" <EOL> def __init__ ( self , * children ) : <EOL> """<STR_LIT>""" <EOL> super ( Scene , self ) . __init__ ( ) <EOL> self . _handlers_enabled = False <EOL> for i , c in enumerate ( children ) : <EOL> self . add ( c , z = i ) <EOL> x , y = director . get_window_size ( ) <EOL> self . transform_anchor_x = x // <NUM_LIT:2> <EOL> self . transform_anchor_y = y // <NUM_LIT:2> <EOL> self . music = None <EOL> self . music_playing = False <EOL> def on_enter ( self ) : <EOL> for c in self . get_children ( ) : <EOL> c . parent = self <EOL> super ( Scene , self ) . on_enter ( ) <EOL> if self . music is not None : <EOL> cocos . audio . music . control . load ( self . music ) <EOL> if self . music_playing : <EOL> cocos . audio . music . control . play ( ) <EOL> def on_exit ( self ) : <EOL> super ( Scene , self ) . on_exit ( ) <EOL> if self . music_playing : <EOL> cocos . audio . music . control . stop ( ) <EOL> def push_all_handlers ( self ) : <EOL> for child in self . get_children ( ) : <EOL> if isinstance ( child , cocos . layer . Layer ) : <EOL> child . push_all_handlers ( ) <EOL> def remove_all_handlers ( self ) : <EOL> for child in self . get_children ( ) : <EOL> if isinstance ( child , cocos . layer . Layer ) : <EOL> child . remove_all_handlers ( ) <EOL> def enable_handlers ( self , value = True ) : <EOL> """<STR_LIT>""" <EOL> if value and not self . _handlers_enabled and self . is_running : <EOL> self . push_all_handlers ( ) <EOL> elif not value and self . _handlers_enabled and self . is_running : <EOL> self . remove_all_handlers ( ) <EOL> self . _handlers_enabled = value <EOL> def end ( self , value = None ) : <EOL> """<STR_LIT>""" <EOL> director . return_value = value <EOL> director . pop ( ) <EOL> def load_music ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> self . music = filename <EOL> self . music_playing = False <EOL> if self . is_running : <EOL> if filename is not None : <EOL> cocos . audio . music . control . load ( filename ) <EOL> else : <EOL> cocos . audio . music . control . stop ( ) <EOL> def play_music ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . music is not None and not self . music_playing : <EOL> self . music_playing = True <EOL> if self . is_running : <EOL> cocos . audio . music . control . play ( ) <EOL> def stop_music ( self ) : <EOL> """<STR_LIT>""" <EOL> self . load_music ( None ) </s>
