fix non working ignore of markers when multiple bouquets is disabled
[enigma2.git] / lib / python / Screens / PiPSetup.py
1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Components.ActionMap import NumberActionMap
4 from Components.Label import Label
5 from Components.MenuList import MenuList
6 from Components.ChoiceList import ChoiceEntryComponent, ChoiceList
7
8 # this is not so great.
9 MAX_X = 720
10 MAX_Y = 576
11 MAX_W = MAX_X * 3 / 4
12 MAX_H = MAX_Y * 3 / 4
13 MIN_W = MAX_X / 8
14 MIN_H = MAX_Y / 8
15
16 def clip(val, min, max):
17         if min <= val <= max:
18                 return val
19         if min <= val:
20                 return max
21         return min
22
23 class PiPSetup(Screen):
24         def __init__(self, session, pip):
25                 Screen.__init__(self, session)
26                 
27                 self.pip = pip
28                 
29                 self.pos = (self.pip.instance.position().x(), self.pip.instance.position().y())
30                 self.size = self.pip.getSize()
31
32                 self.orgpos = self.pos
33                 self.orgsize = self.size
34                 
35                 self.resize = 100
36
37                 self["text"] = Label(_("Please use direction keys to move the PiP window.\nPress Bouquet +/- to resize the window.\nPress OK to go back to the TV mode or EXIT to cancel the moving."))
38
39                 self["actions"] = NumberActionMap(["PiPSetupActions", "NumberActions"], 
40                 {
41                         "ok": self.go,
42                         "cancel": self.cancel,
43                         "up": self.up,
44                         "down": self.down,
45                         "left": self.left,
46                         "right": self.right,
47                         "size+": self.bigger,
48                         "size-": self.smaller,
49                         "1": self.keyNumberGlobal,
50                         "2": self.keyNumberGlobal,
51                         "3": self.keyNumberGlobal,
52                         "4": self.keyNumberGlobal,
53                         "5": self.keyNumberGlobal,
54                         "6": self.keyNumberGlobal,
55                         "7": self.keyNumberGlobal,
56                         "8": self.keyNumberGlobal,
57                         "9": self.keyNumberGlobal,
58                         "0": self.keyNumberGlobal
59                 }, -1)
60                 
61         def go(self):
62                 self.close()
63         
64         def cancel(self):
65                 self.pos = self.orgpos
66                 self.size = self.orgsize
67                 self.setPiPPosition()
68                 self.close()
69         
70         def setPiPPosition(self):
71                 self.pip.move(self.pos[0], self.pos[1])
72                 self.pip.resize(self.size[0], self.size[1])
73
74         def resizePiP(self, resize):
75                 resize += 100 # resize is in percent, so resize=+20 means: 120%
76                 
77                 oldsize = self.size
78                 w = clip(self.size[0] * resize / 100, MIN_W, MAX_W)
79                 h = clip(self.size[1] * resize / 100, MIN_H, MAX_H)
80                 
81                 # calculate offset from center
82                 mx = (oldsize[0] - w) / 2
83                 my = (oldsize[1] - h) / 2
84                 
85                 self.size = (w, h)
86                 # reclip, account for new center
87                 self.moveRelative(x=mx, y=my)
88         
89         def moveRelative(self, x=0, y=0):
90                 self.pos = (clip(self.pos[0] + x, 0, MAX_X - self.size[0]), clip(self.pos[1] + y, 0, MAX_Y - self.size[1]))
91                 self.setPiPPosition()
92         
93         def up(self):
94                 self.moveRelative(y=-32)
95
96         def down(self):
97                 self.moveRelative(y=+32)
98         
99         def left(self):
100                 self.moveRelative(x=-24)
101         
102         def right(self):
103                 self.moveRelative(x=+24)
104         
105         def bigger(self):
106                 self.resizePiP(+10)
107         
108         def smaller(self):
109                 self.resizePiP(-10)
110         
111         def keyNumberGlobal(self, number):
112                 
113                 if number > 0:
114                         colsize = MAX_X / 3
115                         rowsize = MAX_Y / 3
116                         col = (number-1) % 3
117                         row = (number-1) / 3
118
119                         self.size = (180, 135)
120
121                         # offset to keep center
122                         ox = (colsize - self.size[0]) / 2
123                         oy = (rowsize - self.size[1]) / 2
124
125                         self.pos = (col * colsize + ox, row * rowsize + oy)
126                 else:
127                         # restore old position
128                         self.pos = self.orgpos
129                         self.size = self.orgsize
130                 # reclip
131                 self.moveRelative()