How to use the qtconsole.qt.QtGui 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 jupyter / qtconsole / qtconsole / kill_ring.py View on Github external
def __init__(self, text_edit):
        """ Create a kill ring attached to the specified Qt text edit.
        """
        assert isinstance(text_edit, (QtGui.QTextEdit, QtGui.QPlainTextEdit))
        super(QtKillRing, self).__init__()

        self._ring = KillRing()
        self._prev_yank = None
        self._skip_cursor = False
        self._text_edit = text_edit

        text_edit.cursorPositionChanged.connect(self._cursor_position_changed)
github SanPen / GridCal / Stable / GridCal / gui / main / GridCalMain.py View on Github external
def populate_powerplant_editor(self, index):
        """
        Fill the power plant editor given the generators selected index
        @param index:
        @return:
        """
        if isinstance(index, QtGui.QItemSelection):
            idx = index.indexes()[0].row()
        else:
            idx = index.row()

        self.ui.powerplants_name.setText(self.circuit.gen_names[idx])
        self.ui.powerplants_bus.setCurrentIndex(self.circuit.gen[idx, GEN_BUS])

        self.ui.powerplants_basepower.setValue(self.circuit.gen[idx, MBASE])
        self.ui.powerplants_status.setChecked(self.circuit.gen[idx, GEN_STATUS] == 1)

        self.ui.powerplants_p.setValue(self.circuit.gen[idx, PG])
        self.ui.powerplants_v.setValue(self.circuit.gen[idx, VG])

        self.ui.powerplants_pmax.setValue(self.circuit.gen[idx, PMAX])
        self.ui.powerplants_pmin.setValue(self.circuit.gen[idx, PMIN])
        self.ui.powerplants_qmax.setValue(self.circuit.gen[idx, QMIN])
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 / qtconsole / history_console_widget.py View on Github external
# to determine if the prefix has changed
            n = min(pos, len(self._history_prefix))

            # prefix changed, restart search from the beginning
            if (self._history_prefix[:n] != input_buffer[:n]):
                self._history_index = len(self._history)

            # the only time we shouldn't set the history prefix
            # to the line up to the cursor is if we are already
            # in a simple scroll (no prefix),
            # and the cursor is at the end of the first line

            # check if we are at the end of the first line
            c = self._get_cursor()
            current_pos = c.position()
            c.movePosition(QtGui.QTextCursor.EndOfBlock)
            at_eol = (c.position() == current_pos)

            if self._history_index == len(self._history) or \
                not (self._history_prefix == '' and at_eol) or \
                not (self._get_edited_history(self._history_index)[:pos] == input_buffer[:pos]):
                self._history_prefix = input_buffer[:pos]

            # Perform the search.
            self.history_previous(self._history_prefix,
                                    as_prefix=not shift_modifier)

            # Go to the first line of the prompt for seemless history scrolling.
            # Emulate readline: keep the cursor position fixed for a prefix
            # search.
            cursor = self._get_prompt_cursor()
            if self._history_prefix:
github jupyter / qtconsole / qtconsole / rich_jupyter_widget.py View on Github external
def _insert_img(self, cursor, img, fmt, metadata=None):
        """ insert a raw image, jpg or png """
        if metadata:
            width = metadata.get('width', None)
            height = metadata.get('height', None)
        else:
            width = height = None
        try:
            image = QtGui.QImage()
            image.loadFromData(img, fmt.upper())
            if width and height:
                image = image.scaled(width, height, transformMode=QtCore.Qt.SmoothTransformation)
            elif width and not height:
                image = image.scaledToWidth(width, transformMode=QtCore.Qt.SmoothTransformation)
            elif height and not width:
                image = image.scaledToHeight(height, transformMode=QtCore.Qt.SmoothTransformation)
        except ValueError:
            self._insert_plain_text(cursor, 'Received invalid %s data.'%fmt)
        else:
            format = self._add_image(image)
            cursor.insertBlock()
            cursor.insertImage(format)
            cursor.insertBlock()
github jupyter / qtconsole / qtconsole / pygments_highlighter.py View on Github external
def _get_color(self, color):
        """ Returns a QColor built from a Pygments color string.
        """
        qcolor = QtGui.QColor()
        qcolor.setRgb(int(color[:2], base=16),
                      int(color[2:4], base=16),
                      int(color[4:6], base=16))
        return qcolor
github jupyter / qtconsole / qtconsole / qtconsoleapp.py View on Github external
def init_qt_elements(self):
        # Create the widget.

        base_path = os.path.abspath(os.path.dirname(__file__))
        icon_path = os.path.join(base_path, 'resources', 'icon', 'JupyterConsole.svg')
        self.app.icon = QtGui.QIcon(icon_path)
        QtGui.QApplication.setWindowIcon(self.app.icon)

        ip = self.ip
        local_kernel = (not self.existing) or is_local_ip(ip)
        self.widget = self.widget_factory(config=self.config,
                                        local_kernel=local_kernel)
        self.init_colors(self.widget)
        self.widget._existing = self.existing
        self.widget._may_close = not self.existing
        self.widget._confirm_exit = self.confirm_exit
        self.widget._display_banner = self.display_banner

        self.widget.kernel_manager = self.kernel_manager
        self.widget.kernel_client = self.kernel_client
        self.window = MainWindow(self.app,
                                confirm_exit=self.confirm_exit,
                                new_frontend_factory=self.new_frontend_master,
github jupyter / qtconsole / qtconsole / completion_html.py View on Github external
return self._start

    @property
    def stop(self):
        """end of interval to show"""
        return self._stop

    @property
    def width(self):
        return self._stop - self._start

    @property
    def nth(self):
        return self.current - self.start

class CompletionHtml(QtGui.QWidget):
    """ A widget for tab completion,  navigable by arrow keys """

    #--------------------------------------------------------------------------
    # 'QObject' interface
    #--------------------------------------------------------------------------

    _items = ()
    _index = (0, 0)
    _consecutive_tab = 0
    _size = (1, 1)
    _old_cursor = None
    _start_position = 0
    _slice_start = 0
    _slice_len = 4

    def __init__(self, console_widget):