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

Control KNotify4 using DBus

Tags: None
(comma "," separated)
User avatar
jpetso
Registered Member
Posts
4
Karma
0

RE: Control KNotify4 using DBus

Mon Jan 19, 2009 12:19 am
I changed kdialog so that a standard call of
Code: Select all
kdialog --passive-popup  --title 

(title and timeout are optional) makes use of those VisualNotifications if they are available. The release team allowed me to backport it to 4.2 too, so there you go.

Last edited by jpetso on Mon Jan 19, 2009 12:20 am, edited 1 time in total.
arizonagroovejet
Registered Member
Posts
12
Karma
0

RE: Control KNotify4 using DBus

Tue Feb 03, 2009 5:40 pm
jpetso wrote:I changed kdialog so that a standard call of
Code: Select all
kdialog --passive-popup  --title 

(title and timeout are optional) makes use of those VisualNotifications if they are available. The release team allowed me to backport it to 4.2 too, so there you go.


That is very neat. Not as good as being able to do what I and the OP wanted to, but still a welcome feature. Good work!
peaches
Registered Member
Posts
31
Karma
1

RE: Control KNotify4 using DBus

Tue Apr 28, 2009 5:36 pm
any notify-send in the works? kdialog doesn't set icon :(
User avatar
Rettich
Registered Member
Posts
123
Karma
0
OS

RE: Control KNotify4 using DBus

Mon May 18, 2009 8:27 pm
I needed such a script. Wasn't that difficult to write it in python. Its not complete but I think its not very hard to modify it for your own needs:

Code: Select all
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Default Configuration (will be overridden by cmd line arguments)
APPLICATION   = ''      # name of the calling application (will be shown if now summery is available)
SUMMERY      = ''
BODY      = ''
ICON      = 'kmail'
TIMEOUT      = 2000      # 0 means, never hide the message; value greater than 0 is the time in ms the message is shown

import sys
import getopt
import dbus

def main():
   dbus = DBus()
   args = CmdLine(sys.argv[1:])
   dbus.notify(app_name=args.getApplication(), app_icon=ICON, summery=args.getSummery(), body=args.getBody(), timeout=TIMEOUT)

class CmdLine():
   # TODO: support for more options

   def __init__(self, argv):
      try:
         opts, args = getopt.getopt(argv, 'hs:', ['help', 'summery=', 'app='])
      except getopt.GetoptError:
         usage()
         sys.exit(2)

      for opt, arg in opts:
         if opt in ('-h', '--help'):
            usage()
            sys.exit()
         elif opt in ('-s', '--summery'):
            self.__summery = arg
         elif opt == '--app':
            self.__app = arg

      if len(args) > 0:
         self.__body = ' '.join(args)

   def getApplication(self):
      try:
         return self.__app
      except AttributeError:
         return APPLICATION

   def getSummery(self):
      try:
         return self.__summery
      except AttributeError:
         return SUMMERY

   def getBody(self):
      try:
         return self.__body
      except AttributeError:
         return BODY

def usage():
   """print usage message"""
   # TODO print more useful help message
   print 'Usage: notify.py [--app=] [-s|--summery=] []'

class DBus():
   """Wrapper class for notify daemon dbus interface"""

   def __init__(self):
      self.__notify = dbus.SessionBus().get_object('org.kde.VisualNotifications', '/VisualNotifications')
   
   def notify(self, app_name='', replaces_id=dbus.UInt32(), event_id='', app_icon='', summery='', body='', actions=dbus.Array(signature='s'), hints=dbus.Dictionary(signature='sv'), timeout=0):
      self.__notify.Notify(app_name, replaces_id, event_id, app_icon, summery, body, actions, hints, timeout)

   def closeNotification(self, event_id):
      self.__notify.CloseNotification(event_id)

if __name__ == "__main__":
   main();


Murphy's Law is recursive. Washing your car to make it rain doesn't work.
seastland
Registered Member
Posts
2
Karma
0
OS

Re: Control KNotify4 using DBus

Thu Jan 28, 2010 2:04 am
To dig up an old thread, I have been looking for a such a script, found the one in the post above, did some Googling about Python, and modified it to this:

Code: Select all
#!/usr/bin/python
# -*- coding: utf-8 -*-
# originally script found at viewtopic.php?f=66&t=23580

import dbus
from optparse import OptionParser

def main():
   parser = OptionParser(usage="%prog [options] <summary> [body]", version="%prog 0.1")
   parser.add_option("-a", "--app", dest="app_name", help="Specifies the application name.", default="notify-dbus.py")
   parser.add_option("-i", "--icon", dest="icon", help="Specifies an icon filename or stock icon to display.", default="")
   parser.add_option("-t", "--expire-timeout", type="int", dest="timeout", help="Specifies the timeout in milliseconds at which to expire the notification.", default=0)
   (options, args) = parser.parse_args()
   if len(args) < 1:
      parser.error("No summary specified.")
   if len(args) > 1:
       BODY = args[1]
   else:
       BODY = ""
   dbus = DBus()
   dbus.notify(app_name=options.app_name, app_icon=options.icon, summary=args[0], body=BODY, timeout=options.timeout)

class DBus():
   """Wrapper class for notify daemon dbus interface"""

   def __init__(self):
      self.__notify = dbus.SessionBus().get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
      self.__iface = dbus.Interface(self.__notify, "org.freedesktop.Notifications")
   
   def notify(self, app_name='', replaces_id=dbus.UInt32(), app_icon='', summary='', body='', actions=dbus.Array(signature="s"), hints=dbus.Dictionary(signature="sv"), timeout=0):
      self.__iface.Notify(app_name, replaces_id, app_icon, summary, body, actions, hints, timeout)

if __name__ == "__main__":
   main();


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], ourcraft