def _info_changed(self, timer_name = 'network_timer', update_frequency = UPDATE_FREQ_SECS): ''' Called when information in the buddylist store object changes. It resets a timer, and every so many seconds after no changes have occurred, the changes are synced with the server. ''' t = getattr(self, timer_name, None) if t is None: t = RepeatTimer(update_frequency, lambda: self._on_timer(timer_name)) setattr(self, timer_name, t) t.start() else: t.reset()
def on_before_status_change(self, status): ''' Invoked when the profile's status message changes. ''' log.info('on_status_change') is_music_status = isinstance(status, NowPlayingStatus) timer = getattr(self, 'timer', None) timer_alive = timer is not None and self.timer.isAlive() # If the status is a "music status" and our timer isn't running, start it. if is_music_status and not timer_alive: self.link() log.debug('starting now playing timer') if timer is None: self.timer = timer = RepeatTimer(5, lambda: wx.CallAfter(self.on_timer)) timer.start() # call it now to look responsive! yay # Otherwise if the status is not a "music status" and the timer IS running, stop it. elif not is_music_status and timer_alive: log.debug('stopping now playing timer') self.song = (None, 0) self.unlink() self.timer.stop() releaseAll() if is_music_status: s = status.status if pref(NOWPLAYING_STATUS_PREF, type = str, default = 'available') != s: profile.prefs.__setitem__(NOWPLAYING_STATUS_PREF, s.lower()) if not is_music_status: return status try: if status is not self.status: self.check_song(force=True, status=status) return self.status except Exception: traceback.print_exc() return status
def set_enabled(self, value): # the first time "enabled" is set, create a timer has_been_set = hasattr(self, '_enabled') if not has_been_set: self.change_reason(self.Reasons.NONE) if self.update_mixin_timer: info('%s creating a timer with update frequency %s', self, self.updatefreq) self.timer = RepeatTimer(int(self.updatefreq), self.update_now) self.timer.start() self.timer.stop() if get( self, 'on_connect', None ) is not None and self.update_now not in self.on_connect: self.on_connect += self.update_now # when enabled, start the timer. self._enabled = value if value: info('enabling timer for %s', self) if self.OFFLINE and getattr(self, '_needs_connect', True): self._needs_connect = False get(self, 'Connect', nothing)() if self.update_mixin_timer: self.timer.reset(int(self.updatefreq)) # when disabled, stop the timer. else: if has_been_set: if not self.OFFLINE: get(self, 'Disconnect', nothing)() self._needs_connect = True if self.update_mixin_timer: info('stopping timer for %s', self) self.timer.stop() get(self, 'on_disable', nothing)()
def setup(self): self.links = [] self.timer = RepeatTimer(5, lambda: wx.CallAfter(self.on_timer)) self.song = (None, 0) self.status = None self.on_before_status_change(profile.status)