class PluginInterface(plugin.DaemonPlugin): """ The autostart plugin allows you to define an action that will be called when the user do not interact in the first few seconds. With this it is possible to define a default action e.g. starting radio if there is no other activity. To activate the autostart plugin add to local_conf.py:: plugin.activate('autostart') AUTOSTART_EVENTS = ( 'MENU_DOWN', 'MENU_DOWN', 'MENU_SELECT', 'MENU_SELECT', ) """ __author__ = 'Andreas Dick' __author_email__ = '*****@*****.**' __maintainer__ = __author__ __maintainer_email__ = __author_email__ __version__ = '$Revision$' def __init__(self): """ Init the autostart timeout and the plugin variables """ plugin.DaemonPlugin.__init__(self) self.active = True self.timer = OneShotTimer(self._timer_handler) self.event = EventHandler(self._event_handler) self.event.register() def config(self): return [ ('AUTOSTART_EVENTS', [], 'list of events to send to freevo at start up'), ('AUTOSTART_TIMEOUT', 5, 'Numbers of seconds to time out if there is no action'), ] def _event_handler(self, event): if self.active: if event == FREEVO_READY: self.active = True self.timer.start(config.AUTOSTART_TIMEOUT) elif event == MENU_PROCESS_END: if not self.active: self.timer.start(config.AUTOSTART_TIMEOUT) elif config.AUTOSTART_TIMEOUT: logger.info('Another event is closing the autostart plugin.') self.event.unregister() self.timer.stop() self.active = False def _timer_handler(self): if self.active: logger.info('Timeout reached without an event, posting events now.') for e in config.AUTOSTART_EVENTS: rc.post_event(Event(e)) self.event.unregister() self.timer.stop() self.active = False