def newDBusMenuItem(action: DBusMenuAction, properties, children): item = QDBusArgument() item.beginStructure() item.add(action.value, QMetaType.Int) # id item.add(properties, QMetaType.QVariantMap) item.add(children, QMetaType.QVariantList) item.endStructure() return item
def GetGroupProperties(self, msg): itemIds, propertyNames = msg.arguments() result = QDBusArgument() result.beginArray(GroupPropertyMetaType) for itemId in itemIds: result.beginStructure() result.add(itemId, QMetaType.Int) result.add(self._getItemProperty(itemId), QMetaType.QVariantMap) result.endStructure() result.endArray() reply = msg.createReply([result]) return self.__sessionService.sessionBus.send(reply)
def GetGroupProperties(self, msg): itemIds, propertyNames = msg.arguments() result = QDBusArgument() result.beginArray(GroupPropertyMetaType) for itemId in itemIds: result.beginStructure() result.add(itemId, QMetaType.Int) result.add(self._getItemProperty(itemId), QMetaType.QVariantMap) result.endStructure() result.endArray() reply = msg.createReply([ result ]) return self.__sessionService.sessionBus.send(reply)
def _convert_image(self, qimage: QImage) -> Optional[QDBusArgument]: """Convert a QImage to the structure DBus expects. https://specifications.freedesktop.org/notification-spec/latest/ar01s05.html#icons-and-images-formats """ bits_per_color = 8 has_alpha = qimage.hasAlphaChannel() if has_alpha: image_format = QImage.Format_RGBA8888 channel_count = 4 else: image_format = QImage.Format_RGB888 channel_count = 3 qimage.convertTo(image_format) bytes_per_line = qimage.bytesPerLine() width = qimage.width() height = qimage.height() image_data = QDBusArgument() image_data.beginStructure() image_data.add(width) image_data.add(height) image_data.add(bytes_per_line) image_data.add(has_alpha) image_data.add(bits_per_color) image_data.add(channel_count) try: size = qimage.sizeInBytes() except TypeError: # WORKAROUND for # https://www.riverbankcomputing.com/pipermail/pyqt/2020-May/042919.html # byteCount() is obsolete, but sizeInBytes() is only available with # SIP >= 5.3.0. size = qimage.byteCount() # Despite the spec not mandating this, many notification daemons mandate that # the last scanline does not have any padding bytes. # # Or in the words of dunst: # # The image is serialised rowwise pixel by pixel. The rows are aligned by a # spacer full of garbage. The overall data length of data + garbage is # called the rowstride. # # Mind the missing spacer at the last row. # # len: |<--------------rowstride---------------->| # len: |<-width*pixelstride->| # row 1: | data for row 1 | spacer of garbage | # row 2: | data for row 2 | spacer of garbage | # | . | spacer of garbage | # | . | spacer of garbage | # | . | spacer of garbage | # row n-1: | data for row n-1 | spacer of garbage | # row n: | data for row n | # # Source: # https://github.com/dunst-project/dunst/blob/v1.6.1/src/icon.c#L292-L309 padding = bytes_per_line - width * channel_count assert 0 <= padding <= 3, (padding, bytes_per_line, width, channel_count) size -= padding if padding and self._quirks.no_padded_images: return None bits = qimage.constBits().asstring(size) image_data.add(QByteArray(bits)) image_data.endStructure() return image_data