annotate pyink/frameline.py @ 1108:236a47079c2b

Add pheromone for tank AI
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 06 Dec 2010 12:51:42 +0800
parents 5cefabccfb76
children 214e1f628d63
rev   line source
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1 import pygtk
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2 pygtk.require("2.0")
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
3 import gtk
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
4 import gtk.gdk
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
5 import pango
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
6 import gobject
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
7
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
8 def color_to_rgb(v):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
9 return (((v >> 16) & 0xff) * 65535 / 0xff,
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
10 ((v >> 8) & 0xff) * 65535 / 0xff,
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
11 (v & 0xff) * 65535 / 0xff)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
12
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
13 class keyframe(object):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
14 def __init__(self, frame_idx):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
15 self.idx = frame_idx
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
16 self.left_tween = False
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
17 self.right_tween = False
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
18 self.right_tween_type = 0
972
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
19 self.ref=''
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
20 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
21 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
22
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
23 class frameruler(gtk.DrawingArea):
952
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
24 _type = 0
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
25 _frame_width = 10 # Width for each frame is 10 pixels
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
26 _mark_color = 0x808080 # color of mark lines
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
27 _number_color = 0x000000 # color of frame number
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
28 _number_sz = 8 # font size of frame number
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
29
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
30 def __new__(clz, *args):
952
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
31 if not frameruler._type:
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
32 frameruler._type = gobject.type_register(frameruler)
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
33 pass
952
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
34 fr = gobject.new(frameruler._type)
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
35 return fr
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
36
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
37 def __init__(self, num_frames=20):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
38 self.connect('expose_event', self._fr_expose)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
39 self._num_frames = num_frames
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
40 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
41
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
42 def _fr_expose(self, widget, event):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
43 self.update()
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
44 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
45
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
46 def queue_draw(self):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
47 print 'queue_draw'
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
48 self.update()
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
49 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
50
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
51 def queue_draw_area(self, x, y, w, h):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
52 print 'queue_draw_area'
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
53 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
54
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
55 def update(self):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
56 win = self.window
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
57 w_x, w_y, w_w, w_h, depth = win.get_geometry()
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
58
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
59 gc = gtk.gdk.GC(win)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
60
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
61 #
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
62 # Set color of mark lines
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
63 #
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
64 color_rgb = color_to_rgb(self._mark_color)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
65 color = gtk.gdk.Color(*color_rgb)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
66 gc.set_rgb_fg_color(color)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
67
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
68 #
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
69 # Mark mark lines
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
70 #
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
71 mark_h = w_h / 10
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
72 for i in range(self._num_frames):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
73 mark_x = (i + 1) * self._frame_width
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
74 win.draw_line(gc, mark_x, 0, mark_x, mark_h)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
75 win.draw_line(gc, mark_x, w_h - mark_h - 1, mark_x, w_h - 1)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
76 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
77
950
1bb0780f1036 Add more border line to frameline and frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 949
diff changeset
78 win.draw_line(gc, 0, w_h - 1, w_w, w_h -1)
1bb0780f1036 Add more border line to frameline and frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 949
diff changeset
79
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
80 #
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
81 # Set color of frame number
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
82 #
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
83 color_rgb = color_to_rgb(self._number_color)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
84 color = gtk.gdk.Color(*color_rgb)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
85 gc.set_rgb_fg_color(color)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
86
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
87 font_desc = pango.FontDescription()
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
88 font_desc.set_size(self._number_sz * pango.SCALE)
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
89
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
90 number_y = (w_h - self._number_sz) / 2
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
91
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
92 #
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
93 # Draw frame number
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
94 #
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
95 layout = self.create_pango_layout('1')
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
96 layout.set_font_description(font_desc)
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
97 win.draw_layout(gc, 0, number_y, layout)
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
98 for i in range(4, self._num_frames, 5):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
99 mark_x = i * self._frame_width
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
100 layout.set_text(str(i + 1))
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
101 win.draw_layout(gc, mark_x, number_y, layout)
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
102 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
103 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
104 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
105
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
106 ## Show frame status of a layer
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
107 #
953
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
108 # \section frameline_sigs Signals
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
109 # - 'frame-button-pree' for user press on a frame.
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
110 # - callback(widget, frame_idx, button)
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
111 #
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
112 class frameline(gtk.DrawingArea):
952
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
113 _type = 0
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
114 _frame_width = 10 # Width for each frame is 10 pixels
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
115 _select_color = 0xee2222 # color of border of selected frame
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
116 _key_mark_color = 0x000000 # color of marks for key frames.
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
117 _key_mark_sz = 4 # width and height of a key frame mark
945
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
118 _tween_color = 0x808080 # color of tween line
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
119 _tween_bgcolors = [0x80ff80, 0xff8080] # bg colors of tween frames
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
120 # Colors for normal frames
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
121 _normal_bgcolors = [0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xcccccc]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
122 _normal_border = 0xaaaaaa # border color of normal frames.
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
123 _active_border = 0xff3030 # border color of an active frame
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
124 _hover_border_color = 0xa0a0a0 # border when the pointer over a frame
971
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
125 # tween types
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
126 _tween_type_none=0
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
127 _tween_type_shape=3
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
128
953
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
129
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
130 FRAME_BUT_PRESS = 'frame-button-press'
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
131
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
132 def __new__(clz, *args):
952
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
133 if not frameline._type:
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
134 frameline._type = gobject.type_register(frameline)
953
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
135 but_press = gobject.signal_new(frameline.FRAME_BUT_PRESS,
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
136 frameline._type,
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
137 gobject.SIGNAL_RUN_FIRST,
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
138 gobject.TYPE_NONE,
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
139 (gobject.TYPE_INT,
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
140 gobject.TYPE_INT))
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
141 frameline._sig_frame_but_press = but_press
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
142 pass
952
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
143 fl_obj = gobject.new(frameline._type)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
144 return fl_obj
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
145
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
146 def __init__(self, num_frames=20):
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
147 self.connect('button-press-event', self._press_hdl)
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
148 self.connect('expose-event', self._fl_expose)
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
149 self.connect('motion-notify-event', self._motion_hdl)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
150 self._num_frames = num_frames
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
151 self._keys = []
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
152 self._active_frame = -1
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
153 self._last_hover = -1 # frame index of last hover
968
a715301b5879 Start drawing after an expose event
Thinker K.F. Li <thinker@codemud.net>
parents: 967
diff changeset
154 self._drawing = False
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
155 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
156
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
157 def _press_hdl(self, widget, event):
953
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
158 frame = event.x / self._frame_width
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
159 but = event.button
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
160 self.emit(frameline.FRAME_BUT_PRESS, frame, but)
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
161 pass
977
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
162 def hide_hover(self):
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
163 if self._active_frame != self._last_hover:
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
164 self._draw_normal_frame(self._last_hover)
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
165
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
166 def _motion_hdl(self, widget, event):
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
167 frame = int(event.x / self._frame_width)
977
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
168
969
d4b934d97a62 check range of pointer
Thinker K.F. Li <thinker@codemud.net>
parents: 968
diff changeset
169 if frame < self._num_frames and frame >= 0:
d4b934d97a62 check range of pointer
Thinker K.F. Li <thinker@codemud.net>
parents: 968
diff changeset
170 self._draw_hover(frame)
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
171 pass
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
172
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
173 def _fl_expose(self, widget, event):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
174 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
175 x, y, w, h, depth = win.get_geometry()
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
176 if not hasattr(self, '_gc'):
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
177 self._gc = gtk.gdk.GC(win)
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
178 #
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
179 # register for button press event
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
180 #
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
181 emask = win.get_events()
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
182 emask = emask | gtk.gdk.BUTTON_PRESS_MASK | \
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
183 gtk.gdk.POINTER_MOTION_MASK
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
184 win.set_events(emask)
968
a715301b5879 Start drawing after an expose event
Thinker K.F. Li <thinker@codemud.net>
parents: 967
diff changeset
185 self._drawing = True
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
186 pass
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
187 self.update()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
188 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
189
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
190 def _draw_tween(self, first_key, last_key):
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
191 if not self._drawing:
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
192 return
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
193
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
194 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
195 w_x, w_y, w_w, w_h, depth = win.get_geometry()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
196
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
197 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
198 # Get background color of a tween
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
199 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
200 bg_idx = first_key.right_tween_type
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
201 bg_color_v = self._tween_bgcolors[bg_idx]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
202 bg_color_rgb = color_to_rgb(bg_color_v)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
203 bg_color = gtk.gdk.Color(*bg_color_rgb)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
204
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
205 gc = self._gc
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
206 gc.set_rgb_fg_color(bg_color)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
207
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
208 draw_x = first_key.idx * self._frame_width + 1
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
209 draw_w = (last_key.idx - first_key.idx + 1) * self._frame_width - 1
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
210
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
211 win.draw_rectangle(gc, True, draw_x, 0, draw_w, w_h)
945
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
212
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
213 #
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
214 # Set color of tween line
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
215 #
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
216 line_v = self._tween_color
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
217 line_rgb = color_to_rgb(line_v)
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
218 line_color = gtk.gdk.Color(*line_rgb)
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
219 gc.set_rgb_fg_color(line_color)
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
220
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
221 #
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
222 # Draw tween line
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
223 #
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
224 line_x1 = int((first_key.idx + 0.5) * self._frame_width)
945
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
225 line_x2 = line_x1 + (last_key.idx - first_key.idx) * self._frame_width
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
226 line_y = int(w_h * 2 / 3)
945
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
227 win.draw_line(gc, line_x1, line_y, line_x2, line_y)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
228 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
229
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
230 def _draw_normal_frame(self, idx):
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
231 if not self._drawing:
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
232 return
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
233
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
234 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
235 w_x, w_y, w_w, w_h, depth = win.get_geometry()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
236
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
237 gc = self._gc
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
238 bg_idx = idx % len(self._normal_bgcolors)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
239 rgb = color_to_rgb(self._normal_bgcolors[bg_idx])
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
240 color = gtk.gdk.Color(*rgb)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
241 gc.set_rgb_fg_color(color)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
242
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
243 f_x = self._frame_width * idx
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
244 win.draw_rectangle(gc, True, f_x + 1, 0, self._frame_width - 1, w_h)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
245 next_f_x = f_x + self._frame_width
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
246
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
247 border_rgb = color_to_rgb(self._normal_border)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
248 border_color = gtk.gdk.Color(*border_rgb)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
249 gc.set_rgb_fg_color(border_color)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
250 gc.set_line_attributes(1, gtk.gdk.LINE_SOLID,
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
251 gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
252 win.draw_line(gc, next_f_x, 0, next_f_x, w_h)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
253 pass
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
254
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
255 ## \brief Draw a bottom line from start to the point before stop frame.
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
256 #
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
257 def _draw_bottom_line(self, start, stop):
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
258 if not self._drawing:
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
259 return
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
260
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
261 win = self.window
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
262 w_x, w_y, w_w, w_h, depth = win.get_geometry()
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
263 gc = self._gc
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
264
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
265 border_rgb = color_to_rgb(self._normal_border)
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
266 border_color = gtk.gdk.Color(*border_rgb)
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
267 gc.set_rgb_fg_color(border_color)
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
268 start_x = start * self._frame_width
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
269 stop_x = stop * self._frame_width
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
270 win.draw_line(gc, start_x, w_h - 1, stop_x, w_h - 1)
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
271 pass
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
272
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
273 def _draw_all_frames(self):
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
274 if not self._drawing:
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
275 return
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
276
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
277 win = self.window
950
1bb0780f1036 Add more border line to frameline and frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 949
diff changeset
278 w_x, w_y, w_w, w_h, depth = win.get_geometry()
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
279 gc = self._gc
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
280
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
281 i = 0
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
282 key_i = 0
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
283 try:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
284 key = self._keys[key_i]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
285 except IndexError:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
286 key = keyframe(self._num_frames)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
287 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
288 num_frames = self._num_frames
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
289 while i < num_frames:
970
a1ebbe11354d Fix issue of not drawing background for key frames without any tween
Thinker K.F. Li <thinker@codemud.net>
parents: 969
diff changeset
290 if key.idx == i and key.right_tween:
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
291 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
292 # Skip tween keys
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
293 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
294 first_tween_key = key
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
295 while key.idx == i or key.left_tween:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
296 last_tween_key = key
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
297 key_i = key_i + 1
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
298 try:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
299 key = self._keys[key_i]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
300 except IndexError:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
301 key = keyframe(self._num_frames)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
302 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
303 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
304
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
305 if first_tween_key != last_tween_key:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
306 self._draw_tween(first_tween_key, last_tween_key)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
307
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
308 i = last_tween_key.idx + 1
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
309 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
310 else:
977
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
311 if key.idx == i:
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
312 key_i=key_i+1
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
313 try:
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
314 key = self._keys[key_i]
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
315 except:
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
316 key = keyframe(self._num_frames)
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
317 self._draw_normal_frame(i)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
318 i = i + 1
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
319 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
320 pass
950
1bb0780f1036 Add more border line to frameline and frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 949
diff changeset
321
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
322 self._draw_bottom_line(0, num_frames)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
323 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
324
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
325 def _draw_keyframe(self, frame_idx):
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
326 if not self._drawing:
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
327 return
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
328
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
329 win = self.window
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
330 w_x, w_y, w_w, w_h, depth = win.get_geometry()
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
331
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
332 color_v = self._key_mark_color
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
333 color_rgb = color_to_rgb(color_v)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
334 color = gtk.gdk.Color(*color_rgb)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
335
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
336 gc = self._gc
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
337 gc.set_rgb_fg_color(color)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
338
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
339 mark_sz = self._key_mark_sz
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
340 mark_x = int((frame_idx + 0.5) * self._frame_width - mark_sz / 2)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
341 mark_y = w_h * 2 / 3 - mark_sz / 2
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
342
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
343 win.draw_rectangle(gc, True, mark_x, mark_y, mark_sz, mark_sz)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
344 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
345
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
346 def _draw_keyframes(self):
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
347 if not self._drawing:
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
348 return
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
349
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
350 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
351 w_x, w_y, w_w, w_h, depth = win.get_geometry()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
352
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
353 color_v = self._key_mark_color
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
354 color_rgb = color_to_rgb(color_v)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
355 color = gtk.gdk.Color(*color_rgb)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
356
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
357 gc = self._gc
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
358 gc.set_rgb_fg_color(color)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
359
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
360 for key in self._keys:
971
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
361 if key.left_tween is True and lastkey.right_tween_type == frameline._tween_type_none:
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
362 continue
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
363
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
364 mark_sz = self._key_mark_sz
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
365 mark_x = int((key.idx + 0.5) * self._frame_width - mark_sz / 2)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
366 mark_y = w_h * 2 / 3 - mark_sz / 2
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
367
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
368 win.draw_rectangle(gc, True, mark_x, mark_y, mark_sz, mark_sz)
971
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
369 lastkey = key
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
370 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
371 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
372
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
373 def _draw_active(self):
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
374 if not self._drawing:
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
375 return
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
376
965
dbb5462c471f Do not draw active frame when it is not set
Thinker K.F. Li <thinker@codemud.net>
parents: 958
diff changeset
377 if self._active_frame == -1:
dbb5462c471f Do not draw active frame when it is not set
Thinker K.F. Li <thinker@codemud.net>
parents: 958
diff changeset
378 return
dbb5462c471f Do not draw active frame when it is not set
Thinker K.F. Li <thinker@codemud.net>
parents: 958
diff changeset
379
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
380 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
381 w_x, w_y, w_w, w_h, depth = win.get_geometry()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
382
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
383 color_v = self._active_border
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
384 color_rgb = color_to_rgb(color_v)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
385 color = gtk.gdk.Color(*color_rgb)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
386
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
387 gc = self._gc
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
388 gc.set_rgb_fg_color(color)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
389
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
390 idx = self._active_frame
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
391 line_x1 = idx * self._frame_width
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
392 line_x2 = line_x1 + self._frame_width
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
393
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
394 win.draw_line(gc, line_x1, 0, line_x1, w_h)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
395 win.draw_line(gc, line_x2, 0, line_x2, w_h)
950
1bb0780f1036 Add more border line to frameline and frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 949
diff changeset
396 win.draw_line(gc, line_x1, w_h - 1, line_x2, w_h - 1)
1bb0780f1036 Add more border line to frameline and frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 949
diff changeset
397 win.draw_line(gc, line_x1, 0, line_x2, 0)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
398 pass
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
399
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
400 ## \brief Find the range a continous tween.
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
401 #
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
402 def _find_tween_range(self, key_pos):
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
403 first_pos = key_pos
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
404 while first_pos and self._keys[first_pos].left_tween:
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
405 first_pos = first_pos - 1
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
406 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
407
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
408 max_pos = len(self._keys) - 1
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
409
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
410 last_pos = key_pos
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
411 while last_pos < max_pos and self._keys[last_pos].right_tween:
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
412 last_pos = last_pos + 1
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
413 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
414
972
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
415 return first_pos, last_pos
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
416
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
417 ## \brief Redraw a frame specified by an index.
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
418 #
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
419 def _redraw_frame(self, frame_idx):
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
420 if not self._drawing:
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
421 return
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
422
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
423 keys = [key.idx for key in self._keys]
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
424 if len(keys):
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
425 try:
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
426 pos = keys.index(frame_idx)
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
427 except ValueError:
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
428 keys.append(frame_idx)
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
429 keys.sort()
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
430 pos = keys.index(frame_idx) - 1
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
431 pass
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
432 if pos < 0:
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
433 pos = 0
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
434 pass
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
435 key = self._keys[pos]
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
436 else:
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
437 key = None
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
438 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
439
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
440 if key and (key.right_tween or \
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
441 (key.left_tween and key.idx == frame_idx)):
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
442 #
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
443 # in tween
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
444 #
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
445 first_pos, last_pos = self._find_tween_range(pos)
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
446 first_key = self._keys[first_pos]
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
447 last_key = self._keys[last_pos]
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
448
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
449 self._draw_tween(first_key, last_key)
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
450 self._draw_bottom_line(first_key.idx, last_key.idx + 1)
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
451
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
452 for i in range(first_pos, last_pos + 1):
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
453 key = self._keys[i]
971
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
454 if key.left_tween is False or lastkey.right_tween_type != frameline._tween_type_none:
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
455 self._draw_keyframe(key.idx)
972
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
456 lastkey = key
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
457 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
458 pass
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
459 else: # not in tween
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
460 self._draw_normal_frame(frame_idx)
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
461 self._draw_bottom_line(frame_idx, frame_idx + 1)
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
462 if key and (key.idx == frame_idx):
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
463 self._draw_keyframe(frame_idx)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
464 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
465 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
466 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
467
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
468 ## \brief Show a mark for the pointer for a frame.
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
469 #
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
470 def _draw_hover(self, frame_idx):
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
471 if not self._drawing:
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
472 return
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
473
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
474 if self._last_hover != -1:
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
475 self._redraw_frame(self._last_hover)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
476 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
477
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
478 self._draw_active()
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
479
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
480 win = self.window
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
481 w_x, w_y, w_w, w_h, depth = win.get_geometry()
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
482 gc = self._gc
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
483
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
484 color_rgb = color_to_rgb(self._hover_border_color)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
485 color = gtk.gdk.Color(*color_rgb)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
486 gc.set_rgb_fg_color(color)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
487
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
488 line_x1 = frame_idx * self._frame_width + 1
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
489 line_x2 = line_x1 + self._frame_width - 2
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
490
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
491 win.draw_line(gc, line_x1, 1, line_x1, w_h - 2)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
492 win.draw_line(gc, line_x2, 1, line_x2, w_h - 2)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
493 win.draw_line(gc, line_x1, 1, line_x2, 1)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
494 win.draw_line(gc, line_x1, w_h - 2, line_x2, w_h - 2)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
495
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
496 self._last_hover = frame_idx
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
497 pass
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
498
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
499 def update(self):
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
500 if not self._drawing:
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
501 return
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
502
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
503 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
504 x, y, w, h, depth = win.get_geometry()
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
505 self._draw_all_frames()
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
506 self._draw_keyframes()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
507 if self._active_frame != -1:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
508 self._draw_active()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
509 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
510 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
511
947
a8ddbb6dac9e Doc key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 946
diff changeset
512 ## Add a key frame
a8ddbb6dac9e Doc key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 946
diff changeset
513 #
a8ddbb6dac9e Doc key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 946
diff changeset
514 # A key frame is the frame that user specify actions. For
a8ddbb6dac9e Doc key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 946
diff changeset
515 # example, move a object or add new objects at the frame.
977
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
516 def add_keyframe(self, idx,ref=None):
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
517 key_indic = [key.idx for key in self._keys]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
518 if idx in key_indic:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
519 return
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
520
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
521 key_indic.append(idx)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
522 key_indic.sort()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
523 insert_pos = key_indic.index(idx)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
524
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
525 key = keyframe(idx)
972
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
526 key.ref = ref
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
527 self._keys[insert_pos:insert_pos] = [key]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
528 if insert_pos > 0 and self._keys[insert_pos - 1].right_tween:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
529 key.left_tween = True
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
530 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
531 if insert_pos < (len(self._keys) - 1) and \
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
532 self._keys[insert_pos + 1].left_tween:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
533 key.right_tween = True
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
534 pass
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
535
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
536 self._draw_keyframe(idx)
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
537 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
538
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
539 def rm_keyframe(self, idx):
971
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
540 found=False
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
541 for i in range(0,len(self._keys)):
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
542 if self._keys[i].idx == idx:
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
543 idx = i
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
544 found = True
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
545 break
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
546 if not found: return
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
547 key = self._keys[idx]
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
548
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
549 if key.right_tween ^ key.left_tween:
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
550 #
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
551 # tween in one side
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
552 #
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
553 if key.right_tween:
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
554 right_key = self._keys[idx]
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
555 right_key.left_tween = False
971
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
556 redraw_range = (right_key.idx, idx + 1)
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
557 else:
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
558 left_key = self._keys[idx - 1]
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
559 left_key.right_key = False
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
560 redraw_range = (idx, left_key.idx + 1)
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
561 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
562 for i in range(*redraw_range):
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
563 self._redraw_frame(i)
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
564 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
565 else:
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
566 self._redraw_frame(idx)
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
567 pass
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
568
972
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
569 del self._keys[idx]
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
570 self._draw_active()
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
571 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
572
946
f82ac6740a32 change wording in doc
Thinker K.F. Li <thinker@codemud.net>
parents: 945
diff changeset
573 ## Tween the key frame specified by an index and the key frame at right.
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
574 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
575 # \see http://www.entheosweb.com/Flash/shape_tween.asp
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
576 def tween(self, idx, _type=0):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
577 key_indic = [key.idx for key in self._keys]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
578 pos = key_indic.index(idx)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
579 key = self._keys[pos]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
580
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
581 try:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
582 right_key = self._keys[pos + 1]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
583 except IndexError:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
584 raise ValueError, 'No right key frame'
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
585
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
586 key.right_tween = True
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
587 right_key.left_tween = True
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
588 key.right_tween_type = _type
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
589 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
590
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
591 ## Set active frame
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
592 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
593 # The active frame is the frame that is working on.
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
594 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
595 def active_frame(self, idx):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
596 if idx < 0 or idx >= self._num_frames:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
597 raise IndexError, 'value of index (%d) is out of range' % (idx)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
598
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
599 if self._active_frame != -1:
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
600 self._redraw_frame(self._active_frame)
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
601 pass
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
602 self._active_frame = idx
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
603 self._draw_active()
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
604 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
605
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
606 def deactive(self):
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
607 self._redraw_frame(self._active_frame)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
608 self._active_frame = -1
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
609 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
610
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
611 def set_num_frames(self, num):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
612 self._num_frames = num
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
613 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
614
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
615 def reset(self):
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
616 self._keys = []
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
617 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
618
972
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
619 def addScenes(self,rdoc,node):
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
620 for i in range(0,len(self._keys)):
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
621 key = self._keys[i]
977
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
622 if key.left_tween is True: continue
972
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
623 if key.right_tween is True:
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
624 ss = rdoc.createElement("ns0:scene")
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
625 node.appendChild(ss)
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
626 ss.setAttribute("start", str(key.idx+1),True)
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
627 ss.setAttribute("ref",key.ref.attribute("id"),True)
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
628 ss.setAttribute("end", str(self._keys[i+1].idx+1),True)
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
629 else:
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
630 ss = rdoc.createElement("ns0:scene")
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
631 node.appendChild(ss)
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
632 ss.setAttribute("start", str(key.idx+1),True)
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
633 ss.setAttribute("ref",key.ref.attribute("id"),True)
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
634
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
635
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
636 ## \brief Start future drawing actions
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
637 #
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
638 def start_drawing(self):
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
639 self._drawing = True
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
640 pass
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
641
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
642 ## \brief Stop any future drawing actions
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
643 #
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
644 # When doing massive udpate, to stop drawing the screen make
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
645 # application more effecient. The screen is updated by calling
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
646 # update() method after massive update and calliing start_drawing().
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
647 #
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
648 def stop_drawing(self):
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
649 self._drawing = False
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
650 pass
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
651
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
652 def __len__(self):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
653 return self._num_frames
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
654 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
655
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
656 if __name__ == '__main__':
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
657 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
658 fr = frameruler(40)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
659 fr.set_size_request(300, 20)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
660
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
661 fl = frameline(40)
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
662 fl.set_size_request(300, 20)
977
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
663 fl.add_keyframe(15)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
664 fl.add_keyframe(3)
971
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
665 fl.tween(3)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
666 fl.add_keyframe(9)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
667 fl.add_keyframe(20)
971
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
668 fl.tween(9)
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
669 fl.active_frame(1)
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
670 fl.rm_keyframe(15)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
671 print 'num of frames: %d' % (len(fl))
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
672
953
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
673 def press_sig(fl, frame, but):
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
674 print 'press_sig button %d for frame %d' % (but, frame)
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
675 pass
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
676 fl.connect(frameline.FRAME_BUT_PRESS, press_sig)
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
677
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
678 box = gtk.VBox()
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
679
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
680 box.pack_start(fr, False)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
681 box.pack_start(fl, False)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
682 window.add(box)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
683
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
684 fr.show()
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
685 fl.show()
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
686 box.show()
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
687 window.show()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
688 gtk.main()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
689 pass