Mercurial > MadButterfly
comparison pyink/frameline.py @ 949:c9bf47cc621f
Set font size for frame number in frameruler
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 17 Nov 2010 02:16:32 +0800 |
parents | 518c61784355 |
children | 1bb0780f1036 |
comparison
equal
deleted
inserted
replaced
948:518c61784355 | 949:c9bf47cc621f |
---|---|
1 import pygtk | 1 import pygtk |
2 pygtk.require("2.0") | 2 pygtk.require("2.0") |
3 import gtk | 3 import gtk |
4 import gtk.gdk | 4 import gtk.gdk |
5 import pango | |
5 import gobject | 6 import gobject |
6 | 7 |
7 def color_to_rgb(v): | 8 def color_to_rgb(v): |
8 return (((v >> 16) & 0xff) * 65535 / 0xff, | 9 return (((v >> 16) & 0xff) * 65535 / 0xff, |
9 ((v >> 8) & 0xff) * 65535 / 0xff, | 10 ((v >> 8) & 0xff) * 65535 / 0xff, |
21 class frameruler(gtk.DrawingArea): | 22 class frameruler(gtk.DrawingArea): |
22 _type_id = 0 | 23 _type_id = 0 |
23 _frame_width = 10 # Width for each frame is 10 pixels | 24 _frame_width = 10 # Width for each frame is 10 pixels |
24 _mark_color = 0x808080 # color of mark lines | 25 _mark_color = 0x808080 # color of mark lines |
25 _number_color = 0x000000 # color of frame number | 26 _number_color = 0x000000 # color of frame number |
26 _number_sz = 10 # font size of frame number | 27 _number_sz = 8 # font size of frame number |
27 | 28 |
28 def __new__(clz, *args): | 29 def __new__(clz, *args): |
29 if not frameruler._type_id: | 30 if not frameruler._type_id: |
30 frameruler._type_id = gobject.type_register(frameruler) | 31 frameruler._type_id = gobject.type_register(frameruler) |
31 pass | 32 pass |
54 win = self.window | 55 win = self.window |
55 w_x, w_y, w_w, w_h, depth = win.get_geometry() | 56 w_x, w_y, w_w, w_h, depth = win.get_geometry() |
56 | 57 |
57 gc = gtk.gdk.GC(win) | 58 gc = gtk.gdk.GC(win) |
58 | 59 |
60 # | |
61 # Set color of mark lines | |
62 # | |
59 color_rgb = color_to_rgb(self._mark_color) | 63 color_rgb = color_to_rgb(self._mark_color) |
60 color = gtk.gdk.Color(*color_rgb) | 64 color = gtk.gdk.Color(*color_rgb) |
61 gc.set_rgb_fg_color(color) | 65 gc.set_rgb_fg_color(color) |
62 | 66 |
67 # | |
68 # Mark mark lines | |
69 # | |
63 mark_h = w_h / 10 | 70 mark_h = w_h / 10 |
64 for i in range(self._num_frames): | 71 for i in range(self._num_frames): |
65 mark_x = (i + 1) * self._frame_width | 72 mark_x = (i + 1) * self._frame_width |
66 win.draw_line(gc, mark_x, 0, mark_x, mark_h) | 73 win.draw_line(gc, mark_x, 0, mark_x, mark_h) |
67 win.draw_line(gc, mark_x, w_h - mark_h - 1, mark_x, w_h - 1) | 74 win.draw_line(gc, mark_x, w_h - mark_h - 1, mark_x, w_h - 1) |
68 if (i % 5) == 4: | 75 if (i % 5) == 4: |
69 pass | 76 pass |
70 pass | 77 pass |
71 | 78 |
79 # | |
80 # Set color of frame number | |
81 # | |
72 color_rgb = color_to_rgb(self._number_color) | 82 color_rgb = color_to_rgb(self._number_color) |
73 color = gtk.gdk.Color(*color_rgb) | 83 color = gtk.gdk.Color(*color_rgb) |
74 gc.set_rgb_fg_color(color) | 84 gc.set_rgb_fg_color(color) |
75 | 85 |
86 font_desc = pango.FontDescription() | |
87 font_desc.set_size(self._number_sz * pango.SCALE) | |
88 | |
89 number_y = (w_h - self._number_sz) / 2 | |
90 | |
91 # | |
92 # Draw frame number | |
93 # | |
76 layout = self.create_pango_layout('1') | 94 layout = self.create_pango_layout('1') |
77 win.draw_layout(gc, 0, mark_h, layout) | 95 layout.set_font_description(font_desc) |
96 win.draw_layout(gc, 0, number_y, layout) | |
78 for i in range(4, self._num_frames, 5): | 97 for i in range(4, self._num_frames, 5): |
79 mark_x = i * self._frame_width | 98 mark_x = i * self._frame_width |
80 layout = self.create_pango_layout(str(i + 1)) | 99 layout.set_text(str(i + 1)) |
81 win.draw_layout(gc, mark_x, mark_h, layout) | 100 win.draw_layout(gc, mark_x, number_y, layout) |
82 pass | 101 pass |
83 pass | 102 pass |
84 pass | 103 pass |
85 | 104 |
86 ## Show frame status of a layer | 105 ## Show frame status of a layer |