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)
38 def autostart(reason, **kwargs):
43 if config.plugins.autotimer.autopoll.value and reason == 0:
44 # Initialize AutoTimer
45 from AutoTimer import AutoTimer
46 autotimer = AutoTimer()
49 from AutoPoller import AutoPoller
50 autopoller = AutoPoller()
55 if autopoller is not None:
59 if autotimer is not None:
60 # We re-read the config so we won't save wrong information
64 # XXX: we should at least dump the error
74 def main(session, **kwargs):
79 from AutoTimer import AutoTimer
80 autotimer = AutoTimer()
84 except SyntaxError, se:
87 _("Your config file is not well-formed:\n%s") % (str(se)),
88 type = MessageBox.TYPE_ERROR,
93 # Do not run in background while editing, this might screw things up
94 if autopoller is not None:
97 from AutoTimerOverview import AutoTimerOverview
98 session.openWithCallback(
104 def editCallback(session):
108 # XXX: canceling of GUI (Overview) won't affect config values which might have been changed - is this intended?
110 # Don't parse EPG if editing was canceled
111 if session is not None:
113 ret = autotimer.parseEPG()
116 _("Found a total of %d matching Events.\n%d Timer were added and %d modified.") % (ret[0], ret[1], ret[2]),
117 type = MessageBox.TYPE_INFO,
124 # Start autopoller again if wanted
125 if config.plugins.autotimer.autopoll.value:
126 if autopoller is None:
127 from AutoPoller import AutoPoller
128 autopoller = AutoPoller()
129 autopoller.start(initial = False)
130 # Remove instance if not running in background
136 def movielist(session, service, **kwargs):
137 from AutoTimerEditor import addAutotimerFromService
138 addAutotimerFromService(session, service)
141 def eventinfo(session, servicelist, **kwargs):
142 from AutoTimerEditor import AutoTimerEPGSelection
143 ref = session.nav.getCurrentlyPlayingServiceReference()
144 session.open(AutoTimerEPGSelection, ref)
146 # XXX: we need this helper function to identify the descriptor
148 def extensionsmenu(session, **kwargs):
149 main(session, **kwargs)
151 def housekeepingExtensionsmenu(el):
153 plugins.addPlugin(extDescriptor)
155 plugins.removePlugin(extDescriptor)
157 config.plugins.autotimer.show_in_extensionsmenu.addNotifier(housekeepingExtensionsmenu, initial_call = False, immediate_feedback = False)
158 extDescriptor = PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = extensionsmenu)
160 def Plugins(**kwargs):
162 PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart),
163 PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_PLUGINMENU, icon = "plugin.png", fnc = main),
164 PluginDescriptor(name="AutoTimer", description= _("add AutoTimer..."), where = PluginDescriptor.WHERE_MOVIELIST, fnc = movielist),
165 PluginDescriptor(name=_("add AutoTimer..."), where = PluginDescriptor.WHERE_EVENTINFO, fnc = eventinfo),
167 if config.plugins.autotimer.show_in_extensionsmenu.value:
168 l.append(extDescriptor)