IPython Documentation

Table Of Contents

Previous topic

Module: qt.console.completion_widget

Next topic

Module: qt.console.frontend_widget

This Page

Module: qt.console.console_widget

An abstract base class for console-type widgets.

1 Class

class IPython.qt.console.console_widget.ConsoleWidget(parent=None, **kw)

Bases: IPython.qt.util.NewBase

An abstract base class for console-type widgets. This class has functionality for:

  • Maintaining a prompt and editing region
  • Providing the traditional Unix-style console keyboard shortcuts
  • Performing tab completion
  • Paging text
  • Handling ANSI escape codes

ConsoleWidget also provides a number of utility methods that will be convenient to implementors of a console-style widget.

__init__(parent=None, **kw)

Create a ConsoleWidget.


parent : QWidget, optional [default None]

The parent for this widget.


Returns whether text can be copied to the clipboard.


Returns whether text can be cut to the clipboard.


Returns whether text can be pasted from the clipboard.


Change the font size by the specified amount (in points).


Clear the console.


keep_input : bool, optional (default True)

If set, restores the old input buffer if a new prompt is written.


Copy the currently selected text to the clipboard.


Copy anchor text to the clipboard


Copy the currently selected text to the clipboard and delete it if it’s inside the input buffer.

eventFilter(obj, event)

Reimplemented to ensure a console-like behavior in the underlying text widgets.

execute(source=None, hidden=False, interactive=False)

Executes source or the input buffer, possibly prompting for more input.


source : str, optional

The source to execute. If not specified, the input buffer will be used. If specified and ‘hidden’ is False, the input buffer will be replaced with the source before execution.

hidden : bool, optional (default False)

If set, no output will be shown and the prompt will not be modified. In other words, it will be completely invisible to the user that an execution has occurred.

interactive : bool, optional (default False)

Whether the console is to treat the source as having been manually entered by the user. The effect of this parameter depends on the subclass implementation.


A boolean indicating whether the source was executed.



If incomplete input is given and ‘hidden’ is True. In this case, it is not possible to prompt for more input.


Shows a dialog to export HTML/XML in various formats.


The base font being used by the ConsoleWidget.


The text that the user has entered entered at the current prompt.

If the console is currently executing, the text that is executing will always be returned.


Open selected anchor in the default webbrowser


Paste the contents of the clipboard into the input region.


mode : QClipboard::Mode, optional [default QClipboard::Clipboard]

Controls which part of the system clipboard is used. This can be used to access the selection clipboard in X11 and the Find buffer in Mac OS. By default, the regular clipboard is used.


Print the contents of the ConsoleWidget to the specified QPrinter.


Moves the prompt to the top of the viewport.


Redo the last operation. If there is no operation to redo, nothing happens.


Sets the font to the default fixed-width font for this platform.


Selects all the text in the buffer.


Reimplemented to suggest a size that is 80 characters wide and 25 lines high.


The width (in terms of space characters) for tab characters.


Undo the last operation. If there is no operation to undo, nothing happens.

2 Functions


Get common prefix for completions

Return the longest common prefix of a list of strings, but with special treatment of escape characters that might precede commands in IPython, such as %magic functions. Used in tab completion.

For a more general function, see os.path.commonprefix


Returns whether the specified unicode character is a letter or a number.