comparison pyink/frameline.py @ 948:518c61784355

Add frameruler to show ruler for framelines
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 17 Nov 2010 01:46:10 +0800
parents a8ddbb6dac9e
children c9bf47cc621f
comparison
equal deleted inserted replaced
947:a8ddbb6dac9e 948:518c61784355
13 def __init__(self, frame_idx): 13 def __init__(self, frame_idx):
14 self.idx = frame_idx 14 self.idx = frame_idx
15 self.left_tween = False 15 self.left_tween = False
16 self.right_tween = False 16 self.right_tween = False
17 self.right_tween_type = 0 17 self.right_tween_type = 0
18 pass
19 pass
20
21 class frameruler(gtk.DrawingArea):
22 _type_id = 0
23 _frame_width = 10 # Width for each frame is 10 pixels
24 _mark_color = 0x808080 # color of mark lines
25 _number_color = 0x000000 # color of frame number
26 _number_sz = 10 # font size of frame number
27
28 def __new__(clz, *args):
29 if not frameruler._type_id:
30 frameruler._type_id = gobject.type_register(frameruler)
31 pass
32 fr = gobject.new(frameruler._type_id)
33 return fr
34
35 def __init__(self, num_frames=20):
36 self.connect('expose_event', self._fr_expose)
37 self._num_frames = num_frames
38 pass
39
40 def _fr_expose(self, widget, event):
41 self.update()
42 pass
43
44 def queue_draw(self):
45 print 'queue_draw'
46 self.update()
47 pass
48
49 def queue_draw_area(self, x, y, w, h):
50 print 'queue_draw_area'
51 pass
52
53 def update(self):
54 win = self.window
55 w_x, w_y, w_w, w_h, depth = win.get_geometry()
56
57 gc = gtk.gdk.GC(win)
58
59 color_rgb = color_to_rgb(self._mark_color)
60 color = gtk.gdk.Color(*color_rgb)
61 gc.set_rgb_fg_color(color)
62
63 mark_h = w_h / 10
64 for i in range(self._num_frames):
65 mark_x = (i + 1) * self._frame_width
66 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)
68 if (i % 5) == 4:
69 pass
70 pass
71
72 color_rgb = color_to_rgb(self._number_color)
73 color = gtk.gdk.Color(*color_rgb)
74 gc.set_rgb_fg_color(color)
75
76 layout = self.create_pango_layout('1')
77 win.draw_layout(gc, 0, mark_h, layout)
78 for i in range(4, self._num_frames, 5):
79 mark_x = i * self._frame_width
80 layout = self.create_pango_layout(str(i + 1))
81 win.draw_layout(gc, mark_x, mark_h, layout)
82 pass
18 pass 83 pass
19 pass 84 pass
20 85
21 ## Show frame status of a layer 86 ## Show frame status of a layer
22 # 87 #
270 return self._num_frames 335 return self._num_frames
271 pass 336 pass
272 337
273 if __name__ == '__main__': 338 if __name__ == '__main__':
274 window = gtk.Window(gtk.WINDOW_TOPLEVEL) 339 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
340 fr = frameruler(40)
341 fr.set_size_request(300, 20)
342
275 fl = frameline(40) 343 fl = frameline(40)
276 fl.set_size_request(300, 30) 344 fl.set_size_request(300, 20)
277 fl.add_keyframe(3) 345 fl.add_keyframe(3)
278 fl.add_keyframe(9) 346 fl.add_keyframe(9)
279 fl.add_keyframe(15) 347 fl.add_keyframe(15)
280 fl.add_keyframe(20) 348 fl.add_keyframe(20)
281 fl.tween(3) 349 fl.tween(3)
282 fl.tween(15, 1) 350 fl.tween(15, 1)
283 fl.active_frame(15) 351 fl.active_frame(15)
284 print 'num of frames: %d' % (len(fl)) 352 print 'num of frames: %d' % (len(fl))
285 353
286 window.add(fl) 354 box = gtk.VBox()
355
356 box.pack_start(fr, False)
357 box.pack_start(fl, False)
358 window.add(box)
359
360 fr.show()
287 fl.show() 361 fl.show()
362 box.show()
288 window.show() 363 window.show()
289 gtk.main() 364 gtk.main()
290 pass 365 pass