def split_full_desktop_to_screens( full_image: QtGui.QImage) -> list[QtGui.QImage]: """Split full desktop image into list of images per screen. Also resizes screens according to image:virtual-geometry ratio. """ virtual_geometry = QtWidgets.QApplication.primaryScreen().virtualGeometry() ratio = full_image.rect().width() / virtual_geometry.width() logger.debug("Virtual geometry width: %s", virtual_geometry.width()) logger.debug("Image width: %s", full_image.rect().width()) logger.debug("Resize ratio: %s", ratio) images = [] for screen in QtWidgets.QApplication.screens(): geo = screen.geometry() region = QtCore.QRect( int(geo.x() * ratio), int(geo.y() * ratio), int(geo.width() * ratio), int(geo.height() * ratio), ) image = full_image.copy(region) images.append(image) return images
def decodeQR(self, qr_image: QImage): cropped = qr_image.copy( self.calculate_center_square(qr_image).toRect()) # TODO: the same code is present in slips.py -> move to one place buffer = QBuffer() buffer.open(QBuffer.ReadWrite) cropped.save(buffer, "BMP") try: pillow_image = Image.open(io.BytesIO(buffer.data())) except UnidentifiedImageError: print("Image format isn't supported") return barcodes = pyzbar.decode(pillow_image, symbols=[pyzbar.ZBarSymbol.QRCODE]) if barcodes: self.decodedQR.emit(barcodes[0].data.decode('utf-8'))