Hi Sebastian,

Thanks for the quick answer!
Unfortunately monkey-patching also disqualifies from my requirement of using 
unmodified pyqtgraph objects.
I was hoping that I had missed some existing mechanism (a signal, or a QEvent) 
in some base class that could be used to be notified of new items being added.

If that is not the case, the second part of my question is relevant: would a 
PR adding a signal be welcome? 

Cheers!

Carlos

On Wednesday, November 29, 2017 3:16:39 AM CET Sebastian Höfer wrote:
> Hi,
> 
> if you don't want to create your own class a quick and dirty way is to
> "monkey patch" the addItem() method and insert your own code there.
> Something along the lines:
> 
> oldAddItem = the_viewbox.addItem
> 
> def myAddFunc(*args, **kwargs):
>     # do something before the item is added
>     oldAddItem(*args, **kwargs)
>     # do something after the item is added
>     # or yourSignal.emit()
> 
> the_viewbox.addItem = myAddFunc
> 
> I haven't tested the code, so this might need tweaking.
> 
> 
> Cheers,
> Sebastian
> 
> Am Mittwoch, 29. November 2017 09:16:23 UTC+1 schrieb Carlos Pascual:
> > Hi,
> > 
> > I've been looking for a way of getting a signal when a new item is added
> > to a PlotWidget or ViewBox
> > 
> > Ideally something in the style of "ViewBox.sigItemAdded"
> > 
> > I understand that I could derive ViewBox and/or PlotWidget and reimplement
> > the addItem() method to emit such a signal, but this is really something I
> > would like to avoid because I would need my code to work with the
> > "unmodified" PyQtgraph objects.
> > 
> > So I am wondering if this is already possible in some other way (or if it
> > would be a wanted feature, in which case I would be happy to submit a Pull
> > Request with an implementation)


-- 
+----------------------------------------------------+
 Carlos Pascual Izarra
 Scientific Software Coordinator
 Computing Division
 ALBA Synchrotron  [http://www.albasynchrotron.es]
 Carrer de la Llum 2-26
 E-08290 Cerdanyola del Valles (Barcelona), Spain
 E-mail: [email protected]
 Phone: +34 93 592 4428
+----------------------------------------------------+

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/3032870.adqrjifcEu%40pc218.
For more options, visit https://groups.google.com/d/optout.

Reply via email to