# Running Python macro from C++

**URL:** https://discourse.paraview.org/t/running-python-macro-from-c/8982
**Category:** ParaView Support
**Tags:** python
**Created:** [February 16, 2022, 1:12pm UTC](https://discourse.paraview.org/t/running-python-macro-from-c/8982 "2022-02-16T13:12:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![pindakaas](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/cab0a1/32.png) [@pindakaas](https://discourse.paraview.org/u/pindakaas)
#### Post date: [February 16, 2022, 1:12pm UTC](https://discourse.paraview.org/t/running-python-macro-from-c/8982/1 "2022-02-16T13:12:06Z")

</div>

Hi!

Lately I have been experimenting with plugins and custom interfaces.  
The basic idea is to have custom buttons in a toolbar that execute traced Python scripts.

As far as I am aware, filters with custom property widgets can be written in Python using the VTKPythonAlgorithmBase, but to really add new UI features one has to interact with Qt in C++. Please correct me if I’m wrong.

On the other hand, I don’t want to lose the ease of use of the existing feature like paraview.simple by completely working in C++. So is there a way to, for example, execute a Python macro once a custom button is pressed?

Currently I’ve looked at the pqPythonShell and pqPythonManager classes, but can’t seem to build a version that includes their headers. Tried building with PARAVIEW\_USE\_PYTHON=ON as well as VTK\_MODULE\_ENABLE\_ParaView\_pqPython=YES, but that did not help. Also looked at the PythonQt library, but that seemed outdated as it required Qt4.

Any ideas or suggestions for better approaches are welcome.

Kind regards,  
Davis

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [February 23, 2022, 1:06pm UTC](https://discourse.paraview.org/t/running-python-macro-from-c/8982/2 "2022-02-23T13:06:53Z")

</div>

> [@pindakaas](#):
>
> As far as I am aware, filters with custom property widgets can be written in Python using the VTKPythonAlgorithmBase, but to really add new UI features one has to interact with Qt in C++. Please correct me if I’m wrong.

This is correct

> Tried building with PARAVIEW\_USE\_PYTHON=ON

Should be enough, but be sure to add the dependency in your plugin too.

> Also looked at the PythonQt library, but that seemed outdated as it required Qt4.

Correct
