/usr/share/stackapplet/pynotify_replacement.py is in stackapplet 1.5.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | #=========================
#
# PyNotify for GTK
# drop-in replacement
#
# Copyright 2010
# Nathan Osman
#
#=========================
import pygtk
import gtk
import gobject
# We also have an init() method that does absolutely nothing
def init(unused_param):
pass
# We have a queue here that we store the notifications
# in. When someone calls 'notification::show' then the
# notification is either appended to the queue or shown.
notifications_queue = []
class Notification:
def __init__ (self, title, message, icon):
# Start by creating a window that we will use
# to display the information.
self.window = gtk.Window(gtk.WINDOW_POPUP)
# Set a few properties on the window,
# including background color.
self.window.set_border_width(10)
self.window.set_opacity(0.8)
self.window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#000000'))
# Create two labels to insert into the window
self.title = gtk.Label()
self.message = gtk.Label()
self.title.set_markup("<b>" + title + "</b>")
self.message.set_label(message)
self.title.set_alignment(0,0)
self.message.set_alignment(0,0)
self.title.show()
self.message.show()
# Set some properties on the labels
self.title.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#ffffff'))
self.message.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#ffffff'))
# Create the image
self.image = gtk.Image()
pixbuf = gtk.gdk.pixbuf_new_from_file(icon)
scaled_buf = pixbuf.scale_simple(48, 48, gtk.gdk.INTERP_BILINEAR)
self.image.set_from_pixbuf(scaled_buf)
self.image.set_size_request(48, 48)
self.image.set_alignment(0,0)
self.image.show()
# Now create the layout for the control
vbox = gtk.VBox()
vbox.add(self.title)
vbox.add(self.message)
vbox.show()
hbox = gtk.HBox()
hbox.set_spacing(8)
hbox.add(self.image)
hbox.add(vbox)
hbox.show()
self.window.add(hbox)
# Now we need to position the window
screen = gtk.gdk.Screen()
rect = screen.get_monitor_geometry(0)
xpos = (rect.x + rect.width) - self.window.get_size()[0] - 32
ypos = rect.y + 64
self.window.move(xpos, ypos)
def show(self):
global notifications_queue
# If there is nothing in the queue, then
# do nothing. Otherwise, display this window.
if not len(notifications_queue):
# Done will be called when the notification is done
self.display_window()
# Append this item to the queue
notifications_queue.append(self)
def display_window(self):
self.window.show()
gobject.timeout_add(10000, self.done)
def done(self):
# Hide this window
self.window.hide()
global notifications_queue
# Pop the item being displayed
notifications_queue.remove(self)
# See if there are any others in the queue
if len(notifications_queue):
# Pop and display that item
next = notifications_queue[0]
next.display_window()
|