<s> """<STR_LIT>""" <EOL> from os . path import basename <EOL> from tvtk . api import tvtk <EOL> from traits . api import Instance , Str <EOL> from traitsui . api import View , Item , FileEditor <EOL> from apptools . persistence . file_path import FilePath <EOL> from apptools . persistence . state_pickler import set_state <EOL> from mayavi . core . source import Source <EOL> from mayavi . core . pipeline_info import PipelineInfo <EOL> class VRMLImporter ( Source ) : <EOL> __version__ = <NUM_LIT:0> <EOL> file_name = Str ( '<STR_LIT>' , enter_set = True , auto_set = False , <EOL> desc = '<STR_LIT>' ) <EOL> reader = Instance ( tvtk . VRMLImporter , args = ( ) , allow_none = False , <EOL> record = True ) <EOL> output_info = PipelineInfo ( datasets = [ '<STR_LIT:none>' ] ) <EOL> _file_path = Instance ( FilePath , args = ( ) ) <EOL> view = View ( Item ( name = '<STR_LIT>' , editor = FileEditor ( ) ) ) <EOL> def __get_pure_state__ ( self ) : <EOL> d = super ( VRMLImporter , self ) . __get_pure_state__ ( ) <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> d . pop ( name ) <EOL> return d <EOL> def __set_pure_state__ ( self , state ) : <EOL> fname = state . _file_path . abs_pth <EOL> self . initialize ( fname ) <EOL> set_state ( self , state , ignore = [ '<STR_LIT>' ] ) <EOL> def initialize ( self , file_name ) : <EOL> self . file_name = file_name <EOL> def add_actors ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _actors_added : <EOL> self . reader . render_window = self . scene . render_window <EOL> self . _update_reader ( ) <EOL> self . _actors_added = True <EOL> if not self . visible : <EOL> self . _visible_changed ( self . visible ) <EOL> self . scene . render ( ) <EOL> def remove_actors ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _actors_added : <EOL> self . scene . remove_actors ( self . actors ) <EOL> self . _actors_added = False <EOL> self . scene . render ( ) <EOL> def has_output_port ( self ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> def get_output_object ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . reader . output_port <EOL> def _file_name_changed ( self , value ) : <EOL> reader = self . reader <EOL> reader . file_name = value <EOL> self . _file_path . set ( value ) <EOL> self . _update_reader ( ) <EOL> self . render ( ) <EOL> name = "<STR_LIT>" % basename ( self . file_name ) <EOL> if '<STR_LIT>' in self . name : <EOL> name += '<STR_LIT>' <EOL> self . name = name <EOL> def _update_reader ( self ) : <EOL> reader = self . reader <EOL> if self . scene is None or reader . file_name is None or len ( reader . file_name ) == <NUM_LIT:0> : <EOL> return <EOL> actors1 = [ x for x in self . scene . renderer . actors ] <EOL> reader . read ( ) <EOL> self . scene . render ( ) <EOL> actors2 = [ x for x in self . scene . renderer . actors ] <EOL> self . actors = [ x for x in actors2 if x not in actors1 ] <EOL> if len ( actors1 ) == <NUM_LIT:0> : <EOL> self . scene . reset_zoom ( ) <EOL> def _scene_changed ( self , old , new ) : <EOL> if self . _actors_added : <EOL> old . remove_actors ( self . actors ) <EOL> reader = self . reader <EOL> reader . render_window = new . render_window <EOL> self . _update_reader ( ) <EOL> def _actors_changed ( self , old , new ) : <EOL> if self . _actors_added : <EOL> self . scene . remove_actors ( old ) <EOL> self . scene . render ( ) <EOL> def _actors_items_changed ( self , list_event ) : <EOL> if self . _actors_added : <EOL> self . scene . remove_actors ( list_event . removed ) <EOL> self . scene . render ( ) <EOL> def _visible_changed ( self , value ) : <EOL> if value : <EOL> if not self . _actors_added : <EOL> self . scene . add_actors ( self . actors ) <EOL> self . _actors_added = True <EOL> super ( VRMLImporter , self ) . _visible_changed ( value ) </s>
