从Python IDLE控制Paraview GUI

时间:2017-07-21 11:38:17

标签: python python-2.7 python-idle paraview

我正在尝试使用IDLE以交互方式控制Paraview。这将涉及从IDLE发送命令并查看Paraview中发生的更改。我宁愿不使用in-Paraview python shell。

到目前为止,我已成功从IDLE导入Paraview模块(简单,servermanager等)。但是,发送的命令不会反映在Paraview中。例如:

>>> from paraview.simple import *
>>> cone = Cone()
>>> Show()
>>> Render()

确实创造了一个圆锥体。但是,锥体输出到新的独立OpenGL窗口,而不是Paraview GUI。

是否可以使用IDLE以交互方式控制Paraview?如果是这样,怎么做到这一点?感谢

2 个答案:

答案 0 :(得分:4)

您需要在多客户端/服务器模式下运行paraview。 在终端运行pvserver。

./bin/pvserver --multi-clients

在另一个终端中,运行paraview并连接到您的服务器

./bin/paraview
File->Connect
AddServer -> Choose a name -> Configure -> Save
Connect

在第三个终端中,运行pvpython(或您自己配置的python)

./bin/pvpython
>> from paraview.simple import *
>> Connect("localhost")
>> Cone()
>> Show()

答案 1 :(得分:0)

我针对系统python构建了paraview,以便可以使用ipython和其他软件包。我只需要将PYTHONPATH设置为指向paraview python网站包,然后将LD_LIBRARY_PATH设置为指向paraview lib目录。

export PYTHONPATH=/path/to/paraview/install/lib/python2.7/site-packages
export LD_LIBRARY_PATH=/path/to/paraview/install/lib
$ ipython 
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
Type "copyright", "credits" or "license" for more information.

IPython 5.5.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from paraview.simple import *

In [2]: Connect("localhost")
Out[2]: Connection (cs://localhost:11111) [2]

In [3]: Cone()
Out[3]: <paraview.servermanager.Cone at 0x7f30716cde10>

In [4]: Show()
Out[4]: <paraview.servermanager.GeometryRepresentation at 0x7f307167b210>

In [5]: GetSources()
Out[5]: {('Cone1', '8803'): <paraview.servermanager.Cone at 0x7f30716cde10>}

In [6]: GetActiveSource()
Out[6]: <paraview.servermanager.Cone at 0x7f30716cde10>

Screen shot of the rendered cone from the ipython paraview client

我的paraview版本是由master在Ubuntu 18.04上构建的。

我唯一遇到的问题是python site-__init__.py目录中缺少packages/paraview/modules文件。

In [1]: from paraview.simple import *
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-cc11d49fb28b> in <module>()
----> 1 from paraview.simple import *

/home/dustin/repos/paraview_builds/master/install/lib/python2.7/site-packages/paraview/simple.py in <module>()
     39 
     40 import paraview
---> 41 from paraview import servermanager
     42 import paraview._backwardscompatibilityhelper
     43 

/home/dustin/repos/paraview_builds/master/install/lib/python2.7/site-packages/paraview/servermanager.py in <module>()
     54 from paraview import _backwardscompatibilityhelper as _bc
     55 
---> 56 from paraview.modules.vtkPVServerImplementationCore import *
     57 from paraview.modules.vtkPVClientServerCoreCore import *
     58 from paraview.modules.vtkPVServerManagerCore import *

ImportError: No module named modules.vtkPVServerImplementationCore

我通过在__init__.py目录中创建一个paraview/modules文件来解决此问题:

touch /path/to/paraview/install/lib/python2.7/site-packages/paraview/modules/__init__.py