#NEWLINE# def get_shell_dialog( ) : #NEWLINE# #INDENT# global _shell_dialog #NEWLINE# if ( _shell_dialog is not None ) : #NEWLINE# #INDENT# return _shell_dialog #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# deps = { #NEWLINE# #INDENT# 'pip' : 'ipython>=1.0' , #NEWLINE# 'linux-ubuntu' : 'ipython-qtconsole' , #NEWLINE# 'linux-debian' : 'ipython-qtconsole' , #NEWLINE# #UNINDENT# } #NEWLINE# IPython = py_import ( 'IPython.qt.console.rich_ipython_widget' , deps , True ) #NEWLINE# RichIPythonWidget = IPython . qt . console . rich_ipython_widget . RichIPythonWidget #NEWLINE# py_import ( 'IPython.qt.inprocess' , deps , True ) #NEWLINE# QtInProcessKernelManager = IPython . qt . inprocess . QtInProcessKernelManager #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# km = QtInProcessKernelManager ( ) #NEWLINE# km . start_kernel ( ) #NEWLINE# kernel = km . kernel #NEWLINE# kernel . gui = 'qt4' #NEWLINE# kernel_client = km . client ( ) #NEWLINE# kernel_client . start_channels ( ) #NEWLINE# class IPythonDialog ( RichIPythonWidget , QVistrailsPaletteInterface ) : #NEWLINE# #INDENT# 'This class incorporates an  IPython shell into a dockable widget for use in the\n        VisTrails environment' #NEWLINE# def __init__( self , parent = None ) : #NEWLINE# #INDENT# RichIPythonWidget . __init__ ( self , parent ) #NEWLINE# self . old_streams = None #NEWLINE# self . running_workflow = False #NEWLINE# self . kernel_manager = km #NEWLINE# self . kernel_client = kernel_client #NEWLINE# self . exit_requested . connect ( self . stop ) #NEWLINE# self . setWindowTitle ( 'Console' ) #NEWLINE# self . vistrails_interpreter = get_default_interpreter ( ) #NEWLINE# #UNINDENT# def visibility_changed( self , visible ) : #NEWLINE# #INDENT# QVistrailsPaletteInterface . visibility_changed ( self , visible ) #NEWLINE# if visible : #NEWLINE# #INDENT# self . show ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . hide ( ) #NEWLINE# #UNINDENT# #UNINDENT# def stop( self ) : #NEWLINE# #INDENT# kernel_client . stop_channels ( ) #NEWLINE# km . shutdown_kernel ( ) #NEWLINE# #UNINDENT# def hide( self ) : #NEWLINE# #INDENT# 'suspend() -> None\n            Called when hiding the parent window in order to recover the previous\n            state.\n\n            ' #NEWLINE# if ( self . old_streams is not None ) : #NEWLINE# #INDENT# ( sys . stdout , sys . stderr , sys . stdin ) = self . old_streams #NEWLINE# self . old_streams = None #NEWLINE# #UNINDENT# RichIPythonWidget . hide ( self ) #NEWLINE# #UNINDENT# def show( self ) : #NEWLINE# #INDENT# 'show() -> None\n            Store previous state and starts capturing all interactive input and\n            output.\n\n            ' #NEWLINE# if ( self . old_streams is None ) : #NEWLINE# #INDENT# self . old_streams = ( sys . stdout , sys . stderr , sys . stdin ) #NEWLINE# sys . stdout = self #NEWLINE# sys . stderr = self #NEWLINE# sys . stdin = self #NEWLINE# #UNINDENT# RichIPythonWidget . show ( self ) #NEWLINE# #UNINDENT# def showEvent( self , e ) : #NEWLINE# #INDENT# 'showEvent(e) -> None\n            Event handler called when the dialog acquires focus\n\n            ' #NEWLINE# self . show ( ) #NEWLINE# #UNINDENT# def flush( self ) : #NEWLINE# #INDENT# 'flush() -> None.\n            Simulate stdin, stdout, and stderr.\n\n            ' #NEWLINE# pass #NEWLINE# #UNINDENT# def isatty( self ) : #NEWLINE# #INDENT# 'isatty() -> int\n            Simulate stdin, stdout, and stderr.\n\n            ' #NEWLINE# return 1 #NEWLINE# #UNINDENT# def readline( self ) : #NEWLINE# #INDENT# 'readline() -> str\n\n            Simulate stdin, stdout, and stderr.\n\n            ' #NEWLINE# return '' #NEWLINE# #UNINDENT# def write( self , text ) : #NEWLINE# #INDENT# 'write(text: str) -> None\n            Simulate stdin, stdout, and stderr.\n\n            ' #NEWLINE# self . input_buffer = '' #NEWLINE# if ( not self . running_workflow ) : #NEWLINE# #INDENT# self . running_workflow = True #NEWLINE# self . _append_plain_text ( '\n\x1b[34m<STANDARD OUTPUT>\x1b[0m\n' , True ) #NEWLINE# #UNINDENT# self . _append_plain_text ( text , True ) #NEWLINE# self . _prompt_pos = self . _get_end_cursor ( ) . position ( ) #NEWLINE# self . _control . ensureCursorVisible ( ) #NEWLINE# self . _control . moveCursor ( QtGui . QTextCursor . End ) #NEWLINE# #UNINDENT# def eventFilter( self , obj , event ) : #NEWLINE# #INDENT# ' Reimplemented to ensure a console-like behavior in the underlying\n                text widgets.\n            ' #NEWLINE# etype = event . type ( ) #NEWLINE# if ( etype == QtCore . QEvent . KeyPress ) : #NEWLINE# #INDENT# self . running_workflow = False #NEWLINE# #UNINDENT# return RichIPythonWidget . eventFilter ( self , obj , event ) #NEWLINE# #UNINDENT# #UNINDENT# _shell_dialog = IPythonDialog #NEWLINE# return IPythonDialog