[Paraview] Update Button Work-a-round

pat marion pat.marion at kitware.com
Thu Nov 10 12:18:01 EST 2011


Hi Christian,

You won't be able to do this from python.  In the ParaView GUI, the Qt
event loop has control over the application flow, not python, so python
threads do not work.  You'll need a Qt based solution.  Does your reader
plugin include any Qt components?  It only takes a few lines of code to add
a QTimer that will execute your python code.  Also, you can use
QFileSystemWatcher to watch for new files, assuming the files are available
on a locally mounted filesystem.

The QTimer can connect to a slot with this c++ code that will trigger a
python function:

pqPVApplicationCore::instance()->pythonManager()->pythonShellDialog()->runString("myCallback()");


Pat

On Thu, Nov 10, 2011 at 9:46 AM, Christian Richter <
christian.richter at ovgu.de> wrote:

>  Hello All,
>
> Because there is no Update Button available in Paraview I made a little
> Py-script to reload the filenames in FileSeriesReader for my own reader
> class (should work with other reader classes too).
>
> Now, everytime I hit the button, the new FileNameList is updatet, and the
> last available File is shown. (I love the PointSprite Plugin, if you need
> other representations change some lines).
>
> Now there is on wish left: how to run this script periodicaly every n
> seconds OR everytime thereis a new file in the solution directory.
> I tried python Threading/Timer but they seems not to work in
> Paraview-Python Console.
> Is there any possibility to trigger a python script from inside Paraview ?
>
> I'm not a Python Coder, so maybe I did not try every method to make a loop
> which does not deadlock :-)
>
> Here is the script to update a files-series-reader:
>
> from paraview.simple import *
> import glob
>
> folder="post/*.liggghts"
>
> def try_int(s):
>     "Convert to integer if possible."
>     try: return int(s)
>     except: return s
>
> def natsort_key(s):
>     "Used internally to get a tuple by which s is sorted."
>     import re
>     return map(try_int, re.findall(r'(\d+|\D+)', s))
>
> def natcmp(a, b):
>     "Natural string comparison, case sensitive."
>     return cmp(natsort_key(a), natsort_key(b))
>
> def natcasecmp(a, b):
>     "Natural string comparison, ignores case."
>     return natcmp(a.lower(), b.lower())
>
> # Find the source object
> if (FindSource("liggghts_dump")==None): ##create
>     files = glob.glob(folder)
>     files.sort(natcasecmp)
>     xreader=liggghts_Reader(guiName="liggghts_dump")
>     xreader.FileNames=files
>     SetDisplayProperties(xreader, Representation="Point Sprite")
>     DataRepresentation1 = Show()
>     DataRepresentation1.PointSpriteDefaultsInitialized = 1
>     DataRepresentation1.Texture = []
>     DataRepresentation1.RadiusTransferFunctionEnabled = 1
>     DataRepresentation1.RadiusMode = 'Scalar'
>     DataRepresentation1.Representation = 'Point Sprite'
>     DataRepresentation1.RadiusArray = [None, 'radius']
>     DataRepresentation1.RadiusIsProportional = 1
>
> else:
>     files = glob.glob(folder)
>     files.sort(natcasecmp)
>     xreader.FileNames=files ##update
>     RenderView1 = GetRenderView()
>     AnimationScene1 = GetAnimationScene()
>     end=len(files)-1
>     RenderView1.ViewTime = end
>     AnimationScene1.AnimationTime = end
>     Render()
> Best wishes,
> Christian
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ParaView Wiki at:
> http://paraview.org/Wiki/ParaView
>
> Follow this link to subscribe/unsubscribe:
> http://www.paraview.org/mailman/listinfo/paraview
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20111110/7e747aec/attachment.htm>


More information about the ParaView mailing list