index.lxp@lxpwrap=x8818_252ehtm.htm
来自「GUI Programming with Python」· HTM 代码 · 共 305 行
HTM
305 行
<table border="0" cellspacing="0" cellpadding="3" width="100%"><tr><td> <div align="center" id="bldcontent"> <a href="../default.htm"><img src="../images/opendocs.png" width="63" height="76" border="0"></a> <br> <div class="symbol">Your OpenSource Publisher™</div> </div> </td></tr></table> <div align="center" class="author"> <a href="../products.lxp">Products</a> | <a href="../wheretobuy.lxp">Where to buy</a> | <a href="../bookstore.lxp">Retailers</a> | <a href="../faq.lxp">FAQ</a> | <a href="../writeforus.lxp">Write for Us.</a> | <a href="#contact">Contact Us.</a> </div> <table border="0" cellspacing="3" cellpadding="0" width="100%"><tr><td width="100%"> <div class="content"> <table border="0" cellspacing="2" cellpadding="0" width="100%"><tr><td width="100%"> <div align="center"><H4 CLASS="AUTHOR"><A NAME="AEN5">Boudewijn Rempt</A><br><a href="../../https@secure.linuxports.com/opendocs/default.htm"><img src=odpyqt125.png></a><br>ISBN: 0-97003300-4-4<br><a href="../../https@secure.linuxports.com/opendocs/default.htm">Available from bookstores everywhere or you can order it here.</a><p>You can download the source files for the book <a href="pyqtsrc.tgz">(code / eps) here.</a><hr></div> <HTML><HEAD><TITLE>PyQwt</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.72"><LINKREL="HOME"TITLE="GUI Programming with Python: QT Edition"HREF="book1.htm"><LINKREL="UP"TITLE="PyQwt: Python Bindings for Qwt"HREF="a8743.htm"><LINKREL="PREVIOUS"TITLE="PyQwt: Python Bindings for Qwt"HREF="a8743.htm"><LINKREL="NEXT"TITLE="First Steps with Sip"HREF="a8834.htm"></HEAD><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GUI Programming with Python: QT Edition</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><A accesskey="P" href="index.lxp@lxpwrap=a8743_252ehtm.htm">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Appendix B. PyQwt: Python Bindings for Qwt</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><A accesskey="N" href="index.lxp@lxpwrap=a8834_252ehtm.htm">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1">PyQwt</A></H1><P>Qwt and PyQwt exists for both Linux/Unix and Windows. Qwt is a set of plotting widgets. Installing these is currently not quite as comfortable as installing numpy, but the instructions in the package are excellent:</P><PRECLASS="SCREEN">boud@calcifer:~/src > tar -xzf qwt-0.3.0.tar.gzboud@calcifer:~/src > cd qwt-0.3.0boud@calcifer:~/src/qwt-0.3.0 > lsCHANGES COPYING CVS doc Doxyfile Doxyfile.users examples include INSTALL makefiles propagate qwt.pro README README.QT srcboud@calcifer:~/src/qwt-0.3.0 > cp makefiles/linux-g++ ./Makefileboud@calcifer:~/src/qwt-0.3.0 > make...ln -s libqwt.so.0.3.0 libqwt.soln -s libqwt.so.0.3.0 libqwt.so.0ln -s libqwt.so.0.3.0 libqwt.so.0.3boud@calcifer:~/src/qwt-0.3.0 > nc READMEboud@calcifer:~/src/qwt-0.3.0 > suPassword:root@calcifer:/home/boud/src/qwt-0.3.0 > mv libqwt.* /usr/local/libroot@calcifer:/home/boud/src/qwt-0.3.0 > mkdir /usr/local/include/qwt </PRE><P>This did the trick—at least on my system! Now you just have to instal the Python bindings. This is even easier, since PyQwt now uses Distutils to get itself installed. However, note that you need to have a <SPAN><ICLASS="EMPHASIS">source</I></SPAN> installation of PyQt if you intend to build PyQwt from source. There are currently binary packages for Windows and some versions of Linux, like Mandrake.</P><P>PyQwt has a number of illustrative demo scripts—here, I picked one to demonstrate to you the way it works.</P><PRECLASS="PROGRAMLISTING">#!/usr/bin/env python## qwtdemo.py## Demonstrates that you can plot NumPy arrays and lists of Python floats.# NumPy arrays are more elegant and more than 20 times faster than lists.import sysfrom qt import *from qwt import *from Numeric import *def drange(start, stop, step): start, stop, step = float(start), float(stop), float(step) size = int(round((stop-start)/step)) result = [start]*size for i in xrange(size): result[i] += i*step return result def lorentzian(x): return 1.0/(1.0+(x-5.0)**2)class ListArrayDemo(QWidget): def __init__(self, *args): apply(QWidget.__init__, (self,) + args) # create a plot widget for NumPy arrays self.aplot = QwtPlot('Plot -- NumPy arrays', self) # calculate 2 NumPy arrays xa = arange(0.0, 10.0, 0.01) ya = lorentzian(xa) # insert a curve, make it red and copy the arrays ca = self.aplot.insertCurve('y = lorentzian(x)') self.aplot.setCurvePen(ca, QPen(Qt.red)) self.aplot.setCurveData(ca, xa, ya) # create a plot widget for lists of Python floats self.lplot = QwtPlot('Plot -- List of Python floats', self) # calculate 2 lists of Python floats xl = drange(0.0, 10.0, 0.01) yl = map(lorentzian, xl) # insert a curve, make it blue and copy the lists cl = self.lplot.insertCurve('y = lorentzian(x)') self.lplot.setCurvePen(cl, QPen(Qt.blue)) self.lplot.setCurveData(cl, xl, yl) def resizeEvent(self, e): x = e.size().width() y = e.size().height()/2 self.aplot.resize(x, y) self.aplot.move(0, 0) self.lplot.resize(x, y) self.lplot.move(0, y)# admire app = QApplication(sys.argv)demo = ListArrayDemo()app.setMainWidget(demo)demo.resize(400, 600)demo.show()app.exec_loop() </PRE><DIVCLASS="MEDIAOBJECT"><P><DIVCLASS="CAPTION"><P>Output of qwtdemo.py</P></DIV></P></DIV><P>As you can see, the core of the Qwt library is the <TTCLASS="CLASSNAME">QwtPlot</TT> widget - an object that knows how to plot, but can be used as any other Qt widget.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><A accesskey="P" href="index.lxp@lxpwrap=a8743_252ehtm.htm">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><A accesskey="H" href="index.lxp@lxpwrap=book1_252ehtm">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><A accesskey="N" href="index.lxp@lxpwrap=a8834_252ehtm.htm">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">PyQwt: Python Bindings for Qwt</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><A accesskey="U" href="index.lxp@lxpwrap=a8743_252ehtm.htm">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">First Steps with Sip</TD></TR></TABLE></DIV></BODY></HTML> </td> </tr> </table> </td> </tr> </table>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?