3 #include "PyConsole_Request.h"
5 #include "PyInterp_Event.h"
6 #include "PyConsole_Event.h"
7 #include "PyConsole_EnhInterp.h"
8 #include "PyConsole_EnhEditor.h"
10 #include <QCoreApplication>
14 * @param theInterp interpreter that will execute the command
15 * @param theCommand command text
16 * @param theListener editor object that will receive the response events after execution
20 ExecCommand::ExecCommand( PyInterp_Interp* theInterp,
21 const QString& theCommand,
22 PyConsole_Editor* theListener,
24 : PyInterp_LockRequest( theInterp, theListener, sync ),
25 myCommand( theCommand ), myState( PyInterp_Event::ES_OK )
29 * Execute the command by calling the run() method of the embedded interpreter.
31 void ExecCommand::execute()
33 if ( myCommand != "" )
35 int ret = getInterp()->run( myCommand.toUtf8().data() );
37 myState = PyInterp_Event::ES_ERROR;
39 myState = PyInterp_Event::ES_INCOMPLETE;
44 * Create the event indicating the status of the request execution.
47 QEvent* ExecCommand::createEvent()
50 QCoreApplication::sendPostedEvents( listener(), PrintEvent::EVENT_ID );
51 return new PyInterp_Event( myState, this );
57 Creates a new python completion request.
58 \param theInterp python interpreter
59 \param input string containing the dir() command to be executed
60 \param startMatch part to be matched with the results of the dir() command
61 \param theListener widget to get the notification messages
62 \param sync if True the request is processed synchronously
64 CompletionCommand::CompletionCommand( PyConsole_EnhInterp* theInterp,
66 const QString& startMatch,
67 PyConsole_EnhEditor* theListener,
69 : PyInterp_LockRequest( theInterp, theListener, sync ),
70 _tabSuccess(false), _dirArg(input), _startMatch(startMatch)
74 * Execute the completion command by wrapping the runDirCommand() of the
75 * embedded enhanced interpreter.
77 void CompletionCommand::execute()
79 PyConsole_EnhInterp * interp = static_cast<PyConsole_EnhInterp *>(getInterp());
80 int ret = interp->runDirCommand( _dirArg, _startMatch);
88 * Create the event indicating the return value of the completion command.
91 QEvent* CompletionCommand::createEvent()
93 int typ = _tabSuccess ? PyInterp_Event::ES_TAB_COMPLETE_OK : PyInterp_Event::ES_TAB_COMPLETE_ERR;
95 return new PyInterp_Event( typ, this);