[PyQt] Old vs New Signals

John Floyd jfloyd at bigpond.net.au
Tue Jul 10 13:19:54 BST 2012


On Mon, 9 Jul 2012 13:03:07 Phil Thompson wrote:
> On Mon, 09 Jul 2012 21:54:52 +1000, John Floyd <jfloyd at bigpond.net.au>
> 
> wrote:
> > On Mon, 9 Jul 2012 11:18:40 you wrote:
> >> On Sun, 08 Jul 2012 17:43:55 +1000, John Floyd <jfloyd at bigpond.net.au>
> >> 
> >> wrote:
> >> > Note Corrected Subject (was New vs New ...  sorry)
> >> > 
> >> > I have 2 cases where I am having difficulties in PyQwt signals.
> 
> Since
> 
> >> my
> >> 
> >> > original post I have investiagted the PyQwt code a bit closer and the
> >> > following comes from that.  The previous discussions helped me in
> >> 
> >> looking
> >> 
> >> > further into the problem.
> >> > 
> >> > 1) a c++ typedef variable appears to cause problems
> >> > 
> >> > 	The old style signal works
> >> > 	self.picker.connect(picker,SIGNAL('selected(const QwtPolygon &)')
> >> > 	
> >> > 			,self.slot)
> >> > 			
> >> >    however the new style signal does not work.
> >> > 	
> >> > 	self.picker.selected[QwtPolygon].connect(self.slot)
> >> > 
> >> > Reported error
> >> > 
> >> > 	NameError: global name 'QwtPolygon' is not defined
> >> > 
> >> > Yet the MetaObject lists the following as a signal signature
> >> > 
> >> > 	selected(QwtPolygon).
> >> > 
> >> > The reasoning appears to be that in the c++ code QwtPolygon is
> >> 
> >> typedef'ed
> >> 
> >> > from
> >> > QPolygon. Shouldnt this be handled?
> >> > 
> >> > 2) Problems with template argument the signal definition. For example
> >> > 
> >> > 	self.picker.connect(self.picker,
> >> > 	
> >> > 		SIGNAL('selected(const QwtArray<QwtDoublePoint>&)'), self.slot)
> >> > 
> >> > returns an error
> >> > 
> >> > 	TypeError: C++ type 'QwtArray<QwtDoublePoint>' is not supported as a
> >> 
> >> slot
> >> 
> >> > argument type
> >> > 
> >> > The signature is listed in the GmetaObject.
> >> > 
> >> > In the sip code QwtArray<QwtDoublePoint> is MappedTyped as
> >> > QwtArrayQwtDoublePoint - using this as the signature as below returns
> >> 
> >> yet
> >> 
> >> > another error
> >> > 
> >> > 	self.picker.connect(self.picker,
> >> > 	
> >> > 		SIGNAL('selected(const QwtArrayQwtDoublePoint&)'), self.slot)
> >> > 
> >> > and also as a new signal
> >> > 
> >> > 	self.picker.selected[QwtArrayQwtDoublePoint].connect(self.slot)
> >> > 
> >> > TypeError: connect() failed between selected(QwtArrayQwtDoublePoint)
> >> > and
> >> > 
> >> > unislot()
> >> > 
> >> > Phil Thompson has said that in this case the python code should
> 
> accept
> 
> >> the
> >> 
> >> > c++
> >> > signature but it does not.
> >> > 
> >> > Intriquingly the definition of QwtArray is also a c++ typedef in the
> >> > Qwt
> >> > code.
> >> > 
> >> > The trouble is that for this particlar picker class, the selected
> >> > signal
> >> > is
> >> > overloaded multiple times so the signatures are necessary.
> >> 
> >> As far as I can see the only class with a signal selected(QwtPolygon)
> 
> is
> 
> >> QwtPicker and that doesn't overload the signal. The only class that
> 
> does
> 
> >> is
> >> QwtPlotPicker, but you don't say which you are using.
> >> 
> >> Maybe the problem is your picker is a QwtPlotPicker but you are trying
> 
> to
> 
> >> use QwtPicker.selected? In which case try...
> >> 
> >>     super(QwtPlotPicker, self.picker).connect(self.slot)
> >> 
> >> Phil
> > 
> > There are problems trying to connect both the QwtPicker _and_
> > QwtPlotPicker
> > selected signals.  I have tried to outline what I have encountered in
> 
> the
> 
> > previous email.
> > 
> > Yes I am using QwtPlotPicker, and what I mean with "the MetaObject lists
> > the
> > following as a signal signature" is I have a small function that returns
> > the
> > signatures from the MetaObject of the instance I am using.  And it lists
> > 
> > selected(QwtPolygon) as being there.  But I cannot find a way to use it
> 
> in
> 
> > a
> > new signal style - yet it works in the old signal style?!
> > 
> > Yes you are correct in this case for the QwtPolygon signal described
> > previously in 1), in that it is the signal inherited from the QwtPicker
> > base
> > class that I am catching. It returns the polygon in pixel coords.
> > 
> > The overloading problem comes in when I try the signal described above
> 
> in
> 
> > 2)
> > with the QwtArrayQwtDoublePoint signature (which returns the same
> 
> polygon
> 
> > in
> > data coords).  This is the overloaded signal I want to use.  In this
> 
> case
> 
> > neither old nor new style signals work, with the errors reported in the
> > previous email.  Again the MetaObject has the template version of the
> > signal
> > in its list.
> > 
> > I must thank you, Phil for taking some effort in checking out the Qwt
> 
> code
> 
> > to
> > understand my problems.
> > 
> > regards
> > John
> 
> You need to provide a small and complete test case that demonstrates the
> problem.
> 
> Phil

I have been using the PickerDemo.py from the pyqwt package, something simple 
to introduce me to new signals....  trying to get this to work is where my 
problems started.

I have modified the original slightly, removing excess bagage, adding some 
output annotation.  This tries all the variations discussed previously.

Example is attached.

Thanks
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120710/2897d5dc/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QwtSignalPickerExample.py
Type: text/x-python
Size: 3441 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120710/2897d5dc/attachment-0001.py>


More information about the PyQt mailing list