~ubuntu-branches/ubuntu/vivid/radiotray/vivid

« back to all changes in this revision

Viewing changes to data/plugins/NotificationPlugin.py

  • Committer: Package Import Robot
  • Author(s): Julian Taylor
  • Date: 2013-05-09 21:24:43 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20130509212443-x1rgywggtb3bsorf
Tags: 0.7.3-1ubuntu1
* Merge from Debian unstable. (LP: #1156142, #972259, #972205)
  Remaining changes:
  - patch config to use appindicator by default
  - depend on python-appindicator

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#
19
19
##########################################################################
20
20
 
 
21
 
21
22
from Plugin import Plugin
22
23
import gtk
23
24
import gobject
51
52
 
52
53
 
53
54
    def on_notification(self, data):
54
 
        self.notify(data['title'], data['message'])
55
 
 
56
 
 
57
 
    def notify(self, title, message):
58
 
 
 
55
        
 
56
        message = data['message']
 
57
        title = data['title']
59
58
        if self.lastMessage != message:
60
59
 
61
60
            self.lastMessage = message
65
64
                if pynotify.init(APPNAME):
66
65
                    self.notif = pynotify.Notification(title, message)
67
66
                    self.notif.set_urgency(pynotify.URGENCY_LOW)
68
 
                    pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(APP_ICON, 48, 48)
69
 
                    self.notif.set_icon_from_pixbuf(pixbuf)
 
67
                    self.set_icon(data)
70
68
                    self.notif.set_timeout(pynotify.EXPIRES_DEFAULT)
71
69
                    self.notif.show()
72
70
                else:
73
71
                    self.log.error('Error: there was a problem initializing the pynotify module')
74
72
            
75
73
            else:
 
74
                self.set_icon(data)
76
75
                self.notif.update(title, message)
77
76
                self.notif.show()
 
77
 
 
78
 
 
79
    def set_icon(self, data):
 
80
        #some radios publish cover data in the 'homepage' tag
 
81
        if('icon' in data.keys()):
 
82
 
 
83
            try:
 
84
                pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(data['icon'], 48, 48)
 
85
                self.notif.set_icon_from_pixbuf(pixbuf)
 
86
            except Exception, e:
 
87
                pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(APP_ICON, 48, 48)
 
88
                self.notif.set_icon_from_pixbuf(pixbuf)
 
89
                print e
 
90
        else:
 
91
            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(APP_ICON, 48, 48)
 
92
            self.notif.set_icon_from_pixbuf(pixbuf)