def _qimage_to_pil_image(image: QtGui.QImage): """Cast QImage to pillow Image type.""" ba = QtCore.QByteArray() buffer = QtCore.QBuffer(ba) buffer.open(QtCore.QIODevice.ReadWrite) image.save(buffer, "PNG") # type:ignore return Image.open(io.BytesIO(buffer.data()))
def __init__(self, *args): super().__init__(*args) self._init_connection() self.debug_lines = [] self.debug_dialog = None self._lines = config.CONFIG_DEFAULT_RELAY_LINES self._buffer = QtCore.QByteArray() self._socket = QtNetwork.QSslSocket() self._socket.connected.connect(self._socket_connected) self._socket.readyRead.connect(self._socket_read) self._socket.disconnected.connect(self._socket_disconnected)
def qimage_argb32_from_png_decoding(img_data): '''Effectue le décodage d'un 'buffer' de données correspondant à une image PNG. En entrée se trouve le 'buffer' conforme d'une image de format PNG. En sortie on obtient une QImage du format QImage.Format_ARGB32.''' image = QtGui.QImage() if image.load_from_data(QtCore.QByteArray(bytearray(img_data)), 'png'): return image.convert_to_format(QtGui.QImage.Format_ARGB32) print("Erreur de décodage d'une image avec la fonction _png_decoding.") return image
def fadeStart(obj, fromWidget, toWidget, layout, finishedSlot=None): setattr(obj, "_utilEffect", QtWidgets.QGraphicsOpacityEffect(fromWidget)) fromWidget.setGraphicsEffect(obj._utilEffect) setattr( obj, "_utilAnimation", QtCore.QPropertyAnimation(fromWidget.graphicsEffect(), QtCore.QByteArray("opacity"))) obj._utilAnimation.setDuration(500) obj._utilAnimation.setStartValue(1) obj._utilAnimation.setEndValue(0) obj._utilAnimation.setEasingCurve(QtCore.QEasingCurve.Linear) obj._utilAnimation.finished.connect(lambda: fadeEnd( obj, fromWidget, toWidget, layout, finishedSlot=finishedSlot)) obj._utilAnimation.start()
def sendFortune(self): block = QtCore.QByteArray() out = QtCore.QDataStream(block, QtCore.QIODevice.WriteOnly) out.setVersion(QtCore.QDataStream.Qt_4_0) out.writeUInt16(0) fortune = self.fortunes[random.randint(0, len(self.fortunes) - 1)] out.writeString(fortune) out.device().seek(0) out.writeUInt16(block.size() - 2) clientConnection = self.tcpServer.nextPendingConnection() clientConnection.disconnected.connect(clientConnection.deleteLater) clientConnection.write(block) clientConnection.disconnectFromHost()
def fadeEnd(obj, fromWidget, toWidget, layout, finishedSlot=None): layout.replaceWidget(fromWidget, toWidget) fromWidget.hide() toWidget.show() setattr(obj, "_utilEffect", QtWidgets.QGraphicsOpacityEffect(toWidget)) toWidget.setGraphicsEffect(obj._utilEffect) setattr( obj, "_utilAnimation", QtCore.QPropertyAnimation(toWidget.graphicsEffect(), QtCore.QByteArray("opacity"))) obj._utilAnimation.setDuration(500) obj._utilAnimation.setStartValue(0) obj._utilAnimation.setEndValue(1) obj._utilAnimation.setEasingCurve(QtCore.QEasingCurve.Linear) obj._utilAnimation.finished.connect(lambda: obj._utilEffect.deleteLater()) if finishedSlot is not None: obj._utilAnimation.finished.connect(finishedSlot) obj._utilAnimation.start()
def accept(self): className = self.field('className') baseClass = self.field('baseClass') macroName = self.field('macroName') baseInclude = self.field('baseInclude') outputDir = self.field('outputDir') header = self.field('header') implementation = self.field('implementation') block = '' if self.field('comment'): block += '/*\n' block += ' ' + header + '\n' block += '*/\n' block += '\n' if self.field('protect'): block += '#ifndef ' + macroName + '\n' block += '#define ' + macroName + '\n' block += '\n' if self.field('includeBase'): block += '#include ' + baseInclude + '\n' block += '\n' block += 'class ' + className if baseClass: block += ' : public ' + baseClass block += '\n' block += '{\n' if self.field('qobjectMacro'): block += ' Q_OBJECT\n' block += '\n' block += 'public:\n' if self.field('qobjectCtor'): block += ' ' + className + '(QObject *parent = 0);\n' elif self.field('qwidgetCtor'): block += ' ' + className + '(QWidget *parent = 0);\n' elif self.field('defaultCtor'): block += ' ' + className + '();\n' if self.field('copyCtor'): block += ' ' + className + '(const ' + className + ' &other);\n' block += '\n' block += ' ' + className + ' &operator=' + '(const ' + className + ' &other);\n' block += '};\n' if self.field('protect'): block += '\n' block += '#endif\n' headerFile = QtCore.QFile(outputDir + '/' + header) if not headerFile.open(QtCore.QFile.WriteOnly | QtCore.QFile.Text): QtWidgets.QMessageBox.warning( None, "Class Wizard", "Cannot write file %s:\n%s" % (headerFile.fileName(), headerFile.errorString())) return headerFile.write(QtCore.QByteArray(block.encode("utf-8"))) block = '' if self.field('comment'): block += '/*\n' block += ' ' + implementation + '\n' block += '*/\n' block += '\n' block += '#include "' + header + '"\n' block += '\n' if self.field('qobjectCtor'): block += className + '::' + className + '(QObject *parent)\n' block += ' : ' + baseClass + '(parent)\n' block += '{\n' block += '}\n' elif self.field('qwidgetCtor'): block += className + '::' + className + '(QWidget *parent)\n' block += ' : ' + baseClass + '(parent)\n' block += '{\n' block += '}\n' elif self.field('defaultCtor'): block += className + '::' + className + '()\n' block += '{\n' block += ' // missing code\n' block += '}\n' if self.field('copyCtor'): block += '\n' block += className + '::' + className + '(const ' + className + ' &other)\n' block += '{\n' block += ' *this = other;\n' block += '}\n' block += '\n' block += className + ' &' + className + '::operator=(const ' + className + ' &other)\n' block += '{\n' if baseClass: block += ' ' + baseClass + '::operator=(other);\n' block += ' // missing code\n' block += ' return *this;\n' block += '}\n' implementationFile = QtCore.QFile(outputDir + '/' + implementation) if not implementationFile.open(QtCore.QFile.WriteOnly | QtCore.QFile.Text): QtWidgets.QMessageBox.warning( None, "Class Wizard", "Cannot write file %s:\n%s" % (implementationFile.fileName(), implementationFile.errorString())) return implementationFile.write(QtCore.QByteArray(block.encode("utf-8"))) super(ClassWizard, self).accept()
def convertToMime(self, mime, data, flav): all = QtCore.QByteArray() for i in data: all += i return all