comparison pyink/frameline.py @ 967:5c013e3cadd0

Provide the facility to stop drawing for massive content update. To stop drawing screen when doing massive cotent update makes application more efficient. frameline.stop_drawing() method is called to stop drawing screen before massive updating. After updating, start_drawing() and update() should be called to show latest content.
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 18 Nov 2010 11:37:21 +0800
parents ca993c473379
children a715301b5879
comparison
equal deleted inserted replaced
966:ca993c473379 967:5c013e3cadd0
144 self.connect('motion-notify-event', self._motion_hdl) 144 self.connect('motion-notify-event', self._motion_hdl)
145 self._num_frames = num_frames 145 self._num_frames = num_frames
146 self._keys = [] 146 self._keys = []
147 self._active_frame = -1 147 self._active_frame = -1
148 self._last_hover = -1 # frame index of last hover 148 self._last_hover = -1 # frame index of last hover
149 self._drawing = True
149 pass 150 pass
150 151
151 def _press_hdl(self, widget, event): 152 def _press_hdl(self, widget, event):
152 frame = event.x / self._frame_width 153 frame = event.x / self._frame_width
153 but = event.button 154 but = event.button
174 pass 175 pass
175 self.update() 176 self.update()
176 pass 177 pass
177 178
178 def _draw_tween(self, first_key, last_key): 179 def _draw_tween(self, first_key, last_key):
180 if not self._drawing:
181 return
182
179 win = self.window 183 win = self.window
180 w_x, w_y, w_w, w_h, depth = win.get_geometry() 184 w_x, w_y, w_w, w_h, depth = win.get_geometry()
181 185
182 # 186 #
183 # Get background color of a tween 187 # Get background color of a tween
211 line_y = int(w_h * 2 / 3) 215 line_y = int(w_h * 2 / 3)
212 win.draw_line(gc, line_x1, line_y, line_x2, line_y) 216 win.draw_line(gc, line_x1, line_y, line_x2, line_y)
213 pass 217 pass
214 218
215 def _draw_normal_frame(self, idx): 219 def _draw_normal_frame(self, idx):
220 if not self._drawing:
221 return
222
216 win = self.window 223 win = self.window
217 w_x, w_y, w_w, w_h, depth = win.get_geometry() 224 w_x, w_y, w_w, w_h, depth = win.get_geometry()
218 225
219 gc = self._gc 226 gc = self._gc
220 bg_idx = idx % len(self._normal_bgcolors) 227 bg_idx = idx % len(self._normal_bgcolors)
235 pass 242 pass
236 243
237 ## \brief Draw a bottom line from start to the point before stop frame. 244 ## \brief Draw a bottom line from start to the point before stop frame.
238 # 245 #
239 def _draw_bottom_line(self, start, stop): 246 def _draw_bottom_line(self, start, stop):
247 if not self._drawing:
248 return
249
240 win = self.window 250 win = self.window
241 w_x, w_y, w_w, w_h, depth = win.get_geometry() 251 w_x, w_y, w_w, w_h, depth = win.get_geometry()
242 gc = self._gc 252 gc = self._gc
243 253
244 border_rgb = color_to_rgb(self._normal_border) 254 border_rgb = color_to_rgb(self._normal_border)
248 stop_x = stop * self._frame_width 258 stop_x = stop * self._frame_width
249 win.draw_line(gc, start_x, w_h - 1, stop_x, w_h - 1) 259 win.draw_line(gc, start_x, w_h - 1, stop_x, w_h - 1)
250 pass 260 pass
251 261
252 def _draw_all_frames(self): 262 def _draw_all_frames(self):
263 if not self._drawing:
264 return
265
253 win = self.window 266 win = self.window
254 w_x, w_y, w_w, w_h, depth = win.get_geometry() 267 w_x, w_y, w_w, w_h, depth = win.get_geometry()
255 gc = self._gc 268 gc = self._gc
256 269
257 i = 0 270 i = 0
291 304
292 self._draw_bottom_line(0, num_frames) 305 self._draw_bottom_line(0, num_frames)
293 pass 306 pass
294 307
295 def _draw_keyframe(self, frame_idx): 308 def _draw_keyframe(self, frame_idx):
309 if not self._drawing:
310 return
311
296 win = self.window 312 win = self.window
297 w_x, w_y, w_w, w_h, depth = win.get_geometry() 313 w_x, w_y, w_w, w_h, depth = win.get_geometry()
298 314
299 color_v = self._key_mark_color 315 color_v = self._key_mark_color
300 color_rgb = color_to_rgb(color_v) 316 color_rgb = color_to_rgb(color_v)
309 325
310 win.draw_rectangle(gc, True, mark_x, mark_y, mark_sz, mark_sz) 326 win.draw_rectangle(gc, True, mark_x, mark_y, mark_sz, mark_sz)
311 pass 327 pass
312 328
313 def _draw_keyframes(self): 329 def _draw_keyframes(self):
330 if not self._drawing:
331 return
332
314 win = self.window 333 win = self.window
315 w_x, w_y, w_w, w_h, depth = win.get_geometry() 334 w_x, w_y, w_w, w_h, depth = win.get_geometry()
316 335
317 color_v = self._key_mark_color 336 color_v = self._key_mark_color
318 color_rgb = color_to_rgb(color_v) 337 color_rgb = color_to_rgb(color_v)
329 win.draw_rectangle(gc, True, mark_x, mark_y, mark_sz, mark_sz) 348 win.draw_rectangle(gc, True, mark_x, mark_y, mark_sz, mark_sz)
330 pass 349 pass
331 pass 350 pass
332 351
333 def _draw_active(self): 352 def _draw_active(self):
353 if not self._drawing:
354 return
355
334 if self._active_frame == -1: 356 if self._active_frame == -1:
335 return 357 return
336 358
337 win = self.window 359 win = self.window
338 w_x, w_y, w_w, w_h, depth = win.get_geometry() 360 w_x, w_y, w_w, w_h, depth = win.get_geometry()
372 return first_pox, last_pos 394 return first_pox, last_pos
373 395
374 ## \brief Redraw a frame specified by an index. 396 ## \brief Redraw a frame specified by an index.
375 # 397 #
376 def _redraw_frame(self, frame_idx): 398 def _redraw_frame(self, frame_idx):
399 if not self._drawing:
400 return
401
377 keys = [key.idx for key in self._keys] 402 keys = [key.idx for key in self._keys]
378 if len(keys): 403 if len(keys):
379 try: 404 try:
380 pos = keys.index(frame_idx) 405 pos = keys.index(frame_idx)
381 except ValueError: 406 except ValueError:
418 pass 443 pass
419 444
420 ## \brief Show a mark for the pointer for a frame. 445 ## \brief Show a mark for the pointer for a frame.
421 # 446 #
422 def _draw_hover(self, frame_idx): 447 def _draw_hover(self, frame_idx):
448 if not self._drawing:
449 return
450
423 if self._last_hover != -1: 451 if self._last_hover != -1:
424 self._redraw_frame(self._last_hover) 452 self._redraw_frame(self._last_hover)
425 pass 453 pass
426 454
427 self._draw_active() 455 self._draw_active()
444 472
445 self._last_hover = frame_idx 473 self._last_hover = frame_idx
446 pass 474 pass
447 475
448 def update(self): 476 def update(self):
477 if not self._drawing:
478 return
479
449 win = self.window 480 win = self.window
450 x, y, w, h, depth = win.get_geometry() 481 x, y, w, h, depth = win.get_geometry()
451 482
452 self._draw_all_frames() 483 self._draw_all_frames()
453 self._draw_keyframes() 484 self._draw_keyframes()
504 self._redraw_frame(i) 535 self._redraw_frame(i)
505 pass 536 pass
506 else: 537 else:
507 self._redraw_frame(idx) 538 self._redraw_frame(idx)
508 pass 539 pass
540
541 self._draw_active()
509 pass 542 pass
510 543
511 ## Tween the key frame specified by an index and the key frame at right. 544 ## Tween the key frame specified by an index and the key frame at right.
512 # 545 #
513 # \see http://www.entheosweb.com/Flash/shape_tween.asp 546 # \see http://www.entheosweb.com/Flash/shape_tween.asp
532 # 565 #
533 def active_frame(self, idx): 566 def active_frame(self, idx):
534 if idx < 0 or idx >= self._num_frames: 567 if idx < 0 or idx >= self._num_frames:
535 raise IndexError, 'value of index (%d) is out of range' % (idx) 568 raise IndexError, 'value of index (%d) is out of range' % (idx)
536 569
570 if self._active_frame != -1:
571 self._redraw_frame(self._active_frame)
572 pass
537 self._active_frame = idx 573 self._active_frame = idx
574 self._draw_active()
538 pass 575 pass
539 576
540 def deactive(self): 577 def deactive(self):
578 self._redraw_frame(self._active_frame)
541 self._active_frame = -1 579 self._active_frame = -1
542 pass 580 pass
543 581
544 def set_num_frames(self, num): 582 def set_num_frames(self, num):
545 self._num_frames = num 583 self._num_frames = num
546 pass 584 pass
547 585
548 def reset(self): 586 def reset(self):
549 self._keys = [] 587 self._keys = []
588 pass
589
590 ## \brief Start future drawing actions
591 #
592 def start_drawing(self):
593 self._drawing = True
594 pass
595
596 ## \brief Stop any future drawing actions
597 #
598 # When doing massive udpate, to stop drawing the screen make
599 # application more effecient. The screen is updated by calling
600 # update() method after massive update and calliing start_drawing().
601 #
602 def stop_drawing(self):
603 self._drawing = False
550 pass 604 pass
551 605
552 def __len__(self): 606 def __len__(self):
553 return self._num_frames 607 return self._num_frames
554 pass 608 pass