File: vtkPythonInteractiveInterpreter.h

package info (click to toggle)
paraview 5.13.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 544,220 kB
  • sloc: cpp: 3,374,605; ansic: 1,332,409; python: 150,381; xml: 122,166; sql: 65,887; sh: 7,317; javascript: 5,262; yacc: 4,417; java: 3,977; perl: 2,363; lex: 1,929; f90: 1,397; makefile: 170; objc: 153; tcl: 59; pascal: 50; fortran: 29
file content (92 lines) | stat: -rw-r--r-- 3,523 bytes parent folder | download | duplicates (2)
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
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
/**
 * @class   vtkPythonInteractiveInterpreter
 * @brief   interpreter for interactive shells.
 *
 * vtkPythonInteractiveInterpreter provides an interpreter that can be used in
 * interactive shells. It mimics the behaviour of the interactive
 * console (much like the default Python shell) providing the "read-eval-print"
 * loops. It also handles incomplete statements correctly. It uses "code"
 * module provided by Python standard library to achieve this.
 * It uses vtkPythonInterpreter to ensure that the global
 * Python environment is setup correctly. Note that any time the
 * vtkPythonInterpreter::Finalize() is called, the interactive interpreter will
 * be destroyed as well. Subsequent calls to vtkPythonInterpreter::Push() will
 * reinitialize Python as start a new interactive interpreter shell.
 *
 * This class also observers and forwards all events invoked by a
 * vtkPythonInterpreter instance include vtkCommand::EnterEvent,
 * vtkCommand::ExitEvent, vtkCommand::UpdateEvent, vtkCommand::ErrorEvent and
 * vtkCommand::SetOutputEvent.
 */

#ifndef vtkPythonInteractiveInterpreter_h
#define vtkPythonInteractiveInterpreter_h

#include "vtkObject.h"
#include "vtkPythonInterpreterModule.h" // For export macro

VTK_ABI_NAMESPACE_BEGIN
class vtkPythonInterpreter;

class VTKPYTHONINTERPRETER_EXPORT vtkPythonInteractiveInterpreter : public vtkObject
{
public:
  static vtkPythonInteractiveInterpreter* New();
  vtkTypeMacro(vtkPythonInteractiveInterpreter, vtkObject);
  void PrintSelf(ostream& os, vtkIndent indent) override;

  /**
   * Push a line of code. It should have have trailing newlines. It can have
   * internal newlines. This can accept incomplete input. A command is executed
   * only after the complete input is received.  Look at Python module
   * documentation for code.InteractiveConsole.push() for further details.  The
   * return value is True if more input is required, False if the line was dealt
   * with in some way.
   */
  bool Push(const char* code);

  /**
   * This destroys the internal code.InteractiveConsole instance. Hence, next
   * time Push() will be called, it will use a brand new instance of
   * code.InteractiveConsole().
   */
  void Reset();

  /**
   * Executes the given python source code using the context given by the
   * locals() object used by this interactive console.  This is similar to
   * using vtkPythonInterpreter::RunSimpleString(), except that method will
   * execute code in the context of the __main__ module. Returns 0 on success
   * or -1 if an exception was raised.
   */
  int RunStringWithConsoleLocals(const char* script);

  ///@{
  /**
   * Provides access to the internal PyObject instances used for the
   * code.InteractiveConsole() as well as the dictionary for the locals of the
   * code.InteractiveConsole() instance. Do not use if you are not sure what
   * these are for.
   */
  void* GetInteractiveConsolePyObject();
  void* GetInteractiveConsoleLocalsPyObject();
  ///@}

protected:
  vtkPythonInteractiveInterpreter();
  ~vtkPythonInteractiveInterpreter() override;

  void HandleEvents(vtkObject* caller, unsigned long eventid, void* calldata);

private:
  vtkPythonInteractiveInterpreter(const vtkPythonInteractiveInterpreter&) = delete;
  void operator=(const vtkPythonInteractiveInterpreter&) = delete;

  class vtkInternals;
  vtkInternals* Internals;
};

VTK_ABI_NAMESPACE_END
#endif