##// END OF EJS Templates
improved docs...
florianlink -
r147:83df95056589
parent child
Show More
@@ -1,522 +1,525
1 1 #ifndef _PYTHONQTDOC_H
2 2 #define _PYTHONQTDOC_H
3 3
4 4 /*
5 5 *
6 6 * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved.
7 7 *
8 8 * This library is free software; you can redistribute it and/or
9 9 * modify it under the terms of the GNU Lesser General Public
10 10 * License as published by the Free Software Foundation; either
11 11 * version 2.1 of the License, or (at your option) any later version.
12 12 *
13 13 * This library is distributed in the hope that it will be useful,
14 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 16 * Lesser General Public License for more details.
17 17 *
18 18 * Further, this software is distributed without any warranty that it is
19 19 * free of the rightful claim of any third person regarding infringement
20 20 * or the like. Any license provided herein, whether implied or
21 21 * otherwise, applies only to this software file. Patent licenses, if
22 22 * any, provided herein do not apply to combinations of this program with
23 23 * other software, or any other product whatsoever.
24 24 *
25 25 * You should have received a copy of the GNU Lesser General Public
26 26 * License along with this library; if not, write to the Free Software
27 27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 28 *
29 29 * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29,
30 30 * 28359 Bremen, Germany or:
31 31 *
32 32 * http://www.mevis.de
33 33 *
34 34 */
35 35
36 36 //----------------------------------------------------------------------------------
37 37 /*!
38 38 // \file PythonQtDoc.h
39 39 // \author Florian Link
40 40 // \author Last changed by $Author: florian $
41 41 // \date 2006-10
42 42 */
43 43 //----------------------------------------------------------------------------------
44 44
45 45 /*!
46 46 \if USE_GLOBAL_DOXYGEN_DOC
47 47 \page PythonQtPage PythonQt Overview
48 48 \else
49 49 \mainpage notitle
50 50 \endif
51 51
52 52 \image html PythonQt.jpg
53 53
54 54 \section Introduction
55 55
56 \b PythonQt is a dynamic Python (http://www.python.org) binding for the Qt framework (http://qt.nokia.com).
56 \b PythonQt is a dynamic <a href="http://www.python.org" target="_blank">
57 Python</a> binding for the <a href="http://qt.nokia.com" target="_blank">
58 Qt framework</a>.
57 59 It offers an easy way to embed the Python scripting language into
58 60 your C++ Qt applications. It makes heavy use of the QMetaObject system and thus requires Qt 4.x.
59 61
60 62 The focus of PythonQt is on embedding Python into an existing C++ application, not on writing the whole
61 63 application completely in Python. If you want to write your whole application in Python,
62 you should use <a href="http://www.riverbankcomputing.co.uk/pyqt/">PyQt</a> or <a href="http://www.pyside.org">PySide</a> instead.
64 you should use <a href="http://www.riverbankcomputing.co.uk/pyqt/" target="_blank">PyQt</a> or <a href="http://www.pyside.org" target="_blank">PySide</a> instead.
63 65
64 66 If you are looking for a simple way to embed Python objects into your C++/Qt Application
65 67 and to script parts of your application via Python, PythonQt is the way to go!
66 68
67 69 PythonQt is a stable library that was developed to make the
68 Image Processing and Visualization platform MeVisLab (http://www.mevislab.de)
70 Image Processing and Visualization platform <a href="http://www.mevislab.de" target="_blank">MeVisLab</a>
69 71 scriptable from Python.
70 72
71 73 \page Features Features
72 74
73 75 \section Builtin Built-in Features
74 76
75 77 The following are the built-in features of the PythonQt library:
76 78
77 79 - Access all \b slots, \b properties, children and registered enums of any QObject derived class from Python
78 80 - Connecting Qt Signals to Python functions (both from within Python and from C++)
79 81 - Easy wrapping of Python objects from C++ with smart, reference-counting PythonQtObjectPtr.
80 82 - Convenient conversions to/from QVariant for PythonQtObjectPtr.
81 83 - Wrapping of C++ objects (which are not derived from QObject) via PythonQtCppWrapperFactory
82 84 - Extending C++ and QObject derived classes with additional slots, static methods and constructors (see Decorators)
83 85 - StdOut/Err redirection to Qt signals instead of cout
84 86 - Interface for creating your own \c import replacement, so that Python scripts can be e.g. signed/verified before they are executed (PythonQtImportFileInterface)
85 87 - Mapping of plain-old-datatypes and ALL QVariant types to and from Python
86 88 - Support for wrapping of user QVariant types which are registerd via QMetaType
87 89 - Support for Qt namespace (with all enumerators)
88 90 - All PythonQt wrapped objects support the dir() statement, so that you can see easily which attributes a QObject, CPP object or QVariant has
89 91 - No preprocessing/wrapping tool needs to be started, PythonQt can script any QObject without prior knowledge about it (except for the MetaObject information from the \b moc)
90 92 - Multiple inheritance for C++ objects (e.g. a QWidget is derived from QObject and QPaintDevice, PythonQt will automatically cast a QWidget to a QPaintDevice when needed)
91 93 - Polymorphic downcasting (if e.g. PythonQt sees a QEvent, it can downcast it depending on the type(), so the Python e.g. sees a QPaintEvent instead of a plain QEvent)
92 94 - Deriving C++ objects from Python and overwriting virtual method with a Python implementation (requires usage of wrapper generator or manual work!)
93 95 - Extensible handler for Python/C++ conversion of complex types, e.g. mapping of QVector<SomeObject> to/from a Python array
94 96 - Setting of dynamic QObject properties via setProperty(), dynamic properties can be accessed for reading and writing like normal Python attributes (but creating a new property needs to be done with setProperty(), to distinguish from normal Python attributes)
95 97
96 98 \section FeaturesQtAll Features with wrapper generator
97 99
98 100 Thanks to the new wrapper generator, PythonQt now offers the additional PythonQt_QtAll library which wraps the complete Qt API, including all C++ classes and all non-slots on QObject derived classes.
99 101 This offers the following features:
100 102
101 103 - Complete Qt API wrapped and accessible
102 104 - The following modules are available as submodules of the PythonQt module:
103 105 - QtCore
104 106 - QtGui
105 107 - QtNetwork
106 108 - QtOpenGL
107 109 - QtSql
108 110 - QtSvg
109 111 - QtUiTools
110 112 - QtWebKit
111 113 - QtXml
112 114 - (QtXmlPatterns, QtScript, QtHelp, phonon, assistant, designer are currently not supported, this would require some additional effort on the code generator)
113 115 - For convenience, all classes are also available in the PythonQt.Qt module, for people who do not care in which module a class is located
114 116 - Any Qt class that has virtual methods can be easily derived from Python and the virtual methods can be reimplemented in Python (this feature is considered experimental!)
115 117 - Polymorphic downcasting on QEvent, QGraphicsItem, QStyleOption, ...
116 118 - Multiple inheritance support (e.g., QGraphicsTextItem is a QObject AND a QGraphicsItem, PythonQt will handle this well)
117 119
120 \section Comparison Comparison with PyQt/PySide
121
122 - PythonQt is not as pythonic as PyQt in many details (e.g. buffer protocol, pickling, translation support, ...) and it is mainly thought for embedding and intercommunication between Qt/Cpp and Python
123 - PythonQt allows to communicate in both directions, e.g., calling a Python object from C++ AND calling a C++ method from Python, while PyQt only handles the Python->C++ direction
124 - PythonQt offers properties as Python attributes, while PyQt offers them as setter/getter methods (e.g. QWidget.width is a property in PythonQt and a method in PyQt)
125 - PythonQt currently does not support instanceof checks for Qt classes, except for the exact match and derived Python classes
126 - QObject.emit to emit Qt signals from Python is not yet implemented but PythonQt allows to just emit a signal by calling it like a normal slot
127 - PythonQt does not (yet) offer to add new signals to Python/C++ objects and it does not yet support the newstyle PyQt signals (so you need to connect via C++ string signatures)
128 - Ownership of objects is a bit different in PythonQt, currently Python classes derived from a C++ class need to be manually referenced in Python to not get deleted too early (this will be fixed in a future version)
129 - QStrings are always converted to unicode Python objects, QByteArray always stays a QByteArray and can be converted using str()
130 - There are many details in the generated wrappers that could need some polishing, e.g., methods that use pointer arguments for additional return values could return a results tuple.
131 - Not all types of QList/QVector/QHash templates are supported, some Qt methods use those as arguments/return values (but you can add your own handlers to handle them if you need them).
132 - Probably there are lots of details that differ, I do not know PyQt that well to list them all.
133 - In the long run, PythonQt will consider using/extending PySide with the features of PythonQt to get rid of its own generator and typesystem files, alternatively the KDE Smoke generator might be used in the future (this has not yet been decided, the current PythonQt generator works well and there is no hurry to switch).
134
118 135 \page Download Download
119 136
120 PythonQt is hosted on SourceForge at http://sourceforge.net/projects/pythonqt.
137 PythonQt is hosted on <a href="http://sourceforge.net/projects/pythonqt/" target="_blank">SourceForge</a>.
121 138
122 139 You can download the source code as a tarball at http://sourceforge.net/projects/pythonqt/files/.
123 140 Alternatively you can get the latest version from the svn repository.
124 141
125 142 You can also browse the source code online via ViewVC: http://pythonqt.svn.sourceforge.net/viewvc/pythonqt/trunk/
126 143
127 144 \note We do not offer prebuilt binaries, since there are so many possible combinations of
128 145 platforms (Windows/Linux/MacOs), architectures (32/64 bit) and Python versions.
129 146
130 147 \page License License
131 148
132 149 PythonQt is distributed under the LGPL license, so it pairs well with the LGPL of the Qt 4.5 release and allows
133 150 to be used in commercial applications when following the LGPL 2.1 obligations.
134 151
135 152 The build system of PythonQt makes use of a modified version of the LGPL'ed QtScript generator,
136 153 located in the "generator" directory.
137 154
138 155 See http://qt.gitorious.org/qt-labs/qtscriptgenerator for details on the original project.
139 156 Thanks a lot to the QtJambi guys and the QtScript Generator project for the C++ parser and
140 157 Qt typesystem files!
141 158
142 159 The PythonQt wrappers generated by the generator located in the "generated_cpp" directory are free to be used without any licensing restrictions.
143 160
144 161 The generated wrappers are pre-generated and checked-in for Qt 4.6.1, so you only need to build and run the
145 162 generator when you want to build additional wrappers or you want to upgrade/downgrade to another Qt version.
146 163 You may use the generator to generate C++ bindings for your own C++ classes (e.g., to make them inheritable in Python),
147 164 but this is currently not documented and involves creating your own typesystem files (although the Qt Jambi examples might help you).
148 165
149 \section Comparison Comparison with PyQt/PySide
150
151 - PythonQt is not as pythonic as PyQt in many details (e.g. buffer protocol, pickling, translation support, ...) and it is mainly thought for embedding and intercommunication between Qt/Cpp and Python
152 - PythonQt allows to communicate in both directions, e.g., calling a Python object from C++ AND calling a C++ method from Python, while PyQt only handles the Python->C++ direction
153 - PythonQt offers properties as Python attributes, while PyQt offers them as setter/getter methods (e.g. QWidget.width is a property in PythonQt and a method in PyQt)
154 - PythonQt currently does not support instanceof checks for Qt classes, except for the exact match and derived Python classes
155 - QObject.emit to emit Qt signals from Python is not yet implemented but PythonQt allows to just emit a signal by calling it like a normal slot
156 - PythonQt does not (yet) offer to add new signals to Python/C++ objects and it does not yet support the newstyle PyQt signals (so you need to connect via C++ string signatures)
157 - Ownership of objects is a bit different in PythonQt, currently Python classes derived from a C++ class need to be manually referenced in Python to not get deleted too early (this will be fixed in a future version)
158 - QStrings are always converted to unicode Python objects, QByteArray always stays a QByteArray and can be converted using str()
159 - There are many details in the generated wrappers that could need some polishing, e.g., methods that use pointer arguments for additional return values could return a results tuple.
160 - Not all types of QList/QVector/QHash templates are supported, some Qt methods use those as arguments/return values (but you can add your own handlers to handle them if you need them).
161 - Probably there are lots of details that differ, I do not know PyQt that well to list them all.
162 - In the long run, PythonQt will consider using/extending PySide with the features of PythonQt to get rid of its own generator and typesystem files, alternatively the KDE Smoke generator might be used in the future (this has not yet been decided, the current PythonQt generator works well and there is no hurry to switch).
163 166
164 167 \page Developer Developer
165 168
166 169 \section Interface Interface
167 170
168 171 The main interface to PythonQt is the PythonQt singleton.
169 172 PythonQt needs to be initialized via PythonQt::init() once.
170 173 Afterwards you communicate with the singleton via PythonQt::self().
171 174 PythonQt offers a complete Qt binding, which
172 175 needs to be enabled via PythonQt_QtAll::init().
173 176
174 177
175 178 \section Datatype Datatype Mapping
176 179
177 180 The following table shows the mapping between Python and Qt objects:
178 181 <table>
179 182 <tr><th>Qt/C++</th><th>Python</th></tr>
180 183 <tr><td>bool</td><td>bool</td></tr>
181 184 <tr><td>double</td><td>float</td></tr>
182 185 <tr><td>float</td><td>float</td></tr>
183 186 <tr><td>char/uchar,int/uint,short,ushort,QChar</td><td>integer</td></tr>
184 187 <tr><td>long</td><td>integer</td></tr>
185 188 <tr><td>ulong,longlong,ulonglong</td><td>long</td></tr>
186 189 <tr><td>QString</td><td>unicode string</td></tr>
187 190 <tr><td>QByteArray</td><td>QByteArray wrapper</td></tr>
188 191 <tr><td>char*</td><td>str</td></tr>
189 192 <tr><td>QStringList</td><td>tuple of unicode strings</td></tr>
190 193 <tr><td>QVariantList</td><td>tuple of objects</td></tr>
191 194 <tr><td>QVariantMap</td><td>dict of objects</td></tr>
192 195 <tr><td>QVariant</td><td>depends on type, see below</td></tr>
193 196 <tr><td>QSize, QRect and all other standard Qt QVariants</td><td>variant wrapper that supports complete API of the respective Qt classes</td></tr>
194 197 <tr><td>OwnRegisteredMetaType</td><td>C++ wrapper, optionally with additional information/wrapping provided by registerCPPClass()</td></tr>
195 198 <tr><td>QList<AnyObject*></td><td>converts to a list of CPP wrappers</td></tr>
196 199 <tr><td>QVector<AnyObject*></td><td>converts to a list of CPP wrappers</td></tr>
197 200 <tr><td>EnumType</td><td>Enum wrapper derived from python integer</td></tr>
198 201 <tr><td>QObject (and derived classes)</td><td>QObject wrapper</td></tr>
199 202 <tr><td>C++ object</td><td>CPP wrapper, either wrapped via PythonQtCppWrapperFactory or just decorated with decorators</td></tr>
200 203 <tr><td>PyObject</td><td>PyObject</td></tr>
201 204 </table>
202 205
203 206 PyObject is passed as direct pointer, which allows to pass/return any Python object directly to/from
204 207 a Qt slot that uses PyObject* as its argument/return value.
205 208 QVariants are mapped recursively as given above, e.g. a dictionary can
206 209 contain lists of dictionaries of doubles.
207 210 All Qt QVariant types are implemented, PythonQt supports the complete Qt API for these object.
208 211
209 212 \section QObject QObject Wrapping
210 213
211 214 All classes derived from QObject are automatically wrapped with a python wrapper class
212 215 when they become visible to the Python interpreter. This can happen via
213 216 - the PythonQt::addObject() method
214 217 - when a Qt \b slot returns a QObject derived object to python
215 218 - when a Qt \b signal contains a QObject and is connected to a python function
216 219
217 220 It is important that you call PythonQt::registerClass() for any QObject derived class
218 221 that may become visible to Python, except when you add it via PythonQt::addObject().
219 222 This will register the complete parent hierachy of the registered class, so that
220 223 when you register e.g. a QPushButton, QWidget will be registered as well (and all intermediate
221 224 parents).
222 225
223 226 From Python, you can talk to the returned QObjects in a natural way by calling
224 227 their slots and receiving the return values. You can also read/write all
225 228 properties of the objects as if they where normal python properties.
226 229
227 230 In addition to this, the wrapped objects support
228 231 - className() - returns a string that reprents the classname of the QObject
229 232 - help() - shows all properties, slots, enums, decorator slots and constructors of the object, in a printable form
230 233 - delete() - deletes the object (use with care, especially if you passed the ownership to C++)
231 234 - connect(signal, function) - connect the signal of the given object to a python function
232 235 - connect(signal, qobject, slot) - connect the signal of the given object to a slot of another QObject
233 236 - disconnect(signal, function) - disconnect the signal of the given object from a python function
234 237 - disconnect(signal, qobject, slot) - disconnect the signal of the given object from a slot of another QObject
235 238 - children() - returns the children of the object
236 239 - setParent(QObject) - set the parent
237 240 - QObject* parent() - get the parent
238 241
239 242 The below example shows how to connect signals in Python:
240 243
241 244 \code
242 245 # define a signal handler function
243 246 def someFunction(flag):
244 247 print flag
245 248
246 249 # button1 is a QPushButton that has been added to Python via addObject()
247 250 # connect the clicked signal to a python function:
248 251 button1.connect("clicked(bool)", someFunction)
249 252
250 253 \endcode
251 254
252 255 \section CPP CPP Wrapping
253 256
254 257 You can create dedicated wrapper QObjects for any C++ class. This is done by deriving from PythonQtCppWrapperFactory
255 258 and adding your factory via addWrapperFactory().
256 259 Whenever PythonQt encounters a CPP pointer (e.g. on a slot or signal)
257 260 and it does not known it as a QObject derived class, it will create a generic CPP wrapper. So even unknown C++ objects
258 261 can be passed through Python. If the wrapper factory supports the CPP class, a QObject wrapper will be created for each
259 262 instance that enters Python. An alternative to a complete wrapper via the wrapper factory are decorators, see \ref Decorators
260 263
261 264 \section MetaObject Meta Object/Class access
262 265
263 266 For each known C++ class, PythonQt provides a Python class. These classes are visible
264 267 inside of the "PythonQt" python module or in subpackages if a package is given when the class is registered.
265 268
266 269 A Meta class supports:
267 270
268 271 - access to all declared enum values
269 272 - constructors
270 273 - static methods
271 274 - unbound non-static methods
272 275 - help() and className()
273 276
274 277 From within Python, you can import the module "PythonQt" to access these classes and the Qt namespace.
275 278
276 279 \code
277 280 from PythonQt import QtCore
278 281
279 282 # namespace access:
280 283 print QtCore.Qt.AlignLeft
281 284
282 285 # constructors
283 286 a = QtCore.QSize(12,13)
284 287 b = QtCore.QFont()
285 288
286 289 # static method
287 290 QtCore.QDate.currentDate()
288 291
289 292 # enum value
290 293 QtCore.QFont.UltraCondensed
291 294
292 295 \endcode
293 296
294 297 \section Decorators Decorator slots
295 298
296 299 PythonQt introduces a new generic approach to extend any wrapped QObject or CPP object with
297 300
298 301 - constructors
299 302 - destructors (for CPP objects)
300 303 - additional slots
301 304 - static slots (callable on both the Meta object and the instances)
302 305
303 306 The idea behind decorators is that we wanted to make it as easy as possible to extend
304 307 wrapped objects. Since we already have an implementation for invoking any Qt Slot from
305 308 Python, it looked promising to use this approach for the extension of wrapped objects as well.
306 309 This avoids that the PythonQt user needs to care about how Python arguments are mapped from/to
307 310 Qt when he wants to create static methods, constructors and additional member functions.
308 311
309 312 The basic idea about decorators is to create a QObject derived class that implements slots
310 313 which take one of the above roles (e.g. constructor, destructor etc.) via a naming convention.
311 314 These slots are then assigned to other classes via the naming convention.
312 315
313 316 - SomeClassName* new_SomeClassName(...) - defines a constructor for "SomeClassName" that returns a new object of type SomeClassName (where SomeClassName can be any CPP class, not just QObject classes)
314 317 - void delete_SomeClassName(SomeClassName* o) - defines a destructor, which should delete the passed in object o
315 318 - anything static_SomeClassName_someMethodName(...) - defines a static method that is callable on instances and the meta class
316 319 - anything someMethodName(SomeClassName* o, ...) - defines a slot that will be available on SomeClassName instances (and derived instances). When such a slot is called the first argument is the pointer to the instance and the rest of the arguments can be used to make a call on the instance.
317 320
318 321 The below example shows all kinds of decorators in action:
319 322
320 323 \code
321 324
322 325 // an example CPP object
323 326 class YourCPPObject {
324 327 public:
325 328 YourCPPObject(int arg1, float arg2) { a = arg1; b = arg2; }
326 329
327 330 float doSomething(int arg1) { return arg1*a*b; };
328 331
329 332 private:
330 333
331 334 int a;
332 335 float b;
333 336 };
334 337
335 338 // an example decorator
336 339 class ExampleDecorator : public QObject
337 340 {
338 341 Q_OBJECT
339 342
340 343 public slots:
341 344 // add a constructor to QSize that takes a QPoint
342 345 QSize* new_QSize(const QPoint& p) { return new QSize(p.x(), p.y()); }
343 346
344 347 // add a constructor for QPushButton that takes a text and a parent widget
345 348 QPushButton* new_QPushButton(const QString& text, QWidget* parent=NULL) { return new QPushButton(text, parent); }
346 349
347 350 // add a constructor for a CPP object
348 351 YourCPPObject* new_YourCPPObject(int arg1, float arg2) { return new YourCPPObject(arg1, arg2); }
349 352
350 353 // add a destructor for a CPP object
351 354 void delete_YourCPPObject(YourCPPObject* obj) { delete obj; }
352 355
353 356 // add a static method to QWidget
354 357 QWidget* static_QWidget_mouseGrabber() { return QWidget::mouseGrabber(); }
355 358
356 359 // add an additional slot to QWidget (make move() callable, which is not declared as a slot in QWidget)
357 360 void move(QWidget* w, const QPoint& p) { w->move(p); }
358 361
359 362 // add an additional slot to QWidget, overloading the above move method
360 363 void move(QWidget* w, int x, int y) { w->move(x,y); }
361 364
362 365 // add a method to your own CPP object
363 366 int doSomething(YourCPPObject* obj, int arg1) { return obj->doSomething(arg1); }
364 367 };
365 368
366 369 ...
367 370
368 371 PythonQt::self()->addDecorators(new ExampleDecorator());
369 372 PythonQt::self()->registerCPPClass("YourCPPObject");
370 373
371 374 \endcode
372 375
373 376 After you have registered an instance of the above ExampleDecorator, you can do the following from Python
374 377 (all these calls are mapped to the above decorator slots):
375 378
376 379 \code
377 380 from PythonQt import QtCore, QtGui, YourCPPObject
378 381
379 382 # call our new constructor of QSize
380 383 size = QtCore.QSize(QPoint(1,2));
381 384
382 385 # call our new QPushButton constructor
383 386 button = QtGui.QPushButton("sometext");
384 387
385 388 # call the move slot (overload1)
386 389 button.move(QPoint(0,0))
387 390
388 391 # call the move slot (overload2)
389 392 button.move(0,0)
390 393
391 394 # call the static method
392 395 grabber = QtGui.QWidget.mouseWrapper();
393 396
394 397 # create a CPP object via constructor
395 398 yourCpp = YourCPPObject(1,11.5)
396 399
397 400 # call the wrapped method on CPP object
398 401 print yourCpp.doSomething(1);
399 402
400 403 # destructor will be called:
401 404 yourCpp = None
402 405
403 406 \endcode
404 407
405 408 \page Building Building
406 409
407 410 PythonQt requires at least Qt 4.6.1 (for earlier Qt versions, you will need to run the pythonqt_gerenator, Qt 4.3 is the absolute minimum) and Python 2.5.x or 2.6.x on Windows, Linux and MacOS X. It has not yet been tested with Python 3.x, but it should only require minor changes.
408 411 To compile PythonQt, you will need a python developer installation which includes Python's header files and
409 412 the python2x.[lib | dll | so | dynlib].
410 413 The build scripts a currently set to use Python 2.6.
411 414 You may need to tweak the \b build/python.prf file to set the correct Python includes and libs on your system.
412 415
413 416 \subsection Windows
414 417
415 418 On Windows, the (non-source) Python Windows installer can be used.
416 419 Make sure that you use the same compiler, the current Python distribution is built
417 420 with Visual Studio 2003. If you want to use another compiler, you will need to build
418 421 Python yourself, using your compiler.
419 422
420 423 To build PythonQt, you need to set the environment variable \b PYTHON_PATH to point to the root
421 424 dir of the python installation and \b PYTHON_LIB to point to
422 425 the directory where the python lib file is located.
423 426
424 427 When using the prebuild Python installer, this will be:
425 428
426 429 \code
427 430 > set PYTHON_PATH = c:\Python26
428 431 > set PYTHON_LIB = c:\Python26\libs
429 432 \endcode
430 433
431 434 When using the python sources, this will be something like:
432 435
433 436 \code
434 437 > set PYTHON_PATH = c:\yourDir\Python-2.6.1\
435 438 > set PYTHON_LIB = c:\yourDir\Python-2.6.1\PCbuild8\Win32
436 439 \endcode
437 440
438 441 To build all, do the following (after setting the above variables):
439 442
440 443 \code
441 444 > cd PythonQtRoot
442 445 > vcvars32
443 446 > qmake
444 447 > nmake
445 448 \endcode
446 449
447 450 This should build everything. If Python can not be linked or include files can not be found,
448 451 you probably need to tweak \b build/python.prf
449 452
450 453 The tests and examples are located in PythonQt/lib.
451 454
452 455 \subsection Linux
453 456
454 457 On Linux, you need to install a Python-dev package.
455 458 If Python can not be linked or include files can not be found,
456 459 you probably need to tweak \b build/python.prf
457 460
458 461 To build PythonQt, just do a:
459 462
460 463 \code
461 464 > cd PythonQtRoot
462 465 > qmake
463 466 > make all
464 467 \endcode
465 468
466 469 The tests and examples are located in PythonQt/lib.
467 470 You should add PythonQt/lib to your LD_LIBRARY_PATH so that the runtime
468 471 linker can find the *.so files.
469 472
470 473 \subsection MacOsX
471 474
472 475 On Mac, Python is installed as a Framework, so you should not need to install it.
473 476 To build PythonQt, just do a:
474 477
475 478 \code
476 479 > cd PythonQtRoot
477 480 > qmake
478 481 > make all
479 482 \endcode
480 483
481 484 \section Tests
482 485
483 486 There is a unit test that tests most features of PythonQt, see the \b tests subdirectory for details.
484 487
485 488 \page Examples Examples
486 489
487 490 Examples are available in the \b examples directory. The PyScriptingConsole implements a simple
488 491 interactive scripting console that shows how to script a simple application. The PyLauncher application can be used to run arbitrary PythonQt scripts given on the commandline.
489 492
490 493 The following shows a simple example on how to integrate PythonQt into your Qt application:
491 494
492 495 \code
493 496 #include "PythonQt.h"
494 497 #include <QApplication>
495 498 ...
496 499
497 500 int main( int argc, char **argv )
498 501 {
499 502
500 503 QApplication qapp(argc, argv);
501 504
502 505 // init PythonQt and Python itself
503 506 PythonQt::init();
504 507
505 508 // get a smart pointer to the __main__ module of the Python interpreter
506 509 PythonQtObjectPtr context = PythonQt::self()->getMainModule();
507 510
508 511 // add a QObject as variable of name "example" to the namespace of the __main__ module
509 512 PyExampleObject example;
510 513 context.addObject("example", &example);
511 514
512 515 // do something
513 516 context.evalScript("print example");
514 517 context.evalScript("def multiply(a,b):\n return a*b;\n");
515 518 QVariantList args;
516 519 args << 42 << 47;
517 520 QVariant result = context.call("multiply", args);
518 521 ...
519 522 \endcode
520 523
521 524
522 525 */
General Comments 0
You need to be logged in to leave comments. Login now