def get_thumbNail(self, f, thumbname='thumbnailimage'): """ Extract the (jpg) thumbnail from an image or sidecar file and returns it as a QImage. @param f: path to image or sidecar file @type f: str @param thumbname: tag name @type thumbname: str @return: thumbnail @rtype: QImage """ thumbnail = self.readBinaryData(f, tagname=thumbname) return QImage.fromData(QByteArray.fromRawData(thumbnail), 'JPG')
def setupUi(self): super().setupUi(self) qimg = QImage.fromData(self.shopItem.image) self.itemIconLabel.setPixmap(QPixmap.fromImage(qimg)) self.itemNameLabel.setText(self.shopItem.name) self.priceUnitLabel.setText(str(self.shopItem.price_per_unit)) self.quantitySpinBox.setValue(self.shopEventItemUserData["quantity"]) self.quantitySpinBox.valueChanged.connect(self.onQuantityChanged) self.setTotalPrice() if self.shopItem.usual_max_per_event: self.usualMaxLabel.setText(str(self.shopItem.usual_max_per_event)) else: self.usualMaxLabel.setText("Unknown")
def download(self): self.requiredTiles = self.getTiles() for xTile in range(self.requiredTiles['left'], self.requiredTiles['right'] + 1): for yTile in range(self.requiredTiles['bottom'], self.requiredTiles['top'] + 1): grab = TileKey(self.tileZoomIndex, xTile, yTile) if grab not in self.tilePixmaps: cacheLayerName = self.layerName.split(':')[1] hardDrive = os.path.abspath(os.sep) tilePath = hardDrive + 'cache/{}/{}/{}/{}.png'.format( cacheLayerName, grab.tileZoomIndex, grab.x, grab.y) if ENABLE_CACHE and os.path.exists(tilePath): self.tilePixmaps[grab] = QPixmap(tilePath) else: path = 'http://*****:*****@EPSG:4326' + \ '@png' + \ '/{}/{}/{}.png'.format(grab.tileZoomIndex, grab.x, grab.y) try: contents = urllib.request.urlopen(path).read() img = QImage() img = QImage.fromData(contents, "PNG") pic = QPixmap.fromImage(img) self.tilePixmaps[grab] = pic if ENABLE_CACHE: if not os.path.exists( hardDrive + 'cache/{}/{}/{}/'.format( cacheLayerName, grab.tileZoomIndex, grab.x)): os.makedirs(hardDrive + 'cache/{}/{}/{}/'.format( cacheLayerName, grab. tileZoomIndex, grab.x)) pic.save(tilePath, 'png') except: pass
def setupUi(self): super().setupUi(self) qimg = QImage.fromData(self.researchShip.Shipfu.image) self.shipIconLabel.setPixmap(QPixmap.fromImage(qimg)) self.shipNameLabel.setText(self.researchShip.Shipfu.name) if self.hasFateSimulation(self.researchShip): self.addFateSimulationTable() if self.researchShipUserData["level"] == 30: self.fateSimulationPhaseSpinBox.setEnabled(True) self.fateSimulationPhaseSpinBox.setValue( self.researchShipUserData["fate_simul_phase"]) self.fateSimulationPhaseSpinBox.valueChanged.connect( self.onFieldChanged) self.researchLevelSpinBox.setValue(self.researchShipUserData["level"]) self.researchLevelSpinBox.valueChanged.connect(self.onFieldChanged) self.currentBpSpinBox.setValue(self.researchShipUserData["bp"]) self.currentBpSpinBox.valueChanged.connect(self.onFieldChanged)
def setStaticLabels(self, shipfu1, shipfu2): label_infos_corresp = [ (self.ship1NameLabel, shipfu1.Shipfu.name), (self.ship2NameLabel, shipfu2.Shipfu.name), (self.ship1TypeLabel, shipfu1.ShipType.name), (self.ship2TypeLabel, shipfu2.ShipType.name), (self.ship1NationLabel, shipfu1.Nation.name), (self.ship2NationLabel, shipfu2.Nation.name), (self.ship1RarityLabel, shipfu1.Rarity.name), (self.ship2RarityLabel, shipfu2.Rarity.name), ] for (label, info) in label_infos_corresp: label.setText(str(info)) for (label, img) in [(self.ship1ImageLabel, shipfu1.Shipfu.image), (self.ship2ImageLabel, shipfu2.Shipfu.image)]: qimg = QImage.fromData(img) pixmap = QPixmap.fromImage(qimg) label.setPixmap(pixmap)
def _handle_load_images_sucess(self, images, scrollDirection): img_count = len(images) print('Recevied %s images' % img_count) LOGGER.debug('Recevied %s images' % img_count) for img in images: img['thumb'] = QImage.fromData(img['thumb']) item = QStandardItem() thumb_caption_type = settings.get( SettingType.UI_THUMBS_CAPTION_DISPLAY_MODE, Thumb_Caption_Type.NoCaption.name) if thumb_caption_type == Thumb_Caption_Type.FileName.name: item.setText(img['name']) item.setData(img['id'], QtCore.Qt.UserRole + 1) item.setData(img['serial'], QtCore.Qt.UserRole + 2) item.setIcon(QIcon(QPixmap.fromImage(img['thumb']))) item.setText(str(img['serial'])) if scrollDirection == ScrollDirection.Up: self._thumbs_view_model.insertRow(0, item) if scrollDirection == ScrollDirection.Down: self._thumbs_view_model.appendRow(item)
def decode_image(text: str) -> QImage: encoded_bytes = QByteArray(text.encode('utf8')) image_bytes = QByteArray.fromBase64(encoded_bytes) image = QImage.fromData(image_bytes) return image