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 present(self, newNotification): if self.notification: self.notification.close() sip.delete(self.notification) self.notification = None self.notification = newNotification self.m_title.setText(f"<b>{self.notification.title()}</b>") self.m_message.setText(self.notification.message()) self.m_icon.setPixmap( QPixmap.fromImage(self.notification.icon()).scaledToHeight( self.m_icon.height())) self.show() self.notification.show() self.notification.closed.connect(self.onClosed) QTimer.singleShot( 10000, lambda: self.onClosed() if self.notification is not None else None) # position our popup in the right corner of its parent widget self.move(self.parentWidget().mapToGlobal( self.parentWidget().rect().bottomRight() - QPoint(self.width() + 10, self.height() + 10)))
def set_image(self, encoded_image): from tpDcc.libs.qt.core import image if not encoded_image: return encoded_image = encoded_image.encode('utf-8') self.project_btn.setIcon( QIcon(QPixmap.fromImage(image.base64_to_image(encoded_image))))
def set_image(self, encoded_image): from tpDcc.libs.qt.core import image if not encoded_image: return encoded_image = encoded_image.encode('utf-8') project_icon = QIcon(QPixmap.fromImage(image.base64_to_image(encoded_image))) if project_icon.isNull(): project_icon = resources.icon('tpDcc') self.project_btn.setIcon(project_icon)
def runAnimation(): Col = MainWindow.MainController() # 开机动画 splash = QSplashScreen() scale = 0.5 mgnWidth = int(Data.getWindowWidth() * scale) mgnHeight = int(Data.getWindowHeight() * scale) size = QSize(mgnWidth, mgnHeight) splash.show() for name in os.listdir(filePath + r"\res\ZeusDesign\startup_seq"): path = filePath + r"\res\ZeusDesign\startup_seq\\" + name image = QImage(path) pixmap = QPixmap.fromImage(image.scaled(size, Qt.IgnoreAspectRatio)) splash.setPixmap(pixmap) time.sleep(0.01) splash.finish(Col.view)
def loadFromMemory(self): if not self.sharedMemory.attach(): self.ui.label.setText( self.tr("Unable to attach to shared memory segment.\n" "Load an image first.")) return buffer = QBuffer() _in = QDataStream(buffer) image = QImage() self.sharedMemory.lock() buffer.setData(self.sharedMemory.data()) buffer.open(QBuffer.ReadOnly) _in >> image self.sharedMemory.unlock() self.sharedMemory.detach() self.ui.label.setPixmap(QPixmap.fromImage(image))
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()
def get_project_image(self): """ Returns the image used by the project :return: QPixmap """ from tpDcc.libs.qt.core import image if not self._settings: self._load_project() project_file = self.get_project_file() if not self._settings.has_settings(): logger.warning( 'No valid project data found on Project Data File: {}'.format( project_file)) encoded_image = self._settings.get('image') if not encoded_image: return encoded_image = encoded_image.encode('utf-8') return QPixmap.fromImage(image.base64_to_image(encoded_image))