<s> """<STR_LIT>""" <EOL> import wx <EOL> from traits . api import Any , Bool , Callable <EOL> from traitsui . wx . editor import Editor <EOL> from traitsui . basic_editor_factory import BasicEditorFactory <EOL> from . decorated_scene import DecoratedScene <EOL> class _SceneEditor ( Editor ) : <EOL> """<STR_LIT>""" <EOL> scrollable = Bool ( True ) <EOL> _sizer = Any ( ) <EOL> _scene = Any ( ) <EOL> def init ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> factory = self . factory <EOL> self . control = wx . Panel ( parent , - <NUM_LIT:1> ) <EOL> self . _sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> self . control . SetSizer ( self . _sizer ) <EOL> assert self . value . scene_editor is None , "<STR_LIT>" <EOL> self . _create_scene ( ) <EOL> self . value . activated = True <EOL> def update_editor ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def dispose ( self ) : <EOL> """<STR_LIT>""" <EOL> self . value . closing = True <EOL> self . value . scene_editor = None <EOL> self . _setup_scene_notifications ( remove = True ) <EOL> if self . _scene is not None : <EOL> self . _scene . close ( ) <EOL> self . _scene = None <EOL> self . _sizer = None <EOL> super ( _SceneEditor , self ) . dispose ( ) <EOL> def _create_scene ( self ) : <EOL> """<STR_LIT>""" <EOL> factory = self . factory <EOL> self . _scene = factory . scene_class ( self . control ) <EOL> scene = self . _scene <EOL> self . value . scene_editor = scene <EOL> scene . disable_render = True <EOL> for obj , actors in self . value . actor_map . items ( ) : <EOL> self . _add_actors_widgets ( actors ) <EOL> self . _add_actors_widgets ( self . value . actor_list ) <EOL> self . _setup_scene_notifications ( ) <EOL> scene . disable_render = False <EOL> self . _sizer . Add ( scene . control , <NUM_LIT:1> , wx . EXPAND ) <EOL> self . _sizer . Layout ( ) <EOL> wx . EVT_IDLE ( scene . control , None ) <EOL> scene . render ( ) <EOL> def _setup_scene_notifications ( self , remove = False ) : <EOL> """<STR_LIT>""" <EOL> traits_to_sync = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> model = self . value <EOL> scene = self . _scene <EOL> if not remove : <EOL> scene . set ( ** model . get ( traits_to_sync ) ) <EOL> for trait in traits_to_sync : <EOL> scene . sync_trait ( trait , model , mutual = True , remove = remove ) <EOL> model . on_trait_change ( <EOL> scene . render , <EOL> name = '<STR_LIT>' , <EOL> remove = remove , <EOL> ) <EOL> model . on_trait_change ( <EOL> self . _actors_changed , <EOL> name = '<STR_LIT>' , <EOL> remove = remove , <EOL> ) <EOL> model . on_trait_change ( <EOL> self . _actor_map_changed , <EOL> name = '<STR_LIT>' , <EOL> remove = remove , <EOL> ) <EOL> model . on_trait_change ( <EOL> self . _actor_list_items_changed , <EOL> name = '<STR_LIT>' , <EOL> remove = remove , <EOL> ) <EOL> model . on_trait_change ( <EOL> self . _actor_list_changed , <EOL> name = '<STR_LIT>' , <EOL> remove = remove , <EOL> ) <EOL> def _actors_changed ( self , event ) : <EOL> """<STR_LIT>""" <EOL> scene = self . _scene <EOL> old_disable_render = scene . disable_render <EOL> scene . disable_render = True <EOL> try : <EOL> for obj , actors in event . removed . items ( ) : <EOL> self . _remove_actors_widgets ( actors ) <EOL> for obj , actors in event . added . items ( ) : <EOL> self . _add_actors_widgets ( actors ) <EOL> for obj , actors in event . changed . items ( ) : <EOL> self . _remove_actors_widgets ( actors ) <EOL> self . _add_actors_widgets ( self . value . actor_map [ obj ] ) <EOL> finally : <EOL> scene . disable_render = old_disable_render <EOL> scene . render ( ) <EOL> def _actor_map_changed ( self , object , name , old , new ) : <EOL> """<STR_LIT>""" <EOL> scene = self . _scene <EOL> old_disable_render = scene . disable_render <EOL> scene . disable_render = True <EOL> try : <EOL> for obj , actors in old . items ( ) : <EOL> self . _remove_actors_widgets ( actors ) <EOL> for obj , actors in new . items ( ) : <EOL> self . _add_actors_widgets ( actors ) <EOL> finally : <EOL> scene . disable_render = old_disable_render <EOL> scene . render ( ) <EOL> def _actor_list_items_changed ( self , event ) : <EOL> self . _actor_list_changed ( self . value , '<STR_LIT>' , event . removed , <EOL> event . added ) <EOL> def _actor_list_changed ( self , object , name , old , new ) : <EOL> """<STR_LIT>""" <EOL> scene = self . _scene <EOL> old_disable_render = scene . disable_render <EOL> scene . disable_render = True <EOL> try : <EOL> self . _remove_actors_widgets ( old ) <EOL> self . _add_actors_widgets ( new ) <EOL> finally : <EOL> scene . disable_render = old_disable_render <EOL> scene . render ( ) <EOL> def _separate_actors_widgets ( self , actors_widgets ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( actors_widgets , '<STR_LIT>' ) : <EOL> actors_widgets = [ actors_widgets ] <EOL> actors = [ ] <EOL> widgets = [ ] <EOL> for actor in actors_widgets : <EOL> if actor . is_a ( '<STR_LIT>' ) or actor . is_a ( '<STR_LIT>' ) : <EOL> widgets . append ( actor ) <EOL> else : <EOL> actors . append ( actor ) <EOL> return actors , widgets <EOL> def _add_actors_widgets ( self , actors_widgets ) : <EOL> """<STR_LIT>""" <EOL> scene = self . _scene <EOL> actors , widgets = self . _separate_actors_widgets ( actors_widgets ) <EOL> scene . add_actors ( actors ) <EOL> enabled_info = self . value . enabled_info <EOL> for widget in widgets : <EOL> scene . add_widgets ( widget , enabled_info . get ( widget , True ) ) <EOL> def _remove_actors_widgets ( self , actors_widgets ) : <EOL> """<STR_LIT>""" <EOL> scene = self . _scene <EOL> actors , widgets = self . _separate_actors_widgets ( actors_widgets ) <EOL> scene . remove_actors ( actors ) <EOL> scene . remove_widgets ( widgets ) <EOL> class SceneEditor ( BasicEditorFactory ) : <EOL> """<STR_LIT>""" <EOL> klass = _SceneEditor <EOL> scene_class = Callable ( DecoratedScene ) </s>
