[RecordTimer] fix repeat timer issue.
[vuplus_dvbapp] / lib / python / Screens / PictureInPicture.py
1 from Screens.Screen import Screen
2 from enigma import ePoint, eSize, eServiceCenter, getBestPlayableServiceReference, eServiceReference
3 from Components.VideoWindow import VideoWindow
4 from Components.config import config, ConfigPosition
5
6 pip_config_initialized = False
7
8 on_pip_start_stop = []
9
10 class PictureInPicture(Screen):
11         def __init__(self, session):
12                 global pip_config_initialized
13                 Screen.__init__(self, session)
14                 self["video"] = VideoWindow()
15                 self.currentService = None
16                 if not pip_config_initialized:
17                         config.av.pip = ConfigPosition(default=[-1, -1, -1, -1], args = (719, 567, 720, 568))
18                         pip_config_initialized = True
19                 self.onLayoutFinish.append(self.LayoutFinished)
20                 self.dvbPipStarted = False
21
22         def __del__(self):
23                 if self.dvbPipStarted:
24                         self.onPipStartAndStop()
25
26         def LayoutFinished(self):
27                 self.onLayoutFinish.remove(self.LayoutFinished)
28                 x = config.av.pip.value[0]
29                 y = config.av.pip.value[1]
30                 w = config.av.pip.value[2]
31                 h = config.av.pip.value[3]
32                 if x != -1 and y != -1 and w != -1 and h != -1:
33                         self.move(x, y)
34                         self.resize(w, h)
35
36         def move(self, x, y):
37                 config.av.pip.value[0] = x
38                 config.av.pip.value[1] = y
39                 config.av.pip.save()
40                 self.instance.move(ePoint(x, y))
41
42         def resize(self, w, h):
43                 config.av.pip.value[2] = w
44                 config.av.pip.value[3] = h
45                 config.av.pip.save()
46                 self.instance.resize(eSize(*(w, h)))
47                 self["video"].instance.resize(eSize(*(w, h)))
48
49         def getPosition(self):
50                 return ((self.instance.position().x(), self.instance.position().y()))
51
52         def getSize(self):
53                 return (self.instance.size().width(), self.instance.size().height())
54
55         def playService(self, service):
56                 if service and (service.flags & eServiceReference.isGroup):
57                         ref = getBestPlayableServiceReference(service, eServiceReference())
58                 else:
59                         ref = service
60                 if ref:
61                         self.pipservice = eServiceCenter.getInstance().play(ref)
62                         if self.pipservice and not self.pipservice.setTarget(1):
63                                 if ref.type == 1: # dvb service
64                                         self.dvbPipStarted = True
65                                         self.onPipStartAndStop()
66
67                                 self.pipservice.start()
68                                 self.currentService = service
69                                 return True
70                         else:
71                                 self.pipservice = None
72                 return False
73
74         def getCurrentService(self):
75                 return self.currentService
76
77         def onPipStartAndStop(self):
78                 global on_pip_start_stop
79                 for x in on_pip_start_stop:
80                         x()