[PyQt] PyQwt Signals [Was: Old vs New Signals]

Phil Thompson phil at riverbankcomputing.com
Fri Jul 13 11:44:19 BST 2012


On Fri, 13 Jul 2012 20:13:32 +1000, John Floyd <jfloyd at bigpond.net.au>
wrote:
> On Thu, 12 Jul 2012 13:25:11 Phil Thompson wrote:
>> Taking your examples in turn...
>> 
>> self.picker.connect(self.picker, SIGNAL('selected(QwtPolygon)'),
>> self.slotQwtPolygon)
>> 
>> ...this works as expected.
>> 
>> self.picker.selected[QwtPolygon](self.slotQwtPolygon)
>> 
>> ...this doesn't work because...
>> 
>> - PyQwt does not expose QwtPolygon as a Python type
>> - selected(QwtPolygon) is a signal of QwtPicker, not QwtPlotPicker
>> - the call to connect() is missing
>> 
>> The following is correct...
>> 
>> super(QwtPlotPicker, self.picker).selected.connect(self.slotQwtPolygon)
>> 
>> The following is also correct and would be needed if
QwtPicker.selected()
>> was overloaded and the 'QwtPolygon' overload was not the default...
>> 
>> super(QwtPlotPicker, self.picker).selected['QwtPolygon'].connect(
>>         self.slotQwtPolygon)
>> 
>> These work because PyQwt has told sip how to convert a C++ QwtPolygon
to
>> a
>> Python object.
>> 
>> The last two examples...
>> 
>> self.picker.connect(self.picker,
>>         SIGNAL('selected(QwtArray<QwtDoublePoint>)'),
self.slotQwtArray)
>> 
>> ...and...
>> 
>>
self.picker.selected['QwtArray<QwtDoublePoint>'].connect(self.slotQwtArray)
>> 
>> ...can never work because PyQwt hasn't told sip how to convert a C++
>> QwtArray<QwtDoublePoint> to a Python object. This is a PyQwt bug. It
>> should provide a %MappedType for QwtArray<QwtDoublePoint>.
>> 
>> Phil
> 
> Thanks Phil,
> 
> Is part of the problem with QwtPolygon linked to the fact that in the
qt4 
> version of the code that the c++ QwtPolygon definition is a typedef?
> 
> typedef QPolygon  QwtPolygon
> 
> yet QPolygon is defined as a Python type.

I don't agree that there is a "problem" with QwtPolygon in the first
place. What PyQwt does in this respect is perfectly reasonable.

> This a also the case for QwtArray<QwtDoublePoint> because QwtDoublePoint
> is 
> also typedef'ed 
> 
> typedef QPointF QwtDoublePoint
> 
> and again QwtArray<QPointF> is defined as a python type though a mapped
> type.

No it isn't. QwtArray is not a mapped type in PyQwt. Instead
QwtArrayQwtDoublePoint is defined as a Python type and PyQwt uses C++ code
(that sip doesn't understand) to implement this using
QwtArray<QwtDoublePoint>. This approach means that PyQwt can easily expose
the QwtArray API - again a reasonable approach in my opinion. The thing
that's missing is telling sip about the connection between the C++
QwtArray<QwtDoublePoint> and the Python QwtArrayQwtDoublePoint, which would
be accomplished using a %MappedType.

> Do we have to create separate definitions for all the typedef'ed
variables
> as 
> well in sip?  

You mean typedef'ed types? You use typedef in sip if you need sip to
understand that two types are equivalent.

Phil


More information about the PyQt mailing list