index.lxp@lxpwrap=a8834_252ehtm.htm

来自「GUI Programming with Python」· HTM 代码 · 共 352 行

HTM
352
字号
    <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&#153;</div>    </div>      </td></tr></table>    <div align="center" class="author">      	<a href="../products.lxp">Products</a>	&nbsp;|&nbsp;	<a href="../wheretobuy.lxp">Where to buy</a>	&nbsp;|&nbsp;	<a href="../bookstore.lxp">Retailers</a>	&nbsp;|&nbsp;	<a href="../faq.lxp">FAQ</a>	&nbsp;|&nbsp;        <a href="../writeforus.lxp">Write for Us.</a>        &nbsp;|&nbsp;        <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>First Steps with Sip</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="Appendices"HREF="p8645.htm"><LINKREL="PREVIOUS"TITLE="PyQwt"HREF="x8818.htm"><LINKREL="NEXT"TITLE="How sip works"HREF="x8867.htm"></HEAD><BODYCLASS="APPENDIX"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=x8818_252ehtm.htm">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><A accesskey="N" href="index.lxp@lxpwrap=x8867_252ehtm.htm">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="APPENDIX"><H1>Appendix C. First Steps with Sip</A></H1><DIVCLASS="TOC"><DL><DT><B>Table of Contents</B></DT><DT><A href="index.lxp@lxpwrap=a8834_252ehtm.htm#AEN8842">Introduction</A></DT><DT><A href="index.lxp@lxpwrap=x8867_252ehtm.htm">How sip works</A></DT><DT><A href="index.lxp@lxpwrap=x8887_252ehtm.htm">Creating .sip files</A></DT><DT><A href="index.lxp@lxpwrap=x8949_252ehtm.htm">Things <BCLASS="COMMAND">sip</B> can't do      automatically</A></DT><DT><A href="index.lxp@lxpwrap=x9012_252ehtm.htm">Where to look to start writing your own    wrappers/bindings</A></DT><DT><A href="index.lxp@lxpwrap=x9022_252ehtm.htm">Sip usage and syntax</A></DT><DT><A href="index.lxp@lxpwrap=x9236_252ehtm.htm">Directives</A></DT><DT><A href="index.lxp@lxpwrap=x9571_252ehtm.htm">Accepted C++ / Qt constructs</A></DT><DT><A href="index.lxp@lxpwrap=x9684_252ehtm.htm">SIPLIB Functions</A></DT></DL></DIV><FONTCOLOR="RED">&#13;    Jim Bublitz  </FONT><P>Jim Bublitz knows far more about    <SPAN><ICLASS="EMPHASIS">sip</I></SPAN>, the tool used to wrap C++ libraries for    Python, than I do. For instance, he's the author of the bindings    to the KDE2 libraries. For these reasons, I asked him to write an    appendix on using sip.</P><DIVCLASS="SECT1"><H1CLASS="SECT1">Introduction</A></H1><P>Wrapping C++ libraries for use from Python is      a profitable undertaking, given the wealth of functionality that      becomes available after doing so. Python, in contrast with Java,      has been designed from the outset to be easily extensible with      &#8216;foreign' libraries written in C. C++, however, is a far more      complex language than C, and requires careful attention to the      creation, ownership and destruction of objects. Trolltech have      made the work even more complicated with the invention of a      special meta-object pre-compiler needed to get techniques like      signals and slots working.</P><P>These days it is not usual to wrap C++      libraries by hand. If only because of the size of the Qt      libraries, it probably isn't practical to write these bindings      manually, so an automated tool, <SPAN><ICLASS="EMPHASIS">sip</I></SPAN>, was      developed by Phil Thompson (the PyQt developer) to generate the      necessary binding code.</P><P>As you know, PyQt is a set of Python      bindings for the Qt libraries. That means that PyQt isn't a      translation of Qt into Python&#8212;instead, the &#8216;bindings' let      you access and use the C++ Qt libraries from the Python language      via an intermediate wrapper library, which is also written (or      rather, generated) in C++.</P><P>The <SPAN><ICLASS="EMPHASIS">sip</I></SPAN> program      generates these C++ &#8216;wrappers'. Wrappers are chunks of C++ code      that allow Python to pass data to and from other C++ code and to      invoke C++ methods or functions. <SPAN><ICLASS="EMPHASIS">Sip</I></SPAN> gets      its name (and some of it's architecture) from another wrapper      generator named <SPAN><ICLASS="EMPHASIS">swig</I></SPAN>. In fact,      <SPAN><ICLASS="EMPHASIS">sip</I></SPAN> started out as a small      <SPAN><ICLASS="EMPHASIS">swig</I></SPAN>, although it has grown a bit since      then.  It is specifically designed to generate Python bindings      for C++ libraries, while <SPAN><ICLASS="EMPHASIS">swig</I></SPAN> is more      general purpose, and can wrap C libraries for a variety of      scripting languages. Of course, <SPAN><ICLASS="EMPHASIS">sip</I></SPAN> also      offers some additional functionality, like support for signals      and slots, Python inheritance of C++ objects, and many other C++      language features:</P><P></P><UL><LI><P>Re-implementation of C++ virtual methods          in Python.</P></LI><LI><P>Sub-classing C++ classes from          Python.</P></LI><LI><P>Access to a C++ class's protected          methods.</P></LI><LI><P>Overloading of C++ functions and methods          with different parameter type signatures.</P></LI><LI><P>Automatic translation between C++          classes and similar (but more appropriate) Python          types.</P></LI></UL></DIV></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=x8818_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=x8867_252ehtm.htm">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">PyQwt</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><A accesskey="U" href="index.lxp@lxpwrap=p8645_252ehtm.htm">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">How sip works</TD></TR></TABLE></DIV></BODY></HTML>      </td>      </tr>      </table>      </td>    </tr>  </table>      

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?