Debian Codegraph @

src/Gui/PythonWrapper.h

raw
1 /***************************************************************************
2 * Copyright (c) 2021 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23
24 #ifndef GUI_PYTHONWRAPPER_H
25 #define GUI_PYTHONWRAPPER_H
26
27 #include "qglobal.h"
28 #include <Base/PyObjectBase.h>
29 #include <FCGlobal.h>
30
31 QT_BEGIN_NAMESPACE
32 class QAction;
33 class QDir;
34 class QIcon;
35 class QImage;
36 class QGraphicsObject;
37 class QGraphicsItem;
38 class QObject;
39 class QPrinter;
40 class QWidget;
41 QT_END_NAMESPACE
42
43 namespace Gui
44 {
45
46 class GuiExport PythonWrapper
47 {
48 public:
49 PythonWrapper();
50 bool loadCoreModule();
51 bool loadGuiModule();
52 bool loadWidgetsModule();
53 bool loadPrintSupportModule();
54 bool loadUiToolsModule();
55
56 bool toCString(const Py::Object&, std::string&);
57 QObject* toQObject(const Py::Object&);
58 qsizetype toEnum(PyObject* pyPtr);
59 qsizetype toEnum(const Py::Object& pyobject);
60 Py::Object toStandardButton(qsizetype);
61 QGraphicsItem* toQGraphicsItem(PyObject* ptr);
62 QGraphicsItem* toQGraphicsItem(const Py::Object& pyObject);
63 QGraphicsObject* toQGraphicsObject(PyObject* pyPtr);
64 QGraphicsObject* toQGraphicsObject(const Py::Object& pyObject);
65
66 Py::Object fromQAction(QAction*);
67 Py::Object fromQPrinter(QPrinter*);
68 Py::Object fromQObject(QObject*, const char* className = nullptr);
69 Py::Object fromQWidget(QWidget*, const char* className = nullptr);
70 const char* getWrapperName(QObject*) const;
71
72 Py::Object fromQImage(const QImage&);
73 QImage* toQImage(PyObject* pyobj);
74 /*!
75 Create a Python wrapper for the icon. The icon must be created on the heap
76 and the Python wrapper takes ownership of it.
77 */
78 Py::Object fromQIcon(const QIcon*);
79 QIcon* toQIcon(PyObject* pyobj);
80 Py::Object fromQDir(const QDir&);
81 QDir* toQDir(PyObject* pyobj);
82 static void createChildrenNameAttributes(PyObject* root, QObject* object);
83 static void setParent(PyObject* pyWdg, QObject* parent);
84
85 private:
86 qsizetype tryEnum(PyObject* pyPtr);
87 Py::Object tryToStandardButton(qsizetype value);
88 };
89
90 } // namespace Gui
91
92 #endif // GUI_PYTHONWRAPPER_H