On Mon, 9 Jul 2012 13:03:07 Phil Thompson wrote:
> On Mon, 09 Jul 2012 21:54:52 +1000, John Floyd <jfl...@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 <jfl...@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
#!/usr/bin/env python
#
# Contributed by Darren Dale.
import sys
from PyQt4.Qt import *
from PyQt4.QtGui import QPolygon
from PyQt4.Qwt5 import *
def listSignals(object):
return [object.metaObject().method(j).signature() \
for j in range(object.metaObject().methodCount()) \
if object.metaObject().method(j).methodType() == 1]
try:
import numpy as np
except ImportError:
if not QCoreApplication.instance():
a = QApplication([])
QMessageBox.critical(
None,
'NumPy required',
'This example requires NumPy, but failed to import NumPy.\n'
'NumPy is available at http://sourceforge.net/projects/numpy'
)
raise SystemExit(
'Failed to import NumPy.\n'
'NumPy is available at http://sourceforge.net/projects/numpy'
)
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow,self).__init__(None)
toolBar = QToolBar(self)
toolBar.addAction(QWhatsThis.createAction(toolBar))
self.addToolBar(toolBar)
plot = QwtPlot(self)
self.setCentralWidget(plot)
plot.setTitle('Subclassing QwtPlotPicker Demo')
plot.setCanvasBackground(Qt.white)
self.resize(400, 400)
self.show()
x = np.linspace(-2*np.pi, 2*np.pi, num=501)
y = np.sin(x)*5
curve = QwtPlotCurve()
curve.setData(x,y)
curve.setPen(QPen(Qt.red))
curve.attach(plot)
self.picker = QwtPlotPicker(QwtPlot.xBottom,
QwtPlot.yLeft,
QwtPicker.PolygonSelection,
QwtPlotPicker.PolygonRubberBand,
QwtPicker.AlwaysOff,
plot.canvas())
self.picker.stateMachine=QwtPickerPolygonMachine()
self.picker.setRubberBandPen(QPen(Qt.black, 1))
print 'self.picker MetaObject Signals'
for sig in listSignals(self.picker):
print ' %s'%(sig)
try:
self.picker.connect(self.picker, SIGNAL('selected(QwtPolygon)'), self.slotQwtPolygon)
except Exception,msg:
print
print '1 Error picker.connect with selected(QwtPolygon)'
print msg
try:
self.picker.selected[QwtPolygon](self.slotQwtPolygon)
except Exception,msg:
print
print '2 Error picker.selected with selected(QwtPolygon)'
print msg
try:
self.picker.connect(self.picker, SIGNAL('selected(QwtArray<QwtDoublePoint>)'), self.slotQwtArray)
except Exception,msg:
print
print '3 Error picker.connect with selected(QwtArray<QwtDoublePoint>)'
print msg
try:
self.picker.selected['QwtArray<QwtDoublePoint>'].connect(self.slotQwtArray)
except Exception,msg:
print
print '4 Error picker.selected with selected(QwtArray<QwtDoublePoint>)'
print msg
def slotQwtPolygon(self,loc):
print '\nusing QwtPolygon',loc,self.sender()
print 'Size:',len(loc)
for p in loc:
print p
def slotQwtArray(self,loc):
print '\nusing QwtArrayQwtDoublePoint',loc,self.sender()
try:
print 'Size:',len(loc)
except:
print # cancels the , from the previous print
pass
for p in loc:
print p
def main(args):
app = QApplication(args)
demo = MainWindow()
sys.exit(app.exec_())
# main()
# Admire
if __name__ == '__main__':
if 'settracemask' in sys.argv:
# for debugging, requires: python configure.py --trace ...
import sip
sip.settracemask(0x3f)
main(sys.argv)
# Local Variables: ***
# mode: python ***
# End: ***
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt