From cbac30b07bae6c72be5eefd5e47fe83650a16acd Mon Sep 17 00:00:00 2001 From: Hugo Lima Date: Mon, 17 Aug 2009 17:36:11 -0300 Subject: The genesis... --- doc/Makefile | 88 ++++ doc/_static/basic.css | 417 +++++++++++++++++ doc/_static/bindingexample.tar.bz2 | Bin 0 -> 107006 bytes doc/_static/default.css | 248 ++++++++++ doc/_static/images/._background_search.jpg | Bin 0 -> 4096 bytes doc/_static/images/._bread_crumb.png | Bin 0 -> 4096 bytes doc/_static/images/._button_search.jpg | Bin 0 -> 4096 bytes doc/_static/images/._side_background.jpg | Bin 0 -> 25192 bytes doc/_static/images/._top_background.jpg | Bin 0 -> 4096 bytes doc/_static/images/background_search.jpg | Bin 0 -> 2129 bytes doc/_static/images/bg.jpg | Bin 0 -> 5749 bytes doc/_static/images/bread_crumb.png | Bin 0 -> 743 bytes doc/_static/images/button_search.png | Bin 0 -> 3259 bytes doc/_static/images/side_background.jpg | Bin 0 -> 13760 bytes doc/_static/images/top_background.jpg | Bin 0 -> 500 bytes doc/_templates/index.html | 32 ++ doc/_templates/layout.html | 34 ++ doc/compiling/cmake-primer.rst | 72 +++ doc/compiling/compiling.rst | 9 + doc/compiling/setup-apiextractor.rst | 48 ++ doc/compiling/setup-generator.rst | 49 ++ doc/conf.py | 188 ++++++++ doc/contents.rst | 9 + doc/dependency-pyside.svg | 527 +++++++++++++++++++++ doc/images/.directory | 3 + doc/images/bindinggen-development.png | Bin 0 -> 35681 bytes doc/images/bindinggen-development.svg | 543 ++++++++++++++++++++++ doc/images/boostgenarch.png | Bin 0 -> 80531 bytes doc/images/boostgenarch.svg | 711 +++++++++++++++++++++++++++++ doc/images/boostqtarch.png | Bin 0 -> 31605 bytes doc/images/boostqtarch.svg | 226 +++++++++ doc/overview.rst | 46 ++ doc/tutorial/bindinglibfoo.rst | 77 ++++ doc/tutorial/buildingthebinding.rst | 132 ++++++ doc/tutorial/globalheader.rst | 36 ++ doc/tutorial/images/generatorworkings.png | Bin 0 -> 37257 bytes doc/tutorial/images/generatorworkings.svg | 392 ++++++++++++++++ doc/tutorial/introduction.rst | 32 ++ doc/tutorial/libfoo.rst | 68 +++ doc/tutorial/typesystemcreation.rst | 135 ++++++ 40 files changed, 4122 insertions(+) create mode 100644 doc/Makefile create mode 100644 doc/_static/basic.css create mode 100644 doc/_static/bindingexample.tar.bz2 create mode 100644 doc/_static/default.css create mode 100755 doc/_static/images/._background_search.jpg create mode 100755 doc/_static/images/._bread_crumb.png create mode 100755 doc/_static/images/._button_search.jpg create mode 100755 doc/_static/images/._side_background.jpg create mode 100755 doc/_static/images/._top_background.jpg create mode 100644 doc/_static/images/background_search.jpg create mode 100644 doc/_static/images/bg.jpg create mode 100644 doc/_static/images/bread_crumb.png create mode 100644 doc/_static/images/button_search.png create mode 100644 doc/_static/images/side_background.jpg create mode 100644 doc/_static/images/top_background.jpg create mode 100644 doc/_templates/index.html create mode 100644 doc/_templates/layout.html create mode 100644 doc/compiling/cmake-primer.rst create mode 100644 doc/compiling/compiling.rst create mode 100644 doc/compiling/setup-apiextractor.rst create mode 100644 doc/compiling/setup-generator.rst create mode 100644 doc/conf.py create mode 100644 doc/contents.rst create mode 100644 doc/dependency-pyside.svg create mode 100644 doc/images/.directory create mode 100644 doc/images/bindinggen-development.png create mode 100644 doc/images/bindinggen-development.svg create mode 100644 doc/images/boostgenarch.png create mode 100644 doc/images/boostgenarch.svg create mode 100644 doc/images/boostqtarch.png create mode 100644 doc/images/boostqtarch.svg create mode 100644 doc/overview.rst create mode 100644 doc/tutorial/bindinglibfoo.rst create mode 100644 doc/tutorial/buildingthebinding.rst create mode 100644 doc/tutorial/globalheader.rst create mode 100644 doc/tutorial/images/generatorworkings.png create mode 100644 doc/tutorial/images/generatorworkings.svg create mode 100644 doc/tutorial/introduction.rst create mode 100644 doc/tutorial/libfoo.rst create mode 100644 doc/tutorial/typesystemcreation.rst (limited to 'doc') diff --git a/doc/Makefile b/doc/Makefile new file mode 100644 index 000000000..f9fe2f01c --- /dev/null +++ b/doc/Makefile @@ -0,0 +1,88 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d _build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + -rm -rf _build/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) _build/html + @echo + @echo "Build finished. The HTML pages are in _build/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) _build/dirhtml + @echo + @echo "Build finished. The HTML pages are in _build/dirhtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) _build/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) _build/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) _build/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in _build/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) _build/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in _build/qthelp, like this:" + @echo "# qcollectiongenerator _build/qthelp/BoostPythonGenerator.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile _build/qthelp/BoostPythonGenerator.qhc" + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) _build/latex + @echo + @echo "Build finished; the LaTeX files are in _build/latex." + @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \ + "run these through (pdf)latex." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) _build/changes + @echo + @echo "The overview file is in _build/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) _build/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in _build/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) _build/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in _build/doctest/output.txt." diff --git a/doc/_static/basic.css b/doc/_static/basic.css new file mode 100644 index 000000000..2509c227f --- /dev/null +++ b/doc/_static/basic.css @@ -0,0 +1,417 @@ +/** + * Sphinx stylesheet -- basic theme + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +/* -- main layout ----------------------------------------------------------- */ + +div.documentwrapper { + float: left; + width: 100%; +} + +div.bodywrapper { + margin: 0 0 0 230px; +} + +div.clearer { + clear: both; +} + +/* -- relbar ---------------------------------------------------------------- */ + +div.related { + width: 100%; + font-size: 90%; +} + +div.related h3 { + display: none; +} + +div.related ul { + margin: 0; + padding: 0 0 0 0px; + list-style: none; +} + +div.related li { + float: left; + display: inline; + padding-right:17px; + padding-left:10px; + background-image:url(images/bread_crumb.png); + background-position:right; + background-repeat:no-repeat; +} + +div.related li.right { + float: right; + margin-right: 5px; + padding: 0 0 0 0px; + background-image:none; +} + +/* -- sidebar --------------------------------------------------------------- */ + +div.sphinxsidebarwrapper { + padding: 10px 5px 0 10px; +} + +div.sphinxsidebar { + float: left; + width: 230px; + margin-left: -100%; + font-size: 90%; +} + +div.sphinxsidebar ul { + list-style: none; +} + +div.sphinxsidebar ul ul, +div.sphinxsidebar ul.want-points { + margin-left: 20px; + list-style: square; +} + +div.sphinxsidebar ul ul { + margin-top: 0; + margin-bottom: 0; +} + +div.sphinxsidebar form { + margin-top: 10px; +} + +img { + border: 0; +} + +/* -- search page ----------------------------------------------------------- */ + +ul.search { + margin: 10px 0 0 20px; + padding: 0; +} + +ul.search li { + padding: 5px 0 5px 20px; + background-image: url(file.png); + background-repeat: no-repeat; + background-position: 0 7px; +} + +ul.search li a { + font-weight: bold; +} + +ul.search li div.context { + color: #888; + margin: 2px 0 0 30px; + text-align: left; +} + +ul.keywordmatches li.goodmatch a { + font-weight: bold; +} + +/* -- index page ------------------------------------------------------------ */ + +table.contentstable { + text-align: left; + width: 90%; +} + +table.contentstable p.biglink { + line-height: 150%; +} + +a.biglink { + font-size: 1.3em; +} + +span.linkdescr { + text-align: left; + padding-top: 5px; + font-size: 90%; +} + +/* -- general index --------------------------------------------------------- */ + +table.indextable td { + text-align: left; + vertical-align: top; +} + +table.indextable dl, table.indextable dd { + margin-top: 0; + margin-bottom: 0; +} + +table.indextable tr.pcap { + height: 10px; +} + +table.indextable tr.cap { + margin-top: 10px; + background-color: #f2f2f2; +} + +img.toggler { + margin-right: 3px; + margin-top: 3px; + cursor: pointer; +} + +/* -- general body styles --------------------------------------------------- */ + +a.headerlink { + visibility: hidden; +} + +h1:hover > a.headerlink, +h2:hover > a.headerlink, +h3:hover > a.headerlink, +h4:hover > a.headerlink, +h5:hover > a.headerlink, +h6:hover > a.headerlink, +dt:hover > a.headerlink { + visibility: visible; +} + +div.body p.caption { + text-align: inherit; +} + +div.body td { + text-align: left; +} + +.field-list ul { + padding-left: 1em; +} + +.first { + margin-top: 0 !important; +} + +p.rubric { + margin-top: 30px; + font-weight: bold; +} + +/* -- sidebars -------------------------------------------------------------- */ + +div.sidebar { + margin: 0 0 0.5em 1em; + border: 1px solid #ddb; + padding: 7px 7px 0 7px; + background-color: #ffe; + width: 40%; + float: right; +} + +p.sidebar-title { + font-weight: bold; +} + +/* -- topics ---------------------------------------------------------------- */ + +div.topic { + border: 1px solid #ccc; + padding: 7px 7px 0 7px; + margin: 10px 0 10px 0; +} + +p.topic-title { + font-size: 1.1em; + font-weight: bold; + margin-top: 10px; +} + +/* -- admonitions ----------------------------------------------------------- */ + +div.admonition { + margin-top: 10px; + margin-bottom: 10px; + padding: 7px; +} + +div.admonition dt { + font-weight: bold; +} + +div.admonition dl { + margin-bottom: 0; +} + +p.admonition-title { + margin: 0px 10px 5px 0px; + font-weight: bold; +} + +div.body p.centered { + text-align: center; + margin-top: 25px; +} + +/* -- tables ---------------------------------------------------------------- */ + +table.docutils { + border: 0; + border-collapse: collapse; +} + +table.docutils td, table.docutils th { + padding: 2px 8px 2px 8px; + border-top: 0; + border-left: 0; + border-right: 0; + border-bottom: 1px solid #aaa; +} + +table.field-list td, table.field-list th { + border: 0 !important; +} + +table.footnote td, table.footnote th { + border: 0 !important; +} + +th { + text-align: left; + padding-right: 5px; +} + +/* -- other body styles ----------------------------------------------------- */ + +dl { + margin-bottom: 15px; +} + +dd p { + margin-top: 0px; +} + +dd ul, dd table { + margin-bottom: 10px; +} + +dd { + margin-top: 3px; + margin-bottom: 10px; + margin-left: 30px; +} + +dt:target, .highlight { + background-color: #fbe54e; +} + +dl.glossary dt { + font-weight: bold; + font-size: 1.1em; +} + +.field-list ul { + margin: 0; + padding-left: 1em; +} + +.field-list p { + margin: 0; +} + +.refcount { + color: #060; +} + +.optional { + font-size: 1.3em; +} + +.versionmodified { + font-style: italic; +} + +.system-message { + background-color: #fda; + padding: 5px; + border: 3px solid red; +} + +.footnote:target { + background-color: #ffa +} + +/* -- code displays --------------------------------------------------------- */ + +pre { + overflow: auto; +} + +td.linenos pre { + padding: 5px 0px; + border: 0; + background-color: transparent; + color: #aaa; +} + +table.highlighttable { + margin-left: 0.5em; +} + +table.highlighttable td { + padding: 0 0.5em 0 0.5em; +} + +tt.descname { + background-color: transparent; + font-weight: bold; + font-size: 1.2em; +} + +tt.descclassname { + background-color: transparent; +} + +tt.xref, a tt { + background-color: transparent; + font-weight: bold; +} + +h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt { + background-color: transparent; +} + +/* -- math display ---------------------------------------------------------- */ + +img.math { + vertical-align: middle; +} + +div.math p { + text-align: center; +} + +span.eqno { + float: right; +} + +/* -- printout stylesheet --------------------------------------------------- */ + +@media print { + div.document, + div.documentwrapper, + div.bodywrapper { + margin: 0; + width: 100%; + } + + div.sphinxsidebar, + div.related, + div.footer, + #top-link { + display: none; + } +} diff --git a/doc/_static/bindingexample.tar.bz2 b/doc/_static/bindingexample.tar.bz2 new file mode 100644 index 000000000..bf1fdea66 Binary files /dev/null and b/doc/_static/bindingexample.tar.bz2 differ diff --git a/doc/_static/default.css b/doc/_static/default.css new file mode 100644 index 000000000..721ceb71b --- /dev/null +++ b/doc/_static/default.css @@ -0,0 +1,248 @@ +/** + * Sphinx stylesheet -- default theme + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +@import url("basic.css"); + +/* -- page layout ----------------------------------------------------------- */ + +body { + font-family: sans-serif; + font-size: 100%; + background-color: #000000; + color: #000; + margin: 0; + padding: 0; +} + +div.document { + background-image:url(images/side_background.jpg); + background-repeat:repeat-y; + background-color:#ffd800; +} + +div.body { + position:relative; + background-color:#fff; + color: #000000; + padding: 0 20px 30px 20px; +} + +div.footer { + color: #ffffff; + width: 100%; + padding: 9px 0 9px 0; + text-align: center; + font-size: 75%; +} + +div.footer a { + color: #ffffff; + text-decoration: underline; +} + +div.related { + background-image:url(images/top_background.jpg); + background-repeat:repeat-x; + background-color: #d7aa00; + line-height:33px; + height:33px; + color: #000000; +} + +div.related a { + color: #000000; +} + +div.related img { + padding-top:3px; +} + +div.sphinxsidebar { +} + +div.sphinxsidebar h3 { + font-family: Arial, Verdana, sans-serif; + color: #000000; + font-size: 1.4em; + font-weight: normal; + margin: 0; + padding: 0; +} + +div.sphinxsidebar h3 a { + color: #000000; +} + +div.sphinxsidebar h4 { + font-family: Arial, Verdana, sans-serif; + color: #000000; + font-size: 1.3em; + font-weight: normal; + margin: 5px 0 0 0; + padding: 0; +} + +div.sphinxsidebar p { + color: #ffffff; +} + +div.sphinxsidebar p.topless { + margin: 5px 10px 10px 10px; +} + +div.sphinxsidebar ul { + margin: 10px; + padding: 0; + color: #ffffff; +} + +div#searchbox p.searchtip { + color:#000000; + font-size:90%; + padding-top:50px; +} + +div#searchbox { + background-image:url(images/background_search.jpg); + background-repeat:no-repeat; + background-position:center; + border:none; +} + +div.sphinxsidebar a { + color: #009491; +} + + +/* -- body styles ----------------------------------------------------------- */ + +a { + color: #009491; + text-decoration: underline; +} + +a:hover { + text-decoration: underline; +} + +div.body p, div.body dd, div.body li { + text-align: left; + line-height: 130%; +} + +div.body h1 { + font-family: Arial, Verdana, sans-serif; + background-color: #f2f2f2; + font-weight: normal; + color: #20435c; + border-bottom: 1px solid #ccc; + margin: 20px -20px 10px -20px; + padding: 3px 0 3px 10px; +} + +div.body h2, +div.body h3, +div.body h4, +div.body h5, +div.body h6 { + font-family: Arial, Verdana, Helvetica, sans-serif; + font-size:12px; + font-weight:normal; + border-left-width: 1px; + border-right-width: 1px; + border-top-width: 1px; + border-bottom-width: 2px; + border-style: solid; + border-left-color: #b1b1b1; + border-right-color: #b1b1b1; + border-top-color: #b1b1b1; + border-bottom-color: #009491; + background-color: #e0e0e0; + padding-left:5px; +} + +div.body h1 { margin-top: 0; font-size: 200%; } +div.body h2 { font-size: 120%; } +div.body h3 { font-size: 115%; } +div.body h4 { font-size: 110%; } +div.body h5 { font-size: 105%; } +div.body h6 { font-size: 100%; } + +a.headerlink { + color: #c60f0f; + font-size: 0.8em; + padding: 0 4px 0 4px; + text-decoration: none; +} + +a.headerlink:hover { + background-color: #c60f0f; + color: white; +} + +div.body p, div.body dd, div.body li { + text-align: left; + line-height: 130%; +} + +div.admonition p.admonition-title + p { + display: inline; +} + +div.note { + background-color: #eee; + border: 1px solid #ccc; +} + +div.seealso { + background-color: #ffc; + border: 1px solid #ff6; +} + +div.topic { + background-color: #eee; +} + +div.warning { + background-color: #ffe4e4; + border: 1px solid #f66; +} + +p.admonition-title { + display: inline; +} + +p.admonition-title:after { + content: ":"; +} + +input[type=text]{ + background-color: #009491; + font: 11px verdana, arial, helvetica, sans-serif; + color:#FFFFFF; + width: 150px; + height: 18px; + border: 1px solid #009491; + margin-left:13px; + margin-top:15px; + margin-bottom:4px; + border:none; +} + +pre { + padding: 5px; + background-color: #eeffcc; + color: #333333; + line-height: 120%; + border: 1px solid #ac9; + border-left: none; + border-right: none; +} + +tt { + background-color: #ecf0f3; + padding: 0 1px 0 1px; + font-size: 0.95em; +} diff --git a/doc/_static/images/._background_search.jpg b/doc/_static/images/._background_search.jpg new file mode 100755 index 000000000..d5c689c31 Binary files /dev/null and b/doc/_static/images/._background_search.jpg differ diff --git a/doc/_static/images/._bread_crumb.png b/doc/_static/images/._bread_crumb.png new file mode 100755 index 000000000..46b8591c6 Binary files /dev/null and b/doc/_static/images/._bread_crumb.png differ diff --git a/doc/_static/images/._button_search.jpg b/doc/_static/images/._button_search.jpg new file mode 100755 index 000000000..d5c689c31 Binary files /dev/null and b/doc/_static/images/._button_search.jpg differ diff --git a/doc/_static/images/._side_background.jpg b/doc/_static/images/._side_background.jpg new file mode 100755 index 000000000..a79b91c97 Binary files /dev/null and b/doc/_static/images/._side_background.jpg differ diff --git a/doc/_static/images/._top_background.jpg b/doc/_static/images/._top_background.jpg new file mode 100755 index 000000000..d5c689c31 Binary files /dev/null and b/doc/_static/images/._top_background.jpg differ diff --git a/doc/_static/images/background_search.jpg b/doc/_static/images/background_search.jpg new file mode 100644 index 000000000..c0481c561 Binary files /dev/null and b/doc/_static/images/background_search.jpg differ diff --git a/doc/_static/images/bg.jpg b/doc/_static/images/bg.jpg new file mode 100644 index 000000000..2ceb19583 Binary files /dev/null and b/doc/_static/images/bg.jpg differ diff --git a/doc/_static/images/bread_crumb.png b/doc/_static/images/bread_crumb.png new file mode 100644 index 000000000..f7ebd20e4 Binary files /dev/null and b/doc/_static/images/bread_crumb.png differ diff --git a/doc/_static/images/button_search.png b/doc/_static/images/button_search.png new file mode 100644 index 000000000..0160b81ab Binary files /dev/null and b/doc/_static/images/button_search.png differ diff --git a/doc/_static/images/side_background.jpg b/doc/_static/images/side_background.jpg new file mode 100644 index 000000000..6e6667542 Binary files /dev/null and b/doc/_static/images/side_background.jpg differ diff --git a/doc/_static/images/top_background.jpg b/doc/_static/images/top_background.jpg new file mode 100644 index 000000000..aafe1f72e Binary files /dev/null and b/doc/_static/images/top_background.jpg differ diff --git a/doc/_templates/index.html b/doc/_templates/index.html new file mode 100644 index 000000000..296aae27d --- /dev/null +++ b/doc/_templates/index.html @@ -0,0 +1,32 @@ +{% extends "layout.html" %} +{% set title = 'Overview' %} +{% block body %} +

BoostPythonGenerator {{ version }}

+ +

BoostPythonGenerator is a tool that eases the development of Python bindings for Qt-based + libraries by automating most of the process. It relies heavily on the ApiExtractor library + to parse the header files and manipulate the classes information while generating the code. + This generated code uses the + Boost::Python library + in order to bridge the C++ library and Python.

+ +

BoostPythonGenerator is based on the + QtScriptGenerator project.

+ +

Documentation

+ + + +
+ + + + + +
+ +{% endblock %} diff --git a/doc/_templates/layout.html b/doc/_templates/layout.html new file mode 100644 index 000000000..12fed4d0f --- /dev/null +++ b/doc/_templates/layout.html @@ -0,0 +1,34 @@ +{% extends "!layout.html" %} +{% block rootrellink %} + +
  • {{ shorttitle }}{{ reldelim1 }}
  • +{% endblock %} +{% set reldelim1 = '' %} +{% block extrahead %} + +{{ super() }} +{% endblock %} + +{% block sidebarsearch %} + + +{% endblock %} + diff --git a/doc/compiling/cmake-primer.rst b/doc/compiling/cmake-primer.rst new file mode 100644 index 000000000..7769005be --- /dev/null +++ b/doc/compiling/cmake-primer.rst @@ -0,0 +1,72 @@ + +.. _cmake-primer: + +************ +CMake primer +************ + +This chapter is a basic introduction to CMake, the build system used by PySide +and the boost binding generator. + +The practical steps will focus on how to use cmake on a Unix-like (GNU/Linux) +environment. + + +Configuring +=========== + +Project file - CMakeLists.txt +----------------------------- + +CMake parses the file CMakeLists.txt for information about the project, +like project name, dependencies, what should be compiled, what should be +shipped. + + +CMake variables +--------------- + +CMake can have its default behavior modified by providing some + +* ``CMAKE_INSTALL_PREFIX=`` sets the install prefix to + the specified path. +* ``CMAKE_MODULE_PATH=`` sets the extra directories + where CMake will try to find its modules. +* ``CMAKE_TOOLCHAIN_FILE=`` sets the path to the file that + describes the toolchain used to compile this project. It is very useful + when using CMake with icecc to speedup compilation. + +You can define a variable using the ``-D`` switch like the example +below. + +* ``-DCMAKE_BUILD_TYPE=Release|Debug`` sets the building behavior. Default + value is *Release*. + +Invoking CMake +-------------- + +After writing the CMakeLists.txt and deciding which flags will be used, +you can invoke CMake using:: + + cmake + +For example, if you use the ``build/`` folder to build the project and +want it to be installed into ``/opt/sandbox/``, use the following lines:: + + cd build/ + cmake -DCMAKE_INSTALL_PREFIX=/opt/sandbox .. + +CMake will process the project file and write the output files in the +current directory + +Building +======== + +After the configuration process, the Makefiles are written and you can build +the project using :program:`make`. + +Installing +========== + +As in the building process, ``make install`` will install the files into +the target directory. diff --git a/doc/compiling/compiling.rst b/doc/compiling/compiling.rst new file mode 100644 index 000000000..638efa91a --- /dev/null +++ b/doc/compiling/compiling.rst @@ -0,0 +1,9 @@ +Compiling +********* + +.. toctree:: + :maxdepth: 3 + + cmake-primer + setup-apiextractor + setup-generator diff --git a/doc/compiling/setup-apiextractor.rst b/doc/compiling/setup-apiextractor.rst new file mode 100644 index 000000000..5443f46ea --- /dev/null +++ b/doc/compiling/setup-apiextractor.rst @@ -0,0 +1,48 @@ + +.. _api-extractor: + +************** +API Extractor +************** + +Overview +======== + +The **API Extractor** library is used by the binding generator to +parse the header and typesystem files to create an internal +representation of the API. It is based on the QtScriptGenerator +codebase. + +Getting the sources +=================== + +* Download URL: http://www.pyside.org/downloads/ + +Build requirements +================== + +* Qt4.5 development headers and libraries >= 4.5.0 +* libboost-graph >= 1.38.0 +* cmake >= 2.6.0 + +Building and installing +======================= + +To build and install just follow the generic cmake instructions in section +:ref:`cmake-primer`. + +Debian packaging +================ + +In order to compile this package in a debian environment, make sure the +following packages are installed: + +* debhelper (>= 5) +* cdbs +* cmake (>= 2.6.0) +* libboost-graph1.38-dev (>= 1.38.0) +* libqt4-dev (>= 4.5) + +And then you can build the package using:: + + $ dpkg-buildpackage -rfakeroot diff --git a/doc/compiling/setup-generator.rst b/doc/compiling/setup-generator.rst new file mode 100644 index 000000000..d58f98368 --- /dev/null +++ b/doc/compiling/setup-generator.rst @@ -0,0 +1,49 @@ + +.. _boost-python-generator: + +*********************** +Boost::Python Generator +*********************** + +Overview +========================================= + +The **Boost::Python Generator** (A.K.A. :program:`boostpythongenerator`) is +the program that creates the bindings source files from Qt headers and +auxiliary files (typesystems, ``global.h`` and glue files). It makes +heavy use of the :ref:`api-extractor` library. + + +Getting the sources +=================== + +* Download URL: http://www.pyside.org/downloads/ + +Build requirements +================== + ++ CMake >= 2.6.0 ++ Qt4.5 libraries and development headers >= 4.5.0 ++ :ref:`api-extractor` + development headers + +Building and installing +======================= + +To build and install just follow the generic cmake instructions in +section :ref:`cmake-primer`. + +Debian packaging +================ + +In order to compile this package in a debian environment, make sure the +following packages are installed: + +* debhelper (>= 5) +* cdbs +* cmake (>= 2.6.0) +* libqt4-dev (>= 4.5) +* libapiextractor-dev (>= 0.1) + +And then you can build the package using:: + + $ dpkg-buildpackage -rfakeroot diff --git a/doc/conf.py b/doc/conf.py new file mode 100644 index 000000000..8d196e455 --- /dev/null +++ b/doc/conf.py @@ -0,0 +1,188 @@ +# -*- coding: utf-8 -*- +# +# BoostPythonGenerator documentation build configuration file, created by +# sphinx-quickstart on Wed Apr 22 15:04:20 2009. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys, os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.append(os.path.abspath('.')) + +# -- General configuration ----------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.ifconfig', 'sphinx.ext.refcounting', 'sphinx.ext.coverage'] + +rst_epilog = """ +.. |project| replace:: BoostPythonGenerator +""" + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +source_encoding = 'utf-8' + +# The master toctree document. +#master_doc = 'contents' + +# General information about the project. +project = u'BoostPythonGenerator' +copyright = u'2009, Nokia Corporation' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '0.1' +# The full version, including alpha/beta/rc tags. +release = '0.1' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of documents that shouldn't be included in the build. +#unused_docs = [] + +# List of directories, relative to source directory, that shouldn't be searched +# for source files. +exclude_trees = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. Major themes that come with +# Sphinx are currently 'default' and 'sphinxdoc'. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = { +#} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = { '' : ''} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +html_additional_pages = { 'index' : 'index.html'} + +# If false, no module index is generated. +#html_use_modindex = True + +# If false, no index is generated. +html_use_index = True + +# If true, the index is split into individual pages for each letter. +html_split_index = False + +# If true, links to the reST sources are added to the pages. +html_show_sourcelink = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = '' + +# -- Options for LaTeX output -------------------------------------------------- + +# The paper size ('letter' or 'a4'). +#latex_paper_size = 'letter' + +# The font size ('10pt', '11pt' or '12pt'). +#latex_font_size = '10pt' + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# Additional stuff for the LaTeX preamble. +#latex_preamble = '' + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_use_modindex = True diff --git a/doc/contents.rst b/doc/contents.rst new file mode 100644 index 000000000..5574c7ac1 --- /dev/null +++ b/doc/contents.rst @@ -0,0 +1,9 @@ +Table of contents +***************** +.. toctree:: + :numbered: + :maxdepth: 3 + + overview.rst + tutorial/introduction.rst + compiling/compiling.rst diff --git a/doc/dependency-pyside.svg b/doc/dependency-pyside.svg new file mode 100644 index 000000000..786bdb8a6 --- /dev/null +++ b/doc/dependency-pyside.svg @@ -0,0 +1,527 @@ + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + boost::python + 1.38.0 + headers and libraries - compile-time and run-time + Boost Software License 1.0 + + + + Qt 4.5 + 4.5 + headers and libraries - compile-time and run-time + GNU General Public License v3 /GNU Lesser General Public Licence v2.1 + + + + libapiextractor + 0.1 + headers and libraries - compile-time and run-time + LGPL version 2.1 + + + + BoostPythonGenerator + 0.1 + Binary executable - compile-time + LGPL version 2.1 + + + + Qt Python bindings + 0.1 + Target + LGPL version 2.1 + + + + boost::graph + 1.38.0 + headers and libraries - compile-time and run-time + Boost Software License 1.0 + + + + + + + + + Boost + Qt Software + INdT/Nokia + + + + + diff --git a/doc/images/.directory b/doc/images/.directory new file mode 100644 index 000000000..e65475f65 --- /dev/null +++ b/doc/images/.directory @@ -0,0 +1,3 @@ +[Dolphin] +ShowPreview=true +Timestamp=2009,5,5,17,43,26 diff --git a/doc/images/bindinggen-development.png b/doc/images/bindinggen-development.png new file mode 100644 index 000000000..3d64e7641 Binary files /dev/null and b/doc/images/bindinggen-development.png differ diff --git a/doc/images/bindinggen-development.svg b/doc/images/bindinggen-development.svg new file mode 100644 index 000000000..3b6b3a26e --- /dev/null +++ b/doc/images/bindinggen-development.svg @@ -0,0 +1,543 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + Qt bindings(generated code) + + + + generatorfront-end + + + + + + + + + + + + + API Extractor + + + + 1 + + + + 2 + + + + + + + + + + + typesystem(handwritten) + + + + + + + + + + + injected code(handwritten) + + + + 3 + + + + 4 + + + + diff --git a/doc/images/boostgenarch.png b/doc/images/boostgenarch.png new file mode 100644 index 000000000..001b84435 Binary files /dev/null and b/doc/images/boostgenarch.png differ diff --git a/doc/images/boostgenarch.svg b/doc/images/boostgenarch.svg new file mode 100644 index 000000000..8a5f74b0b --- /dev/null +++ b/doc/images/boostgenarch.svg @@ -0,0 +1,711 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + API Extractor (Generator Back-End) + + + TypeDatabaseparses typesystemand stores information + + + + Parserparses thelib headers + + + + ApiExtractorcommands the parsing andbuilding of the data modeland calls the user generators + + + + Generatorbase class for front-endoutput classes + + + boostpythongenerator (Front-End) + + + + BoostGeneratorcommon functionalityfor all generators + + + + + + + + + + + + + + + + + CppGeneratorwrites main body of codefor the binding classes + + + + ConverterGeneratorwrites converters for classeswith Python equivalents + + + + HppGeneratorwrites headers for thebinding classes + + + + + + + + + + + + + + + + + + + + + + + + + + + AbstractMetaBuilderbuilds the data model with informationfrom headers and binding directives + + + + diff --git a/doc/images/boostqtarch.png b/doc/images/boostqtarch.png new file mode 100644 index 000000000..a82f97088 Binary files /dev/null and b/doc/images/boostqtarch.png differ diff --git a/doc/images/boostqtarch.svg b/doc/images/boostqtarch.svg new file mode 100644 index 000000000..9fbb38271 --- /dev/null +++ b/doc/images/boostqtarch.svg @@ -0,0 +1,226 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + Boost::Pythonhelper library to interface with CPython APIand expose C++ entities to Python + + + + Qt-Python BindingsQt classes and functionsexported to Python + + + + + CPythonAPI + + + + Qt4Libraries + + + + + diff --git a/doc/overview.rst b/doc/overview.rst new file mode 100644 index 000000000..122019760 --- /dev/null +++ b/doc/overview.rst @@ -0,0 +1,46 @@ +.. _gen-overview: + +****************** +Generator Overview +****************** + +In a few words, the Generator is a utility that parses a collecion of header and +typesystem files, generating other files (code, documentation, etc.) as result. + +Creating new bindings +===================== + +.. figure:: images/bindinggen-development.png + :scale: 80 + :align: center + + Creating new bindings + +Each module of the generator system has an specific role. + +1. Provide enough data about the classes and functions. +2. Generate valid code, with modifications from typesystems and injected codes. +3. Modify the API to expose the objects in a Python-friendly way. +4. Insert customizations where handwritten code is needed. + +.. figure:: images/boostqtarch.png + :scale: 80 + :align: center + + Runtime architecture + +The newly created binding will run on top of Boost.Python library which takes +care of interfacing Python and the underlying C++ library. + +Handwritten inputs +================== + +Creating new bindings involves creating two pieces of "code": the typesystem and +the inject code. + +:typesystem: XML files that provides the developer with a tool to customize the + way that the generators will see the classes and functions. For + example, functions can be renamed, have its signature changed and + many other actions. +:inject code: allows the developer to insert handwritten code where the generated + code is not suitable or needs some customization. diff --git a/doc/tutorial/bindinglibfoo.rst b/doc/tutorial/bindinglibfoo.rst new file mode 100644 index 000000000..87b7e482a --- /dev/null +++ b/doc/tutorial/bindinglibfoo.rst @@ -0,0 +1,77 @@ +.. highlight:: xml + +.. _gentut-bindinglibfoo: + +Binding libfoo with the Generator +================================= + +In order to create bindings for a library based on Qt4 a number of components +must be available on the system. + + + Qt4 library (with headers and pkg-config .pc files for development -- the + ``-dev`` packages in a Debian distribution). + + Qt4 Python bindings made with :program:`boostpythongenerator`. + + Typesystems for the Qt4 Python bindings. + + Headers for the library to be bound. + +With the items listed above the developer must write the components from +where the generator will gather information to create the binding source code. + + + Typesystem file describing the way the binding must be done. + + **global.h** including all the **libfoo** headers and defining required macros. + + A build system to direct the process of generating, compiling and linking the + binding. + +The directory structure for the binding project could be something like the tree +shown below: + +:: + + foobinding/ + |-- data/ + `-- module_dir/ + `-- glue/ + + +The **data** directory should contain the **global.h** and the typesystem +file. This typesystem need to refer to the ones used to create the Qt4 bindings, +commonly located on **/usr/share/PySide/typesystem**, the exact location +can be checked with pkg-config: + +:: + + $ pkg-config pyside --variable=typesystemdir + + +The **module_dir** directory is the place where the sources generated should +be placed. It starts empty except for the build instructions file (Makefile, +Makefile.am, CMakeLists.txt, etc). The realname of this directory must be the +same written in the typesystem file: + +:: + + + + +If there is any need for handwritten source code longer than a couple of lines, +making them unconfortable to be put on the typesystem xml file, the sources +could be orderly placed in a **glue** directory, also referred in the +new binding typesystem. + +When writing the typesystem file (more on this later) there is no need to refer +to the other required typesystem files with absolute paths, the locations where +they can be found could be passed to the generator through a command line +option (``--typesystem-paths=PATH1:PATH2:[...]``) or the environment variable +**TYPESYSTEMPATH**. + +For **libfoo** no glue code will be needed so this directory is not used, +the other directories are created with proper names. + +:: + + foobinding/ + |-- data/global.h + | `-- typesystem_foo.xml + `-- foo/ + `-- Makefile + diff --git a/doc/tutorial/buildingthebinding.rst b/doc/tutorial/buildingthebinding.rst new file mode 100644 index 000000000..b5bec28e3 --- /dev/null +++ b/doc/tutorial/buildingthebinding.rst @@ -0,0 +1,132 @@ +.. _gentut-buildingthebinding: + +Building The Binding +==================== + +As mentioned before the build system used must perform the following tasks +in the correct order: + + + Gather data about locations of headers and external needed typesystems. + + Run the generator with the correct parameters. + + Compile and link the binding. + +The first and last are the usual, being the second the only novelty in the +process. + +Running the Generator +--------------------- + +The generator is called with the following parameters and options: + +:: + + $ boostpythongenerator global_headers.h \ + --include-paths=$(PATHS_TO_HEADERS)) \ + --typesystem-paths=$(PATHS_TO_TYPESYSTEMS) \ + --output-directory=. \ + typesystem.xml + +Notice that the variables for include and typesystem paths could be determined +at build time with the pkg-config tool. + +Collecting information with pkg-config +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The Qt4 bindings include compile and build information through the pkg-config +mechanism. The pkg-config name for Qt4 Python bindings is **pyside** and a +simple ``pkg-config pyside --cflags --libs`` will retrieve the information +needed to build the new binding. + +The Qt4 bindings file ``pyside.pc`` for the use of pkg-config requires +the ``.pc`` files from Qt4 to be installed. If the library is in an unusual +location, e.g. ``/opt/qt45``, remember to export it to the ``PKG_CONFIG_PATH`` +environment variable. +For example: ``export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/qt45/lib/pkgconfig`` + +There is a vital information also available through pkg-config: +the **typesystemdir** variable. It is used like this: +``pkg-config pyside --variable=typesystemdir`` This provides information +where to find the typesystem files used to create the Qt4 bindings, and as said +before the binding being created needs this to complement its own binding +information for the generation proccess. + +Makefile +-------- + +Below is a plain Makefile for the binding project. + +**foobinding/foo/Makefile** +:: + + LIBFOO_DIR = ../../libfoo + LIBS = -lboost_python `python-config --libs` \ + `pkg-config pyside --libs` \ + -lfoo -L$(LIBFOO_DIR) \ + -lpthread -ldl -lutil + CXXFLAGS = -I/usr/share/qt4/mkspecs/linux-g++ -I. \ + -I$(LIBFOO_DIR) \ + `pkg-config pyside --cflags` \ + -I`python-config --includes` \ + -I/usr/include/boost/python + QT4TYPESYSTEM_DIR = `pkg-config --variable=typesystemdir pyside` + QT4HEADER_DIRS = `pkg-config --variable=includedir QtCore`:`pkg-config --variable=includedir QtCore`/.. + + SOURCES = foo_globals_wrapper.cpp foo_module_wrapper.cpp math_wrapper.cpp + OBJECTS = foo_globals_wrapper.o foo_module_wrapper.o math_wrapper.o + + all: generate compile link + + generate: + boostpythongenerator ../data/global.h \ + --include-paths=$(LIBFOO_DIR):$(QT4HEADER_DIRS):/usr/include \ + --typesystem-paths=../data:$(QT4TYPESYSTEM_DIR) \ + --output-directory=.. \ + ../data/typesystem_foo.xml + + compile: $(SOURCES) + g++ -Wall -fPIC -DPIC $(CXXFLAGS) -c foo_globals_wrapper.cpp + g++ -Wall -fPIC -DPIC $(CXXFLAGS) -c foo_module_wrapper.cpp + g++ -Wall -fPIC -DPIC $(CXXFLAGS) -c math_wrapper.cpp + + link: + g++ -shared -Wl,-soname,foo.so -o foo.so $(LIBS) $(OBJECTS) + + test: + LD_LIBRARY_PATH=$(LIBFOO_DIR):$LD_LIBRARY_PATH python -c \ + "import PySide.QtCore; import foo; print dir(foo); m = foo.Math(); print \"5 squared is %d\" % m.squared(5)" + + clean: + rm -rf *.o *.so *.?pp *.log + + +Keep in mind that the Makefile above expects the ``libfoo`` and +``foobinding`` directories to be in the same level in the directory +hierarchy, remember to change any path references accordingly if +you choose to change things. + +**Warning:** + The order in which the link flags are passed matters. + **libboost_python** must come first, otherwise weeping + and gnashing of teeth will follow. + +Testing the Binding +------------------- +Now compile the binding with ``make``: + +:: + + $ cd foobinding/foo + $ make + +To test if the new binding is working (it can pass the build phase but still +blow up at runtime) start up a Python terminal and import it by the name. + +:: + + $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/libfoo/shared/object/dir + $ export PYTHONPATH=$PYTHONPATH:/path/to/foo/python/module/file/dir + $ python + >> import foo + >> print dir(foo) + >> m = foo.Math() + >> print m.squared(5) diff --git a/doc/tutorial/globalheader.rst b/doc/tutorial/globalheader.rst new file mode 100644 index 000000000..d1ac2392e --- /dev/null +++ b/doc/tutorial/globalheader.rst @@ -0,0 +1,36 @@ +.. highlight:: cpp + +.. _gentut-globalheader: + +The Global Header +================= + +Besides the information provided by the typesystem, the generator needs to +gather more data from the library headers containing the classes to be exposed +in Python. If there is a header that include all the others (or just one, as is +the case of **libfoo**) this could be passed directly to the generator. + +If such a file is not available, or only a subset of the library is desired, or +if some flags must be defined before parsing the library headers, then a +``global.h`` file must be provided. + +The use of a ``global.h`` file is preferred if some macros must be defined +before the parser gather data from the headers. For example, if ``NULL`` is not +defined and it is used as a default paramater for some constructor or method, +the parser will not recognize it. + +The solve this create a ``global.h`` including all the desired headers and the +defined (and undefined) flags as follows: + +**foobinding/data/global.h** +:: + + #undef QT_NO_STL + #undef QT_NO_STL_WCHAR + + #ifndef NULL + #define NULL 0 + #endif + + #include + diff --git a/doc/tutorial/images/generatorworkings.png b/doc/tutorial/images/generatorworkings.png new file mode 100644 index 000000000..d35a565ff Binary files /dev/null and b/doc/tutorial/images/generatorworkings.png differ diff --git a/doc/tutorial/images/generatorworkings.svg b/doc/tutorial/images/generatorworkings.svg new file mode 100644 index 000000000..85a7782af --- /dev/null +++ b/doc/tutorial/images/generatorworkings.svg @@ -0,0 +1,392 @@ + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + bindingsource code + + + + + + + typesystemdescriptions + + + + customsourcecode + + + + + + libraryheaders + + + + + + Parser + + + + GeneratorBackend + + + + TypeDatabase + + + + + diff --git a/doc/tutorial/introduction.rst b/doc/tutorial/introduction.rst new file mode 100644 index 000000000..62372af1b --- /dev/null +++ b/doc/tutorial/introduction.rst @@ -0,0 +1,32 @@ +Binding Generation Tutorial +*************************** + +This tutorial intends to describe the process of binding creation with +BoostPythonGenerator and using a very simple Qt4 based library will be used as an +example. + +The image below shows the inputs needed to generate the binding source code. + +.. image:: images/generatorworkings.png + +Putting in words, the user provides the headers for the library along with a +typesystem file describing how the classes will be exposed in the target +language, as well as any needed custom source code to be merged with +the generated source code. + +This tutorial will go through the steps needed to have the binding +being able to be imported and used from a Python program. The tutorial +source code is available as a tar ball `here <../_static/bindingexample.tar.bz2>`_. + +**NOTE:** the binding generator is intended to be used with Qt4 based libraries +only, at least for the time being. + +.. toctree:: + :maxdepth: 3 + + libfoo + bindinglibfoo + typesystemcreation + globalheader + buildingthebinding + diff --git a/doc/tutorial/libfoo.rst b/doc/tutorial/libfoo.rst new file mode 100644 index 000000000..76246570d --- /dev/null +++ b/doc/tutorial/libfoo.rst @@ -0,0 +1,68 @@ +.. highlight:: cpp + +.. _gentut-libfoo: + +Creating the foo library +========================= + +In this section it will be presented the code and the build instructions for a +very simple Qt4 based library. It will be used as the subject for this tutorial. + +The Source Code +--------------- + +There is only one class on this foo library plus a ``.pro`` file which means +that the build system used will be Trolltech's **qmake**. + +Put the files below in a directory called **libfoo**. Be aware that this +directory will be refered by the binding Makefile presented in a next section +of this tutorial. If you want to use other names or paths change the binding +Makefile accordingly. Blind copy'n'paste shortens your life. + +**libfoo/foo.h** +:: + + #ifndef FOO_H + #define FOO_H + + #include + + class Math : public QObject + { + Q_OBJECT + public: + Math() {} + virtual ~Math() {} + int squared(int x); + }; + #endif // FOO_H + + +**libfoo/foo.cpp** +:: + + #include "foo.h" + + int Math::squared(int x) + { + return x * x; + } + + +**libfoo/foo.pro** +:: + + TEMPLATE = lib + TARGET = foo + DEPENDPATH += . + INCLUDEPATH += . + HEADERS += foo.h + SOURCES += foo.cpp + +To build the lib: + +:: + + $ cd libfoo + $ qmake + $ make diff --git a/doc/tutorial/typesystemcreation.rst b/doc/tutorial/typesystemcreation.rst new file mode 100644 index 000000000..ae33ccb9e --- /dev/null +++ b/doc/tutorial/typesystemcreation.rst @@ -0,0 +1,135 @@ +.. highlight:: xml + +.. _gentut-typesystem: + +Creating the Typesystem Description +=================================== + +The typesystem is an specification used when mapping a C++ based library onto a +corresponding Python module. The specification is a handwritten XML document +listing the types that will be available in the generated binding, alterations +to classes and function signatures to better suit the target language, +and listing the components that should be rejected for the binding. + +**PySide** uses a typesystem format similar to the ones used by **QtJambi** and +**QtScript**, thoroughly described in the page *"The Qt Jambi Type System"*. [#]_ + +The divergences between **PySide** and QtScript/QtJambi typesystems will be +highlighted whenever they appear. Things to be aware of when writing +a typesystem will be also mentioned. + +Describing **libfoo** for Python Audiences +------------------------------------------ + +All typesystem files start with the root ``typesystem`` tag. The +``package`` attribute carries the name of the package as it will be seen +from Python. + +Right after that, all the typesystem files providing information required for +the generation process are included in the same fashion as header files in C. + +**foobinding/data/typesystem_foo.xml** +:: + + + + + + + + +The inclusion of other typesystem files is achieved with the +``load-typesystem`` tag. The ``generate`` attribute must be set to ``"no"`` +otherwise the generator will try to create more source code for the already +existing bindings included for reference. + +The C++ classes derived from **QObject** intended to be exposed in the target +language are described with ``object-type`` tags. + + +For this example binding just specifying the name of the class does the trick, +since the generator system will automatically catch the methods with arguments +and return value of types known. These types can be described in the same +typesystem file or in the ones referenced with the ``load-typesystem`` tag. + +In more complex situations method signatures can be changed or rejected with +other tags that can be checked out in the typesystem reference. + + +Other Common Cases and Differences +---------------------------------- + +What follows now is some common uses of the typesystem capabilities. All of them +can be seen in the Qt4 typesystem files. They are not used for this binding +tutorial example, so if you just want to have things working ASAP, move along. + +Templates +~~~~~~~~~ + +To ease the process of writing custom code for the binding, recurring pieces of +code can be turned generic with the typesystem template mechanism. +They are declared in a way similar to this snippet: + +:: + + + +And is used as in this example: + +:: + + + + + + +The ``typesystem_template.xml`` file from the Qt4 bindings can be used as a +good resource for examples of this. Check also the QtJambi documentation on +typesystem templates. [#]_ + +Non-QObject Derived Classes +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Even in a Qt4 based library it is common to find classes that doesn't +pertain to the QObject hierarchy, these must be declared as ``value-type``: + +:: + + + + +Unused Tags +~~~~~~~~~~~ + +Some tags defined in the QtScript/QtJambi typesystem has no effect in **PySide** +typesystem, they are: + + + conversion-rule + + argument-map + +Changes to ``"inject-code"`` Tag +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can pass a file name to the **inject-code** tag so the file contents will +be injected in the generated code. + +The ``class`` attribute value ``java`` was changed to ``target``, while +``native`` remained the same. + +Global Functions +~~~~~~~~~~~~~~~~ + +The BoostPythonGenerator supports global functions, you can also reject these functions using +the **rejection** tag like is done to reject classes. Just pass an empty string to +the class attribute. + +:: + + + + +.. [#] http://doc.trolltech.com/qtjambi-4.4/html/com/trolltech/qt/qtjambi-typesystem.html +.. [#] http://doc.trolltech.com/qtjambi-4.4/html/com/trolltech/qt/qtjambi-typesystem.html#using-code-templates -- cgit v1.2.3