1 from Screens.Screen import Screen
2 from Components.ActionMap import NumberActionMap
3 from Components.Label import Label
5 # this is not so great.
13 def clip(val, min, max):
20 class PiPSetup(Screen):
21 def __init__(self, session, pip):
22 Screen.__init__(self, session)
26 self.pos = (self.pip.instance.position().x(), self.pip.instance.position().y())
27 self.size = self.pip.getSize()
29 self.orgpos = self.pos
30 self.orgsize = self.size
34 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."))
36 self["actions"] = NumberActionMap(["PiPSetupActions", "NumberActions"],
39 "cancel": self.cancel,
45 "size-": self.smaller,
46 "1": self.keyNumberGlobal,
47 "2": self.keyNumberGlobal,
48 "3": self.keyNumberGlobal,
49 "4": self.keyNumberGlobal,
50 "5": self.keyNumberGlobal,
51 "6": self.keyNumberGlobal,
52 "7": self.keyNumberGlobal,
53 "8": self.keyNumberGlobal,
54 "9": self.keyNumberGlobal,
55 "0": self.keyNumberGlobal
62 self.pos = self.orgpos
63 self.size = self.orgsize
67 def setPiPPosition(self):
68 self.pip.move(self.pos[0], self.pos[1])
69 self.pip.resize(self.size[0], self.size[1])
71 def resizePiP(self, resize):
72 resize += 100 # resize is in percent, so resize=+20 means: 120%
75 w = clip(self.size[0] * resize / 100, MIN_W, MAX_W)
76 h = clip(self.size[1] * resize / 100, MIN_H, MAX_H)
78 # calculate offset from center
79 mx = (oldsize[0] - w) / 2
80 my = (oldsize[1] - h) / 2
83 # reclip, account for new center
84 self.moveRelative(x=mx, y=my)
86 def moveRelative(self, x=0, y=0):
87 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.moveRelative(y=-32)
94 self.moveRelative(y=+32)
97 self.moveRelative(x=-24)
100 self.moveRelative(x=+24)
108 def keyNumberGlobal(self, number):
116 self.size = (180, 135)
118 # offset to keep center
119 ox = (colsize - self.size[0]) / 2
120 oy = (rowsize - self.size[1]) / 2
122 self.pos = (col * colsize + ox, row * rowsize + oy)
124 # restore old position
125 self.pos = self.orgpos
126 self.size = self.orgsize