Version: 6.3.1
Public Slots | Public Member Functions | Protected Member Functions | Private Attributes

PyConsole_Editor Class Reference

Python command line interpreter front-end GUI widget. More...

#include <PyConsole_Editor.h>

Inheritance diagram for PyConsole_Editor:
Inheritance graph

Public Slots

void cut ()
 "Copy" operation.
void paste ()
 "Paste" operation.
void clear ()
 "Clear" operation.
void handleReturn ()
 Process "Enter" key press event.
void onPyInterpChanged (PyConsole_Interp *)
 Handle Python interpreter change.
void dump ()
 "Dump commands" operation.

Public Member Functions

 PyConsole_Editor (PyConsole_Interp *theInterp, QWidget *theParent=0)
 Constructor.
 ~PyConsole_Editor ()
 Destructor.
virtual void addText (const QString &str, const bool newBlock=false)
 Put the string str to the python editor.
bool isCommand (const QString &str) const
 Check if the string is command.
virtual void exec (const QString &command)
 Convenient method for executing a Python command, as if the user typed it manually.
void execAndWait (const QString &command)
 Execute command in the python interpreter and wait until it is finished.
bool isSync () const
 Get synchronous mode flag value.
void setIsSync (const bool)
 Set synchronous mode flag value.
bool isSuppressOutput () const
 Get suppress output flag value.
void setIsSuppressOutput (const bool)
 Set suppress output flag value.
bool isShowBanner () const
 Get 'show banner' flag value.
void setIsShowBanner (const bool)
 Set 'show banner' flag value.
virtual QSize sizeHint () const
 Get size hint for the Python console window.

Protected Member Functions

virtual void dropEvent (QDropEvent *event)
 Process drop event.
virtual void mouseReleaseEvent (QMouseEvent *event)
 Process mouse button release event.
virtual void keyPressEvent (QKeyEvent *event)
 Handle keyboard event.
virtual void customEvent (QEvent *event)
 Handle notification event coming from Python dispatcher.
virtual PyInterp_RequestcreateRequest (const QString &)
 Create request to the python dispatcher for the command execution.

Private Attributes

PyConsole_InterpmyInterp
 python interpreter
QString myCommandBuffer
 python command buffer
QString myCurrentCommand
 currently being printed command
QString myPrompt
 current command line prompt
int myCmdInHistory
 current history command index
QStringList myHistory
 commands history buffer
QEventLoop * myEventLoop
 internal event loop
QString myBanner
 current banner
bool myShowBanner
 'show banner' flag
QStringList myQueue
 python commands queue
bool myIsSync
 synchronous mode flag
bool myIsSuppressOutput
 suppress output flag

Detailed Description

This class provides simple GUI interface to the Python interpreter, including basic navigation operations, executing commands (both interactively and programmatically), copy-paste operations, history of the commands and so on.

Here below is the shortcut keyboard boundings used for navigation and other operations:

TODO:

  • paste multiline text: process each line as separate command (including mouse middle-button click pasting)
  • the same for drag-n-drop of multiline text


Constructor & Destructor Documentation

PyConsole_Editor::PyConsole_Editor ( PyConsole_Interp theInterp,
QWidget theParent = 0 
)

Creates python editor window.

Parameters:
theInterppython interper
theParentparent widget

References myPrompt, onPyInterpChanged(), READY_PROMPT, PyInterp_Interp.setverrcb(), PyInterp_Interp.setvoutcb(), staticCallback(), and SUIT_Tools.stringToFont().

PyConsole_Editor::~PyConsole_Editor ( )

Does nothing for the moment.


Member Function Documentation

void PyConsole_Editor::addText ( const QString &  str,
const bool  newBlock = false 
) [virtual]
Parameters:
strstring to be put in the command line of the editor
newBlockif True, then the string is printed on a new line
bool PyConsole_Editor::isCommand ( const QString &  str) const

Return True if the string str is likely to be the command (i.e. it is started from the '>>>' or '...').

Parameters:
strstring to be checked

References DOTS_PROMPT, and READY_PROMPT.

void PyConsole_Editor::exec ( const QString &  command) [virtual]
void PyConsole_Editor::execAndWait ( const QString &  command)
Parameters:
commandpython command to be executed

References exec(), and myEventLoop.

bool PyConsole_Editor::isSync ( ) const
See also:
setIsSync()
Returns:
True if python console works in synchronous mode

References myIsSync.

void PyConsole_Editor::setIsSync ( const bool  on)

In synhronous mode the Python commands are executed in the GUI thread and the GUI is blocked until the command is finished. In the asynchronous mode each Python command is executed in the separate thread that does not block the main GUI loop.

Parameters:
onsynhronous mode flag

References myIsSync.

bool PyConsole_Editor::isSuppressOutput ( ) const
See also:
setIsSuppressOutput()
Returns:
true if python console output is suppressed.

References myIsSuppressOutput.

void PyConsole_Editor::setIsSuppressOutput ( const bool  on)

In case if suppress output flag is true, the python console output suppressed.

Parameters:
onsuppress output flag

References myIsSuppressOutput.

bool PyConsole_Editor::isShowBanner ( ) const
See also:
setIsShowBanner()
Returns:
true if python console shows banner

References myShowBanner.

void PyConsole_Editor::setIsShowBanner ( const bool  on)

The banner is shown in the top of the python console window.

See also:
isShowBanner()
Parameters:
on'show banner' flag

References clear(), and myShowBanner.

QSize PyConsole_Editor::sizeHint ( ) const [virtual]
Returns:
size hint value

References isShowBanner(), and myBanner.

void PyConsole_Editor::dropEvent ( QDropEvent *  event) [protected, virtual]

Paste dragged text.

Parameters:
eventdrop event

References PROMPT_SIZE.

void PyConsole_Editor::mouseReleaseEvent ( QMouseEvent *  event) [protected, virtual]

Left mouse button: copy selection to the clipboard. Middle mouse button: paste clipboard's contents.

Parameters:
eventmouse event

References PROMPT_SIZE.

void PyConsole_Editor::keyPressEvent ( QKeyEvent *  event) [protected, virtual]

Implement navigation, history browsing, copy/paste and other common operations.

Parameters:
eventkeyboard event

References addText(), cut(), handleReturn(), isCommand(), myCmdInHistory, myCommandBuffer, myCurrentCommand, myHistory, myPrompt, paste(), PROMPT_SIZE, and READY_PROMPT.

void PyConsole_Editor::customEvent ( QEvent event) [protected, virtual]
PyInterp_Request * PyConsole_Editor::createRequest ( const QString &  command) [protected, virtual]
Parameters:
commandpython command to be executed

References isSync(), and myInterp.

void PyConsole_Editor::cut ( ) [slot]

Reimplemented from Qt. Warning! In Qt4 this method is not virtual.

References PROMPT_SIZE.

void PyConsole_Editor::paste ( ) [slot]

Reimplemented from Qt. Warning! In Qt4 this method is not virtual.

References PROMPT_SIZE.

void PyConsole_Editor::clear ( ) [slot]

Reimplemented from Qt. Warning! In Qt4 this method is not virtual.

References addText(), isShowBanner(), myBanner, myPrompt, and READY_PROMPT.

void PyConsole_Editor::handleReturn ( ) [slot]
void PyConsole_Editor::onPyInterpChanged ( PyConsole_Interp interp) [slot]

Perform initialization actions if the interpreter is changed.

Parameters:
interppython interpreter is being set

References addText(), clear(), PyInterp_Interp.getbanner(), isShowBanner(), myBanner, myCmdInHistory, myCommandBuffer, myEventLoop, myInterp, and myPrompt.

void PyConsole_Editor::dump ( ) [slot]

Field Documentation

QString PyConsole_Editor.myPrompt [private]
QStringList PyConsole_Editor.myHistory [private]
QEventLoop* PyConsole_Editor.myEventLoop [private]
QString PyConsole_Editor.myBanner [private]
QStringList PyConsole_Editor.myQueue [private]
bool PyConsole_Editor.myIsSync [private]
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS