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)
35 config.plugins.autotimer.maxdaysinfuture = ConfigNumber(default = 0)
36 config.plugins.autotimer.show_help = ConfigYesNo(default = True)
43 from Plugins.SystemPlugins.MPHelp import registerHelp, XMLHelpReader
44 from Tools.Directories import resolveFilename, SCOPE_PLUGINS
45 reader = XMLHelpReader(resolveFilename(SCOPE_PLUGINS, "Extensions/AutoTimer/mphelp.xml"))
46 autotimerHelp = registerHelp(*reader)
48 print "[AutoTimer] Unable to initialize MPHelp:", e,"- Help not available!"
53 def autostart(reason, **kwargs):
58 if config.plugins.autotimer.autopoll.value and reason == 0:
59 # Initialize AutoTimer
60 from AutoTimer import AutoTimer
61 autotimer = AutoTimer()
64 from AutoPoller import AutoPoller
65 autopoller = AutoPoller()
70 if autopoller is not None:
74 if autotimer is not None:
75 # We re-read the config so we won't save wrong information
79 # XXX: we should at least dump the error
89 def main(session, **kwargs):
94 from AutoTimer import AutoTimer
95 autotimer = AutoTimer()
99 except SyntaxError, se:
102 _("Your config file is not well-formed:\n%s") % (str(se)),
103 type = MessageBox.TYPE_ERROR,
108 # Do not run in background while editing, this might screw things up
109 if autopoller is not None:
112 from AutoTimerOverview import AutoTimerOverview
113 session.openWithCallback(
119 def editCallback(session):
123 # XXX: canceling of GUI (Overview) won't affect config values which might have been changed - is this intended?
125 # Don't parse EPG if editing was canceled
126 if session is not None:
128 ret = autotimer.parseEPG()
131 _("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])),
132 type = MessageBox.TYPE_INFO,
139 # Start autopoller again if wanted
140 if config.plugins.autotimer.autopoll.value:
141 if autopoller is None:
142 from AutoPoller import AutoPoller
143 autopoller = AutoPoller()
144 autopoller.start(initial = False)
145 # Remove instance if not running in background
151 def movielist(session, service, **kwargs):
152 from AutoTimerEditor import addAutotimerFromService
153 addAutotimerFromService(session, service)
156 def eventinfo(session, servicelist, **kwargs):
157 from AutoTimerEditor import AutoTimerEPGSelection
158 ref = session.nav.getCurrentlyPlayingServiceReference()
159 session.open(AutoTimerEPGSelection, ref)
161 # XXX: we need this helper function to identify the descriptor
163 def extensionsmenu(session, **kwargs):
164 main(session, **kwargs)
166 def housekeepingExtensionsmenu(el):
168 plugins.addPlugin(extDescriptor)
171 plugins.removePlugin(extDescriptor)
172 except ValueError, ve:
173 print "[AutoTimer] housekeepingExtensionsmenu got confused, tried to remove non-existant plugin entry... ignoring."
175 config.plugins.autotimer.show_in_extensionsmenu.addNotifier(housekeepingExtensionsmenu, initial_call = False, immediate_feedback = True)
176 extDescriptor = PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = extensionsmenu, needsRestart = False)
178 def Plugins(**kwargs):
180 PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart, needsRestart = False),
181 # TRANSLATORS: description of AutoTimer in PluginBrowser
182 PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_PLUGINMENU, icon = "plugin.png", fnc = main, needsRestart = False),
183 # TRANSLATORS: AutoTimer title in MovieList (automatically opens importer, I consider this no further interaction)
184 PluginDescriptor(name="AutoTimer", description= _("add AutoTimer"), where = PluginDescriptor.WHERE_MOVIELIST, fnc = movielist, needsRestart = False),
185 # TRANSLATORS: AutoTimer title in EventInfo dialog (requires the user to select an event to base the AutoTimer on)
186 PluginDescriptor(name=_("add AutoTimer..."), where = PluginDescriptor.WHERE_EVENTINFO, fnc = eventinfo, needsRestart = False),
188 if config.plugins.autotimer.show_in_extensionsmenu.value:
189 l.append(extDescriptor)