X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/340ad36b95c98a5de43d065c435bdcbdf6100fb8..39f705dd80ae8b9e30ff2a76e1089b3cf0d3b4c1:/lib/python/Screens/PiPSetup.py diff --git a/lib/python/Screens/PiPSetup.py b/lib/python/Screens/PiPSetup.py index 76212089..d7d0e167 100644 --- a/lib/python/Screens/PiPSetup.py +++ b/lib/python/Screens/PiPSetup.py @@ -1,13 +1,21 @@ -from enigma import * from Screens.Screen import Screen -from Screens.MessageBox import MessageBox from Components.ActionMap import NumberActionMap from Components.Label import Label -from Components.MenuList import MenuList -from Components.GUIComponent import * -from Components.ChoiceList import ChoiceEntryComponent, ChoiceList -import os +# this is not so great. +MAX_X = 720 +MAX_Y = 576 +MAX_W = MAX_X * 3 / 4 +MAX_H = MAX_Y * 3 / 4 +MIN_W = MAX_X / 8 +MIN_H = MAX_Y / 8 + +def clip(val, min, max): + if min <= val <= max: + return val + if min <= val: + return max + return min class PiPSetup(Screen): def __init__(self, session, pip): @@ -16,15 +24,16 @@ class PiPSetup(Screen): self.pip = pip self.pos = (self.pip.instance.position().x(), self.pip.instance.position().y()) - self.orgpos = self.pos - self.size = self.pip.getSize() + + self.orgpos = self.pos + self.orgsize = self.size self.resize = 100 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.")) - self["actions"] = NumberActionMap(["PiPSetupActions"], + self["actions"] = NumberActionMap(["PiPSetupActions", "NumberActions"], { "ok": self.go, "cancel": self.cancel, @@ -34,44 +43,86 @@ class PiPSetup(Screen): "right": self.right, "size+": self.bigger, "size-": self.smaller, + "1": self.keyNumberGlobal, + "2": self.keyNumberGlobal, + "3": self.keyNumberGlobal, + "4": self.keyNumberGlobal, + "5": self.keyNumberGlobal, + "6": self.keyNumberGlobal, + "7": self.keyNumberGlobal, + "8": self.keyNumberGlobal, + "9": self.keyNumberGlobal, + "0": self.keyNumberGlobal }, -1) def go(self): self.close() def cancel(self): - self.movePiP(self.orgpos[0], self.orgpos[1]) - self.resizePiP(100) + self.pos = self.orgpos + self.size = self.orgsize + self.setPiPPosition() self.close() + + def setPiPPosition(self): + self.pip.move(self.pos[0], self.pos[1]) + self.pip.resize(self.size[0], self.size[1]) + + def resizePiP(self, resize): + resize += 100 # resize is in percent, so resize=+20 means: 120% - def movePiP(self, x, y): - if x < 0: - x = 0 - if y < 0: - y = 0 - self.pip.move(x, y) - self.pos = (x, y) + oldsize = self.size + w = clip(self.size[0] * resize / 100, MIN_W, MAX_W) + h = clip(self.size[1] * resize / 100, MIN_H, MAX_H) - def resizePiP(self, resize): - w = int(self.size[0] * self.resize / 100) - h = int(self.size[1] * self.resize / 100) - self.pip.resize(w, h) - self.resize = resize + # calculate offset from center + mx = (oldsize[0] - w) / 2 + my = (oldsize[1] - h) / 2 + + self.size = (w, h) + # reclip, account for new center + self.moveRelative(x=mx, y=my) + + def moveRelative(self, x=0, y=0): + self.pos = (clip(self.pos[0] + x, 0, MAX_X - self.size[0]), clip(self.pos[1] + y, 0, MAX_Y - self.size[1])) + self.setPiPPosition() def up(self): - self.movePiP(self.pos[0], self.pos[1] - 10) + self.moveRelative(y=-32) def down(self): - self.movePiP(self.pos[0], self.pos[1] + 10) + self.moveRelative(y=+32) def left(self): - self.movePiP(self.pos[0] - 10, self.pos[1]) + self.moveRelative(x=-24) def right(self): - self.movePiP(self.pos[0] + 10, self.pos[1]) - + self.moveRelative(x=+24) + def bigger(self): - self.resizePiP(self.resize + 5) + self.resizePiP(+10) def smaller(self): - self.resizePiP(self.resize - 5) \ No newline at end of file + self.resizePiP(-10) + + def keyNumberGlobal(self, number): + + if number > 0: + colsize = MAX_X / 3 + rowsize = MAX_Y / 3 + col = (number-1) % 3 + row = (number-1) / 3 + + self.size = (180, 135) + + # offset to keep center + ox = (colsize - self.size[0]) / 2 + oy = (rowsize - self.size[1]) / 2 + + self.pos = (col * colsize + ox, row * rowsize + oy) + else: + # restore old position + self.pos = self.orgpos + self.size = self.orgsize + # reclip + self.moveRelative()