1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
// This is the implementatation of an embedded qt.conf file.
//
// Copyright (c) 2018 Riverbank Computing Limited <info@riverbankcomputing.com>
//
// This file is part of PyQt5.
//
// This file may be used under the terms of the GNU General Public License
// version 3.0 as published by the Free Software Foundation and appearing in
// the file LICENSE included in the packaging of this file. Please review the
// following information to ensure the GNU General Public License version 3.0
// requirements will be met: http://www.gnu.org/copyleft/gpl.html.
//
// If you do not wish to use this file under the terms of the GPL version 3.0
// then you may purchase a commercial license. For more information contact
// info@riverbankcomputing.com.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#if defined(PYQT_QTCONF_PREFIX)
#include <Python.h>
#include <QByteArray>
#include <QDir>
#include <QFileInfo>
#include "qpycore_api.h"
static const unsigned char qt_resource_name[] = {
// qt
0x0,0x2,
0x0,0x0,0x7,0x84,
0x0,0x71,
0x0,0x74,
// etc
0x0,0x3,
0x0,0x0,0x6c,0xa3,
0x0,0x65,
0x0,0x74,0x0,0x63,
// qt.conf
0x0,0x7,
0x8,0x74,0xa6,0xa6,
0x0,0x71,
0x0,0x74,0x0,0x2e,0x0,0x63,0x0,0x6f,0x0,0x6e,0x0,0x66,
};
static const unsigned char qt_resource_struct[] = {
// :
0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x1,
// :/qt
0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x2,
// :/qt/etc
0x0,0x0,0x0,0xa,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x3,
// :/qt/etc/qt.conf
0x0,0x0,0x0,0x16,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,
};
bool qRegisterResourceData(int, const unsigned char *, const unsigned char *,
const unsigned char *);
// Embed a qt.conf file.
bool qpycore_qt_conf()
{
// Get PyQt5.__file__.
PyObject *pyqt5 = PyImport_ImportModule("PyQt5");
if (!pyqt5)
return false;
PyObject *init = PyObject_GetAttrString(pyqt5, "__file__");
Py_DECREF(pyqt5);
if (!init)
return false;
QString init_impl(qpycore_PyObject_AsQString(init));
Py_DECREF(init);
if (init_impl.isEmpty())
return false;
// Get the directory containing the PyQt5 extension modules.
QDir pyqt5_dir = QFileInfo(QDir::fromNativeSeparators(init_impl)).absoluteDir();
// Get the prefix path with non-native separators.
static QByteArray qt_conf = pyqt5_dir.absoluteFilePath(PYQT_QTCONF_PREFIX).toLocal8Bit();
qt_conf.prepend("[Paths]\nPrefix = ");
qt_conf.append("\n");
// Prepend the 4-byte size.
int size = qt_conf.size();
for (int i = 0; i < 4; ++i)
{
qt_conf.prepend(size & 0xff);
size >>= 8;
}
// Register the structures.
qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name,
(const unsigned char *)qt_conf.constData());
return true;
}
#endif
|