2 from Screens.MessageBox import MessageBox
5 from Plugins.Plugin import PluginDescriptor
8 from xml.parsers.expat import ExpatError
11 from Components.config import config, ConfigSubsection, ConfigEnableDisable, \
12 ConfigInteger, ConfigSelection
14 # Initialize Configuration
15 config.plugins.autotimer = ConfigSubsection()
16 config.plugins.autotimer.autopoll = ConfigEnableDisable(default = False)
17 config.plugins.autotimer.interval = ConfigInteger(default = 3, limits=(1, 24))
18 config.plugins.autotimer.refresh = ConfigSelection(choices = [("none", _("None")), ("auto", _("Only AutoTimers created during this Session")), ("all", _("All non-repeating Timers"))], default = "none")
19 config.plugins.autotimer.try_guessing = ConfigEnableDisable(default = True)
25 def autostart(reason, **kwargs):
30 if config.plugins.autotimer.autopoll.value and reason == 0:
31 # Initialize AutoTimer
32 from AutoTimer import AutoTimer
33 autotimer = AutoTimer()
36 from AutoPoller import AutoPoller
37 autopoller = AutoPoller()
42 if autopoller is not None:
43 # We might shutdown when configuring, timer won't be runnign then
46 except ValueError, ve:
51 if autotimer is not None:
59 def main(session, **kwargs):
64 from AutoTimer import AutoTimer
65 autotimer = AutoTimer()
69 except ExpatError, ee:
72 "Your config file is not well-formed.\nError parsing in line: %s" % (ee.lineno),
73 type = MessageBox.TYPE_ERROR,
78 # Don't crash during development
80 traceback.print_exc(file=sys.stdout)
83 "An unexpected error occured: %s" % (e),
84 type = MessageBox.TYPE_ERROR,
89 # Do not run in background while editing, this might screw things up
90 if autopoller is not None:
93 from AutoTimerOverview import AutoTimerOverview
94 session.openWithCallback(
100 def editCallback(session):
104 # Start autopoller again if wanted
105 if config.plugins.autotimer.autopoll.value:
106 if autopoller is None:
107 from AutoPoller import AutoPoller
108 autopoller = AutoPoller()
109 autopoller.start(initial = False)
111 # Don't do anything when editing was canceled
115 # We might re-parse Xml so catch parsing error
117 ret = autotimer.parseEPG()
120 "Found a total of %d matching Events.\n%d Timer were added and %d modified.." % (ret[0], ret[1], ret[2]),
121 type = MessageBox.TYPE_INFO,
125 # Don't crash during development
126 import traceback, sys
127 traceback.print_exc(file=sys.stdout)
130 "An unexpected error occured: %s" % (e),
131 type = MessageBox.TYPE_ERROR,
135 # Remove instance if not running in background
136 if not config.plugins.autotimer.autopoll.value:
143 def Plugins(**kwargs):
145 PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart),
146 PluginDescriptor(name="AutoTimer", description = "Edit Timers and scan for new Events", where = PluginDescriptor.WHERE_PLUGINMENU, icon = "plugin.png", fnc = main),
147 PluginDescriptor(name="AutoTimer", description = "Edit Timers and scan for new Events", where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = main)