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:
47 if autotimer is not None:
55 def main(session, **kwargs):
60 from AutoTimer import AutoTimer
61 autotimer = AutoTimer()
65 except ExpatError, ee:
68 "Your config file is not well-formed.\nError parsing in line: %s" % (ee.lineno),
69 type = MessageBox.TYPE_ERROR,
74 # Don't crash during development
76 traceback.print_exc(file=sys.stdout)
79 "An unexpected error occured: %s" % (e),
80 type = MessageBox.TYPE_ERROR,
85 # Do not run in background while editing, this might screw things up
86 if autopoller is not None:
89 from AutoTimerOverview import AutoTimerOverview
90 session.openWithCallback(
96 def editCallback(session):
100 # Start autopoller again if wanted
101 if config.plugins.autotimer.autopoll.value:
102 if autopoller is None:
103 from AutoPoller import AutoPoller
104 autopoller = AutoPoller()
105 autopoller.start(initial = False)
107 # Don't do anything when editing was canceled
111 # We might re-parse Xml so catch parsing error
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,
121 # Don't crash during development
122 import traceback, sys
123 traceback.print_exc(file=sys.stdout)
126 "An unexpected error occured: %s" % (e),
127 type = MessageBox.TYPE_ERROR,
131 # Remove instance if not running in background
132 if not config.plugins.autotimer.autopoll.value:
139 def Plugins(**kwargs):
141 PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart),
142 PluginDescriptor(name="AutoTimer", description = "Edit Timers and scan for new Events", where = PluginDescriptor.WHERE_PLUGINMENU, icon = "plugin.png", fnc = main),
143 PluginDescriptor(name="AutoTimer", description = "Edit Timers and scan for new Events", where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = main)