forked from oe-mirrors/PlanerFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.py
171 lines (155 loc) · 5.38 KB
/
timer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# PYTHON IMPORTS
from configparser import ConfigParser
from datetime import datetime, date
from os import unlink
from os.path import exists
from time import mktime
# ENIGMA IMPORTS
from enigma import eTimer, eActionMap, eDVBVolumecontrol
from Screens import Standby
from Screens.MessageBox import MessageBox
from Tools import Notifications
# PLUGIN IMPORTS
from . import CONFIGFILE, _ # for localized messages
from .PFSanzeige import Timermeldung
try:
from Plugins.Extensions.LCD4linux.module import L4Lelement
MyElements = L4Lelement()
conf = {"l4lm_font": 60, "l4l_screen": 4, "l4l_lcd": 1, "l4l_on": "Yes", "m_dauer": 0}
l4l = None
if exists(CONFIGFILE):
configparser = ConfigParser()
configparser.read(CONFIGFILE)
if configparser.has_section("settings"):
l1 = configparser.items("settings")
for k, v in l1:
if k in conf and v.strip() != "":
if v.strip() in ("False", "false", "None", "none"):
conf[k] = False
elif v.strip() in ("True", "true"):
conf[k] = True
else:
conf[k] = v.strip()
if conf["l4l_on"] == "Yes":
l4l = True
l4lm_font = conf["l4lm_font"]
l4l_lcd = conf["l4l_lcd"]
l4l_screen = conf["l4l_screen"]
alarmdauer = conf["m_dauer"]
except Exception:
l4l = None
class TimerList():
def __init__(self):
self.timerlist = []
if 1 == 2:
for x in open("/tmp/pfsalert_list", "r").readlines():
if len(str(x)):
wdhlg = "unique"
sound = x[4]
aktiv = "aktiv"
if x[5]:
aktiv = str(x[5])
if x[6] and x[6] != None:
wdhlg = "repeat"
if wdhlg == "unique" and date(x[3].year, x[3].month, x[3].day) < date.today(): # ToDo
aktiv = "no_activ"
stunde = x[3].hour # ToDo
minute = x[3].minute # ToDo
melder = ((3600 * int(stunde)) + (60 * int(minute)), x[0], aktiv, sound, wdhlg, x[1], x[7])
self.timerlist.append(melder)
class Timer_dats:
def __init__(self, Akt=None, liste=None, DPKG=None):
self.termin_timer = eTimer()
self.termin_timer.callback.append(self.T_Box)
self.ti_liste = []
if Akt:
self.from_deep(liste)
def startTimer(self, session=None, timerliste=[], DPKG=None):
if session is not None:
self.session = session
tmliste = timerliste # TimerList().timerlist
if len(tmliste) > 0:
now = datetime.now()
u = mktime(now.timetuple())
self.timerlist2 = []
for x in tmliste:
self.zeitdiff = int(x[10] - u)
if self.zeitdiff > 60:
self.timerlist2.append((self.zeitdiff, x[1], x[6], x[11], x[4], x[7], x[5]))
self.timerlist2.sort()
if len(self.timerlist2):
self.Next_Termin()
def Next_Termin(self):
if len(self.timerlist2):
new_timer = self.timerlist2[0]
self.timerdats = self.timerlist2[0]
if new_timer[0] > 10:
self.termin_timer.startLongTimer(new_timer[0])
del self.timerlist2[0]
def from_deep(self, timerdat=None):
if timerdat:
self.timerdats = timerdat
self.T_Box()
def T_Box(self):
url = self.timerdats[5]
text = self.timerdats[1]
vol = self.timerdats[2]
sound = self.timerdats[4]
anz_dauer = self.timerdats[3]
aktiv = self.timerdats[6]
startvol = int(vol[0])
self.sound = sound
self.ex_timer = eTimer()
if l4l:
txt = _("Timer message") + "\n\n" + text
s1 = MyElements.getResolution(l4l_lcd)
MyElements.add("plFS.07.wait1", {"Typ": "wait", "Lcd": str(l4l_lcd)})
MyElements.add("plFS.08.box1", {"Typ": "box", "PosX": 0, "PosY": 0, "Color": "red", "Fill": True, "Width": s1[0], "Height": s1[1], "Screen": str(l4l_screen), "Mode": "OnMediaIdle", "Lcd": str(l4l_lcd)})
MyElements.add("plFS.09.txt1", {"Typ": "txt", "Text": txt, "Pos": 30, "Size": str(l4lm_font), "Lines": 3, "Screen": str(l4l_screen), "Mode": "OnMediaIdle", "Lcd": str(l4l_lcd)})
MyElements.setScreen(str(l4l_screen), str(l4l_lcd))
# if Standby.inStandby:
# self.ti_liste.append(text)
# Standby.inStandby.onHide.append(self.T_Liste)
# if l4l and alarmdauer>0:
# self.ex_timer.timeout.get().append(self.l4l_exit)
# self.ex_timer.startLongTimer(alarmdauer)
# text="",anz_dauer=0,sound=None,vol=(10,100),url=None
if Standby.inStandby:
eActionMap.getInstance().bindAction('', -0x7FFFFFFF, self.rcKeyPressed)
if aktiv == "sb" or aktiv == "dsb":
self.vol_down(startvol)
Standby.inStandby.Power()
Notifications.AddNotification(Timermeldung, text, anz_dauer, sound, vol, url, None)
else:
if not exists("/tmp/plfst1"):
Standby.inStandby.onHide.append(self.T_Liste)
else:
self.vol_down(startvol)
self.session.open(Timermeldung, text, anz_dauer, sound, vol, url, None)
self.Next_Termin()
def vol_down(self, startvol):
if self.sound == "radio" or self.sound == "AUDIO":
volctrl = eDVBVolumecontrol.getInstance()
volctrl.setVolume(startvol, startvol)
def l4l_exit(self):
MyElements.delete("plFS.07.wait1")
MyElements.delete("plFS.08.box1")
MyElements.delete("plFS.09.txt1")
MyElements.setScreen("0", "1")
def rcKeyPressed(self, key, flag):
if l4l and str(key) == "352": # ok
self.l4l_exit()
def T_Liste(self):
if exists("/tmp/plfst1"):
fp = open('/tmp/plfst1', 'r')
t_lines = fp.readlines()
fp.close()
text = "verpasste Timer-Meldungen:\n\n"
for x in t_lines:
text = text + x + "\n"
Notifications.AddNotification(MessageBox, text, type=MessageBox.TYPE_INFO)
unlink("/tmp/plfst1")
def restart(self, session=None, tm_liste=[], DPKG=None):
self.termin_timer.stop()
if len(tm_liste):
self.startTimer(session, tm_liste)