I have done it in past. Attached is a python script. The key is to avoid
using anything but direct SMproxies or SMproperties, never their python
wrapped counter parts.
(Note you may not be able to use the script directly since it expects a
certain kind of state file loaded, but should serve as an example
nonetheless)

Utkarsh

2011/5/17 Stephane PLOIX <stephane.pl...@edf.fr>

>
> Hi,
>
> Did anyone try to use pyqt in a macro (to get some input from the user)?
> I can't make anything working with signal and slots, it seems to mess with
> the python threads.
> I can understand that it may not be possible to use non modal dialogs
> because the paraview gui in single-threaded, but even modal dialogs freeze
> if I use signals.
>
> Any hint or recommendation?
>
> Best,
> Stephane
>
>
>       *Stephane PLOIX**
> Pilote Opérationnel - Visualisation scientifique*
> EDF - R&D
> SINETICS
> 1, Av du Général de Gaulle
> 92140 Clamart
>
> *stephane.pl...@edf.fr*
> Tél. : +33 (0) 1 47 65 51 10   Un geste simple pour l'environnement,
> n'imprimez ce message que si vous en avez l'utilité.
>
>
>
> Ce message et toutes les pièces jointes (ci-après le 'Message') sont
> établis à l'intention exclusive des destinataires et les informations qui y
> figurent sont strictement confidentielles. Toute utilisation de ce Message
> non conforme à sa destination, toute diffusion ou toute publication totale
> ou partielle, est interdite sauf autorisation expresse.
>
> Si vous n'êtes pas le destinataire de ce Message, il vous est interdit de
> le copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou
> partie. Si vous avez reçu ce Message par erreur, merci de le supprimer de
> votre système, ainsi que toutes ses copies, et de n'en garder aucune trace
> sur quelque support que ce soit. Nous vous remercions également d'en avertir
> immédiatement l'expéditeur par retour du message.
>
> Il est impossible de garantir que les communications par messagerie
> électronique arrivent en temps utile, sont sécurisées ou dénuées de toute
> erreur ou virus.
> ____________________________________________________
>
> This message and any attachments (the 'Message') are intended solely for
> the addressees. The information contained in this Message is confidential.
> Any use of information contained in this Message not in accord with its
> purpose, any dissemination or disclosure, either whole or partial, is
> prohibited except formal approval.
>
> If you are not the addressee, you may not copy, forward, disclose or use
> any part of it. If you have received this message in error, please delete it
> and all copies from your system and notify the sender immediately by return
> message.
>
> E-mail communication cannot be guaranteed to be timely secure, error or
> virus-free.
> _______________________________________________
> 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
>
>

<<image/gif>>

<<image/gif>>

try: paraview.simple
except: from paraview.simple import *
#paraview.simple._DisableFirstRenderCameraReset()

if not servermanager.fromGUI:
  raise RuntimeError, "This script can only be used from ParaView GUI"

import PyQt4.QtCore as qtcore
import PyQt4.QtGui as qt

# discover views.
for view in GetRenderViews():
  if view.ViewPosition[0] == 0 and view.ViewPosition[1] == 0:
    AxialView = view
  elif view.ViewPosition[0] == 0:
    SagittalView = view
  elif view.ViewPosition[1] == 0:
    CoronalView = view
  else:
    RenderView = view

try:
  VolumeReader = FindSource("VolumeReader")
  AxialSlice = FindSource("AxialSlice")
  CoronalSlice =FindSource("CoronalSlice")
  SagittalSlice = FindSource("SagittalSlice")

  AxialSliceOrigin = AxialSlice.SliceType.SMProxy
  CoronalSliceOrigin = CoronalSlice.SliceType.SMProxy
  SagittalSliceOrigin= SagittalSlice.SliceType.SMProxy

  AxialRepr = GetDisplayProperties(VolumeReader, AxialView)
  SagittalRepr = GetDisplayProperties(VolumeReader,SagittalView)
  CoronalRepr = GetDisplayProperties(VolumeReader, CoronalView)

  AxialRepr.Representation = "Slice"
  CoronalRepr.Representation = "Slice"
  SagittalRepr.Representation = "Slice"

  Render(AxialView)
  Render(SagittalView)
  Render(CoronalView)

  AxialRepr = AxialRepr.SMProxy
  SagittalRepr = SagittalRepr.SMProxy
  CoronalRepr = CoronalRepr.SMProxy
except:
  raise RuntimeError, "Have you loaded the ParaView.Validation.pvsm state correctly?"

def DetermineSpacingAndOrigin(source):
    """Determines the spacing for the image"""
    source.UpdatePipeline()
    bounds = source.GetDataInformation().GetBounds()
    extents = source.GetDataInformation().GetExtent()
    origin = (bounds[0] - extents[0], bounds[2] - extents[2],
      bounds[4] - extents[4])
    cell_dims = (extents[1] - extents[0],
            extents[3] - extents[2],
            extents[5] - extents[4])
    spacing = ( (bounds[1] - bounds[0]) / cell_dims[0],
                (bounds[3] - bounds[2]) / cell_dims[1],
                (bounds[5] - bounds[4]) / cell_dims[2] )
    return (spacing, origin, bounds, extents)

VolumeSpacing, VolumeOrigin, VolumeBounds, VolumeExtents = DetermineSpacingAndOrigin(VolumeReader)

def SetAxialSlice(number):
  AxialRepr.GetProperty("Slice").SetElement(0, int(number))
  AxialRepr.UpdateVTKObjects()
  AxialSliceOrigin.GetProperty("Origin").SetElement(0, (VolumeBounds[1] - VolumeBounds[0]) * 0.5)
  AxialSliceOrigin.GetProperty("Origin").SetElement(1, (VolumeBounds[3] - VolumeBounds[2]) * 0.5)
  AxialSliceOrigin.GetProperty("Origin").SetElement(2, number * VolumeSpacing[2] + VolumeBounds[4])
  AxialSliceOrigin.UpdateVTKObjects()
  AxialView.StillRender()

def SetSagittalSlice(number):
  SagittalRepr.GetProperty("Slice").SetElement(0, int(number))
  SagittalRepr.UpdateVTKObjects()
  SagittalSliceOrigin.GetProperty("Origin").SetElement(0, number * VolumeSpacing[0] + VolumeBounds[0])
  SagittalSliceOrigin.GetProperty("Origin").SetElement(1, (VolumeBounds[3] - VolumeBounds[2]) * 0.5)
  SagittalSliceOrigin.GetProperty("Origin").SetElement(2, (VolumeBounds[5] - VolumeBounds[4]) * 0.5)
  SagittalSliceOrigin.UpdateVTKObjects()
  SagittalView.StillRender()

def SetCoronalSlice(number):
  CoronalRepr.GetProperty("Slice").SetElement(0, int(number))
  CoronalRepr.UpdateVTKObjects()
  CoronalSliceOrigin.GetProperty("Origin").SetElement(0,(VolumeBounds[1] - VolumeBounds[0]) * 0.5) 
  CoronalSliceOrigin.GetProperty("Origin").SetElement(1,number * VolumeSpacing[1] + VolumeBounds[2] )
  CoronalSliceOrigin.GetProperty("Origin").SetElement(2,(VolumeBounds[5] - VolumeBounds[4]) * 0.5)
  CoronalSliceOrigin.UpdateVTKObjects()
  CoronalView.StillRender()

# Setup the dialog for changing parameters.
class ParametersDialog(qt.QDialog):
  def __init__(self, *args):
      qt.QDialog.__init__(self, *args)

  def setup(self):
    Form = self
    self.resize(184, 290)
    verticalLayout = qt.QVBoxLayout(Form);
    groupBox = qt.QGroupBox(Form);
    groupBox.setTitle("Slice Parameters")
    gridLayout = qt.QGridLayout(groupBox);
    label_2 = qt.QLabel(groupBox);
    gridLayout.addWidget(label_2, 0, 0, 1, 1);
    axialSpinBox = qt.QSpinBox(groupBox);
    gridLayout.addWidget(axialSpinBox, 0, 1, 1, 1);
    label = qt.QLabel(groupBox);
    gridLayout.addWidget(label, 1, 0, 1, 1);
    sagittalSpinBox = qt.QSpinBox(groupBox);
    gridLayout.addWidget(sagittalSpinBox, 1, 1, 1, 1);
    label_3 = qt.QLabel(groupBox);
    gridLayout.addWidget(label_3, 2, 0, 1, 1);
    coronalSpinBox = qt.QSpinBox(groupBox);
    gridLayout.addWidget(coronalSpinBox, 2, 1, 1, 1);
    verticalLayout.addWidget(groupBox);
    verticalSpacer = qt.QSpacerItem(20, 109, qt.QSizePolicy.Minimum,
      qt.QSizePolicy.Expanding);
    verticalLayout.addItem(verticalSpacer);
    horizontalLayout = qt.QHBoxLayout();
    horizontalSpacer = qt.QSpacerItem(40, 20, qt.QSizePolicy.Expanding,
      qt.QSizePolicy.Minimum);
    horizontalLayout.addItem(horizontalSpacer);
    verticalLayout.addLayout(horizontalLayout)
    groupBox.setTitle("Slice Parameters")
    label_2.setText("Axial:")
    label.setText("Sagittal:")
    label_3.setText("Coronal:");

    axialSpinBox.setRange(VolumeExtents[4], VolumeExtents[5])
    axialSpinBox.setValue(AxialRepr.GetProperty("Slice").GetElement(0))

    coronalSpinBox.setRange(VolumeExtents[2], VolumeExtents[3])
    coronalSpinBox.setValue(CoronalRepr.GetProperty("Slice").GetElement(0))

    sagittalSpinBox.setRange(VolumeExtents[0], VolumeExtents[1])
    sagittalSpinBox.setValue(SagittalRepr.GetProperty("Slice").GetElement(0))

    self.connect(axialSpinBox, qtcore.SIGNAL("valueChanged(int)"),
      self.changeAxial)
    self.connect(sagittalSpinBox, qtcore.SIGNAL("valueChanged(int)"),
      self.changeSagittal)
    self.connect(coronalSpinBox, qtcore.SIGNAL("valueChanged(int)"),
      self.changeCoronal)

  def changeCoronal(self, value):
    SetCoronalSlice(value)
  def changeSagittal(self, value):
    SetSagittalSlice(value)
  def changeAxial(self, value):
    SetAxialSlice(value)

dialog = ParametersDialog()
dialog.setup()
dialog.show()
_______________________________________________
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

Reply via email to