root/branches/gajim_0.8.2/src/cell_renderer_image.py

Revision 3449, 3.9 kB (checked in by nk, 3 years ago)

fig bg desktop file

Line 
1##      cell_renderer_image.py
2##
3## Gajim Team:
4## - Yann Le Boulanger <asterix@lagaule.org>
5## - Vincent Hanquez <tab@snarc.org>
6## - Nikos Kouremenos <kourem@gmail.com>
7##
8##      Copyright (C) 2003-2005 Gajim Team
9##
10## This program is free software; you can redistribute it and/or modify
11## it under the terms of the GNU General Public License as published
12## by the Free Software Foundation; version 2 only.
13##
14## This program is distributed in the hope that it will be useful,
15## but WITHOUT ANY WARRANTY; without even the implied warranty of
16## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17## GNU General Public License for more details.
18##
19
20import gtk
21import gobject
22
23class CellRendererImage(gtk.GenericCellRenderer):
24
25        __gproperties__ = {
26                'image': (gobject.TYPE_OBJECT, 'Image', 
27                        'Image', gobject.PARAM_READWRITE),
28        }
29
30        def __init__(self):
31                self.__gobject_init__()
32                self.image = None
33
34        def do_set_property(self, pspec, value):
35                setattr(self, pspec.name, value)
36
37        def do_get_property(self, pspec):
38                return getattr(self, pspec.name)
39
40        def func(self, model, path, iter, (image, tree)):
41                if model.get_value(iter, 0) != image:
42                        return
43                self.redraw = 1
44                cell_area = tree.get_cell_area(path, tree.get_column(0))
45                tree.queue_draw_area(cell_area.x, cell_area.y,
46                                        cell_area.width, cell_area.height)
47
48        def animation_timeout(self, tree, image):
49                if image.get_storage_type() != gtk.IMAGE_ANIMATION:
50                        return
51                self.redraw = 0
52                image.get_data('iter').advance()
53                model = tree.get_model()
54                model.foreach(self.func, (image, tree))
55                if self.redraw:
56                        i = image.get_data('iter')
57                        gobject.timeout_add(i.get_delay_time(),
58                                        self.animation_timeout, tree, image)
59                else:
60                        image.set_data('iter', None)
61                               
62        def on_render(self, window, widget, background_area, cell_area,
63                                        expose_area, flags):
64                if not self.image:
65                        return
66                pix_rect = gtk.gdk.Rectangle()
67                pix_rect.x, pix_rect.y, pix_rect.width, pix_rect.height = \
68                                        self.on_get_size(widget, cell_area)
69
70                pix_rect.x += cell_area.x
71                pix_rect.y += cell_area.y
72                pix_rect.width -= 2 * self.get_property('xpad')
73                pix_rect.height -= 2 * self.get_property('ypad')
74
75                draw_rect = cell_area.intersect(pix_rect)
76                draw_rect = expose_area.intersect(draw_rect)
77
78                if self.image.get_storage_type() == gtk.IMAGE_ANIMATION:
79                        if not self.image.get_data('iter'):
80                                animation = self.image.get_animation()
81                                self.image.set_data('iter', animation.get_iter())
82                                i = self.image.get_data('iter')
83                                gobject.timeout_add(i.get_delay_time(),
84                                                self.animation_timeout,
85                                                widget, self.image)
86
87                        pix = self.image.get_data('iter').get_pixbuf()
88                elif self.image.get_storage_type() == gtk.IMAGE_PIXBUF:
89                        pix = self.image.get_pixbuf()
90                else:
91                        return
92                window.draw_pixbuf(widget.style.black_gc, pix,
93                                        draw_rect.x - pix_rect.x,
94                                        draw_rect.y - pix_rect.y,
95                                        draw_rect.x, draw_rect.y + 2,
96                                        draw_rect.width, draw_rect.height,
97                                        gtk.gdk.RGB_DITHER_NONE, 0, 0)
98
99        def on_get_size(self, widget, cell_area):
100                if not self.image:
101                        return 0, 0, 0, 0
102                if self.image.get_storage_type() == gtk.IMAGE_ANIMATION:
103                        animation = self.image.get_animation()
104                        pix = animation.get_iter().get_pixbuf()
105                elif self.image.get_storage_type() == gtk.IMAGE_PIXBUF:
106                        pix = self.image.get_pixbuf()
107                else:
108                        return 0, 0, 0, 0
109                pixbuf_width = pix.get_width()
110                pixbuf_height = pix.get_height()
111                calc_width = self.get_property('xpad') * 2 + pixbuf_width
112                calc_height = self.get_property('ypad') * 2 + pixbuf_height
113                x_offset = 0
114                y_offset = 0
115                if cell_area and pixbuf_width > 0 and pixbuf_height > 0:
116                        x_offset = self.get_property('xalign') * \
117                                        (cell_area.width - calc_width - \
118                                        self.get_property('xpad'))
119                        y_offset = self.get_property('yalign') * \
120                                        (cell_area.height - calc_height - \
121                                        self.get_property('ypad'))
122                return x_offset, y_offset, calc_width, calc_height
123
124if gtk.pygtk_version < (2, 8, 0): 
125        gobject.type_register(CellRendererImage)
Note: See TracBrowser for help on using the browser.