📄 index.lxp@lxpwrap=x9022_252ehtm.htm
字号:
<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>Sip usage and syntax</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="First Steps with Sip"HREF="a8834.htm"><LINKREL="PREVIOUS"TITLE="Where to look to start writing your own wrappers/bindings"HREF="x9012.htm"><LINKREL="NEXT"TITLE="Directives"HREF="x9236.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=x9012_252ehtm.htm">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Appendix C. First Steps with Sip</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><A accesskey="N" href="index.lxp@lxpwrap=x9236_252ehtm.htm">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1">Sip usage and syntax</A></H1><FONTCOLOR="RED"> Wilken Boie </FONT><P>This section has been prepared from the sip manual written by Wilken Boie, who has graciously given permission to use it in this book.</P><DIVCLASS="SECT2"><H2CLASS="SECT2">Usage</A></H2><DIVCLASS="SECT3"><H3CLASS="SECT3">Invocation, Command Line</A></H3><P><BCLASS="COMMAND">sip</B> [-h] [-V] [-c <TTCLASS="REPLACEABLE"><I>dir</I></TT>] [-d <TTCLASS="REPLACEABLE"><I>file</I></TT>] [-m <TTCLASS="REPLACEABLE"><I>file</I></TT>] [-I <TTCLASS="REPLACEABLE"><I>dir</I></TT>] [-s <TTCLASS="REPLACEABLE"><I>suffix</I></TT>] [-p <TTCLASS="REPLACEABLE"><I>module</I></TT>] [<TTCLASS="REPLACEABLE"><I>file</I></TT>]</P><P> where: </A><BLOCKQUOTECLASS="BLOCKQUOTE"><DIVCLASS="TABLE"></A><P><B>Table C-2. Command line options</B></P><TABLEBORDER="1"CLASS="CALSTABLE"><TBODY><TR><TDALIGN="LEFT"VALIGN="TOP">-h</TD><TDALIGN="LEFT"VALIGN="TOP">display help message</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">-V</TD><TDALIGN="LEFT"VALIGN="TOP">display the SIP version number</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">-c <TTCLASS="REPLACEABLE"><I>dir</I></TT></TD><TDALIGN="LEFT"VALIGN="TOP">the name of the code directory [default not generated]</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">-d <TTCLASS="REPLACEABLE"><I>file</I></TT> </TD><TDALIGN="LEFT"VALIGN="TOP">the name of the documentation file [default not generated]</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">-m <TTCLASS="REPLACEABLE"><I>file</I></TT> </TD><TDALIGN="LEFT"VALIGN="TOP">the name of the Makefile [default none generated]</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">-I <TTCLASS="REPLACEABLE"><I>dir</I></TT> </TD><TDALIGN="LEFT"VALIGN="TOP">look in this directory when including files</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">-s <TTCLASS="REPLACEABLE"><I>suffix</I></TT></TD><TDALIGN="LEFT"VALIGN="TOP">the suffix to use for C++ source files [default ".cpp"]</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">-p <TTCLASS="REPLACEABLE"><I>module</I></TT></TD><TDALIGN="LEFT"VALIGN="TOP">the name of the generated C++ module [default Module]</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">file</TD><TDALIGN="LEFT"VALIGN="TOP">the name of the specification file [default stdin]</TD></TR></TBODY></TABLE></DIV></BLOCKQUOTE> </P></DIV><DIVCLASS="SECT3"><H3CLASS="SECT3">Limitations</A></H3><P> The following limitations are SIP compile time options: <P></P><ULCOMPACT="COMPACT"><LI><P>Maximum number of arguments to a function: 20</P></LI><LI><P>Maximum nesting depth of <SPANCLASS="ACTION">%If</SPAN> directives: 10</P></LI><LI><P>Maximum number of nested version qualifiers in the generated Python: 10</P></LI><LI><P>Maximum number of option flags in function declarations: 5</P></LI></UL> </P></DIV><DIVCLASS="SECT3"><H3CLASS="SECT3">Files</A></H3><DIVCLASS="SECT4"><H4CLASS="SECT4">Source Files</A></H4></A><BLOCKQUOTECLASS="BLOCKQUOTE"><DIVCLASS="GLOSSLIST"><DL><DT><B> <TTCLASS="FILENAME">*.sip</TT> </B></DT><DD><P> and possibly further included files are processed by SIP. They are the source file(s) defining the wrapping. They closely resemble the header files they describe but also contain additional <A href="index.lxp@lxpwrap=x9236_252ehtm.htm">directives</A> for a range of special cases and purposes (e.g. production of documentation, treatment of different versions a wrapped libraries). </P></DD></DL></DIV></BLOCKQUOTE></DIV><DIVCLASS="SECT4"><H4CLASS="SECT4">Files containing the wrapping</A></H4></A><BLOCKQUOTECLASS="BLOCKQUOTE"><DIVCLASS="GLOSSLIST"><DL><DT><B> </A> <TTCLASS="FILENAME">$(module).py</TT> </B></DT><DD><P>is produced by SIP. It initializes the wrapping and imports the dynamic lib lib$(module)c.pyd which contains the actual C++ wrapping code.</P><P>Code from <SPANCLASS="ACTION">%PrePythonCode</SPAN> and <SPANCLASS="ACTION">%PythonCode</SPAN> sections is also placed in this file as in the following example (assuming a module MOD wrapping classes A and B):</P><PRECLASS="SCREEN"> # Python wrapper code # Copying: Copyright (c) .... import libMODc libMc.sipInitModule() # here comes code from %PrePythonCode sections class A: ... class B: ... libMc.sipRegisterClasses() # here comes code from %PythonCode sections </PRE></DD><DT><B> <TTCLASS="FILENAME">lib$(module)c.pyd</TT> </B></DT><DD><P>This dynamic library is compiled from the following, SIP generate intermediate files:</P></DD></DL></DIV></BLOCKQUOTE></DIV><DIVCLASS="SECT4"><H4CLASS="SECT4">Intermediate Files</A></H4></A><BLOCKQUOTECLASS="BLOCKQUOTE"><DIVCLASS="GLOSSLIST"><DL><DT><B> <TTCLASS="FILENAME">sip$(module)$(class).h</TT>, <TTCLASS="FILENAME">sip$(module)$(class).cpp</TT> </B></DT><DD><P>A pair of corresponding header and C++ files for each wrapped class.</P></DD><DT><B> <TTCLASS="FILENAME">sip$(module)Decl$(module).h</TT> </B></DT><DD><P> A global module header, which (beside all im- and exports) contains all <SPANCLASS="ACTION">%ExportedHeaderCode</SPAN> and <SPANCLASS="ACTION">%HeaderCode</SPAN> (from imported .sip files only <SPANCLASS="ACTION">%ExportedHeaderCode</SPAN>). </P></DD><DT><B> <TTCLASS="FILENAME">$(module)cmodule.cpp</TT> </B></DT><DD><P>Which contains the module global and initialisation code.</P></DD></DL></DIV></BLOCKQUOTE></DIV><DIVCLASS="SECT4"><H4CLASS="SECT4">Auxilliary Files</A></H4></A><BLOCKQUOTECLASS="BLOCKQUOTE"><DIVCLASS="GLOSSLIST"><DL><DT><B> <TTCLASS="REPLACEABLE"><I>makefile_name</I></TT> </B></DT><DD><P>If SIP option <SPANCLASS="QUOTE">"-m <TTCLASS="REPLACEABLE"><I>makefile_name</I></TT>"</SPAN> is given, one of a set of makefile templates (defined in the SIP files) is seletected and instantiated with the appropriate module and class names. It is typically used to compile the wrapping.</P></DD><DT><B> </A> <TTCLASS="FILENAME">sip_helper.cpp</TT> </B></DT><DD><P>All code from <SPANCLASS="ACTION">%VersionCode</SPAN> sections will be placed in this file. Typically it is compiled into <TTCLASS="FILENAME">sip_helper.exe</TT>, which then produces <TTCLASS="FILENAME">sip$(module)Version.h</TT>. This is included in all relevant files to maintain version information for the conditional sections.</P><P>Why not just #include the necessary file that provides the version information and use the C++ test specified as part of the version definition in the .sip files?</P><P>The answer is that moc can't handle C++ pre-processor commands, so the proxy header file must be run through the C++ pre-processor beforehand. The code generated by moc is then #included by the main module code.</P><P>The net result is that the header file specifying the version information is #included by the main module code and #included a second time - but the second time is a version that has already been run through the C++ pre-processor and has therefore lost it's usual means of protecting itself from being #included twice.</P><P>Unless the file follows certain rules (like having no function definitions) it is likely to make the C++ compiler complain. Therefore the solution is to use a generated file that isn't going to cause complaints.</P></DD><DT><B> <TTCLASS="REPLACEABLE"><I>docfile_name</I></TT> </B></DT><DD><P>If SIP option <SPANCLASS="QUOTE">"-m <TTCLASS="REPLACEABLE"><I>docfile_name</I></TT>"</SPAN> is given, documentation records are extracted from the SIP file(s) and written to <TTCLASS="REPLACEABLE"><I>docfile_name</I></TT>.</P></DD></DL></DIV></BLOCKQUOTE></DIV></DIV><DIVCLASS="SECT3"><H3CLASS="SECT3">.sip File Syntax</A></H3><DIVCLASS="SECT4"><H4CLASS="SECT4">General rules</A></H4><P> <P></P><ULCOMPACT="COMPACT"><LI><P>All <SPANCLASS="ACTION">%keywords</SPAN> must start at beginning of line.</P></LI><LI><P>All <SPAN><ICLASS="EMPHASIS">_block_</I></SPAN>s must be closed by a matching <SPANCLASS="ACTION">%End</SPAN> directive.</P></LI><LI><P>Parameters are separated by whitespace, string parameters are enclosed by double quotes.</P></LI></UL> </P></DIV><DIVCLASS="SECT4"><H4CLASS="SECT4">Macros</A></H4><P>A number of macros can be used in the .sip files (e.g. class definitions, makefile templates). When SIP parses the definitions, the macros are replaced by actual values as follows: </A><BLOCKQUOTECLASS="BLOCKQUOTE"><DIVCLASS="TABLE"></A><P><B>Table C-3. Macros in Makefile Templates</B></P><TABLEBORDER="1"CLASS="CALSTABLE"><TBODY><TR><TDALIGN="LEFT"VALIGN="TOP">$$</TD><TDALIGN="LEFT"VALIGN="TOP">a '$' character</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">$C</TD><TDALIGN="LEFT"VALIGN="TOP">Class name</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">$S</TD><TDALIGN="LEFT"VALIGN="TOP">Source files</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">$O</TD><TDALIGN="LEFT"VALIGN="TOP">Object files</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">$c</TD><TDALIGN="LEFT"VALIGN="TOP">C++ file suffix</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">$o</TD><TDALIGN="LEFT"VALIGN="TOP">Object_file_suffix</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">$m</TD><TDALIGN="LEFT"VALIGN="TOP">C++ module name</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">$P</TD><TDALIGN="LEFT"VALIGN="TOP">Percent sign</TD></TR></TBODY></TABLE></DIV></BLOCKQUOTE> </P></DIV></DIV></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=x9012_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=x9236_252ehtm.htm">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Where to look to start writing your own wrappers/bindings</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><A accesskey="U" href="index.lxp@lxpwrap=a8834_252ehtm.htm">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Directives</TD></TR></TABLE></DIV></BODY></HTML> </td> </tr> </table> </td> </tr> </table>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -