code: def refresh_timer_cb(self, timer, flags):
          
          # this is the timer call back, from the GUI thread
          start_time = time.time()
  
          if flags.get('done', False):
              return
  
          # calculate next deadline
          deadline = self.rf_deadline
          self.rf_deadline += self.rf_rate
  
          self.rf_timer_count += 1
          delta = abs(start_time - deadline)
          self.rf_delta_total += delta
          adjust = 0.0
  
          if start_time > deadline:
              # we are late
              self.rf_late_total += delta
              self.rf_late_count += 1
              late_avg = self.rf_late_total / self.rf_late_count
              adjust = - (late_avg / 2.0)
              self.rf_skip_total += delta
              if self.rf_skip_total < self.rf_rate:
                  self.rf_draw_count += 1
                  # TODO: can we optimize whence?
                  self.redraw_now(whence=0)
              else:
                  # <-- we are behind by amount of time equal to one frame.
                  # skip a redraw and attempt to catch up some time
                  self.rf_skip_total = 0
          else:
              if start_time < deadline:
                  # we are early
                  self.rf_early_total += delta
                  self.rf_early_count += 1
                  self.rf_skip_total = max(0.0, self.rf_skip_total - delta)
                  early_avg = self.rf_early_total / self.rf_early_count
                  adjust = early_avg / 4.0
  
              self.rf_draw_count += 1
              # TODO: can we optimize whence?
              self.redraw_now(whence=0)
  
          delay = max(0.0, self.rf_deadline - time.time() + adjust)
          timer.start(delay)
docs: Refresh timer callback.
          This callback will normally only be called internally.
  
          Parameters
          ----------
          timer : a Ginga GUI timer
              A GUI-based Ginga timer
  
          flags : dict-like
              A set of flags controlling the timer