def loadFromFile(self): if self.sharedMemory.isAttached(): self.detach() self.ui.label.setText(self.tr("Select an image file")) fileName, _ = QFileDialog.getOpenFileName( None, "", "", self.tr("Images (*.png *.xpm *.jpg)")) image = QImage() if not image.load(fileName): self.ui.label.setText( self.tr( "Selected file is not an image, please select another.")) return self.ui.label.setPixmap(QPixmap.fromImage(image)) buffer = QBuffer() buffer.open(QBuffer.ReadWrite) out = QDataStream(buffer) out << image size = buffer.size() if not self.sharedMemory.create(size): self.ui.label.setText( self.tr("Unable to create shared memory segment.")) return self.sharedMemory.lock() size = min(self.sharedMemory.size(), size) self.sharedMemory.data()[:size] = buffer.data()[:size] self.sharedMemory.unlock()
def handleNetworkData(self, reply: QNetworkReply) -> None: img = QImage() tp = reply.request().attribute(QNetworkRequest.User) if not reply.error(): if not img.load(reply, ""): img = QImage() reply.deleteLater() self.m_tilePixmaps[QPointH(tp)] = (self.m_emptyTile if img.isNull() else QPixmap.fromImage(img)) self.updated.emit(self.tileRect(tp)) # purge unused spaces bound = self.m_tilesRect.adjusted(-2, -2, 2, 2) self.m_tilePixmaps = { tp: pixmap for tp, pixmap in self.m_tilePixmaps.items() if bound.contains(tp) } self.download()