114
124
gdkcontext = gtk.gdk.CairoContext(cr)
115
125
gdkcontext.set_antialias(cairo.ANTIALIAS_NONE)
117
# Coordinates of the origin point
118
x_align = self.get_property("xalign")
119
y_align = self.get_property("yalign")
120
orig_x = cell_area.x + int((cell_area.width - 16*vw_tags -\
121
self.PADDING*2*(vw_tags-1)) * x_align)
122
orig_y = cell_area.y + int((cell_area.height - 16) * y_align)
127
rect = gtk.gdk.Rectangle()
128
rect.x, rect.y, rect.width, rect.height = \
129
self.on_get_size(widget, cell_area)
131
rect.x += cell_area.x + self.get_property("xpad")
132
rect.y += cell_area.y + self.get_property("ypad")
124
134
# We draw the icons & squares
125
136
for my_tag in tags:
127
138
my_tag_icon = my_tag.get_attribute("icon")
128
139
my_tag_color = my_tag.get_attribute("color")
130
rect_x = orig_x + self.PADDING*2*count + 16*count
140
my_tag_name = my_tag.get_attribute("name")[1:]
135
# pixbuf = gtk.gdk.pixbuf_new_from_file(my_tag_icon)
136
143
pixbuf = gtk.icon_theme_get_default().load_icon(\
138
gdkcontext.set_source_pixbuf(pixbuf, rect_x, rect_y)
144
my_tag_icon, self.HEIGHT, 0)
145
gdkcontext.set_source_pixbuf(pixbuf, rect.x, rect.y)
139
146
gdkcontext.paint()
147
rect.x = rect.x + 2 * self.PADDING + self.MINWIDTH
142
148
elif my_tag_color:
144
# Draw rounded rectangle
145
my_color = gtk.gdk.color_parse(my_tag_color)
146
gdkcontext.set_source_color(my_color)
147
self.__roundedrec(gdkcontext, rect_x, rect_y, 16, 16, 8)
152
gdkcontext.set_source_rgba(0, 0, 0, 0.20)
153
gdkcontext.set_line_width(1.0)
154
self.__roundedrec(gdkcontext, rect_x, rect_y, 16, 16, 8)
153
gdkcontext.set_font_size(self.FONT_SIZE)
154
xb, yb_ref, fw, fh_ref = cr.text_extents("peoplemoney")[:4]
155
x_bearing, y_bearing, f_width, f_height = cr.text_extents(my_tag_name)[:4]
159
width = max(f_width, self.MINWIDTH) + 2 * box_padding
161
# Draw rounded rectangle
162
my_color = gtk.gdk.color_parse(my_tag_color)
163
# gdkcontext.set_source_rgba(my_color.red/65535.0, \
164
# my_color.green/65535.0, \
165
# my_color.blue/65535.0, 0.75)
166
gdkcontext.set_source_color(my_color)
167
self.__roundedrec(gdkcontext, rect.x, rect.y, width, height, 6)
171
# gdkcontext.set_source_rgba(0, 0, 0, 0.20)
172
# gdkcontext.set_line_width(1.0)
173
# self.__roundedrec(gdkcontext, rect.x, rect.y, width, height, 8)
174
# gdkcontext.stroke()
177
b = (my_color.red*299.0 + my_color.green*587 + \
178
my_color.blue*114) / 65535.0 / 1000.0
183
gdkcontext.set_source_rgba(c, c, c, 1.0)
184
gdkcontext.move_to(rect.x + width/2 - f_width/2,\
185
rect.y + (height - fh_ref)/2 - yb_ref)
186
gdkcontext.show_text(my_tag_name)
188
rect.x = rect.x + 2 * self.PADDING + width
193
width = self.MINWIDTH
195
# Draw rounded rectangle
196
my_color = gtk.gdk.color_parse(my_tag_color)
197
gdkcontext.set_source_color(my_color)
198
self.__roundedrec(gdkcontext, rect.x, rect.y, width, height, 8)
202
gdkcontext.set_source_rgba(0, 0, 0, 0.20)
203
gdkcontext.set_line_width(1.0)
204
self.__roundedrec(gdkcontext, rect.x, rect.y, width, height, 8)
207
rect.x = rect.x + 2 * self.PADDING + width
157
209
if self.tag and my_tag: #pylint: disable-msg=W0631
164
216
# Draw rounded rectangle
165
217
gdkcontext.set_source_rgba(0.95, 0.95, 0.95, 1)
166
self.__roundedrec(gdkcontext, rect_x, rect_y, 16, 16, 8)
218
self.__roundedrec(gdkcontext, rect.x, rect.y, 16, 16, 8)
167
219
gdkcontext.fill()
170
222
gdkcontext.set_source_rgba(0, 0, 0, 0.20)
171
223
gdkcontext.set_line_width(1.0)
172
self.__roundedrec(gdkcontext, rect_x, rect_y, 16, 16, 8)
224
self.__roundedrec(gdkcontext, rect.x, rect.y, 16, 16, 8)
173
225
gdkcontext.stroke()
175
227
def on_get_size(self, widget, cell_area=None): #pylint: disable-msg=W0613
229
retval = (0, 0, 0, 0)
231
xpad = self.get_property("xpad")
232
ypad = self.get_property("ypad")
177
234
count = self.__count_viewable_tags()
180
return (self.xpad, self.ypad, self.xpad*2 + 16*count +\
181
2*count*self.PADDING, 16 + 2*self.ypad)
183
return (self.xpad, self.ypad, self.xpad*2, self.ypad*2)
238
# it's a tag "rectangle"
240
window = widget.get_window()
241
if window is not None:
242
cr = window.cairo_create()
244
# window is not realized yet, but we must create a cairo
245
# context to compute text extents
246
surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, 1, 1)
247
cr = cairo.Context (surface)
248
gdkcontext = gtk.gdk.CairoContext(cr)
249
gdkcontext.set_font_size(self.FONT_SIZE)
251
if self.tag_list != None:
253
elif self.tag != None:
255
# accumulate text widths
257
my_tag_color = my_tag.get_attribute("color")
259
my_tag_name = my_tag.get_attribute("name")[1:]
260
x_bearing, y_bearing, f_width, f_height = cr.text_extents(my_tag_name)[:4]
262
width = max(int(f_width), self.MINWIDTH) + 2 * self.PADDING + 2 * 3
263
acc_width = acc_width + width
265
# it's a square on an icon
266
acc_width = (16 + 2 * self.PADDING) * count
267
# compute width, height and offsets
268
width = acc_width + 2 * xpad
269
height = self.HEIGHT + 2 * ypad
271
xoffset = max(self.get_property("xalign") * (cell_area.width - width), 0)
272
yoffset = max(self.get_property("yalign") * (cell_area.height - height), 0)
276
retval = (xoffset, yoffset, width, height)
185
279
gobject.type_register(CellRendererTags)