1 # for localized messages
5 from Screens.MessageBox import MessageBox
8 from Components.config import config, ConfigSubsection, ConfigEnableDisable, \
9 ConfigNumber, ConfigSelection, ConfigYesNo
12 from Components.PluginComponent import plugins
13 from Plugins.Plugin import PluginDescriptor
15 # Initialize Configuration
16 config.plugins.autotimer = ConfigSubsection()
17 config.plugins.autotimer.autopoll = ConfigEnableDisable(default = False)
18 config.plugins.autotimer.interval = ConfigNumber(default = 3)
19 config.plugins.autotimer.refresh = ConfigSelection(choices = [
21 ("auto", _("Only AutoTimers created during this session")),
22 ("all", _("All non-repeating timers"))
25 config.plugins.autotimer.try_guessing = ConfigEnableDisable(default = True)
26 config.plugins.autotimer.editor = ConfigSelection(choices = [
27 ("plain", _("Classic")),
28 ("wizard", _("Wizard"))
31 config.plugins.autotimer.disabled_on_conflict = ConfigEnableDisable(default = False)
32 config.plugins.autotimer.show_in_extensionsmenu = ConfigYesNo(default = False)
33 config.plugins.autotimer.fastscan = ConfigYesNo(default = False)
34 config.plugins.autotimer.notifconflict = ConfigYesNo(default = True)
40 def autostart(reason, **kwargs):
45 if config.plugins.autotimer.autopoll.value and reason == 0:
46 # Initialize AutoTimer
47 from AutoTimer import AutoTimer
48 autotimer = AutoTimer()
51 from AutoPoller import AutoPoller
52 autopoller = AutoPoller()
57 if autopoller is not None:
61 if autotimer is not None:
62 # We re-read the config so we won't save wrong information
66 # XXX: we should at least dump the error
76 def main(session, **kwargs):
81 from AutoTimer import AutoTimer
82 autotimer = AutoTimer()
86 except SyntaxError, se:
89 _("Your config file is not well-formed:\n%s") % (str(se)),
90 type = MessageBox.TYPE_ERROR,
95 # Do not run in background while editing, this might screw things up
96 if autopoller is not None:
99 from AutoTimerOverview import AutoTimerOverview
100 session.openWithCallback(
106 def editCallback(session):
110 # XXX: canceling of GUI (Overview) won't affect config values which might have been changed - is this intended?
112 # Don't parse EPG if editing was canceled
113 if session is not None:
115 ret = autotimer.parseEPG()
118 _("Found a total of %d matching Events.\n%d Timer were added and %d modified, %d conflicts encountered.") % (ret[0], ret[1], ret[2], len(ret[4])),
119 type = MessageBox.TYPE_INFO,
126 # Start autopoller again if wanted
127 if config.plugins.autotimer.autopoll.value:
128 if autopoller is None:
129 from AutoPoller import AutoPoller
130 autopoller = AutoPoller()
131 autopoller.start(initial = False)
132 # Remove instance if not running in background
138 def movielist(session, service, **kwargs):
139 from AutoTimerEditor import addAutotimerFromService
140 addAutotimerFromService(session, service)
143 def eventinfo(session, servicelist, **kwargs):
144 from AutoTimerEditor import AutoTimerEPGSelection
145 ref = session.nav.getCurrentlyPlayingServiceReference()
146 session.open(AutoTimerEPGSelection, ref)
148 # XXX: we need this helper function to identify the descriptor
150 def extensionsmenu(session, **kwargs):
151 main(session, **kwargs)
153 def housekeepingExtensionsmenu(el):
155 plugins.addPlugin(extDescriptor)
157 plugins.removePlugin(extDescriptor)
159 config.plugins.autotimer.show_in_extensionsmenu.addNotifier(housekeepingExtensionsmenu, initial_call = False, immediate_feedback = False)
160 extDescriptor = PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = extensionsmenu)
162 def Plugins(**kwargs):
164 PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart),
165 PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_PLUGINMENU, icon = "plugin.png", fnc = main),
166 PluginDescriptor(name="AutoTimer", description= _("add AutoTimer..."), where = PluginDescriptor.WHERE_MOVIELIST, fnc = movielist),
167 PluginDescriptor(name=_("add AutoTimer..."), where = PluginDescriptor.WHERE_EVENTINFO, fnc = eventinfo),
169 if config.plugins.autotimer.show_in_extensionsmenu.value:
170 l.append(extDescriptor)