Public Types | Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
pqPythonShell Class Reference

Widget for a Python shell. More...

#include <pqPythonShell.h>

Inherits QWidget.

Collaboration diagram for pqPythonShell:
Collaboration graph
[legend]

Public Types

enum  PrintMode { STATUS, OUTPUT, ERROR }
 

Public Slots

void printMessage (const QString &)
 Prints some text on the shell. More...
 
void clear ()
 Clears the terminal. More...
 
void executeScript (const QString &)
 Execute an arbitrary python script/string. More...
 
void reset ()
 Resets the python interactive interpreter. More...
 
bool isExecuting () const
 Returns true is the shell is currently executing a script/command. More...
 
void printString (const QString &, PrintMode mode=STATUS)
 Use this method instead of calling pqConsoleWidget::printString() directly. More...
 
static void setPreamble (const QStringList &statements)
 Set a list of statements to be run each time the interpreter is reset. More...
 
static const QStringList & preamble ()
 
void initialize ()
 Initialize the Python interpreter in the shell, if not already. More...
 

Signals

void executing (bool starting)
 signal fired whenever the shell starts (starting=true) and finishes (starting=false) executing a Python command/script. More...
 

Public Member Functions

 pqPythonShell (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags{})
 
 ~pqPythonShell () override
 
void * consoleLocals ()
 Returns the interactive console context (the locals() dict). More...
 
void setFontSize (int fontSize)
 Set/get the font size in points for the Python shell text. More...
 

Protected Slots

void pushScript (const QString &)
 
void runScript ()
 

Protected Member Functions

bool prompt (const QString &indent=QString())
 Show the user-input prompt, if needed. More...
 
void HandleInterpreterEvents (vtkObject *caller, unsigned long eventid, void *calldata)
 

Static Protected Member Functions

static const char * PS1 ()
 
static const char * PS2 ()
 

Protected Attributes

pqConsoleWidgetConsoleWidget
 
const char * Prompt
 

Static Protected Attributes

static QStringList Preamble
 

Friends

class pqInternals
 

Detailed Description

Widget for a Python shell.

pqPythonShell is a QWidget subclass that provides an interactive Python shell. It uses vtkPythonInteractiveInterpreter to provide an interactive Python interpreter. Note that this is still executing Python code using the application wide global Python interpreter, it just keeps the context separate using an instance of core.InteractiveConsole internally.

Python initialization

pqPythonShell does not initialize Python on creation. By default, it waits till the pqConsoleWidget gets focus or pqPythonShell::executeScript is called. One can also call pqPythonShell::initialize explicitly to initialize the interpreter.

See also
pqConsoleWidget.

Definition at line 61 of file pqPythonShell.h.

Member Enumeration Documentation

◆ PrintMode

Enumerator
STATUS 
OUTPUT 
ERROR 

Definition at line 84 of file pqPythonShell.h.

Constructor & Destructor Documentation

◆ pqPythonShell()

pqPythonShell::pqPythonShell ( QWidget *  parent = nullptr,
Qt::WindowFlags  flags = Qt::WindowFlags{} 
)

◆ ~pqPythonShell()

pqPythonShell::~pqPythonShell ( )
override

Member Function Documentation

◆ consoleLocals()

void* pqPythonShell::consoleLocals ( )

Returns the interactive console context (the locals() dict).

You can use static_cast<PythonObject*>() to convert the void pointer. See vtkPythonInteractiveInterpreter::GetInteractiveConsoleLocalsPyObject().

◆ setFontSize()

void pqPythonShell::setFontSize ( int  fontSize)

Set/get the font size in points for the Python shell text.

◆ printMessage

void pqPythonShell::printMessage ( const QString &  )
slot

Prints some text on the shell.

◆ clear

void pqPythonShell::clear ( )
slot

Clears the terminal.

This does not change the state of the Python interpreter, just clears the text shown in the Widget.

◆ executeScript

void pqPythonShell::executeScript ( const QString &  )
slot

Execute an arbitrary python script/string.

This simply execute the Python script in the global Python interpreter.

◆ reset

void pqPythonShell::reset ( )
slot

Resets the python interactive interpreter.

This does not affect the global Python interpreter. If the interactive interpreter hasn't been initialized this has no effect.

◆ isExecuting

bool pqPythonShell::isExecuting ( ) const
slot

Returns true is the shell is currently executing a script/command.

◆ printString

void pqPythonShell::printString ( const QString &  ,
PrintMode  mode = STATUS 
)
slot

Use this method instead of calling pqConsoleWidget::printString() directly.

That helps us keep track of whether we need to show the prompt or not.

◆ setPreamble

static void pqPythonShell::setPreamble ( const QStringList &  statements)
staticslot

Set a list of statements to be run each time the interpreter is reset.

By default, this imports the paraview.simple module. If you call this method, be aware that the preamble is assumed not to have any multi-line statements.

◆ preamble

static const QStringList& pqPythonShell::preamble ( )
staticslot

◆ initialize

void pqPythonShell::initialize ( )
slot

Initialize the Python interpreter in the shell, if not already.

Has no effect if the interpreter has already been initialized.

◆ executing

void pqPythonShell::executing ( bool  starting)
signal

signal fired whenever the shell starts (starting=true) and finishes (starting=false) executing a Python command/script.

This can be used by the UI to block user input while the script is executing.

◆ pushScript

void pqPythonShell::pushScript ( const QString &  )
protectedslot

◆ runScript

void pqPythonShell::runScript ( )
protectedslot

◆ PS1()

static const char* pqPythonShell::PS1 ( )
inlinestaticprotected

Definition at line 161 of file pqPythonShell.h.

◆ PS2()

static const char* pqPythonShell::PS2 ( )
inlinestaticprotected

Definition at line 162 of file pqPythonShell.h.

◆ prompt()

bool pqPythonShell::prompt ( const QString &  indent = QString())
protected

Show the user-input prompt, if needed.

Returns true if the prompt was re-rendered, otherwise false.

◆ HandleInterpreterEvents()

void pqPythonShell::HandleInterpreterEvents ( vtkObject caller,
unsigned long  eventid,
void *  calldata 
)
protected

Friends And Related Function Documentation

◆ pqInternals

friend class pqInternals
friend

Definition at line 176 of file pqPythonShell.h.

Member Data Documentation

◆ ConsoleWidget

pqConsoleWidget* pqPythonShell::ConsoleWidget
protected

Definition at line 157 of file pqPythonShell.h.

◆ Prompt

const char* pqPythonShell::Prompt
protected

Definition at line 158 of file pqPythonShell.h.

◆ Preamble

QStringList pqPythonShell::Preamble
staticprotected

Definition at line 159 of file pqPythonShell.h.


The documentation for this class was generated from the following file: