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, ConfigInteger, ConfigSelection
13 # Initialize Configuration
14 config.plugins.autotimer = ConfigSubsection()
15 config.plugins.autotimer.autopoll = ConfigEnableDisable(default = False)
16 config.plugins.autotimer.interval = ConfigInteger(default = 3, limits=(1, 24))
17 config.plugins.autotimer.refresh = ConfigSelection(choices = [("none", _("None")), ("auto", _("Only AutoTimers created during this Session")), ("all", _("All non-repeating Timers"))], default = "none")
18 config.plugins.autotimer.try_guessing = ConfigEnableDisable(default = False)
24 def autostart(reason, **kwargs):
29 if config.plugins.autotimer.autopoll.value and reason == 0:
30 # Initialize AutoTimer
31 from AutoTimer import AutoTimer
32 autotimer = AutoTimer()
35 from AutoPoller import AutoPoller
36 autopoller = AutoPoller()
41 if autopoller is not None:
46 if autotimer is not None:
54 def main(session, **kwargs):
59 from AutoTimer import AutoTimer
60 autotimer = AutoTimer()
64 except ExpatError, ee:
67 "Your config file is not well-formed.\nError parsing in line: %s" % (ee.lineno),
68 type = MessageBox.TYPE_ERROR,
73 # Don't crash during development
75 traceback.print_exc(file=sys.stdout)
78 "An unexpected error occured: %s" % (e),
79 type = MessageBox.TYPE_ERROR,
84 # Do not run in background while editing, this might screw things up
85 if autopoller is not None:
88 from AutoTimerOverview import AutoTimerOverview
89 session.openWithCallback(
95 def editCallback(session):
99 # Start autopoller again if wanted
100 if config.plugins.autotimer.autopoll.value:
101 if autopoller is None:
102 from AutoPoller import AutoPoller
103 autopoller = AutoPoller()
104 autopoller.start(initial = False)
106 # Don't do anything when editing was canceled
110 # We might re-parse Xml so catch parsing error
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,
120 # Don't crash during development
121 import traceback, sys
122 traceback.print_exc(file=sys.stdout)
125 "An unexpected error occured: %s" % (e),
126 type = MessageBox.TYPE_ERROR,
130 # Remove instance if not running in background
131 if not config.plugins.autotimer.autopoll.value:
138 def Plugins(**kwargs):
140 PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart),
141 PluginDescriptor(name="AutoTimer", description = "Edit Timers and scan for new Events", where = PluginDescriptor.WHERE_PLUGINMENU, icon = "plugin.png", fnc = main),
142 PluginDescriptor(name="AutoTimer", description = "Edit Timers and scan for new Events", where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = main)