| 27 | | self.connect("expose-event", self.expose_cb) |
| 28 | | |
| 29 | | def push_frame(self, (source, ipl_image)): |
| 30 | | @gobject.idle_add |
| 31 | | def update_gui(): |
| 32 | | self.pixbuf = ipl_image.to_gdk_pixbuf() |
| 33 | | self.scaled_pixbuf = None |
| 34 | | self.queue_draw() |
| 35 | | return False |
| | 28 | self.connect("expose-event", self.expose_cb) |
| | 29 | |
| | 30 | def push_frame(self, (source, ipl_image)): |
| | 31 | @gobject.idle_add |
| | 32 | def update_gui(): |
| | 33 | self.pixbuf = ipl_image.to_gdk_pixbuf() |
| | 34 | self.scaled_pixbuf = None |
| | 35 | self.queue_draw() |
| | 36 | return False |
| 37 | | def expose_cb(self, da, event): |
| 38 | | # This rescales and redraws the image at every expose event, which |
| 39 | | # is pretty awful. This could pretty easily be changed to at least |
| 40 | | # keep the scaled image around between exposes. |
| 41 | | if not self.pixbuf: |
| 42 | | return |
| 43 | | alloc = self.get_allocation() |
| 44 | | if self.scaled_pixbuf is None or self.scale != (alloc.width, alloc.height): |
| 45 | | drawable = da.window |
| 46 | | self.scaled_pixbuf = self.pixbuf.scale_simple( |
| 47 | | alloc.width, alloc.height, |
| 48 | | gtk.gdk.INTERP_NEAREST) |
| 49 | | self.scale = (alloc.width, alloc.height) |
| 50 | | drawable.draw_pixbuf( |
| 51 | | drawable.new_gc(), |
| 52 | | self.scaled_pixbuf, |
| 53 | | 0, 0, # src_x, src_y, |
| 54 | | 0, 0, # dest_x, dest_y, |
| 55 | | alloc.width, alloc.height |
| 56 | | ) |
| | 38 | def expose_cb(self, da, event): |
| | 39 | if not self.pixbuf: |
| | 40 | return |
| | 41 | alloc = self.get_allocation() |
| | 42 | drawable = da.window |
| | 43 | if self.scaled_pixbuf is None or self.scale != (alloc.width, alloc.height): |
| | 44 | self.scaled_pixbuf = self.pixbuf.scale_simple( |
| | 45 | alloc.width, |
| | 46 | alloc.height, |
| | 47 | gtk.gdk.INTERP_NEAREST |
| | 48 | ) |
| | 49 | self.scale = (alloc.width, alloc.height) |
| | 50 | drawable.draw_pixbuf( |
| | 51 | drawable.new_gc(), |
| | 52 | self.scaled_pixbuf, |
| | 53 | 0, 0, # src_x, src_y, |
| | 54 | 0, 0, # dest_x, dest_y, |
| | 55 | alloc.width, alloc.height |
| | 56 | ) |