2005-04-18 16:05:30 +02:00
|
|
|
## cell_renderer_image.py
|
|
|
|
##
|
2005-12-09 18:15:30 +01:00
|
|
|
## Contributors for this file:
|
2005-04-18 16:05:30 +02:00
|
|
|
## - Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## - Nikos Kouremenos <kourem@gmail.com>
|
|
|
|
##
|
2005-12-10 00:30:28 +01:00
|
|
|
## Copyright (C) 2003-2004 Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## Vincent Hanquez <tab@snarc.org>
|
|
|
|
## Copyright (C) 2005 Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## Vincent Hanquez <tab@snarc.org>
|
2006-09-28 13:31:25 +02:00
|
|
|
## Nikos Kouremenos <kourem@gmail.com>
|
2005-12-10 00:30:28 +01:00
|
|
|
## Dimitur Kirov <dkirov@gmail.com>
|
|
|
|
## Travis Shirk <travis@pobox.com>
|
|
|
|
## Norman Rasmussen <norman@rasmussen.co.za>
|
2005-04-18 16:05:30 +02:00
|
|
|
##
|
|
|
|
## This program is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 2 only.
|
|
|
|
##
|
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
|
|
|
|
import gtk
|
|
|
|
import gobject
|
|
|
|
|
|
|
|
class CellRendererImage(gtk.GenericCellRenderer):
|
|
|
|
|
|
|
|
__gproperties__ = {
|
|
|
|
'image': (gobject.TYPE_OBJECT, 'Image',
|
2005-04-22 01:36:18 +02:00
|
|
|
'Image', gobject.PARAM_READWRITE),
|
2005-04-18 16:05:30 +02:00
|
|
|
}
|
|
|
|
|
Merged revisions 5030-5031,5033-5038 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r5030 | asterix | 2006-01-07 10:04:18 -0700 (Sat, 07 Jan 2006) | 2 lines
when we add a bookmark, we add our nick by default
........
r5031 | nicfit | 2006-01-07 10:24:50 -0700 (Sat, 07 Jan 2006) | 2 lines
Grammatical fix
........
r5033 | asterix | 2006-01-07 11:36:56 -0700 (Sat, 07 Jan 2006) | 2 lines
cell_renderer_image now take in argument the index of the column and the index in the model
........
r5034 | asterix | 2006-01-07 11:37:28 -0700 (Sat, 07 Jan 2006) | 2 lines
typo
........
r5035 | asterix | 2006-01-07 11:38:18 -0700 (Sat, 07 Jan 2006) | 2 lines
don't show header in emoticonManager so that cellrenderer correctly compute the area to redraw
........
r5036 | asterix | 2006-01-07 11:39:41 -0700 (Sat, 07 Jan 2006) | 2 lines
prevent a TB
........
r5037 | nicfit | 2006-01-07 13:26:08 -0700 (Sat, 07 Jan 2006) | 2 lines
Increment later
........
r5038 | nicfit | 2006-01-07 13:29:05 -0700 (Sat, 07 Jan 2006) | 2 lines
Fixed syntax error
........
2006-01-07 21:47:06 +01:00
|
|
|
def __init__(self, col_index, tv_index):
|
2005-04-18 16:05:30 +02:00
|
|
|
self.__gobject_init__()
|
|
|
|
self.image = None
|
Merged revisions 5030-5031,5033-5038 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r5030 | asterix | 2006-01-07 10:04:18 -0700 (Sat, 07 Jan 2006) | 2 lines
when we add a bookmark, we add our nick by default
........
r5031 | nicfit | 2006-01-07 10:24:50 -0700 (Sat, 07 Jan 2006) | 2 lines
Grammatical fix
........
r5033 | asterix | 2006-01-07 11:36:56 -0700 (Sat, 07 Jan 2006) | 2 lines
cell_renderer_image now take in argument the index of the column and the index in the model
........
r5034 | asterix | 2006-01-07 11:37:28 -0700 (Sat, 07 Jan 2006) | 2 lines
typo
........
r5035 | asterix | 2006-01-07 11:38:18 -0700 (Sat, 07 Jan 2006) | 2 lines
don't show header in emoticonManager so that cellrenderer correctly compute the area to redraw
........
r5036 | asterix | 2006-01-07 11:39:41 -0700 (Sat, 07 Jan 2006) | 2 lines
prevent a TB
........
r5037 | nicfit | 2006-01-07 13:26:08 -0700 (Sat, 07 Jan 2006) | 2 lines
Increment later
........
r5038 | nicfit | 2006-01-07 13:29:05 -0700 (Sat, 07 Jan 2006) | 2 lines
Fixed syntax error
........
2006-01-07 21:47:06 +01:00
|
|
|
self.col_index = col_index
|
|
|
|
self.tv_index = tv_index
|
2005-09-22 09:42:08 +02:00
|
|
|
self.iters = {}
|
2005-04-18 16:05:30 +02:00
|
|
|
|
|
|
|
def do_set_property(self, pspec, value):
|
|
|
|
setattr(self, pspec.name, value)
|
|
|
|
|
|
|
|
def do_get_property(self, pspec):
|
|
|
|
return getattr(self, pspec.name)
|
|
|
|
|
|
|
|
def func(self, model, path, iter, (image, tree)):
|
Merged revisions 5030-5031,5033-5038 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r5030 | asterix | 2006-01-07 10:04:18 -0700 (Sat, 07 Jan 2006) | 2 lines
when we add a bookmark, we add our nick by default
........
r5031 | nicfit | 2006-01-07 10:24:50 -0700 (Sat, 07 Jan 2006) | 2 lines
Grammatical fix
........
r5033 | asterix | 2006-01-07 11:36:56 -0700 (Sat, 07 Jan 2006) | 2 lines
cell_renderer_image now take in argument the index of the column and the index in the model
........
r5034 | asterix | 2006-01-07 11:37:28 -0700 (Sat, 07 Jan 2006) | 2 lines
typo
........
r5035 | asterix | 2006-01-07 11:38:18 -0700 (Sat, 07 Jan 2006) | 2 lines
don't show header in emoticonManager so that cellrenderer correctly compute the area to redraw
........
r5036 | asterix | 2006-01-07 11:39:41 -0700 (Sat, 07 Jan 2006) | 2 lines
prevent a TB
........
r5037 | nicfit | 2006-01-07 13:26:08 -0700 (Sat, 07 Jan 2006) | 2 lines
Increment later
........
r5038 | nicfit | 2006-01-07 13:29:05 -0700 (Sat, 07 Jan 2006) | 2 lines
Fixed syntax error
........
2006-01-07 21:47:06 +01:00
|
|
|
if model.get_value(iter, self.tv_index) != image:
|
2005-04-22 01:36:18 +02:00
|
|
|
return
|
|
|
|
self.redraw = 1
|
Merged revisions 5030-5031,5033-5038 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r5030 | asterix | 2006-01-07 10:04:18 -0700 (Sat, 07 Jan 2006) | 2 lines
when we add a bookmark, we add our nick by default
........
r5031 | nicfit | 2006-01-07 10:24:50 -0700 (Sat, 07 Jan 2006) | 2 lines
Grammatical fix
........
r5033 | asterix | 2006-01-07 11:36:56 -0700 (Sat, 07 Jan 2006) | 2 lines
cell_renderer_image now take in argument the index of the column and the index in the model
........
r5034 | asterix | 2006-01-07 11:37:28 -0700 (Sat, 07 Jan 2006) | 2 lines
typo
........
r5035 | asterix | 2006-01-07 11:38:18 -0700 (Sat, 07 Jan 2006) | 2 lines
don't show header in emoticonManager so that cellrenderer correctly compute the area to redraw
........
r5036 | asterix | 2006-01-07 11:39:41 -0700 (Sat, 07 Jan 2006) | 2 lines
prevent a TB
........
r5037 | nicfit | 2006-01-07 13:26:08 -0700 (Sat, 07 Jan 2006) | 2 lines
Increment later
........
r5038 | nicfit | 2006-01-07 13:29:05 -0700 (Sat, 07 Jan 2006) | 2 lines
Fixed syntax error
........
2006-01-07 21:47:06 +01:00
|
|
|
col = tree.get_column(self.col_index)
|
|
|
|
cell_area = tree.get_cell_area(path, col)
|
|
|
|
|
2005-04-22 01:36:18 +02:00
|
|
|
tree.queue_draw_area(cell_area.x, cell_area.y,
|
|
|
|
cell_area.width, cell_area.height)
|
2005-04-18 16:05:30 +02:00
|
|
|
|
|
|
|
def animation_timeout(self, tree, image):
|
2005-04-22 01:36:18 +02:00
|
|
|
if image.get_storage_type() != gtk.IMAGE_ANIMATION:
|
|
|
|
return
|
|
|
|
self.redraw = 0
|
2005-09-22 09:42:08 +02:00
|
|
|
iter = self.iters[image]
|
|
|
|
iter.advance()
|
2005-04-22 01:36:18 +02:00
|
|
|
model = tree.get_model()
|
Merged revisions 5030-5031,5033-5038 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r5030 | asterix | 2006-01-07 10:04:18 -0700 (Sat, 07 Jan 2006) | 2 lines
when we add a bookmark, we add our nick by default
........
r5031 | nicfit | 2006-01-07 10:24:50 -0700 (Sat, 07 Jan 2006) | 2 lines
Grammatical fix
........
r5033 | asterix | 2006-01-07 11:36:56 -0700 (Sat, 07 Jan 2006) | 2 lines
cell_renderer_image now take in argument the index of the column and the index in the model
........
r5034 | asterix | 2006-01-07 11:37:28 -0700 (Sat, 07 Jan 2006) | 2 lines
typo
........
r5035 | asterix | 2006-01-07 11:38:18 -0700 (Sat, 07 Jan 2006) | 2 lines
don't show header in emoticonManager so that cellrenderer correctly compute the area to redraw
........
r5036 | asterix | 2006-01-07 11:39:41 -0700 (Sat, 07 Jan 2006) | 2 lines
prevent a TB
........
r5037 | nicfit | 2006-01-07 13:26:08 -0700 (Sat, 07 Jan 2006) | 2 lines
Increment later
........
r5038 | nicfit | 2006-01-07 13:29:05 -0700 (Sat, 07 Jan 2006) | 2 lines
Fixed syntax error
........
2006-01-07 21:47:06 +01:00
|
|
|
if model:
|
|
|
|
model.foreach(self.func, (image, tree))
|
2005-04-22 01:36:18 +02:00
|
|
|
if self.redraw:
|
2005-09-22 09:42:08 +02:00
|
|
|
gobject.timeout_add(iter.get_delay_time(),
|
2005-04-18 16:05:30 +02:00
|
|
|
self.animation_timeout, tree, image)
|
2005-09-22 09:42:08 +02:00
|
|
|
elif image in self.iters:
|
|
|
|
del self.iters[image]
|
2005-04-18 16:05:30 +02:00
|
|
|
|
2005-04-22 01:36:18 +02:00
|
|
|
def on_render(self, window, widget, background_area, cell_area,
|
|
|
|
expose_area, flags):
|
2005-04-18 16:05:30 +02:00
|
|
|
if not self.image:
|
|
|
|
return
|
|
|
|
pix_rect = gtk.gdk.Rectangle()
|
|
|
|
pix_rect.x, pix_rect.y, pix_rect.width, pix_rect.height = \
|
2005-09-22 09:42:08 +02:00
|
|
|
self.on_get_size(widget, cell_area)
|
2005-04-18 16:05:30 +02:00
|
|
|
|
|
|
|
pix_rect.x += cell_area.x
|
|
|
|
pix_rect.y += cell_area.y
|
2005-04-22 01:36:18 +02:00
|
|
|
pix_rect.width -= 2 * self.get_property('xpad')
|
2005-04-18 16:05:30 +02:00
|
|
|
pix_rect.height -= 2 * self.get_property('ypad')
|
|
|
|
|
|
|
|
draw_rect = cell_area.intersect(pix_rect)
|
|
|
|
draw_rect = expose_area.intersect(draw_rect)
|
|
|
|
|
|
|
|
if self.image.get_storage_type() == gtk.IMAGE_ANIMATION:
|
2005-09-22 09:42:08 +02:00
|
|
|
if self.image not in self.iters:
|
2005-04-18 16:05:30 +02:00
|
|
|
animation = self.image.get_animation()
|
2005-09-22 09:42:08 +02:00
|
|
|
iter = animation.get_iter()
|
|
|
|
self.iters[self.image] = iter
|
|
|
|
gobject.timeout_add(iter.get_delay_time(),
|
|
|
|
self.animation_timeout, widget, self.image)
|
2005-04-18 16:05:30 +02:00
|
|
|
|
2005-09-22 09:42:08 +02:00
|
|
|
pix = self.iters[self.image].get_pixbuf()
|
2005-04-18 16:05:30 +02:00
|
|
|
elif self.image.get_storage_type() == gtk.IMAGE_PIXBUF:
|
|
|
|
pix = self.image.get_pixbuf()
|
|
|
|
else:
|
|
|
|
return
|
2005-12-30 22:37:36 +01:00
|
|
|
if draw_rect.x < 1:
|
|
|
|
return
|
2005-04-22 01:36:18 +02:00
|
|
|
window.draw_pixbuf(widget.style.black_gc, pix,
|
|
|
|
draw_rect.x - pix_rect.x,
|
|
|
|
draw_rect.y - pix_rect.y,
|
|
|
|
draw_rect.x, draw_rect.y + 2,
|
|
|
|
draw_rect.width, draw_rect.height,
|
|
|
|
gtk.gdk.RGB_DITHER_NONE, 0, 0)
|
2005-04-18 16:05:30 +02:00
|
|
|
|
|
|
|
def on_get_size(self, widget, cell_area):
|
|
|
|
if not self.image:
|
|
|
|
return 0, 0, 0, 0
|
|
|
|
if self.image.get_storage_type() == gtk.IMAGE_ANIMATION:
|
|
|
|
animation = self.image.get_animation()
|
|
|
|
pix = animation.get_iter().get_pixbuf()
|
|
|
|
elif self.image.get_storage_type() == gtk.IMAGE_PIXBUF:
|
|
|
|
pix = self.image.get_pixbuf()
|
|
|
|
else:
|
|
|
|
return 0, 0, 0, 0
|
2005-04-22 01:36:18 +02:00
|
|
|
pixbuf_width = pix.get_width()
|
2005-04-18 16:05:30 +02:00
|
|
|
pixbuf_height = pix.get_height()
|
2005-04-22 01:36:18 +02:00
|
|
|
calc_width = self.get_property('xpad') * 2 + pixbuf_width
|
2005-04-18 16:05:30 +02:00
|
|
|
calc_height = self.get_property('ypad') * 2 + pixbuf_height
|
|
|
|
x_offset = 0
|
|
|
|
y_offset = 0
|
|
|
|
if cell_area and pixbuf_width > 0 and pixbuf_height > 0:
|
2005-04-22 01:51:16 +02:00
|
|
|
x_offset = self.get_property('xalign') * \
|
|
|
|
(cell_area.width - calc_width - \
|
2005-04-22 01:36:18 +02:00
|
|
|
self.get_property('xpad'))
|
2005-04-22 01:51:16 +02:00
|
|
|
y_offset = self.get_property('yalign') * \
|
|
|
|
(cell_area.height - calc_height - \
|
2005-04-22 01:36:18 +02:00
|
|
|
self.get_property('ypad'))
|
2005-04-18 16:05:30 +02:00
|
|
|
return x_offset, y_offset, calc_width, calc_height
|