Example #1
0
        def tick(self):
            t0 = GObject.get_current_time()
            keep_playing = self.call(self.use_lightbox)
            if not keep_playing:
                return False

            t1 = GObject.get_current_time()
            dt = t1-t0
            # error here is the total error accumulated during playback
            self.error += t1 - (self.prev_t + self.frame_time)
            self.prev_t = t0

            ms_per_frame = int(round(1000 * (self.frame_time-dt - self.error)))
            if ms_per_frame < 0:
                logger.warning("behind by %.1fms, trying to catch up." \
                                % (1000*(self.error-self.frame_time)))
                              #  % (-ms_per_frame))
                ms_per_frame = 0

            # if the time-per-frame needs to be adjusted at all,
            # add new timeout and end this one
            if ms_per_frame != self.prev_ms_per_frame:
                self.prev_ms_per_frame = ms_per_frame
                GObject.timeout_add(ms_per_frame, self.tick)
                return False
            return keep_playing
Example #2
0
        def tick(self):
            t0 = GObject.get_current_time()
            keep_playing = self.call(self.use_lightbox)
            if not keep_playing:
                return False

            t1 = GObject.get_current_time()
            dt = t1 - t0
            # error here is the total error accumulated during playback
            self.error += t1 - (self.prev_t + self.frame_time)
            self.prev_t = t0

            ms_per_frame = int(
                round(1000 * (self.frame_time - dt - self.error)))
            if ms_per_frame < 0:
                logger.warning("behind by %.1fms, trying to catch up." \
                                % (1000*(self.error-self.frame_time)))
                #  % (-ms_per_frame))
                ms_per_frame = 0

            # if the time-per-frame needs to be adjusted at all,
            # add new timeout and end this one
            if ms_per_frame != self.prev_ms_per_frame:
                self.prev_ms_per_frame = ms_per_frame
                GObject.timeout_add(ms_per_frame, self.tick)
                return False
            return keep_playing
Example #3
0
 def _timer_reset(self):
     ''' Reset the timer for each level '''
     self._start_time = GObject.get_current_time()
     if self._timer_id is not None:
         GObject.source_remove(self._timer_id)
         self._timer_id = None
     self.score += self._seconds
     self._time_increment()
Example #4
0
 def _counter(self):
     ''' Display of seconds since start_time. '''
     seconds = int(GObject.get_current_time() - self.start_time)
     self.set_label('clock', str(seconds))
     if self.robot and self.robot_time < seconds:
         self._find_a_match(robot_match=True)
     else:
         self.timeout_id = GObject.timeout_add(1000, self._counter)
Example #5
0
 def _timer_reset(self):
     ''' Reset the timer for each level '''
     self._start_time = GObject.get_current_time()
     if self._timer_id is not None:
         GObject.source_remove(self._timer_id)
         self._timer_id = None
     self.score += self._seconds
     self._time_increment()
Example #6
0
 def _test_game_over(self):
     ''' Check to see if game is over '''
     for dot in self._dots:
         if dot.type == 1 or dot.type == 2:
             return False
     self._parent.all_scores.append(
         str(int(GObject.get_current_time() - self._start_time)))
     _logger.debug(self._parent.all_scores)
     self._smile()
     return True
Example #7
0
    def do_fade_inout(self, fadein):
        fadein = bool(fadein)
        self.fading_in = fadein
        now = GObject.get_current_time()

        fraction = self.get_opacity()
        if not fadein:
            fraction = 1.0 - fraction
        self.fade_start_time = now - fraction * self.FADETIME

        if self.iteration_source is None:
            self.iteration_source = GLib.timeout_add(
                self.MS, self.fade_iteration_callback)
Example #8
0
    def do_fade_inout(self, fadein):
        fadein = bool(fadein)
        self.fading_in = fadein
        now = GObject.get_current_time()

        fraction = self.get_opacity()
        if not fadein:
            fraction = 1.0 - fraction
        self.fade_start_time = now - fraction * self.FADETIME

        if self.iteration_source is None:
            self.iteration_source = GLib.timeout_add(self.MS,
                    self.fade_iteration_callback)
Example #9
0
  def dim(self):
    if self.pause_fadeout:
      if self.is_composited():
        self.set_opacity(1)
      self._reset_t0()
      return True

    t = gobject.get_current_time()
    opacity = 1.0 - ((t-self.fade_time0)/self.fade_dt)**3.0
    if opacity <= 0.0:
      self.hide()
      return False

    if self.is_composited():
      self.set_opacity( opacity )
    return True
Example #10
0
    def _test_for_a_match(self):
        ''' If we have a match, then we have work to do. '''
        if self._match_check([self.deck.spr_to_card(self.clicked[0].spr),
                              self.deck.spr_to_card(self.clicked[1].spr),
                              self.deck.spr_to_card(self.clicked[2].spr)],
                             self.card_type):
            # Stop the timer.
            if hasattr(self, 'timeout_id'):
                if self.timeout_id is not None:
                    GObject.source_remove(self.timeout_id)
                self.total_time += GObject.get_current_time() - self.start_time

            # Increment the match counter and add the match to the match list.
            self.matches += 1
            for c in self.clicked:
                self.match_list.append(c.spr)
            self._matches_on_display = True

            # Test to see if the game is over.
            if self._game_over():
                if hasattr(self, 'timeout_id'):
                    GObject.source_remove(self.timeout_id)
                if self.low_score[self.level] == -1:
                    self.low_score[self.level] = self.total_time
                elif self.total_time < self.low_score[self.level]:
                    self.low_score[self.level] = self.total_time
                    self.set_label('status', '%s (%d:%02d)' %
                        (_('New record'), int(self.total_time / 60),
                         int(self.total_time % 60)))
                # Round to nearest second
                self.all_scores.append(int(self.total_time + 0.5))
                if not self._sugar:
                    self.activity.save_score()
                else:
                    self._auto_increase_difficulty()
                return True
            else:
                # Wait a few seconds before dealing new cards.
                self._dealing = True
                GObject.timeout_add(2000, self._deal_new_cards)

            # Keep playing.
            self._update_labels()
            self._timer_reset()

        else:
            self._matches_on_display = False
Example #11
0
    def fade_iteration_callback(self):
        delta = GObject.get_current_time() - self.fade_start_time
        fraction = delta / self.FADETIME

        if self.fading_in:
            self.set_opacity(fraction)
        else:
            self.set_opacity(1.0 - fraction)

        if not self.is_composited():
            self.queue_draw()

        if fraction >= 1.0:
            self.iteration_source = None
            self.emit('fade-finished', self.fading_in)
            return False
        return True
Example #12
0
    def fade_iteration_callback(self):
        delta = GObject.get_current_time() - self.fade_start_time
        fraction = delta / self.FADETIME

        if self.fading_in:
            self.set_opacity(fraction)
        else:
            self.set_opacity(1.0 - fraction)

        if not self.is_composited():
            self.queue_draw()

        if fraction >= 1.0:
            self.iteration_source = None
            self.emit('fade-finished', self.fading_in)
            return False
        return True
Example #13
0
 def _timer_reset(self):
     ''' Reset the timer for the robot '''
     self.start_time = GObject.get_current_time()
     self.timeout_id = None
     self._counter()
Example #14
0
	def Activate(self,checker,widnow):
		widnow.activate(int(gobject.get_current_time()))
Example #15
0
 def _reset_t0(self):
   self.fade_time0 = gobject.get_current_time()
Example #16
0
 def _time_increment(self):
     ''' Track seconds since start_time. '''
     self._seconds = int(GObject.get_current_time() - self._start_time)
     self.timer_id = GObject.timeout_add(1000, self._time_increment)
Example #17
0
 def _start_timer(self):
     ''' Start/reset the timer '''
     self._start_time = GObject.get_current_time()
     self._timeout_id = None
     self._counter()
Example #18
0
 def _counter(self):
     ''' Display of seconds since start_time. '''
     self._set_label(str(int(GObject.get_current_time() -
                             self._start_time)))
     self._timeout_id = GObject.timeout_add(1000, self._counter)
Example #19
0
 def _time_increment(self):
     ''' Track seconds since start_time. '''
     self._seconds = int(GObject.get_current_time() - self._start_time)
     self.timer_id = GObject.timeout_add(1000, self._time_increment)
Example #20
0
 def __init__(self, fps, use_lightbox, call):
     self.frame_time = 1.0 / fps
     self.use_lightbox, self.call = use_lightbox, call
     self.prev_t, self.error = GObject.get_current_time(), 0
     self.prev_ms_per_frame = int(round(1000 * self.frame_time))
     GObject.timeout_add(self.prev_ms_per_frame, self.tick)
Example #21
0
 def __init__(self, fps, use_lightbox, call):
     self.frame_time = 1.0/fps
     self.use_lightbox, self.call = use_lightbox, call
     self.prev_t, self.error = GObject.get_current_time(), 0
     self.prev_ms_per_frame = int(round(1000 * self.frame_time))
     GObject.timeout_add(self.prev_ms_per_frame, self.tick)