1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : PyConsole_Request.cxx
20 // Author : Vadim SANDLER (OPEN CASCADE), Adrien Bruneton (CEA/DEN)
22 #include "PyConsole_Request.h"
23 #include "PyConsole_Interp.h"
24 #include "PyConsole_Event.h"
26 #include <QCoreApplication>
29 \class PyConsole_ExecCommand
30 \brief Python command execution request.
37 Creates new python command execution request.
39 \param theInterp python interpreter
40 \param theCommand python command
41 \param theListener widget to get the notification messages
42 \param theSync if \c true, the request is processed synchronously
44 PyConsole_ExecCommand::PyConsole_ExecCommand( PyInterp_Interp* theInterp,
45 const QString& theCommand,
48 : PyInterp_LockRequest( theInterp, theListener, theSync ),
49 myCommand( theCommand ), myState( PyInterp_Event::ES_OK )
53 \brief Execute the python command in the interpreter and
54 get its execution status.
56 void PyConsole_ExecCommand::execute()
58 if ( myCommand != "" ) {
59 int ret = getInterp()->run(myCommand.toUtf8());
61 myState = PyInterp_Event::ES_ERROR;
63 myState = PyInterp_Event::ES_INCOMPLETE;
68 \brief Create and return a notification event.
69 \return new notification event
71 QEvent* PyConsole_ExecCommand::createEvent()
74 QCoreApplication::sendPostedEvents( listener(), PyConsole_PrintEvent::EVENT_ID );
75 return new PyInterp_Event( myState, this );
79 \class PyConsole_CompletionCommand
80 \brief Python command completion request.
87 Creates a new python completion request.
89 \param theInterp python interpreter
90 \param theInput string containing the dir() command to be executed
91 \param theStartMatch part to be matched with the results of the dir() command
92 \param theListener widget to get the notification messages
93 \param theSync if \c true the request is processed synchronously
95 PyConsole_CompletionCommand::PyConsole_CompletionCommand( PyInterp_Interp* theInterp,
96 const QString& theInput,
97 const QString& theStartMatch,
100 : PyInterp_LockRequest( theInterp, theListener, theSync ),
101 myDirArg( theInput ), myStartMatch( theStartMatch ), myStatus( false )
105 \brief Execute the completion command by invoking runDirCommand() function
108 void PyConsole_CompletionCommand::execute()
110 myStatus = static_cast<PyConsole_Interp*>( getInterp() )->runDirCommand( myDirArg, myStartMatch, myMatches, myDoc );
114 \brief Create and return completion event
115 \return new completion event
117 QEvent* PyConsole_CompletionCommand::createEvent()
119 return new PyConsole_CompletionEvent( this, myStatus, myMatches, myDoc );