File: pqPythonManager.h

package info (click to toggle)
paraview 5.13.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: 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 (110 lines) | stat: -rw-r--r-- 3,267 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
// SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
// SPDX-FileCopyrightText: Copyright (c) Sandia Corporation
// SPDX-License-Identifier: BSD-3-Clause
#ifndef pqPythonManager_h
#define pqPythonManager_h

#include "pqPythonModule.h" // for exports
#include "vtkType.h"        // for vtkTypeUInt32

#include <QObject>
#include <QVector>

class QWidget;
class QToolBar;
class pqPythonMacroSupervisor;
class pqServer;

/**
 * pqPythonManager is a class to facilitate the use of a python interpreter
 * by various paraview GUI components.
 *
 * @section Roadmap Roadmap
 *
 * pqPythonManager is slated for deprecation. It's unclear there's a need for
 * such a manager anymore since Python interpreter is globally accessible via
 * vtkPythonInterpreter.
 */
class PQPYTHON_EXPORT pqPythonManager : public QObject
{
  Q_OBJECT

public:
  pqPythonManager(QObject* parent = nullptr);
  ~pqPythonManager() override;

  /**
   * Provides access to the macro supervisor.
   */
  pqPythonMacroSupervisor* macroSupervisor() const;

  /**
   * Convienience method to call `vtkPythonInterpreter::Initialize()`.
   */
  bool initializeInterpreter();

  /**
   * Returns true if the interpreter has been initialized.
   * Same as calling `vtkPythonInterpreter::IsInitialized()`.
   */
  bool interpreterIsInitialized();

  ///@{
  /**
   * Add a widget to be given macro actions.  QActions representing script macros
   * will be added to the widget.  This could be a QToolBar, QMenu, or other type
   * of widget.
   */
  void addWidgetForRunMacros(QWidget* widget);
  void addWidgetForEditMacros(QWidget* widget);
  void addWidgetForDeleteMacros(QWidget* widget);
  ///@}

  /**
   * Save the macro in ParaView configuration and update widget automatically
   */
  void addMacro(const QString& fileName, vtkTypeUInt32 location = 0x10 /*vtkPVSession::CLIENT*/);

  /**
   * Invalidate the macro list, so the menu/toolbars are updated according to
   * the content of the Macros directories...
   */
  void updateMacroList();

public Q_SLOTS: // NOLINT(readability-redundant-access-specifiers)

  /**
   * @brief Executes the given code.  If the python interpreter hasn't been initialized
   * yet it will be initialized.
   * @param code: lines of code to execute
   * @param pre_push: instructions to execute before the code execution
   * @param post_push: instructions to execute after the code execution
   */
  void executeCode(const QByteArray& code, const QVector<QByteArray>& pre_push = {},
    const QVector<QByteArray>& post_push = {});

  /**
   * Executes the given script.  If the python interpreter hasn't been initialized
   * yet it will be initialized.
   */
  void executeScript(
    const QString& filename, vtkTypeUInt32 location = 0x10 /*vtkPVSession::CLIENT*/);

  /**
   * Same as `executeScript()` except that is also triggers a render on all
   * views in the application after the script has been processed. This is used
   * when playing back macros, for example.
   */
  void executeScriptAndRender(
    const QString& filename, vtkTypeUInt32 location = 0x10 /*vtkPVSession::CLIENT*/);

  /**
   * Launch python editor to edit the macro
   */
  void editMacro(const QString& fileName);

private:
  struct pqInternal;
  pqInternal* Internal;
};
#endif