Mercurial > MadButterfly
comparison pyink/frameline.py @ 951:e06a8d90592c
Handle button press event for frameline
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 17 Nov 2010 03:15:11 +0800 |
parents | 1bb0780f1036 |
children | 88bf64efcc1d |
comparison
equal
deleted
inserted
replaced
950:1bb0780f1036 | 951:e06a8d90592c |
---|---|
123 pass | 123 pass |
124 fl_obj = gobject.new(frameline._type_id) | 124 fl_obj = gobject.new(frameline._type_id) |
125 return fl_obj | 125 return fl_obj |
126 | 126 |
127 def __init__(self, num_frames=20): | 127 def __init__(self, num_frames=20): |
128 self.connect('expose_event', self._fl_expose) | 128 self.connect('button-press-event', self._press_hdl) |
129 self.connect('expose-event', self._fl_expose) | |
129 self._num_frames = num_frames | 130 self._num_frames = num_frames |
130 self._keys = [] | 131 self._keys = [] |
131 self._active_frame = -1 | 132 self._active_frame = -1 |
132 pass | 133 pass |
133 | 134 |
135 def _press_hdl(self, widget, event): | |
136 button = event.x / self._frame_width | |
137 print 'button %d - %d,%d' % (button, event.x, event.y) | |
138 pass | |
139 | |
134 def _fl_expose(self, widget, event): | 140 def _fl_expose(self, widget, event): |
135 print 'Expose %s' % (repr(event)) | |
136 win = self.window | 141 win = self.window |
137 x, y, w, h, depth = win.get_geometry() | 142 x, y, w, h, depth = win.get_geometry() |
138 print ' Geometry of window: %dx%d+%d+%d' % (w, h, x, y) | 143 if not hasattr(self, '_gc'): |
144 self._gc = gtk.gdk.GC(win) | |
145 # | |
146 # register for button press event | |
147 # | |
148 emask = win.get_events() | |
149 emask = emask | gtk.gdk.BUTTON_PRESS_MASK | |
150 win.set_events(emask) | |
151 pass | |
139 self.update() | 152 self.update() |
140 pass | 153 pass |
141 | 154 |
142 def _draw_tween(self, first_key, last_key): | 155 def _draw_tween(self, first_key, last_key): |
143 win = self.window | 156 win = self.window |
168 gc.set_rgb_fg_color(line_color) | 181 gc.set_rgb_fg_color(line_color) |
169 | 182 |
170 # | 183 # |
171 # Draw tween line | 184 # Draw tween line |
172 # | 185 # |
173 line_x1 = (first_key.idx + 0.5) * self._frame_width | 186 line_x1 = int(first_key.idx + 0.5) * self._frame_width |
174 line_x2 = line_x1 + (last_key.idx - first_key.idx) * self._frame_width | 187 line_x2 = line_x1 + (last_key.idx - first_key.idx) * self._frame_width |
175 line_y = w_h * 2 / 3 | 188 line_y = int(w_h * 2 / 3) |
176 win.draw_line(gc, line_x1, line_y, line_x2, line_y) | 189 win.draw_line(gc, line_x1, line_y, line_x2, line_y) |
177 pass | 190 pass |
178 | 191 |
179 def _draw_frame(self, idx): | 192 def _draw_frame(self, idx): |
180 win = self.window | 193 win = self.window |
199 pass | 212 pass |
200 | 213 |
201 def _draw_frames(self): | 214 def _draw_frames(self): |
202 win = self.window | 215 win = self.window |
203 w_x, w_y, w_w, w_h, depth = win.get_geometry() | 216 w_x, w_y, w_w, w_h, depth = win.get_geometry() |
204 gc = gtk.gdk.GC(win) | 217 gc = self._gc |
205 self._gc = gc | |
206 | 218 |
207 i = 0 | 219 i = 0 |
208 key_i = 0 | 220 key_i = 0 |
209 try: | 221 try: |
210 key = self._keys[key_i] | 222 key = self._keys[key_i] |