1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, 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 // Author : Adrien Bruneton (CEA/DEN)
20 // Created on: 3 avr. 2013
22 #include "PyConsole_Request.h"
24 #include "PyInterp_Event.h"
25 #include "PyConsole_Event.h"
26 #include "PyConsole_EnhInterp.h"
27 #include "PyConsole_EnhEditor.h"
29 #include <QCoreApplication>
33 * @param theInterp interpreter that will execute the command
34 * @param theCommand command text
35 * @param theListener editor object that will receive the response events after execution
39 ExecCommand::ExecCommand( PyInterp_Interp* theInterp,
40 const QString& theCommand,
41 PyConsole_Editor* theListener,
43 : PyInterp_LockRequest( theInterp, theListener, sync ),
44 myCommand( theCommand ), myState( PyInterp_Event::ES_OK )
48 * Execute the command by calling the run() method of the embedded interpreter.
50 void ExecCommand::execute()
52 if ( myCommand != "" )
54 int ret = getInterp()->run( myCommand.toUtf8().data() );
56 myState = PyInterp_Event::ES_ERROR;
58 myState = PyInterp_Event::ES_INCOMPLETE;
63 * Create the event indicating the status of the request execution.
66 QEvent* ExecCommand::createEvent()
69 QCoreApplication::sendPostedEvents( listener(), PrintEvent::EVENT_ID );
70 return new PyInterp_Event( myState, this );
76 Creates a new python completion request.
77 \param theInterp python interpreter
78 \param input string containing the dir() command to be executed
79 \param startMatch part to be matched with the results of the dir() command
80 \param theListener widget to get the notification messages
81 \param sync if True the request is processed synchronously
83 CompletionCommand::CompletionCommand( PyConsole_EnhInterp* theInterp,
85 const QString& startMatch,
86 PyConsole_EnhEditor* theListener,
88 : PyInterp_LockRequest( theInterp, theListener, sync ),
89 _tabSuccess(false), _dirArg(input), _startMatch(startMatch)
93 * Execute the completion command by wrapping the runDirCommand() of the
94 * embedded enhanced interpreter.
96 void CompletionCommand::execute()
98 PyConsole_EnhInterp * interp = static_cast<PyConsole_EnhInterp *>(getInterp());
99 int ret = interp->runDirCommand( _dirArg, _startMatch);
107 * Create the event indicating the return value of the completion command.
110 QEvent* CompletionCommand::createEvent()
112 int typ = _tabSuccess ? PyInterp_Event::ES_TAB_COMPLETE_OK : PyInterp_Event::ES_TAB_COMPLETE_ERR;
114 return new PyInterp_Event( typ, this);