[vtk-developers] setting AbortFlag from Python impossible?

Berk Geveci berk.geveci at kitware.com
Thu Sep 20 09:54:02 EDT 2007


Oops. I forgot that vtkCommand is sub-classes from vtkObjectBase...
Errr.... Ok, now that I finally understand the issue, I vote in favor
of Charl's solution.

-berk


On 9/20/07, David Gobbi <david.gobbi at gmail.com> wrote:
> The python wrappers don't have the GetCommand() method.  From inside
> python, the vtkCommand class doesn't exist, all callbacks are just methods.
>
> Charl has added a hack to the wrappers to get the call data if it is a string,
> but it hasn't been extended to other types.  It could be made to work nicely
> for all types, if it e.g. checked for "ProgressEvent" and then converted the
> calldata to a double.
>
>   David
>
>
>
> On 9/20/07, Berk Geveci <berk.geveci at kitware.com> wrote:
> > Oops. My bad. It was the progress that I couldn't get because it is
> > send in the call data, which the python function does not have access
> > to. I shouldn't be writing e-mails before 7am in the morning I guess
> > :-)
> > By the way, it is not impossible to get the command, just hard. If you
> > keep the tag that gets returned when you add the command, you can call
> > GetCommand() on the caller to get it. You can the set the abort on it.
> > (Of course, I am assuming that the python version of AddCommand() does
> > return the tag)
> >
> > -berk
> >
> >
> > On 9/20/07, David Gobbi <david.gobbi at gmail.com> wrote:
> > > Hi Berk,
> > >
> > > Accessing the object that invoked an event is straightforward, the
> > > following code fragment shows how:
> > >
> > > def callback(object, event):
> > >      print object.GetClassName(), event
> > >
> > > o = vtk.vtkObject()
> > > o.AddObserver("ModifiedEvent", callback)
> > > o.Modified()
> > >
> > > Accessing the vtkCommand object from python, though, is
> > > impossible as Charl has noted.  I think that using the return value
> > > for the AbortFlag is a good workaround.  Maybe a special return
> > > object should be used to signal an abort, rather than a boolean
> > > or integer.  Something like "return vtk.CommandAbort"
> > >
> > >   David
> > >
> > >
> > > On 9/20/07, Berk Geveci <berk.geveci at kitware.com> wrote:
> > > > I don't know how but modifying things such that the observer can
> > > > access the object that invoked the event would be awesome. I ran into
> > > > this in paraview but didn't have time (or the guts) to address it :-)
> > > >
> > > > -berk
> > > >
> > > >
> > > > On 9/20/07, Charl Botha <c.p.botha at tudelft.nl> wrote:
> > > > > Dear all,
> > > > >
> > > > > It seems that it's impossible for a Python observer to do SetAbortFlag
> > > > > (in order to stop event processing), as the vtkCommand that's used (an
> > > > > instance of vtkPythonCommand) is not accessible from Python.  I also
> > > > > couldn't find any dirty workarounds for this... I would really
> > > > > appreciate being told I'm wrong, because that would mean less work.
> > > > >
> > > > > I would propose modifying the vtkPythonCommand::Execute() method so
> > > > > that the return value of the Python observer is used to determine
> > > > > whether event processing should stop or not.  If it returns a positive
> > > > > value,  it means the event was handled and processing should stop.  If
> > > > > it returns 0, it means that it wants other event handling to continue.
> > > > >
> > > > > What do other people think?  Is there a work-around I somehow missed?
> > > > > (searching on "vtk python AbortFlag" yields one irrelevant link over
> > > > > here.
> > > > >
> > > > > Thanks for any thoughts,
> > > > > Charl
> > > > > _______________________________________________
> > > > > vtk-developers mailing list
> > > > > vtk-developers at vtk.org
> > > > > http://www.vtk.org/mailman/listinfo/vtk-developers
> > > > >
> > > > _______________________________________________
> > > > vtk-developers mailing list
> > > > vtk-developers at vtk.org
> > > > http://www.vtk.org/mailman/listinfo/vtk-developers
> > > >
> > >
> >
>



More information about the vtk-developers mailing list