Logo Search packages:      
Sourcecode: ibus-table version File versions  Download package

def speedmeter::SpeedMeter::update_speed (   self,
  phrase_len 
)

Call this after locking, and then relase lock

Definition at line 307 of file speedmeter.py.

00307                                          :
        '''Call this after locking, and then relase lock'''
        now = time.time()
        # only do lock here
        self.timer.tlock.acquire()
        self.list.append( (phrase_len, now) ) 
        self.list = map (lambda x: (x[0], x[1], now - x[1]), self.list )
        self.list = filter (lambda x: x[2] < 61, self.list)
        # unlock here
        self.timer.tlock.release()
        if not self.full:
            self.c_time = self.list[-1][1] - self.list[0][1] 
            self.c_time = (self.c_time > 1 and self.c_time or 1 )
            self.full = (self.c_time >=60)
        speed = ( sum( map( lambda x: x[0], self.list) ) * 60\
                / self.c_time )
        speed = int(speed)
        # now we calculate the color,
        # the color of HSV we want is from (240, 1, 1) -> (360, 1, 1)
        # this is very easy, since S & V are both 1, only H need to take
        # care.
        # we want 10 -> 112 to be marked from blue to red
        if speed > 10:
            # speed > 10
            if speed < 112:
                # 10 < speed < 112
                if speed >= 61:
                    #  61 <= speed < 112
                    # the blue is
                    color = (112-speed) * 5
                    self.label_color.red = 0xffff
                    self.label_color.blue = (color << 8) + color
                else:
                    # 10 < speed < 61
                    # the red is
                    color = (speed-10) * 5
                    self.label_color.red = (color << 8) + color
                    self.label_color.blue = 0xffff
            else:
                # speed >= 112
                    self.label_color.red = 0xffff
                    self.label_color.blue = 0
        else:
            #speed <= 10:
            self.label_color.red=0
            self.label_color.blue = 0xffff
        # update speed label
        self.speed_label.set_text( "%d" % speed )
        self.speed_label.modify_fg(gtk.STATE_NORMAL,
                self.label_color)

    def reset(self):


Generated by  Doxygen 1.6.0   Back to index