How to use the qtconsole.rich_jupyter_widget.RichJupyterWidget function in qtconsole

To help you get started, we’ve selected a few qtconsole examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CountryTk / Hydra / src / main.py View on Github external
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)
github taurus-org / taurus / lib / taurus / qt / qtgui / console / taurusconsole.py View on Github external
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()
github nexpy / nexpy / src / nexpy / gui / mainwindow.py View on Github external
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 = {}
github mantidproject / mantid / qt / python / mantidqt / widgets / jupyterconsole.py View on Github external
# 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)
github mcedit / mcedit2 / src / mcedit2 / util / ipython_widget.py View on Github external
def terminal_widget(**kwargs):

    # Create an in-process kernel
    # >>> print_process_id()
    # will print the same process ID as the main process
    kernel_manager = QtInProcessKernelManager()
    kernel_manager.start_kernel()
    kernel = kernel_manager.kernel
    kernel.gui = 'qt4'
    kernel.shell.push(kwargs)

    kernel_client = kernel_manager.client()
    kernel_client.start_channels()

    control = RichJupyterWidget()
    control.kernel_manager = kernel_manager
    control.kernel_client = kernel_client
    return control
github jupyter / qtconsole / qtconsole / rich_jupyter_widget.py View on Github external
def __init__(self, *args, **kw):
        """ Create a RichJupyterWidget.
        """
        kw['kind'] = 'rich'
        super(RichJupyterWidget, self).__init__(*args, **kw)

        # Configure the ConsoleWidget HTML exporter for our formats.
        self._html_exporter.image_tag = self._get_image_tag

        # Dictionary for resolving document resource names to SVG data.
        self._name_to_svg_map = {}

        # Do we support jpg ?
        # it seems that sometime jpg support is a plugin of QT, so try to assume
        # it is not always supported.
        self._jpg_supported = 'jpeg' in QtGui.QImageReader.supportedImageFormats()
github jupyter / qtconsole / examples / embed_qtconsole.py View on Github external
def make_jupyter_widget_with_kernel():
    """Start a kernel, connect to it, and create a RichJupyterWidget to use it
    """
    kernel_manager = QtKernelManager(kernel_name=USE_KERNEL)
    kernel_manager.start_kernel()

    kernel_client = kernel_manager.client()
    kernel_client.start_channels()

    jupyter_widget = RichJupyterWidget()
    jupyter_widget.kernel_manager = kernel_manager
    jupyter_widget.kernel_client = kernel_client
    return jupyter_widget
github glue-viz / glue / glue / app / qt / terminal.py View on Github external
glue_banner = """
This is the built-in IPython terminal. You can type any valid Python code here, and you also have access to the following pre-defined variables:

  * data_collection (aliased to dc)
  * application
  * hub

In addition, you can drag and drop any dataset or subset onto the terminal to create a new variable, and you will be prompted for a name.
"""


def howto():
    print(glue_banner.strip())


class DragAndDropTerminal(RichJupyterWidget):

    def __init__(self, **kwargs):
        super(DragAndDropTerminal, self).__init__(**kwargs)
        self.setAcceptDrops(True)
        self.shell = None

    def mdi_wrap(self):
        sub = GlueMdiSubWindow()
        sub.setWidget(self)
        self.destroyed.connect(sub.close)
        sub.resize(self.size())
        self._mdi_wrapper = sub
        return sub

    @property
    def namespace(self):
github sjdv1982 / seamless / seamless / shell.py View on Github external
def __init__(self, namespace, inputpin, windowtitle=None):
        assert isinstance(namespace, dict), namespace
        from . import qt_error
        if qt_error is not None:
            self._dummy = True
            return
        p = inputpin.path
        if p not in _shells:
            _shells[p] = []
        _shells[p].append(self)
        self.namespace = namespace
        self.inputpin = inputpin
        self.windowtitle = windowtitle
        self.kernel_manager = MyQtInProcessKernelManager()
        control = RichJupyterWidget()
        self.control = control
        control.kernel_manager = self.kernel_manager
        self.start()
    def start(self):
github jupyter / qtconsole / examples / inprocess_qtconsole.py View on Github external
def show():
    global ipython_widget  # Prevent from being garbage collected

    # Create an in-process kernel
    kernel_manager = QtInProcessKernelManager()
    kernel_manager.start_kernel(show_banner=False)
    kernel = kernel_manager.kernel
    kernel.gui = 'qt4'

    kernel_client = kernel_manager.client()
    kernel_client.start_channels()

    ipython_widget = RichJupyterWidget()
    ipython_widget.kernel_manager = kernel_manager
    ipython_widget.kernel_client = kernel_client
    ipython_widget.show()