This forum has been archived. All content is frozen. Please use KDE Discuss instead.

change icon in notification

Tags: None
(comma "," separated)
hateshark
Registered Member
Posts
6
Karma
0
OS

change icon in notification

Sat Jan 04, 2014 2:35 pm
Could someone please give me an example of how to change the icon when showing a knotify message via dbus?
It should be the chronometer-icon.

The code is part of a plasmoid using python.

Code: Select all
self.knotify = dbus.SessionBus().get_object("org.kde.knotify", "/Notify")
self.knotify.event(
                "notification",
                "kde",
                [],
                self.NOTIFICATION_TITLE,
                self.NOTIFICATION_MESSAGE,
                [],
                [],
               10000,
                0,
                dbus_interface="org.kde.KNotify")


BTW: Is there a possibility to mute the sound of this single notification?

KDE version: 4.8.5
Kubuntu 12.04
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: change icon in notification

Sat Jan 04, 2014 11:21 pm
Unfortunately the only way to mute it would be by using the native KNotification infrastructure, which is provided via the PyKDE4 bindings - as this allows for notifications to be extensively customised.

In terms of setting the icon to be used, it appears the API you are using requires a pixmap to be passed along. You will need to use KIcon to load the icon you need in question, and then pass along the appropriate binary data from that. You might also want to set "plasma-desktop" as the application name, rather than "kde".

Code: Select all
method int org.kde.KNotify.event(QString event, QString fromApp, QVariantList contexts, QString title, QString text, QByteArray pixmap, QStringList actions, int timeout, qlonglong winId)


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
hateshark
Registered Member
Posts
6
Karma
0
OS

Re: change icon in notification

Sun Jan 05, 2014 1:35 pm
Code: Select all
 
icon =KIcon("chronometer")

self.knotify.event(
                "notification",
                "kde",
                [],
                self.NOTIFICATION_TITLE,
                self.NOTIFICATION_MESSAGE %  (self.notificationCycle, 's' if self.notificationCycle > 1 else ''),
                icon.pixmap(32, 32),
                [],
                self.notificationDuration * 1000 if self.hideNotification else 0,
                0,
                dbus_interface="org.kde.KNotify")


The above code gives the message:
TypeError: 'QPixmap' object is not iterable


Changing "kde" to "plasma-desktop" does nothing. No notification or error comes up.

I am rather a novice in KDE programming and python.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: change icon in notification

Tue Jan 07, 2014 9:18 am
You might find http://www.qtcentre.org/threads/2037-Co ... QByteArray to be of use - although that is C++ code you will need to port into the Python equivalent.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
hateshark
Registered Member
Posts
6
Karma
0
OS

Re: change icon in notification  Topic is solved

Sun Jan 12, 2014 8:30 pm
I've found the solution here: http://qt-project.org/doc/qt-4.8/qpixmap.html#save-2

I've got the bytearray with the following steps:
Code: Select all
kicon = KIcon("chronometer")
bytearray = QByteArray()
buffer = QBuffer(bytearray)
kicon.pixmap(64, 64).save(buffer, 'PNG')


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], Yahoo [Bot]