def pixmap_to_data(pixmap, format='PNG'): ''' Return the QPixmap pixmap as a string saved in the specified format. ''' ba = QByteArray() buf = QBuffer(ba) buf.open(QIODeviceBase.OpenModeFlag.WriteOnly) pixmap.save(buf, format) return bytes(ba.data())
def get_welcome_html(): if not hasattr(get_welcome_html, 'html'): d = get_data('welcome.html').decode('utf-8') ic = get_data('images/vise.svg') d = d.replace('VISE_ICON', 'data:image/svg+xml;base64,' + base64.standard_b64encode(ic).decode('ascii')) get_welcome_html.html = QByteArray(d.encode('utf-8')) return get_welcome_html.html
def serialize(obj: _QtSerializable) -> QByteArray: """Serialize an object into a QByteArray.""" data = QByteArray() stream = QDataStream(data, QIODevice.OpenModeFlag.WriteOnly) check_dstream(stream) stream << obj # type: ignore[operator] check_dstream(stream) return data
def getInitialSettings(self): """Get initial settings of the application using QSettings upon startup.""" position = self.settings.value("position", QPoint(200, 0)) size = self.settings.value("size", QSize(800, 500)) self.is_delete_checked = self.settings.value("delete_images", type=bool) # restoreState() is used here to restore the image_preview_dock widget self.restoreState(self.settings.value("window_state", bytes(QByteArray()))) self.resize(size) self.move(position) return self.is_delete_checked
def filename_icon_data(encoded_file_name): return QByteArray(icon_data_for_filename(unhexlify(encoded_file_name).decode('utf-8'), size=64) or get_data('images/blank.png'))
def get_downloads_html(): if not hasattr(get_downloads_html, 'html'): get_downloads_html.html = QByteArray(get_data('downloads.html').decode('utf-8').replace('_TITLE_', _('Downloads')).encode('utf-8')) return get_downloads_html.html