Refactor Python for 3.12 integration (#1807)

* Correct JS requestConfig call

* Update requestWriteConfig to new API format

* Add hyperion-light and bare-minimum preset scenarios

* Refactor Python

* Windows add bcrypt until mbedtls  is fixed
(https://github.com/Mbed-TLS/mbedtls/pull/9554)

* Corrections

* Use ScreenCaptureKit under macOS 15 and above

* ReSigning macOS package

* Python 3.11.10 test

* Revert "Python 3.11.10 test"

This reverts commit ee921e4f12.

* Handle defined exits from python scripts

* Update change.log

* CodeQL findings

---------

Co-authored-by: Paulchen-Panther <16664240+Paulchen-Panther@users.noreply.github.com>
This commit is contained in:
LordGrey
2024-12-01 17:08:25 +01:00
committed by GitHub
parent 6e3357ea2d
commit 733aa662bf
18 changed files with 841 additions and 521 deletions

View File

@@ -24,13 +24,13 @@ public:
friend class EffectModule;
Effect(Hyperion *hyperion
, int priority
, int timeout
, const QString &script
, const QString &name
, const QJsonObject &args = QJsonObject()
, const QString &imageData = ""
Effect(Hyperion* hyperion
, int priority
, int timeout
, const QString& script
, const QString& name
, const QJsonObject& args = QJsonObject()
, const QString& imageData = ""
);
~Effect() override;
@@ -64,20 +64,20 @@ public:
QString getScript() const { return _script; }
QString getName() const { return _name; }
int getTimeout() const {return _timeout; }
int getTimeout() const { return _timeout; }
bool isEndless() const { return _isEndless; }
QJsonObject getArgs() const { return _args; }
signals:
void setInput(int priority, const std::vector<ColorRgb> &ledColors, int timeout_ms, bool clearEffect);
void setInputImage(int priority, const Image<ColorRgb> &image, int timeout_ms, bool clearEffect);
void setInput(int priority, const std::vector<ColorRgb>& ledColors, int timeout_ms, bool clearEffect);
void setInputImage(int priority, const Image<ColorRgb>& image, int timeout_ms, bool clearEffect);
private:
void setModuleParameters();
bool setModuleParameters();
void addImage();
Hyperion *_hyperion;
Hyperion* _hyperion;
const int _priority;
@@ -95,12 +95,12 @@ private:
/// Buffer for colorData
QVector<ColorRgb> _colors;
Logger *_log;
Logger* _log;
// Reflects whenever this effects should interrupt (timeout or external request)
std::atomic<bool> _interupt {};
std::atomic<bool> _interupt{};
QSize _imageSize;
QImage _image;
QPainter *_painter;
QPainter* _painter;
QVector<QImage> _imageStack;
};

View File

@@ -8,47 +8,41 @@
class Effect;
class EffectModule: public QObject
class EffectModule : public QObject
{
Q_OBJECT
public:
// Python 3 module def
static struct PyModuleDef moduleDef;
// Init module
static PyObject* PyInit_hyperion();
// Register module once
static void registerHyperionExtensionModule();
// json 2 python
static PyObject * json2python(const QJsonValue & jsonData);
static PyObject* json2python(const QJsonValue& jsonData);
// Wrapper methods for Python interpreter extra buildin methods
static PyMethodDef effectMethods[];
static PyObject* wrapSetColor (PyObject *self, PyObject *args);
static PyObject* wrapSetImage (PyObject *self, PyObject *args);
static PyObject* wrapGetImage (PyObject *self, PyObject *args);
static PyObject* wrapAbort (PyObject *self, PyObject *args);
static PyObject* wrapImageShow (PyObject *self, PyObject *args);
static PyObject* wrapImageLinearGradient (PyObject *self, PyObject *args);
static PyObject* wrapImageConicalGradient (PyObject *self, PyObject *args);
static PyObject* wrapImageRadialGradient (PyObject *self, PyObject *args);
static PyObject* wrapImageSolidFill (PyObject *self, PyObject *args);
static PyObject* wrapImageDrawLine (PyObject *self, PyObject *args);
static PyObject* wrapImageDrawPoint (PyObject *self, PyObject *args);
static PyObject* wrapImageDrawRect (PyObject *self, PyObject *args);
static PyObject* wrapImageDrawPolygon (PyObject *self, PyObject *args);
static PyObject* wrapImageDrawPie (PyObject *self, PyObject *args);
static PyObject* wrapImageSetPixel (PyObject *self, PyObject *args);
static PyObject* wrapImageGetPixel (PyObject *self, PyObject *args);
static PyObject* wrapImageSave (PyObject *self, PyObject *args);
static PyObject* wrapImageMinSize (PyObject *self, PyObject *args);
static PyObject* wrapImageWidth (PyObject *self, PyObject *args);
static PyObject* wrapImageHeight (PyObject *self, PyObject *args);
static PyObject* wrapImageCRotate (PyObject *self, PyObject *args);
static PyObject* wrapImageCOffset (PyObject *self, PyObject *args);
static PyObject* wrapImageCShear (PyObject *self, PyObject *args);
static PyObject* wrapImageResetT (PyObject *self, PyObject *args);
static PyObject* wrapSetColor(PyObject* self, PyObject* args);
static PyObject* wrapSetImage(PyObject* self, PyObject* args);
static PyObject* wrapGetImage(PyObject* self, PyObject* args);
static PyObject* wrapAbort(PyObject* self, PyObject* args);
static PyObject* wrapImageShow(PyObject* self, PyObject* args);
static PyObject* wrapImageLinearGradient(PyObject* self, PyObject* args);
static PyObject* wrapImageConicalGradient(PyObject* self, PyObject* args);
static PyObject* wrapImageRadialGradient(PyObject* self, PyObject* args);
static PyObject* wrapImageSolidFill(PyObject* self, PyObject* args);
static PyObject* wrapImageDrawLine(PyObject* self, PyObject* args);
static PyObject* wrapImageDrawPoint(PyObject* self, PyObject* args);
static PyObject* wrapImageDrawRect(PyObject* self, PyObject* args);
static PyObject* wrapImageDrawPolygon(PyObject* self, PyObject* args);
static PyObject* wrapImageDrawPie(PyObject* self, PyObject* args);
static PyObject* wrapImageSetPixel(PyObject* self, PyObject* args);
static PyObject* wrapImageGetPixel(PyObject* self, PyObject* args);
static PyObject* wrapImageSave(PyObject* self, PyObject* args);
static PyObject* wrapImageMinSize(PyObject* self, PyObject* args);
static PyObject* wrapImageWidth(PyObject* self, PyObject* args);
static PyObject* wrapImageHeight(PyObject* self, PyObject* args);
static PyObject* wrapImageCRotate(PyObject* self, PyObject* args);
static PyObject* wrapImageCOffset(PyObject* self, PyObject* args);
static PyObject* wrapImageCShear(PyObject* self, PyObject* args);
static PyObject* wrapImageResetT(PyObject* self, PyObject* args);
};

View File

@@ -1,6 +1,6 @@
#pragma once
// OSX includes
// CoreGraphics
#include <CoreGraphics/CoreGraphics.h>
// Utils includes

View File

@@ -1,5 +1,9 @@
#pragma once
#undef slots
#include <Python.h>
#define slots Q_SLOTS
///
/// @brief Handle the PythonInit, module registers and DeInit
///
@@ -10,4 +14,8 @@ private:
PythonInit();
~PythonInit();
#if (PY_VERSION_HEX >= 0x03080000)
void handlePythonError(PyStatus status, PyConfig& config);
#endif
};

View File

@@ -9,6 +9,8 @@
#include "Python.h"
#define slots
#include <python/PythonUtils.h>
class Logger;
class PythonProgram
@@ -17,9 +19,15 @@ public:
PythonProgram(const QString & name, Logger * log);
~PythonProgram();
operator PyThreadState* ()
{
return _tstate;
}
void execute(const QByteArray &python_code);
private:
QString _name;
Logger* _log;
PyThreadState* _tstate;