File: PyConsole_Request.cxx

package info (click to toggle)
persalys 13.1.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 71,916 kB
  • sloc: xml: 496,859; cpp: 53,848; python: 3,435; sh: 332; makefile: 131; ansic: 14
file content (120 lines) | stat: -rw-r--r-- 4,146 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File   : PyConsole_Request.cxx
// Author : Vadim SANDLER (OPEN CASCADE), Adrien Bruneton (CEA/DEN)

#include "PyConsole_Request.h"
#include "PyConsole_Interp.h"
#include "PyConsole_Event.h"

#include <QCoreApplication>

/*!
  \class PyConsole_ExecCommand
  \brief Python command execution request.
  \internal
*/

/*!
  \brief Constructor.
  
  Creates new python command execution request.

  \param theInterp   python interpreter
  \param theCommand  python command
  \param theListener widget to get the notification messages
  \param theSync     if \c true, the request is processed synchronously
*/
PyConsole_ExecCommand::PyConsole_ExecCommand( PyInterp_Interp*        theInterp,
                                              const QString&          theCommand,
                                              QObject*                theListener,
                                              bool                    theSync )
  : PyInterp_LockRequest( theInterp, theListener, theSync ),
    myCommand( theCommand ), myState( PyInterp_Event::ES_OK )
{}

/*!
  \brief Execute the python command in the interpreter and
  get its execution status.
*/
void PyConsole_ExecCommand::execute()
{
  if ( myCommand != "" ) {
    int ret = getInterp()->run(myCommand.toUtf8());
    if ( ret < 0 )
      myState = PyInterp_Event::ES_ERROR;
    else if ( ret > 0 )
      myState = PyInterp_Event::ES_INCOMPLETE;
  }
}

/*!
  \brief Create and return a notification event.
  \return new notification event
*/
QEvent* PyConsole_ExecCommand::createEvent()
{
  if ( IsSync() )
    QCoreApplication::sendPostedEvents( listener(), PyConsole_PrintEvent::EVENT_ID );
  return new PyInterp_Event( myState, this );
}

/*!
  \class PyConsole_CompletionCommand
  \brief Python command completion request.
  \internal
*/

/*!
  \brief Constructor.

  Creates a new python completion request.

  \param theInterp python interpreter
  \param theInput  string containing the dir() command to be executed
  \param theStartMatch part to be matched with the results of the dir() command
  \param theListener widget to get the notification messages
  \param theSync if \c true the request is processed synchronously
*/
PyConsole_CompletionCommand::PyConsole_CompletionCommand( PyInterp_Interp*   theInterp,
                                                          const QString&     theInput,
                                                          const QString&     theStartMatch,
                                                          QObject*           theListener,
                                                          bool               theSync )
  : PyInterp_LockRequest( theInterp, theListener, theSync ),
    myDirArg( theInput ), myStartMatch( theStartMatch ), myStatus( false )
{}

/*!
  \brief Execute the completion command by invoking runDirCommand() function
  of interpreter.
*/
void PyConsole_CompletionCommand::execute()
{
  myStatus = static_cast<PyConsole_Interp*>( getInterp() )->runDirCommand( myDirArg,  myStartMatch, myMatches, myDoc );
}

/*!
 \brief Create and return completion event
  \return new completion event
 */
QEvent* PyConsole_CompletionCommand::createEvent()
{
  return new PyConsole_CompletionEvent( this, myStatus, myMatches, myDoc );
}