<s> """<STR_LIT>""" <EOL> import os . path <EOL> from pyface . api import FileDialog , GUI , OK , PythonShell <EOL> from pyface . api import SplitApplicationWindow , ApplicationWindow <EOL> from pyface . api import SplitPanel <EOL> from tvtk . pyface . api import Scene , DecoratedScene <EOL> from pyface . action . api import Action , MenuBarManager , MenuManager , Separator <EOL> from pyface . image_resource import ImageResource <EOL> from pyface . resource . api import resource_path <EOL> from traits . api import Float , Str , Instance , Callable <EOL> from tvtk . api import tvtk <EOL> from tvtk . pipeline . browser import PipelineBrowser <EOL> def mk_scene_icon ( ) : <EOL> icon_path = os . path . join ( resource_path ( ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> return ImageResource ( icon_path ) <EOL> scene_icon = mk_scene_icon ( ) <EOL> class ExitAction ( Action ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , window ) : <EOL> """<STR_LIT>""" <EOL> self . _window = window <EOL> self . name = "<STR_LIT>" <EOL> def perform ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _window . close ( ) <EOL> class SaveImageAction ( Action ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , window ) : <EOL> self . _window = window <EOL> self . name = "<STR_LIT>" <EOL> def perform ( self ) : <EOL> """<STR_LIT>""" <EOL> extns = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> dlg = FileDialog ( parent = self . _window . control , action = '<STR_LIT>' , <EOL> wildcard = '<STR_LIT:|>' . join ( extns ) , title = "<STR_LIT>" ) <EOL> if dlg . open ( ) == OK : <EOL> self . _window . scene . save ( dlg . path ) <EOL> class SaveToClipboardAction ( Action ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , window ) : <EOL> """<STR_LIT>""" <EOL> self . _window = window <EOL> self . name = "<STR_LIT>" <EOL> def perform ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _window . scene . save_to_clipboard ( ) <EOL> class SpecialViewAction ( Action ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , window , name , view ) : <EOL> """<STR_LIT>""" <EOL> self . _window = window <EOL> self . name = name <EOL> self . view = view <EOL> def perform ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> meth = getattr ( self . _window . scene , self . view ) <EOL> meth ( ) <EOL> except AttributeError : <EOL> pass <EOL> def create_ivtk_menu ( obj ) : <EOL> """<STR_LIT>""" <EOL> menu_bar_manager = MenuBarManager ( <EOL> MenuManager ( SaveImageAction ( obj ) , <EOL> Separator ( ) , <EOL> ExitAction ( obj ) , <EOL> name = '<STR_LIT>' , <EOL> ) , <EOL> MenuManager ( SaveToClipboardAction ( obj ) , <EOL> name = '<STR_LIT>' , <EOL> ) , <EOL> MenuManager ( SpecialViewAction ( obj , "<STR_LIT>" , '<STR_LIT>' ) , <EOL> Separator ( ) , <EOL> SpecialViewAction ( obj , "<STR_LIT>" , '<STR_LIT>' ) , <EOL> SpecialViewAction ( obj , "<STR_LIT>" , '<STR_LIT>' ) , <EOL> SpecialViewAction ( obj , "<STR_LIT>" , '<STR_LIT>' ) , <EOL> SpecialViewAction ( obj , "<STR_LIT>" , '<STR_LIT>' ) , <EOL> SpecialViewAction ( obj , "<STR_LIT>" , '<STR_LIT>' ) , <EOL> SpecialViewAction ( obj , "<STR_LIT>" , '<STR_LIT>' ) , <EOL> SpecialViewAction ( obj , "<STR_LIT>" , '<STR_LIT>' ) , <EOL> name = '<STR_LIT>' , <EOL> ) <EOL> ) <EOL> return menu_bar_manager <EOL> class SceneWithBrowser ( SplitPanel ) : <EOL> """<STR_LIT>""" <EOL> ratio = Float ( <NUM_LIT> ) <EOL> direction = Str ( '<STR_LIT>' ) <EOL> scene = Instance ( Scene ) <EOL> browser = Instance ( PipelineBrowser ) <EOL> def destroy ( self ) : <EOL> if self . scene is not None : <EOL> self . scene . close ( ) <EOL> super ( SceneWithBrowser , self ) . destroy ( ) <EOL> def _create_lhs ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> self . _create_scene ( parent ) <EOL> self . browser = PipelineBrowser ( self . scene ) <EOL> self . browser . show ( parent = parent ) <EOL> return self . browser . ui . control <EOL> def _create_rhs ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> self . _create_scene ( parent ) <EOL> self . scene . renderer . background = <NUM_LIT:0.5> , <NUM_LIT:0.5> , <NUM_LIT:0.5> <EOL> return self . scene . control <EOL> def _create_scene ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> if self . scene is None : <EOL> self . scene = DecoratedScene ( parent ) <EOL> class IVTKWithCrust ( SplitApplicationWindow ) : <EOL> """<STR_LIT>""" <EOL> ratio = Float ( <NUM_LIT> ) <EOL> direction = Str ( '<STR_LIT>' ) <EOL> scene = Instance ( Scene ) <EOL> python_shell = Instance ( PythonShell ) <EOL> def __init__ ( self , ** traits ) : <EOL> """<STR_LIT>""" <EOL> super ( IVTKWithCrust , self ) . __init__ ( ** traits ) <EOL> self . title = '<STR_LIT>' <EOL> self . menu_bar_manager = create_ivtk_menu ( self ) <EOL> def close ( self ) : <EOL> if self . scene is not None : <EOL> self . scene . close ( ) <EOL> super ( IVTKWithCrust , self ) . close ( ) <EOL> def _create_lhs ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> self . scene = DecoratedScene ( parent ) <EOL> self . scene . renderer . background = <NUM_LIT:0.5> , <NUM_LIT:0.5> , <NUM_LIT:0.5> <EOL> return self . scene . control <EOL> def _create_rhs ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> self . python_shell = PythonShell ( parent ) <EOL> self . python_shell . bind ( '<STR_LIT>' , self . scene ) <EOL> self . python_shell . bind ( '<STR_LIT:s>' , self . scene ) <EOL> self . python_shell . bind ( '<STR_LIT>' , tvtk ) <EOL> return self . python_shell . control <EOL> class IVTKWithCrustAndBrowser ( SplitApplicationWindow ) : <EOL> """<STR_LIT>""" <EOL> ratio = Float ( <NUM_LIT> ) <EOL> direction = Str ( '<STR_LIT>' ) <EOL> scene = Instance ( Scene ) <EOL> browser = Instance ( PipelineBrowser ) <EOL> browser_scene = Instance ( SceneWithBrowser ) <EOL> python_shell = Instance ( PythonShell ) <EOL> def __init__ ( self , ** traits ) : <EOL> """<STR_LIT>""" <EOL> super ( IVTKWithCrustAndBrowser , self ) . __init__ ( ** traits ) <EOL> self . title = '<STR_LIT>' <EOL> self . menu_bar_manager = create_ivtk_menu ( self ) <EOL> def close ( self ) : <EOL> if self . scene is not None : <EOL> self . scene . close ( ) <EOL> super ( IVTKWithCrustAndBrowser , self ) . close ( ) <EOL> icon = Instance ( ImageResource , scene_icon ) <EOL> def _create_lhs ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> self . browser_scene = SceneWithBrowser ( parent ) <EOL> self . scene = self . browser_scene . scene <EOL> self . browser = self . browser_scene . browser <EOL> return self . browser_scene . control <EOL> def _create_rhs ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> self . python_shell = PythonShell ( parent ) <EOL> self . python_shell . bind ( '<STR_LIT>' , self . scene ) <EOL> self . python_shell . bind ( '<STR_LIT:s>' , self . scene ) <EOL> self . python_shell . bind ( '<STR_LIT>' , self . browser ) <EOL> self . python_shell . bind ( '<STR_LIT:b>' , self . browser ) <EOL> self . python_shell . bind ( '<STR_LIT>' , tvtk ) <EOL> return self . python_shell . control <EOL> class IVTK ( ApplicationWindow ) : <EOL> """<STR_LIT>""" <EOL> scene = Instance ( Scene ) <EOL> _scene_factory = Callable ( DecoratedScene ) <EOL> def __init__ ( self , ** traits ) : <EOL> """<STR_LIT>""" <EOL> super ( IVTK , self ) . __init__ ( ** traits ) <EOL> self . title = '<STR_LIT>' <EOL> self . menu_bar_manager = create_ivtk_menu ( self ) <EOL> def close ( self ) : <EOL> if self . scene is not None : <EOL> self . scene . close ( ) <EOL> super ( IVTK , self ) . close ( ) <EOL> icon = Instance ( ImageResource , scene_icon ) <EOL> def _create_contents ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> self . scene = self . _scene_factory ( parent ) <EOL> return self . scene . control <EOL> class IVTKWithBrowser ( ApplicationWindow ) : <EOL> """<STR_LIT>""" <EOL> scene = Instance ( Scene ) <EOL> browser = Instance ( PipelineBrowser ) <EOL> browser_scene = Instance ( SceneWithBrowser ) <EOL> def __init__ ( self , ** traits ) : <EOL> """<STR_LIT>""" <EOL> super ( IVTKWithBrowser , self ) . __init__ ( ** traits ) <EOL> self . title = '<STR_LIT>' <EOL> self . menu_bar_manager = create_ivtk_menu ( self ) <EOL> def close ( self ) : <EOL> if self . scene is not None : <EOL> self . scene . close ( ) <EOL> super ( IVTKWithBrowser , self ) . close ( ) <EOL> icon = Instance ( ImageResource , scene_icon ) <EOL> def _create_contents ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> self . browser_scene = SceneWithBrowser ( parent ) <EOL> self . scene = self . browser_scene . scene <EOL> self . browser = self . browser_scene . browser <EOL> return self . browser_scene . control <EOL> def viewer ( browser = True , instantiate_gui = False ) : <EOL> """<STR_LIT>""" <EOL> if instantiate_gui : <EOL> gui = GUI ( ) <EOL> if browser : <EOL> v = IVTKWithBrowser ( size = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> else : <EOL> v = IVTK ( size = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> v . open ( ) <EOL> return v <EOL> def main ( ) : <EOL> gui = GUI ( ) <EOL> window = IVTKWithCrustAndBrowser ( size = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> window . open ( ) <EOL> gui . start_event_loop ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
