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
73 def main(session, **kwargs):
78 from AutoTimer import AutoTimer
79 autotimer = AutoTimer()
83 except SyntaxError, se:
86 _("Your config file is not well-formed:\n%s") % (str(se)),
87 type = MessageBox.TYPE_ERROR,
92 # Do not run in background while editing, this might screw things up
93 if autopoller is not None:
96 from AutoTimerOverview import AutoTimerOverview
97 session.openWithCallback(
103 def editCallback(session):
107 # XXX: canceling of GUI (Overview) won't affect config values which might have been changed - is this intended?
109 # Don't parse EPG if editing was canceled
110 if session is not None:
112 ret = autotimer.parseEPG()
115 _("Found a total of %d matching Events.\n%d Timer were added and %d modified.") % (ret[0], ret[1], ret[2]),
116 type = MessageBox.TYPE_INFO,
123 # Start autopoller again if wanted
124 if config.plugins.autotimer.autopoll.value:
125 if autopoller is None:
126 from AutoPoller import AutoPoller
127 autopoller = AutoPoller()
128 autopoller.start(initial = False)
129 # Remove instance if not running in background
135 def movielist(session, service, **kwargs):
136 from AutoTimerEditor import addAutotimerFromService
137 addAutotimerFromService(session, service)
140 def eventinfo(session, servicelist, **kwargs):
141 from AutoTimerEditor import AutoTimerEPGSelection
142 ref = session.nav.getCurrentlyPlayingServiceReference()
143 session.open(AutoTimerEPGSelection, ref)
145 # XXX: we need this helper function to identify the descriptor
147 def extensionsmenu(session, **kwargs):
148 main(session, **kwargs)
150 def housekeepingExtensionsmenu(el):
152 plugins.addPlugin(extDescriptor)
154 plugins.removePlugin(extDescriptor)
156 config.plugins.autotimer.show_in_extensionsmenu.addNotifier(housekeepingExtensionsmenu, initial_call = False, immediate_feedback = False)
157 extDescriptor = PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = extensionsmenu)
159 def Plugins(**kwargs):
161 PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart),
162 PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_PLUGINMENU, icon = "plugin.png", fnc = main),
163 PluginDescriptor(name="AutoTimer", description= _("Add AutoTimer..."), where = PluginDescriptor.WHERE_MOVIELIST, fnc = movielist),
164 PluginDescriptor(name="AutoTimer", description= _("Add AutoTimer..."), where = PluginDescriptor.WHERE_EVENTINFO, fnc = eventinfo),
166 if config.plugins.autotimer.show_in_extensionsmenu.value:
167 l.append(extDescriptor)