Package dtk ::
Package ui ::
Module listview_preview_pixbuf
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from utils import get_content_size
24 import cairo
25 import gtk
26 import pango
27 import sys
28
29
30 from draw import draw_vlinear, draw_text
31
33 '''
34 Render and save pixbuf.
35
36 @param widget: Gtk.Widget instance.
37 @param event: Expose event.
38 @param input_args: Input arguments as format: (select_num, vlinear_color, text_color, filepath).
39 '''
40
41 (select_num, vlinear_color, text_color, filepath) = input_args
42
43 cr = widget.window.cairo_create()
44 rect = widget.allocation
45 num_pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, rect.width, rect.height)
46
47
48 cr.set_operator(cairo.OPERATOR_OVER)
49 draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, eval(vlinear_color))
50
51
52 draw_text(cr, select_num, rect.x, rect.y, rect.width, rect.height, text_color=text_color,
53 alignment=pango.ALIGN_CENTER)
54
55
56 num_pixbuf.get_from_drawable(
57 widget.window, widget.get_colormap(), 0, 0, 0, 0,
58 rect.width, rect.height).save(filepath, "png")
59
60
61 gtk.main_quit()
62
63 if __name__ == "__main__":
64
65 input_args = sys.argv[1::]
66 (select_num, vlinear_color, text_color, filepath) = input_args
67
68
69 num_padding_x = 8
70 num_padding_y = 1
71 (num_width, num_height) = get_content_size(select_num)
72 pixbuf_width = num_width + num_padding_x * 2
73 pixbuf_height = num_height + num_padding_y * 2
74
75
76 window = gtk.Window(gtk.WINDOW_POPUP)
77 window.set_colormap(gtk.gdk.Screen().get_rgba_colormap())
78 window.move(-pixbuf_width, -pixbuf_height)
79 window.set_default_size(pixbuf_width, pixbuf_height)
80 window.connect(
81 "expose-event",
82 lambda w, e: render_pixbuf(w, e, input_args))
83
84 window.show_all()
85
86 gtk.main()
87