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