index.lxp@lxpwrap=r9791_252ehtm.htm

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

HTM
709
字号
    <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>sipParseArgs</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="Conversions and argument parsing"HREF="x9684.htm#CONVFUNCS"><LINKREL="PREVIOUS"TITLE="SIPLIB Functions"HREF="x9684.htm"><LINKREL="NEXT"TITLE="sipConvertToCpp"HREF="r9932.htm"></HEAD><BODYCLASS="REFENTRY"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=x9684_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=r9932_252ehtm">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1>sipParseArgs</A></H1><DIVCLASS="REFNAMEDIV"></A><H2>Name</H2>sipParseArgs&nbsp;--&nbsp;Parse the arguments to a C/C++ function              without any side effects</DIV><DIVCLASS="REFSYNOPSISDIV"></A><H2>Synopsis</H2><DIVCLASS="FUNCSYNOPSIS"></A><P></P><P><CODE><CODECLASS="FUNCDEF">int                  sipParseArgs</CODE>(int *                  argsParsedp, PyObject *                  sipArgs, char * fmt, ...);</CODE></P><P></P></DIV></DIV><DIVCLASS="REFSECT1"></A><H2>Description</H2><DIVCLASS="REFSECT2"></A><H3>Return Value</H3><P>                false (or 0) if an error occurred, else true (or 1).              </P></DIV><DIVCLASS="REFSECT2"></A><H3>argsParsedp</H3><P>                      Parsing stops if an error is encountered or all                arguments / format specifiers are exhausted. The                number of arguments parsed so far is stored here along                with error flags. </A><BLOCKQUOTECLASS="BLOCKQUOTE"><DIVCLASS="TABLE"></A><P><B>Table C-1. Error flags in sipParseArgs()</B></P><TABLEBORDER="1"CLASS="CALSTABLE"><THEAD><TR><THWIDTH="100"ALIGN="CENTER"VALIGN="TOP">Flag Name</TH><THWIDTH="200"ALIGN="LEFT"VALIGN="TOP">Meaning</TH></TR></THEAD><TBODY><TR><TDWIDTH="100"ALIGN="CENTER"VALIGN="TOP">PARSE_OK</TD><TDWIDTH="200"ALIGN="LEFT"VALIGN="TOP">Parse is Ok so far</TD></TR><TR><TDWIDTH="100"ALIGN="CENTER"VALIGN="TOP">PARSE_MANY</TD><TDWIDTH="200"ALIGN="LEFT"VALIGN="TOP">Too many arguments</TD></TR><TR><TDWIDTH="100"ALIGN="CENTER"VALIGN="TOP">PARSE_FEW</TD><TDWIDTH="200"ALIGN="LEFT"VALIGN="TOP">Too few arguments</TD></TR><TR><TDWIDTH="100"ALIGN="CENTER"VALIGN="TOP">PARSE_TYPE</TD><TDWIDTH="200"ALIGN="LEFT"VALIGN="TOP">Argument with a bad type</TD></TR><TR><TDWIDTH="100"ALIGN="CENTER"VALIGN="TOP">PARSE_MASK</TD><TDWIDTH="200"ALIGN="LEFT"VALIGN="TOP">Mask covering the error flag                            bits</TD></TR></TBODY></TABLE></DIV></BLOCKQUOTE>              </P></DIV><DIVCLASS="REFSECT2"></A><H3>sipArgs</H3><P>                A pointer to a tuple which supplies the arguments to                be parsed.              </P></DIV><DIVCLASS="REFSECT2"></A><H3>fmt</H3><P>                      Format string describing arguments. A leading                '-' in the format string disposes of the arguments on                a successful parse. A '|' in the format string                signifies that the following arguments are optional.                The following format specifiers are recognized:                </A><BLOCKQUOTECLASS="BLOCKQUOTE"><DIVCLASS="TABLE"></A><P><B>Table C-2. Format specifiers for                      sipParseArgs()</B></P><TABLEBORDER="1"CLASS="CALSTABLE"><THEAD><TR><THWIDTH="30"ALIGN="CENTER"VALIGN="TOP">fmt</TH><THWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Operand type</TH><THWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">expected C argument(s)</TH></TR></THEAD><TBODY><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">s</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">String or None</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">char **</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">S</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Slot name, return the name</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">char **</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">G</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Signal name, return the name</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">char **</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">I</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Class instance</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">int (*convfunc)(PyObject *), PyObject                            **</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">O</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Python object of any type</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">PyObject **</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">T</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Python object of given type</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">PyTypeObject *, PyObject **</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">R</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Sub-class of QObject</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">PyObject **</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">F</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Python callable object</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">PyObject **</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">a</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Byte array or None</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">char **, int *</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">c</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Character</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">char *</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">i</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Integer</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">int *</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">h</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Short integer</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">short *</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">l</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Long integer</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">long *</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">f</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Float</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">float *</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">d</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Double float</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">double *</TD></TR><TR><TDWIDTH="30"ALIGN="CENTER"VALIGN="TOP">v</TD><TDWIDTH="150"ALIGN="LEFT"VALIGN="TOP">Void pointer</TD><TDWIDTH="100%"ALIGN="LEFT"VALIGN="TOP">void **</TD></TR></TBODY></TABLE></DIV></BLOCKQUOTE>              </P></DIV><DIVCLASS="REFSECT2"></A><H3>...</H3><P>                A variable number of pointers to the arguments which                will take the parsed values.              </P></DIV></DIV><DIVCLASS="REFSECT1"></A><H2>Examples</H2><DIVCLASS="EXAMPLE"></A><P><B>Example C-1. Interface for                QRegExp::match</B></P><PRECLASS="PROGRAMLISTING">// Attempts to match in str, starting from position index. // Returns the position of the match, or -1 if there was no match.// if len is not a null pointer, the length of the match is stored in *len. int match(const char* str, int index=0, int*=0) const;%MemberCode    // The Python interface returns the position and length as a tuple.    const char *str;    int index = 0;    if (sipParseArgs(&#38;sipArgsParsed, sipArgs, "s|i", &#38;str, &#38;index))    {        int pos, len;        QRegExp *ptr;        if ((ptr = (QRegExp*) sipGetCppPtr(sipThis, sipClass_QRegExp)) == NULL)            return NULL;        pos = ptr -&#62; QRegExp::match(str, index, &#38;len);        return Py_BuildValue("(ii)", pos, len);    }%End            </PRE></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=x9684_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=r9932_252ehtm">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">SIPLIB Functions</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><A accesskey="U" href="index.lxp@lxpwrap=x9684_252ehtm.htm#CONVFUNCS">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">sipConvertToCpp</TD></TR></TABLE></DIV></BODY></HTML>      </td>      </tr>      </table>      </td>    </tr>  </table>      

⌨️ 快捷键说明

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