only show pip option in contextmenu when the hardware can handle pip
[enigma2.git] / 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 class PictureInPicture(Screen):
9         def __init__(self, session):
10                 global pip_config_initialized
11                 Screen.__init__(self, session)
12                 self["video"] = VideoWindow()
13                 self.currentService = None
14                 if not pip_config_initialized:
15                         config.av.pip = ConfigPosition(default=[-1, -1, -1, -1], args = (719, 567, 720, 568))
16                         pip_config_initialized = True
17                 self.onLayoutFinish.append(self.LayoutFinished)
18
19         def LayoutFinished(self):
20                 self.onLayoutFinish.remove(self.LayoutFinished)
21                 x = config.av.pip.value[0]
22                 y = config.av.pip.value[1]
23                 w = config.av.pip.value[2]
24                 h = config.av.pip.value[3]
25                 if x != -1 and y != -1 and w != -1 and h != -1:
26                         self.move(x, y)
27                         self.resize(w, h)
28
29         def move(self, x, y):
30                 config.av.pip.value[0] = x
31                 config.av.pip.value[1] = y
32                 config.av.pip.save()
33                 self.instance.move(ePoint(x, y))
34
35         def resize(self, w, h):
36                 config.av.pip.value[2] = w
37                 config.av.pip.value[3] = h
38                 config.av.pip.save()
39                 self.instance.resize(eSize(*(w, h)))
40                 self["video"].instance.resize(eSize(*(w, h)))
41
42         def getPosition(self):
43                 return ((self.instance.position().x(), self.instance.position().y()))
44
45         def getSize(self):
46                 return (self.instance.size().width(), self.instance.size().height())
47
48         def playService(self, service):
49                 if service and (service.flags & eServiceReference.isGroup):
50                         ref = getBestPlayableServiceReference(service, eServiceReference())
51                 else:
52                         ref = service
53                 if ref:
54                         self.pipservice = eServiceCenter.getInstance().play(ref)
55                         if self.pipservice and not self.pipservice.setTarget(1):
56                                 self.pipservice.start()
57                                 self.currentService = service
58                                 return True
59                         else:
60                                 self.pipservice = None
61                 return False
62
63         def getCurrentService(self):
64                 return self.currentService
65