def __init__(
        self,
        parent=None,
        name=None,
        kernel=None,
        inprocess=False
    ):

        super(JupyterConsole, self).__init__(parent)
        if kernel is None:
            kernel = cfg.jupyter_default_kernel
        self._console_tabwidget = parent
        self.name = name
        # Initialize Jupyter Widget
        if inprocess:
            from qtconsole.inprocess import (
                QtInProcessKernelManager as QtKernelManager
            )
            from jupyter_tabwidget.transparent_jupyter_widget import (
                InprocessJupyterWidget as JupyterWidget
            )
        else:
            from qtconsole.manager import QtKernelManager
            from jupyter_tabwidget.transparent_jupyter_widget import (
                OutprocessJupyterWidget as JupyterWidget
            )
        self._inprocess = inprocess
        self._kernel = kernel
        self._kernel_manager = QtKernelManager(kernel_name=kernel)
        self._kernel_manager.start_kernel()
        self._kernel_client = self._kernel_manager.client()
        self._kernel_client.start_channels()
        self._jupyter_widget = JupyterWidget(self)
        self._jupyter_widget.kernel_manager = self._kernel_manager
        self._jupyter_widget.kernel_client = self._kernel_client
        # Set theme
        self._jupyter_widget._control.setFont(
            QFont(
                cfg.pyqode_font_name,
                cfg.pyqode_font_size
            )
        )
        self._jupyter_widget.style_sheet = styles.sheet_from_template(
            cfg.pyqode_color_scheme,
            u'linux' if styles.dark_style(cfg.pyqode_color_scheme)
            else 'lightbg'
        )
        self._jupyter_widget.syntax_style = cfg.pyqode_color_scheme
        self._jupyter_widget._syntax_style_changed()
        self._jupyter_widget._style_sheet_changed()
        # Add to layout
        self._layout = QHBoxLayout(self)
        self._layout.setContentsMargins(6, 6, 6, 6)
        self._layout.addWidget(self._jupyter_widget)
        self.setLayout(self._layout)
Beispiel #2
0
    def init_colors(self, widget):
        """Configure the coloring of the widget"""
        # Note: This will be dramatically simplified when colors
        # are removed from the backend.

        # parse the colors arg down to current known labels
        cfg = self.config
        colors = cfg.ZMQInteractiveShell.colors if 'ZMQInteractiveShell.colors' in cfg else None
        style = cfg.JupyterWidget.syntax_style if 'JupyterWidget.syntax_style' in cfg else None
        sheet = cfg.JupyterWidget.style_sheet if 'JupyterWidget.style_sheet' in cfg else None

        # find the value for colors:
        if colors:
            colors=colors.lower()
            if colors in ('lightbg', 'light'):
                colors='lightbg'
            elif colors in ('dark', 'linux'):
                colors='linux'
            else:
                colors='nocolor'
        elif style:
            if style=='bw':
                colors='nocolor'
            elif styles.dark_style(style):
                colors='linux'
            else:
                colors='lightbg'
        else:
            colors=None

        # Configure the style
        if style:
            widget.style_sheet = styles.sheet_from_template(style, colors)
            widget.syntax_style = style
            widget._syntax_style_changed()
            widget._style_sheet_changed()
        elif colors:
            # use a default dark/light/bw style
            widget.set_default_style(colors=colors)

        if self.stylesheet:
            # we got an explicit stylesheet
            if os.path.isfile(self.stylesheet):
                with open(self.stylesheet) as f:
                    sheet = f.read()
            else:
                raise IOError("Stylesheet %r not found." % self.stylesheet)
        if sheet:
            widget.style_sheet = sheet
            widget._style_sheet_changed()
Beispiel #3
0
    def init_colors(self, widget):
        """Configure the coloring of the widget"""
        # Note: This will be dramatically simplified when colors
        # are removed from the backend.

        # parse the colors arg down to current known labels
        cfg = self.config
        colors = cfg.ZMQInteractiveShell.colors if "ZMQInteractiveShell.colors" in cfg else None
        style = cfg.JupyterWidget.syntax_style if "JupyterWidget.syntax_style" in cfg else None
        sheet = cfg.JupyterWidget.style_sheet if "JupyterWidget.style_sheet" in cfg else None

        # find the value for colors:
        if colors:
            colors = colors.lower()
            if colors in ("lightbg", "light"):
                colors = "lightbg"
            elif colors in ("dark", "linux"):
                colors = "linux"
            else:
                colors = "nocolor"
        elif style:
            if style == "bw":
                colors = "nocolor"
            elif styles.dark_style(style):
                colors = "linux"
            else:
                colors = "lightbg"
        else:
            colors = None

        # Configure the style
        if style:
            widget.style_sheet = styles.sheet_from_template(style, colors)
            widget.syntax_style = style
            widget._syntax_style_changed()
            widget._style_sheet_changed()
        elif colors:
            # use a default dark/light/bw style
            widget.set_default_style(colors=colors)

        if self.stylesheet:
            # we got an explicit stylesheet
            if os.path.isfile(self.stylesheet):
                with open(self.stylesheet) as f:
                    sheet = f.read()
            else:
                raise IOError("Stylesheet %r not found." % self.stylesheet)
        if sheet:
            widget.style_sheet = sheet
            widget._style_sheet_changed()
Beispiel #4
0
 def set_syntax_style(self, syntax_style):
     """Set up syntax style for the current console."""
     if syntax_style == 'bw':
         colors = 'nocolor'
     elif styles.dark_style(syntax_style):
         colors = 'linux'
     else:
         colors = 'lightbg'
     self.active_frontend.syntax_style = syntax_style
     style_sheet = styles.sheet_from_template(syntax_style, colors)
     self.active_frontend.style_sheet = style_sheet
     self.active_frontend._syntax_style_changed()
     self.active_frontend._style_sheet_changed()
     self.active_frontend.reset(clear=True)
     self.active_frontend._execute("%colors linux", True)
Beispiel #5
0
 def set_syntax_style(self, syntax_style):
     """Set up syntax style for the current console."""
     if syntax_style=='bw':
         colors='nocolor'
     elif styles.dark_style(syntax_style):
         colors='linux'
     else:
         colors='lightbg'
     self.active_frontend.syntax_style = syntax_style
     style_sheet = styles.sheet_from_template(syntax_style, colors)
     self.active_frontend.style_sheet = style_sheet
     self.active_frontend._syntax_style_changed()
     self.active_frontend._style_sheet_changed()
     self.active_frontend.reset(clear=True)
     self.active_frontend._execute("%colors linux", True)
    def set_background_color(self, style):
        """
        Given a syntax style, attempt to set a color map that will be
        aesthetically pleasing.
        """
        # Set a new default color map.
        self.default_color_map = self.darkbg_color_map.copy()

        if not dark_style(style):
            # Colors appropriate for a terminal with a light background. For
            # now, only use non-bright colors...
            for i in range(8):
                self.default_color_map[i + 8] = self.default_color_map[i]

            # ...and replace white with black.
            self.default_color_map[7] = self.default_color_map[15] = 'black'

        # Update the current color map with the new defaults.
        self.color_map.update(self.default_color_map)
    def set_background_color(self, style):
        """
        Given a syntax style, attempt to set a color map that will be
        aesthetically pleasing.
        """
        # Set a new default color map.
        self.default_color_map = self.darkbg_color_map.copy()

        if not dark_style(style):
            # Colors appropriate for a terminal with a light background. For
            # now, only use non-bright colors...
            for i in range(8):
                self.default_color_map[i + 8] = self.default_color_map[i]

            # ...and replace white with black.
            self.default_color_map[7] = self.default_color_map[15] = 'black'

        # Update the current color map with the new defaults.
        self.color_map.update(self.default_color_map)
Beispiel #8
0
 def test_dark_style(self):
     self.assertTrue(dark_style('monokai'))
     self.assertTrue(not dark_style('default'))
Beispiel #9
0
 def test_dark_style(self):
     self.assertTrue(dark_style('monokai'))
     self.assertTrue(not dark_style('default'))