~jconti/recent-notifications/trunk

« back to all changes in this revision

Viewing changes to unity/Notification.py

  • Committer: Jason Conti
  • Date: 2011-03-30 23:38:14 UTC
  • Revision ID: jason.conti@gmail.com-20110330233814-ibjx6zi0ma3exvtu
Introducing an ugly hack to load image_data until GdkPixbuf.Pixbuf.new_from_data is fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
"""
10
10
 
11
11
import dbus
12
 
from gi.repository import GdkPixbuf, GObject, Gtk
 
12
import Image
13
13
import logging
 
14
import os
14
15
 
15
16
from dbus.mainloop.glib import DBusGMainLoop
 
17
from gi.repository import GdkPixbuf, GObject, Gtk
16
18
 
17
19
import Icon
18
20
import Timestamp
19
21
 
20
22
logger = logging.getLogger("Notification")
21
23
 
 
24
# BEGIN_UGLY_HACK
 
25
BROKEN_IMAGE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "broken_image.png")
 
26
def broken_gdkpixbuf_hack(data, w, h):
 
27
  im = Image.fromstring("RGBA", (w, h), data)
 
28
  im.save(BROKEN_IMAGE_PATH)
 
29
  return GdkPixbuf.Pixbuf.new_from_file(BROKEN_IMAGE_PATH)
 
30
# END_UGLY_HACK
 
31
 
22
32
class ImageDataException(Exception):
23
33
  pass
24
34
 
41
51
 
42
52
  def get_pixbuf(self, size):
43
53
    """Creates a pixbuf from the image data and scale it to the appropriate size."""
44
 
    pixbuf = GdkPixbuf.Pixbuf.new_from_data(self.data, GdkPixbuf.Colorspace.RGB,
45
 
        self.has_alpha, self.bits_per_sample, self.width, self.height,
46
 
        self.rowstride, lambda *args: None, None)
 
54
    #pixbuf = GdkPixbuf.Pixbuf.new_from_data(self.data, GdkPixbuf.Colorspace.RGB,
 
55
    #    self.has_alpha, self.bits_per_sample, self.width, self.height,
 
56
    #    self.rowstride, lambda *args: None, None)
 
57
    pixbuf = broken_gdkpixbuf_hack(self.data, self.width, self.height)
47
58
 
48
59
    return pixbuf.scale_simple(size, size, GdkPixbuf.InterpType.BILINEAR)
49
60