- use confignumber instead of configinteger in autotimer, epgrefresh and simplerss;
[vuplus_dvbapp-plugin] / autotimer / src / plugin.py
1 # GUI (Screens)
2 from Screens.MessageBox import MessageBox
3
4 # Config
5 from Components.config import config, ConfigSubsection, ConfigEnableDisable, \
6         ConfigNumber, ConfigSelection
7
8 # Initialize Configuration
9 config.plugins.autotimer = ConfigSubsection()
10 config.plugins.autotimer.autopoll = ConfigEnableDisable(default = False)
11 config.plugins.autotimer.interval = ConfigNumber(default = 3)
12 config.plugins.autotimer.refresh = ConfigSelection(choices = [
13                 ("none", _("None")),
14                 ("auto", _("Only AutoTimers created during this Session")),
15                 ("all", _("All non-repeating Timers"))
16         ], default = "none"
17 )
18 config.plugins.autotimer.try_guessing = ConfigEnableDisable(default = True)
19
20 autotimer = None
21 autopoller = None
22
23 # Autostart
24 def autostart(reason, **kwargs):
25         global autotimer
26         global autopoller
27
28         # Startup
29         if config.plugins.autotimer.autopoll.value and reason == 0:
30                 # Initialize AutoTimer
31                 from AutoTimer import AutoTimer
32                 autotimer = AutoTimer()
33
34                 # Start Poller
35                 from AutoPoller import AutoPoller
36                 autopoller = AutoPoller()
37                 autopoller.start()
38         # Shutdown
39         elif reason == 1:
40                 # Stop Poller
41                 if autopoller is not None:
42                         # We might shutdown when configuring, timer won't be runnign then
43                         try:
44                                 autopoller.stop()
45                         except ValueError, ve:
46                                 pass
47
48                         autopoller = None
49
50                 if autotimer is not None:
51                         # Save xml
52                         autotimer.writeXml()
53
54                         # Remove AutoTimer
55                         autotimer = None
56
57 # Mainfunction
58 def main(session, **kwargs):
59         global autotimer
60         global autopoller
61
62         if autotimer is None:
63                 from AutoTimer import AutoTimer
64                 autotimer = AutoTimer()
65
66         from xml.parsers.expat import ExpatError
67
68         try:
69                 autotimer.readXml()
70         except ExpatError, ee:
71                 session.open(
72                         MessageBox,
73                         "Your config file is not well-formed.\nError parsing in line: %s" % (ee.lineno),
74                         type = MessageBox.TYPE_ERROR,
75                         timeout = 10
76                 )
77                 return
78         except Exception, e:
79                 # Don't crash during development
80                 import traceback, sys
81                 traceback.print_exc(file=sys.stdout)
82                 session.open(
83                         MessageBox,
84                         "An unexpected error occured: %s" % (e),
85                         type = MessageBox.TYPE_ERROR,
86                         timeout = 15
87                 )
88                 return
89
90         # Do not run in background while editing, this might screw things up
91         if autopoller is not None:
92                 autopoller.stop()
93
94         from AutoTimerOverview import AutoTimerOverview
95         session.openWithCallback(
96                 editCallback,
97                 AutoTimerOverview,
98                 autotimer
99         )
100
101 def editCallback(session):
102         global autotimer
103         global autopoller
104
105         # Start autopoller again if wanted
106         if config.plugins.autotimer.autopoll.value:
107                 if autopoller is None:
108                         from AutoPoller import AutoPoller
109                         autopoller = AutoPoller()
110                 autopoller.start(initial = False)
111
112         # Don't do anything when editing was canceled
113         if session is None:
114                 return
115
116         # We might re-parse Xml so catch parsing error
117         try:
118                 ret = autotimer.parseEPG()
119                 session.open(
120                         MessageBox,
121                         "Found a total of %d matching Events.\n%d Timer were added and %d modified.." % (ret[0], ret[1], ret[2]),
122                         type = MessageBox.TYPE_INFO,
123                         timeout = 10
124                 )
125         except Exception, e:
126                 # Don't crash during development
127                 import traceback, sys
128                 traceback.print_exc(file=sys.stdout)
129                 session.open(
130                         MessageBox,
131                         "An unexpected error occured: %s" % (e),
132                         type = MessageBox.TYPE_ERROR,
133                         timeout = 15
134                 )
135
136         # Remove instance if not running in background
137         if not config.plugins.autotimer.autopoll.value:
138                 autopoller = None
139
140                 # Save xml
141                 autotimer.writeXml()
142                 autotimer = None
143
144 def Plugins(**kwargs):
145         from Plugins.Plugin import PluginDescriptor
146
147         return [
148                 PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart),
149                 PluginDescriptor(name="AutoTimer", description = "Edit Timers and scan for new Events", where = PluginDescriptor.WHERE_PLUGINMENU, icon = "plugin.png", fnc = main),
150                 PluginDescriptor(name="AutoTimer", description = "Edit Timers and scan for new Events", where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = main)
151         ]