Rose-Hulman Robotics Team

Changeset 748 for trunk

Show
Ignore:
Timestamp:
06/06/10 14:34:54 (20 months ago)
Author:
mosttw
Message:

Untested changes to video display (fixing an obvious bug and converting tabs to spaces)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/software/rb/gui/camera.py

    r666 r748  
    11# Copyright (C) 2009 Andy Spencer 
    2 # Copyright (C) 2009 Thomas W. Most 
     2# Copyright (C) 2009-2010 Thomas W. Most 
    33# 
    44# This program is free software: you can redistribute it and/or modify 
     
    2020 
    2121class VideoDisplay(gtk.DrawingArea): 
    22         def __init__(self): 
    23                 gtk.DrawingArea.__init__(self) 
    24                 self.pixbuf = None 
    25                 #self.pipeline = gst.parse_launch('appsrc ! autovideosink') 
     22    def __init__(self): 
     23        gtk.DrawingArea.__init__(self) 
     24        self.pixbuf = None 
     25        self.scaled_pixbuf = None 
     26        self.pipeline = gst.parse_launch('appsrc ! autovideosink') 
    2627 
    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 
    3637 
    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        ) 
    5757