1 // Copyright (C) 2007-2015 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"
23 #include "PyConsole_Interp.h"
24 #include "PyConsole_Event.h"
25 #include "PyInterp_Event.h"
27 #include <QCoreApplication>
31 * @param theInterp interpreter that will execute the command
32 * @param theCommand command text
33 * @param theListener editor object that will receive the response events after execution
37 ExecCommand::ExecCommand( PyInterp_Interp* theInterp,
38 const QString& theCommand,
41 : PyInterp_LockRequest( theInterp, theListener, theSync ),
42 myCommand( theCommand ), myState( PyInterp_Event::ES_OK )
46 * Execute the command by calling the run() method of the embedded interpreter.
48 void ExecCommand::execute()
50 if ( myCommand != "" )
52 int ret = getInterp()->run( myCommand.toLatin1().data() );
54 myState = PyInterp_Event::ES_ERROR;
56 myState = PyInterp_Event::ES_INCOMPLETE;
61 * Create the event indicating the status of the request execution.
64 QEvent* ExecCommand::createEvent()
67 QCoreApplication::sendPostedEvents( listener(), PrintEvent::EVENT_ID );
68 return new PyInterp_Event( myState, this );
74 Creates a new python completion request.
75 \param theInterp python interpreter
76 \param input string containing the dir() command to be executed
77 \param startMatch part to be matched with the results of the dir() command
78 \param theListener widget to get the notification messages
79 \param sync if True the request is processed synchronously
81 CompletionCommand::CompletionCommand( PyInterp_Interp* theInterp,
82 const QString& theInput,
83 const QString& theStartMatch,
86 : PyInterp_LockRequest( theInterp, theListener, theSync ),
87 _tabSuccess(false), _dirArg(theInput), _startMatch(theStartMatch)
91 * Execute the completion command by wrapping the runDirCommand() of the
92 * embedded enhanced interpreter.
94 void CompletionCommand::execute()
96 int ret = static_cast<PyConsole_Interp*>(getInterp())->runDirCommand( _dirArg, _startMatch );
97 _tabSuccess = ret == 0;
101 * Create the event indicating the return value of the completion command.
104 QEvent* CompletionCommand::createEvent()
106 int typ = _tabSuccess ? PyInterp_Event::ES_TAB_COMPLETE_OK : PyInterp_Event::ES_TAB_COMPLETE_ERR;
107 return new PyInterp_Event( typ, this);