Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(
self,
history_widget: QtWidgets.QPlainTextEdit = None,
*args,
**kwargs
):
"""
:param args:
:param kwargs:
"""
super().__init__(*args, **kwargs)
self.history_widget = history_widget
self.kernel_manager = kernel_manager = qtconsole.inprocess.QtInProcessKernelManager()
kernel_manager.start_kernel()
self.kernel_client = kernel_client = kernel_manager.client()
kernel_client.start_channels()
def stop():
kernel_client.stop_channels()
kernel_manager.shutdown_kernel()
IPython.lib.guisupport.get_app_qt4().exit()
self.exit_requested.connect(stop)
self.width = kwargs.get(
'width',
chisurf.settings.gui['console']['width']
)
self._macro = ""
self.recording = False
IPython.lib.guisupport.get_app_qt4().exit()
self.exit_requested.connect(stop)
self.width = kwargs.get(
'width',
chisurf.settings.gui['console']['width']
)
self._macro = ""
self.recording = False
# save nevertheless every inputs into a session file
self.session_file = chisurf.settings.session_file
#self.set_default_style(
# chisurf.settings.gui['console']['style']
#)
self.style_sheet = qtconsole.styles.default_light_style_sheet
def getKernelManager():
"""
Returns a QtInProcessKernelManager, already initialized.
:return: `qtconsole.inprocess.QtInProcessKernelManager`
"""
kernel_manager = QtInProcessKernelManager()
kernel_manager.start_kernel(show_banner=False)
kernel_manager.kernel.gui = 'qt4'
return kernel_manager
def __init__(
self,
history_widget: QtWidgets.QPlainTextEdit = None,
*args,
**kwargs
):
"""
:param args:
:param kwargs:
"""
super().__init__(*args, **kwargs)
self.history_widget = history_widget
self.kernel_manager = kernel_manager = QtInProcessKernelManager()
kernel_manager.start_kernel()
self.kernel_client = kernel_client = kernel_manager.client()
kernel_client.start_channels()
def stop():
kernel_client.stop_channels()
kernel_manager.shutdown_kernel()
guisupport.get_app_qt4().exit()
self.exit_requested.connect(stop)
self.width = kwargs.get(
'width',
mfm.settings.gui['console']['width']
)
self._macro = ""
self.recording = False
def main():
"""Start kernel manager and client, create window, run app event loop,
auto execute some code in user namespace. A minimalist example is shown in
qt_ip_test.py.
NOTE: Make sure that the Qt v2 API is being used by IPython by running `export
QT_API=pyqt` at the command line before running neuropy, or by adding it to `.bashrc`"""
app = guisupport.get_app_qt4()
if INPROCESS:
from qtconsole.inprocess import QtInProcessKernelManager
km = QtInProcessKernelManager()
else:
from qtconsole.manager import QtKernelManager
km = QtKernelManager()
km.start_kernel()
km.kernel.gui = 'qt4'
kc = km.client()
kc.start_channels()
nw = NeuropyWindow()
ipw = nw.ipw
config_ipw(ipw)
ipw.kernel_manager = km
ipw.kernel_client = kc
ipw.exit_requested.connect(nw.stop)
nw.show()
if self.replace_tabs:
chars = ' '
indentation /= self.replace_tabs
if line.endswith(':'):
if self.replace_tabs:
indentation += 1
super().keyPressEvent(e)
self.insertPlainText(chars * int(indentation))
else:
super().keyPressEvent(e)
class ConsoleWidget(RichJupyterWidget, QThread):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.font_size = 12
self.kernel_manager = kernel_manager = QtInProcessKernelManager()
kernel_manager.start_kernel(show_banner=False)
kernel_manager.kernel.gui = 'qt'
self.kernel_client = kernel_client = self._kernel_manager.client()
kernel_client.start_channels()
def stop():
kernel_client.stop_channels()
kernel_manager.shutdown_kernel()
sys.exit()
self.exit_requested.connect(stop)
def __init__(self, *args, **kw):
"""
:param start_on_init: (bool) If True (default), the kernel manager will
be initialized and the kernel threads will be
started
.. note:: `TaurusConsole.__init__` also accepts all args and kwargs
of :class:`qtconsole.rich_jupyter_widget.RichJupyterWidget`
"""
self.kernel_manager = None
start_on_init = kw.pop('start_on_init', True)
RichJupyterWidget.__init__(self, *args, **kw)
if start_on_init:
self.startKernelClient()
from qtconsole.inprocess import QtInProcessKernelManager
from IPython.core.magic import magic_escapes
from nexusformat.nexus import *
from .. import __version__
from .treeview import NXTreeView
from .plotview import NXPlotView
from .datadialogs import *
from .scripteditor import NXScriptWindow, NXScriptEditor
from .utils import confirm_action, report_error, display_message, is_file_locked
from .utils import natural_sort, import_plugin, timestamp
from .utils import get_name, get_colors, load_image
class NXRichJupyterWidget(RichJupyterWidget):
def _is_complete(self, source, interactive=True):
shell = self.kernel_manager.kernel.shell
status, indent_spaces = shell.input_transformer_manager.check_complete(
source)
if indent_spaces is None:
indent = ''
else:
indent = ' ' * indent_spaces
return status != 'incomplete', indent
class MainWindow(QtWidgets.QMainWindow):
_magic_menu_dict = {}
# qtpy must be the first import here as it makes the selection of the PyQt backend
# by preferring PyQt5 as we would like
from qtpy.QtWidgets import QApplication
try:
# Later versions of Qtconsole are part of Jupyter
from qtconsole.rich_jupyter_widget import RichJupyterWidget
from qtconsole.inprocess import QtInProcessKernelManager
except ImportError:
from IPython.qt.console.rich_ipython_widget import RichIPythonWidget as RichJupyterWidget
from IPython.qt.inprocess import QtInProcessKernelManager
# local imports
from mantidqt.utils.asynchronous import BlockingAsyncTaskWithCallback
class InProcessJupyterConsole(RichJupyterWidget):
def __init__(self, *args, **kwargs):
"""
A constructor matching that of RichJupyterWidget
:param args: Positional arguments passed directly to RichJupyterWidget
:param kwargs: Keyword arguments. The following keywords are understood by this widget:
- banner: Replace the default banner with this text
- startup_code: A code snippet to run on startup. It is also added to the banner to inform the user.
the rest are passed to RichJupyterWidget
"""
banner = kwargs.pop("banner", "")
startup_code = kwargs.pop("startup_code", "")
super(InProcessJupyterConsole, self).__init__(*args, **kwargs)
def start_python_kernel(self):
"""Starts kernel manager and client and attaches
the client to the Python Console."""
self._kernel_starting = True
km = QtKernelManager(kernel_name=self.kernel_name)
try:
blackhole = open(os.devnull, 'w')
km.start_kernel(stdout=blackhole, stderr=blackhole)
kc = km.client()
kc.start_channels()
self.kernel_manager = km
self.kernel_client = kc
self.connect_signals()
return True
except FileNotFoundError:
self._toolbox.msg_error.emit("\tCouldn't find the Python executable specified by the Jupyter kernel")
self._kernel_starting = False
return False
except NoSuchKernel: # kernelspecs for the selected kernel_name not available
self._toolbox.msg_error.emit(
"\tCouldn't find the specified IPython kernel specs [{0}]".format(self.kernel_name)