PythonQt
PythonQtDoc.h
Go to the documentation of this file.
1#ifndef _PYTHONQTDOC_H
2 #define _PYTHONQTDOC_H
3
4/*
5 *
6 * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * Further, this software is distributed without any warranty that it is
19 * free of the rightful claim of any third person regarding infringement
20 * or the like. Any license provided herein, whether implied or
21 * otherwise, applies only to this software file. Patent licenses, if
22 * any, provided herein do not apply to combinations of this program with
23 * other software, or any other product whatsoever.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29,
30 * 28359 Bremen, Germany or:
31 *
32 * http://www.mevis.de
33 *
34 */
35
36//----------------------------------------------------------------------------------
43//----------------------------------------------------------------------------------
44
466 PythonQtPassOwnershipToPython<QGraphicsItem*> createNewItemOwnedByPython();
467
469 void addItemToCPP(PythonQtPassOwnershipToPython<QGraphicsItem*> item);
470
472 void addItemToCPP(PythonQtPassOwnershipToPython<QList<QGraphicsItem*> > items);
473
475 void addItemParent(QGraphicsItem* wrappedObject, PythonQtNewOwnerOfThis<QGraphicsItem*> parent);
476 \endcode
477
478 \page Building Building
479
480 PythonQt requires at least Qt 5.0 and Python 2.7.x or Python 3.6 (or higher).
481 To compile PythonQt, you will need a python developer installation which includes Python's header files and
482the python2x.[lib | dll | so | dynlib].
483 The recommended way to build PythonQt is to use the QMake-based *.pro file.
484 The build scripts are currently set to use Python 3.10 by default.
485 You may need to tweak the \b build/python.prf file to set the correct Python includes and libs on your system.
486
487 \subsection Windows
488
489 On Windows, the (non-source) Python Windows installer can be used.
490 Make sure that you use the same compiler as the one that your Python distribution is built with.
491 If you want to use another compiler, you will need to build
492 Python yourself, using your compiler.
493
494 To build PythonQt, you need to set the environment variable \b PYTHON_PATH to point to the root
495 dir of the python installation and \b PYTHON_VERSION should state the used Python version.
496
497 When using the prebuild Python installer, this will be:
498
499 \code
500 > set PYTHON_PATH = c:\Python310
501 > set PYTHON_VERSION = 3.10
502 \endcode
503
504 When using the python sources, this will be something like:
505
506 \code
507 > set PYTHON_PATH = c:\yourDir\Python-3.10.12\
508 > set PYTHON_VERSION = 3.10
509 \endcode
510
511 To build all, do the following (after setting the above variables):
512
513 \code
514 > cd PythonQtRoot
515 > vcvars32
516 > qmake
517 > nmake
518 \endcode
519
520 This should build everything. If Python can not be linked or include files can not be found,
521 you probably need to tweak \b build/python.prf
522
523 The tests and examples are located in PythonQt/lib.
524
525 When using a Python distribution, the debug build typically does not work because the
526 pythonxx_d.lib/.dll are not provided. You can tweak linking of the debug build to the release
527 Python version, but this typically requires patching pyconfig.h and removing Py_DEBUG and linker pragmas
528 (google for it!).
529
530 \subsection Linux
531
532 On Linux, you need to install a Python-dev package.
533 If Python can not be linked or include files can not be found,
534 you probably need to tweak \b build/python.prf
535
536 To build PythonQt, just do a:
537
538 \code
539 > cd PythonQtRoot
540 > qmake
541 > make all
542 \endcode
543
544 The tests and examples are located in PythonQt/lib.
545 You should add PythonQt/lib to your LD_LIBRARY_PATH so that the runtime
546 linker can find the *.so files.
547
548 \subsection MacOS
549
550 On Mac, Python is installed as a Framework, so you should not need to install it.
551 To build PythonQt, just do a:
552
553 \code
554 > cd PythonQtRoot
555 > qmake
556 > make all
557 \endcode
558
559 \section Tests
560
561 There is a unit test that tests most features of PythonQt, see the \b tests subdirectory for details.
562
563 \page Examples Examples
564
565 Examples are available in the \b examples directory. The PyScriptingConsole implements a simple
566 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.
567
568 The following shows a simple example on how to integrate PythonQt into your Qt application:
569
570 \code
571 #include "PythonQt.h"
572 #include <QApplication>
573 ...
574
575 int main(int argc, char *argv[])
576 {
577
578 QApplication qapp(argc, argv);
579
580 // init PythonQt and Python itself
581 PythonQt::init();
582
583 // get a smart pointer to the __main__ module of the Python interpreter
584 PythonQtObjectPtr context = PythonQt::self()->getMainModule();
585
586 // add a QObject as variable of name "example" to the namespace of the __main__ module
587 PyExampleObject example;
588 context.addObject("example", &example);
589
590 // do something
591 context.evalScript("print example");
592 context.evalScript("def multiply(a,b):\n return a*b;\n");
593 QVariantList args;
594 args << 42 << 47;
595 QVariant result = context.call("multiply", args);
596 ...
597 \endcode
598
599
600*/