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)
39 def autostart(reason, **kwargs):
44 if config.plugins.autotimer.autopoll.value and reason == 0:
45 # Initialize AutoTimer
46 from AutoTimer import AutoTimer
47 autotimer = AutoTimer()
50 from AutoPoller import AutoPoller
51 autopoller = AutoPoller()
56 if autopoller is not None:
60 if autotimer is not None:
61 # We re-read the config so we won't save wrong information
65 # XXX: we should at least dump the error
75 def main(session, **kwargs):
80 from AutoTimer import AutoTimer
81 autotimer = AutoTimer()
85 except SyntaxError, se:
88 _("Your config file is not well-formed:\n%s") % (str(se)),
89 type = MessageBox.TYPE_ERROR,
94 # Do not run in background while editing, this might screw things up
95 if autopoller is not None:
98 from AutoTimerOverview import AutoTimerOverview
99 session.openWithCallback(
105 def editCallback(session):
109 # XXX: canceling of GUI (Overview) won't affect config values which might have been changed - is this intended?
111 # Don't parse EPG if editing was canceled
112 if session is not None:
114 ret = autotimer.parseEPG()
117 _("Found a total of %d matching Events.\n%d Timer were added and %d modified.") % (ret[0], ret[1], ret[2]),
118 type = MessageBox.TYPE_INFO,
125 # Start autopoller again if wanted
126 if config.plugins.autotimer.autopoll.value:
127 if autopoller is None:
128 from AutoPoller import AutoPoller
129 autopoller = AutoPoller()
130 autopoller.start(initial = False)
131 # Remove instance if not running in background
137 def movielist(session, service, **kwargs):
138 from AutoTimerEditor import addAutotimerFromService
139 addAutotimerFromService(session, service)
142 def eventinfo(session, servicelist, **kwargs):
143 from AutoTimerEditor import AutoTimerEPGSelection
144 ref = session.nav.getCurrentlyPlayingServiceReference()
145 session.open(AutoTimerEPGSelection, ref)
147 # XXX: we need this helper function to identify the descriptor
149 def extensionsmenu(session, **kwargs):
150 main(session, **kwargs)
152 def housekeepingExtensionsmenu(el):
154 plugins.addPlugin(extDescriptor)
156 plugins.removePlugin(extDescriptor)
158 config.plugins.autotimer.show_in_extensionsmenu.addNotifier(housekeepingExtensionsmenu, initial_call = False, immediate_feedback = False)
159 extDescriptor = PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = extensionsmenu)
161 def Plugins(**kwargs):
163 PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart),
164 PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_PLUGINMENU, icon = "plugin.png", fnc = main),
165 PluginDescriptor(name="AutoTimer", description= _("add AutoTimer..."), where = PluginDescriptor.WHERE_MOVIELIST, fnc = movielist),
166 PluginDescriptor(name=_("add AutoTimer..."), where = PluginDescriptor.WHERE_EVENTINFO, fnc = eventinfo),
168 if config.plugins.autotimer.show_in_extensionsmenu.value:
169 l.append(extDescriptor)