From c68943c97eeb0107f724ec96aae311e319c750a9 Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Mon, 15 Jun 2009 01:38:16 +0200 Subject: [PATCH] allow position="center,center" to center screen client area on screen --- lib/python/Components/GUISkin.py | 3 +++ skin.py | 24 +++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/python/Components/GUISkin.py b/lib/python/Components/GUISkin.py index 9eb4a80..1bd2729 100644 --- a/lib/python/Components/GUISkin.py +++ b/lib/python/Components/GUISkin.py @@ -85,6 +85,9 @@ class GUISkin: if not self.instance: from enigma import eWindow self.instance = eWindow(self.desktop, z) + + # we need to make sure that certain attributes come last + self.skinAttributes.sort(key=lambda a: {"position": 1}.get(a[0], 0)) self.title = title applyAllAttributes(self.instance, self.desktop, self.skinAttributes, self.scale) self.createGUIScreen(self.instance, self.desktop) diff --git a/skin.py b/skin.py index a76f794..5fcaa11 100644 --- a/skin.py +++ b/skin.py @@ -70,9 +70,27 @@ profile("LoadSkinDefault") loadSkin('skin_default.xml') profile("LoadSkinDefaultDone") -def parsePosition(str, scale): +def evalPos(pos, wsize, ssize, scale): + if pos == "center": + pos = (ssize - wsize) / 2 + else: + pos = int(pos) * scale[0] / scale[1] + return int(pos) + +def parsePosition(str, scale, desktop = None, size = None): x, y = str.split(',') - return ePoint(int(x) * scale[0][0] / scale[0][1], int(y) * scale[1][0] / scale[1][1]) + + wsize = 1, 1 + ssize = 1, 1 + if desktop is not None: + ssize = desktop.size().width(), desktop.size().height() + if size is not None: + wsize = size.width(), size.height() + + x = evalPos(x, wsize[0], ssize[0], scale[0]) + y = evalPos(y, wsize[1], ssize[1], scale[1]) + + return ePoint(x, y) def parseSize(str, scale): x, y = str.split(',') @@ -119,7 +137,7 @@ def applySingleAttribute(guiObject, desktop, attrib, value, scale = ((1,1),(1,1) # and set attributes try: if attrib == 'position': - guiObject.move(parsePosition(value, scale)) + guiObject.move(parsePosition(value, scale, desktop, guiObject.csize())) elif attrib == 'size': guiObject.resize(parseSize(value, scale)) elif attrib == 'title': -- 2.7.4