400111d720d62b645c8f4271162b4bd956dbc27b
[jamaendo] / jamaui / draw.py
1 import gtk
2 import pango
3
4 def text_box_centered(ctx, widget, w_width, w_height, text, font_desc=None):
5     style = widget.rc_get_style()
6     text_color = style.text[gtk.STATE_PRELIGHT]
7     red, green, blue = text_color.red, text_color.green, text_color.blue
8     text_color = [float(x)/65535. for x in (red, green, blue)]
9     text_color.append(.5)
10
11     if font_desc is None:
12         font_desc = style.font_desc
13         font_desc.set_size(14*pango.SCALE)
14
15     pango_context = widget.create_pango_context()
16     layout = pango.Layout(pango_context)
17     layout.set_font_description(font_desc)
18     layout.set_text(text)
19     width, height = layout.get_pixel_size()
20
21     ctx.move_to(w_width/2-width/2, w_height/2-height/2)
22     ctx.set_source_rgba(*text_color)
23     ctx.show_layout(layout)