When I run the program before cythonize, with pure .py files everything works as it should, the method connected to valueChanged is called when the animation value changes. But, after I did build cythonize, and the program runs from .pyd extensions the method connected to the valueChanged signal is never called.
Although I checked the same thing with the QVariantAnimation finished signal and it is called, everything works, it is with valueChanged that this is a problem.
Python version: 3.11 PyQt6 version: 6.4.0 Cython version: 3.0.0a11 OS: Windows 11
Here's an example of how it looks in my code:
from PyQt6.QtCore import QAbstractAnimation, QVariant, QVariantAnimation, pyqtSlot
from PyQt6.QtWidgets import QHBoxLayout, QPushButton, QWidget
class SampleWidget(QWidget):
def __init__(self, parent: QWidget | None = None) -> None:
super().__init__(parent)
horizontal_layout = QHBoxLayout()
horizontal_layout.setContentsMargins(0, 0, 0, 0)
horizontal_layout.setSpacing(0)
self.button = QPushButton(self)
self.button.setText("Start animation")
self.button.clicked.connect(lambda: self.start_animation(180))
horizontal_layout.addWidget(self.button)
self.setLayout(horizontal_layout)
def start_animation(self, value: float) -> None:
self._animation = QVariantAnimation(self)
self._animation.setStartValue(0)
self._animation.setEndValue(value)
self._animation.setDuration(400)
self._animation.valueChanged.connect(self._on_animation_value_changed)
self._animation.finished.connect(self._on_animation_finished)
self._animation.start(QAbstractAnimation.DeletionPolicy.DeleteWhenStopped)
@pyqtSlot()
def _on_animation_finished(self) -> None:
# This executes as it should be after cythonize.
print("Animation finished")
@pyqtSlot(QVariant)
def _on_animation_value_changed(self, value: float) -> None:
# Here is problem. This is never executes after cythonize.
print("Animation value changed to", value)
And cythonize function:
...
cythonize(
module_list=extension_modules,
# Don't build in source tree (this leaves behind .c files)
build_dir=BUILD_DIR,
# Don't generate an .html output file. This will contain source.
annotate=False,
# Tell Cython we're using Python 3
compiler_directives={"language_level": "3", "always_allow_keywords": True},
# (Optional) Always rebuild, even if files untouched
force=True,
)
...