From fe0534f76b59b814caca3648933c45d3add31889 Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Wed, 23 Apr 2008 11:32:18 +0000 Subject: [PATCH] prepare for skin updating and scaling --- lib/python/Components/GUIComponent.py | 17 ++++++---- lib/python/Components/GUISkin.py | 44 ++++++++++++++++++++----- lib/python/Components/Renderer/Picon.py | 4 +-- lib/python/Components/Renderer/Pig.py | 6 ++-- lib/python/Components/ScrollLabel.py | 8 ++--- lib/python/Components/ServiceList.py | 4 +-- mytest.py | 26 ++------------- skin.py | 32 +++++++++--------- 8 files changed, 76 insertions(+), 65 deletions(-) diff --git a/lib/python/Components/GUIComponent.py b/lib/python/Components/GUIComponent.py index a3b1b9e1..b67937e4 100644 --- a/lib/python/Components/GUIComponent.py +++ b/lib/python/Components/GUIComponent.py @@ -1,6 +1,6 @@ import skin -from enigma import ePoint +from enigma import ePoint, eSize class GUIComponent(object): """ GUI component """ @@ -29,14 +29,14 @@ class GUIComponent(object): self.__dict__.clear() # this works only with normal widgets - if you don't have self.instance, override this. - def applySkin(self, desktop): + def applySkin(self, desktop, parent): if not self.visible: self.instance.hide() if self.skinAttributes is None: return False - skin.applyAllAttributes(self.instance, desktop, self.skinAttributes) + skin.applyAllAttributes(self.instance, desktop, self.skinAttributes, parent.scale) return True def move(self, x, y = None): @@ -45,10 +45,13 @@ class GUIComponent(object): self.instance.move(x) else: self.instance.move(ePoint(int(x), int(y))) - - def resize(self, size): - self.instance.resize(size) - + + def resize(self, x, y = None): + if y is None: + self.instance.resize(x) + else: + self.instance.resize(eSize(int(x), int(y))) + def setZPosition(self, z): self.instance.setZPosition(z) diff --git a/lib/python/Components/GUISkin.py b/lib/python/Components/GUISkin.py index ce4d397d..9eb4a80b 100644 --- a/lib/python/Components/GUISkin.py +++ b/lib/python/Components/GUISkin.py @@ -8,20 +8,24 @@ class GUISkin: def __init__(self): self.onLayoutFinish = [ ] self.summaries = CList() + self.instance = None + self.desktop = None - def createGUIScreen(self, parent, desktop): + def createGUIScreen(self, parent, desktop, updateonly = False): for val in self.renderer: if isinstance(val, GUIComponent): - val.GUIcreate(parent) - if not val.applySkin(desktop): + if not updateonly: + val.GUIcreate(parent) + if not val.applySkin(desktop, self): print "warning, skin is missing renderer", val, "in", self for key in self: val = self[key] if isinstance(val, GUIComponent): - val.GUIcreate(parent) + if not updateonly: + val.GUIcreate(parent) depr = val.deprecationInfo - if val.applySkin(desktop): + if val.applySkin(desktop, self): if depr: print "WARNING: OBSOLETE COMPONENT '%s' USED IN SKIN. USE '%s' INSTEAD!" % (key, depr[0]) print "OBSOLETE COMPONENT WILL BE REMOVED %s, PLEASE UPDATE!" % (depr[1]) @@ -29,9 +33,10 @@ class GUISkin: print "warning, skin is missing element", key, "in", self for w in self.additionalWidgets: - w.instance = w.widget(parent) - # w.instance.thisown = 0 - applyAllAttributes(w.instance, desktop, w.skinAttributes) + if not updateonly: + w.instance = w.widget(parent) + # w.instance.thisown = 0 + applyAllAttributes(w.instance, desktop, w.skinAttributes, self.scale) for f in self.onLayoutFinish: if type(f) is not type(self.close): # is this the best way to do this? @@ -60,3 +65,26 @@ class GUISkin: self.instance.setTitle(title) self.title = title self.summaries.setTitle(title) + + def setDesktop(self, desktop): + self.desktop = desktop + + def applySkin(self): + z = 0 + title = "" + baseres = (720, 576) # FIXME: a skin might have set another resolution, which should be the base res + for (key, value) in self.skinAttributes: + if key == "zPosition": + z = int(value) + elif key == "title": + title = value + elif key == "baseResolution": + baseres = tuple([int(x) for x in value.split(',')]) + self.scale = ((baseres[0], baseres[0]), (baseres[1], baseres[1])) + + if not self.instance: + from enigma import eWindow + self.instance = eWindow(self.desktop, z) + self.title = title + applyAllAttributes(self.instance, self.desktop, self.skinAttributes, self.scale) + self.createGUIScreen(self.instance, self.desktop) diff --git a/lib/python/Components/Renderer/Picon.py b/lib/python/Components/Renderer/Picon.py index ca934c8e..de19c9aa 100644 --- a/lib/python/Components/Renderer/Picon.py +++ b/lib/python/Components/Renderer/Picon.py @@ -16,7 +16,7 @@ class Picon(Renderer): self.nameCache = { } self.pngname = "" - def applySkin(self, desktop): + def applySkin(self, desktop, parent): attribs = [ ] for (attrib, value) in self.skinAttributes: if attrib == "path": @@ -24,7 +24,7 @@ class Picon(Renderer): else: attribs.append((attrib,value)) self.skinAttributes = attribs - return Renderer.applySkin(self, desktop) + return Renderer.applySkin(self, desktop, parent) GUI_WIDGET = ePixmap diff --git a/lib/python/Components/Renderer/Pig.py b/lib/python/Components/Renderer/Pig.py index 99488e4a..23e1393d 100644 --- a/lib/python/Components/Renderer/Pig.py +++ b/lib/python/Components/Renderer/Pig.py @@ -14,10 +14,10 @@ class Pig(Renderer): def postWidgetCreate(self, instance): instance.setDecoder(0) - def applySkin(self, desktop): - ret = Renderer.applySkin(self, desktop) + def applySkin(self, desktop, parent): + ret = Renderer.applySkin(self, desktop, parent) if ret: - self.Position = self.instance.position() + self.Position = self.instance.position() # fixme, scaling! self.Size = self.instance.size() return ret diff --git a/lib/python/Components/ScrollLabel.py b/lib/python/Components/ScrollLabel.py index 253353bb..46d22abc 100644 --- a/lib/python/Components/ScrollLabel.py +++ b/lib/python/Components/ScrollLabel.py @@ -13,10 +13,10 @@ class ScrollLabel(HTMLComponent, GUIComponent): self.pages = None self.total = None - def applySkin(self, desktop): + def applySkin(self, desktop, parent): ret = False if self.skinAttributes is not None: - skin.applyAllAttributes(self.long_text, desktop, self.skinAttributes) + skin.applyAllAttributes(self.long_text, desktop, self.skinAttributes, parent.scale) widget_attribs = [ ] scrollbar_attribs = [ ] for (attrib, value) in self.skinAttributes: @@ -24,8 +24,8 @@ class ScrollLabel(HTMLComponent, GUIComponent): scrollbar_attribs.append((attrib,value)) if attrib.find("transparent") != -1 or attrib.find("backgroundColor") != -1: widget_attribs.append((attrib,value)) - skin.applyAllAttributes(self.instance, desktop, widget_attribs) - skin.applyAllAttributes(self.scrollbar, desktop, scrollbar_attribs+widget_attribs) + skin.applyAllAttributes(self.instance, desktop, widget_attribs, parent.scale) + skin.applyAllAttributes(self.scrollbar, desktop, scrollbar_attribs+widget_attribs, parent.scale) ret = True s = self.long_text.size() self.instance.move(self.long_text.position()) diff --git a/lib/python/Components/ServiceList.py b/lib/python/Components/ServiceList.py index ced4b0c3..059b8906 100644 --- a/lib/python/Components/ServiceList.py +++ b/lib/python/Components/ServiceList.py @@ -45,7 +45,7 @@ class ServiceList(HTMLComponent, GUIComponent): self.mode = self.MODE_NORMAL self.onSelectionChanged = [ ] - def applySkin(self, desktop): + def applySkin(self, desktop, parent): attribs = [ ] if self.skinAttributes is not None: attribs = [ ] @@ -63,7 +63,7 @@ class ServiceList(HTMLComponent, GUIComponent): else: attribs.append((attrib, value)) self.skinAttributes = attribs - return GUIComponent.applySkin(self, desktop) + return GUIComponent.applySkin(self, desktop, parent) def connectSelChanged(self, fnc): if not fnc in self.onSelectionChanged: diff --git a/mytest.py b/mytest.py index 2597f8d6..baa481c2 100644 --- a/mytest.py +++ b/mytest.py @@ -8,7 +8,7 @@ from Tools.Profile import profile, profile_final profile("PYTHON_START") from enigma import runMainloop, eDVBDB, eTimer, quitMainloop, eDVBVolumecontrol, \ - getDesktop, ePythonConfigQuery, eAVSwitch, eWindow, eServiceEvent + getDesktop, ePythonConfigQuery, eAVSwitch, eServiceEvent from tools import * profile("LANGUAGE") @@ -99,14 +99,6 @@ def dump(dir, p = ""): # display -class OutputDevice: - def create(self, screen): pass - -class GUIOutputDevice(OutputDevice): - parent = None - def create(self, comp, desktop): - comp.createGUIScreen(self.parent, desktop) - profile("LOAD:ScreenGlobals") from Screens.Globals import Globals from Screens.SessionGlobals import SessionGlobals @@ -249,20 +241,8 @@ class Session: # create GUI view of this dialog assert desktop is not None - z = 0 - title = "" - for (key, value) in dlg.skinAttributes: - if key == "zPosition": - z = int(value) - elif key == "title": - title = value - - dlg.instance = eWindow(desktop, z) - dlg.title = title - applyAllAttributes(dlg.instance, desktop, dlg.skinAttributes) - gui = GUIOutputDevice() - gui.parent = dlg.instance - gui.create(dlg, desktop) + dlg.setDesktop(desktop) + dlg.applySkin() return dlg diff --git a/skin.py b/skin.py index 4f2260d6..8789e877 100644 --- a/skin.py +++ b/skin.py @@ -68,17 +68,17 @@ profile("LoadSkinDefault") loadSkin('skin_default.xml') profile("LoadSkinDefaultDone") -def parsePosition(str): +def parsePosition(str, scale): x, y = str.split(',') - return ePoint(int(x), int(y)) + return ePoint(int(x) * scale[0][0] / scale[0][1], int(y) * scale[1][0] / scale[1][1]) -def parseSize(str): +def parseSize(str, scale): x, y = str.split(',') - return eSize(int(x), int(y)) + return eSize(int(x) * scale[0][0] / scale[0][1], int(y) * scale[1][0] / scale[1][1]) -def parseFont(str): +def parseFont(str, scale): name, size = str.split(';') - return gFont(name, int(size)) + return gFont(name, int(size) * scale[0][0] / scale[0][1]) def parseColor(str): if str[0] != '#': @@ -113,19 +113,19 @@ def loadPixmap(path, desktop): raise SkinError("pixmap file %s not found!" % (path)) return ptr -def applySingleAttribute(guiObject, desktop, attrib, value): +def applySingleAttribute(guiObject, desktop, attrib, value, scale = ((1,1),(1,1))): # and set attributes try: if attrib == 'position': - guiObject.move(parsePosition(value)) + guiObject.move(parsePosition(value, scale)) elif attrib == 'size': - guiObject.resize(parseSize(value)) + guiObject.resize(parseSize(value, scale)) elif attrib == 'title': guiObject.setTitle(_(value)) elif attrib == 'text': guiObject.setText(_(value)) elif attrib == 'font': - guiObject.setFont(parseFont(value)) + guiObject.setFont(parseFont(value, scale)) elif attrib == 'zPosition': guiObject.setZPosition(int(value)) elif attrib in ["pixmap", "backgroundPixmap", "selectionPixmap"]: @@ -206,11 +206,11 @@ def applySingleAttribute(guiObject, desktop, attrib, value): guiObject.setWrapAround(True) elif attrib == "pointer" or attrib == "seek_pointer": (name, pos) = value.split(':') - pos = parsePosition(pos) + pos = parsePosition(pos, scale) ptr = loadPixmap(name, desktop) guiObject.setPointer({"pointer": 0, "seek_pointer": 1}[attrib], ptr, pos) elif attrib == 'shadowOffset': - guiObject.setShadowOffset(parsePosition(value)) + guiObject.setShadowOffset(parsePosition(value, scale)) elif attrib == 'noWrap': guiObject.setNoWrap(1) else: @@ -219,9 +219,9 @@ def applySingleAttribute(guiObject, desktop, attrib, value): # AttributeError: print "widget %s (%s) doesn't support attribute %s!" % ("", guiObject.__class__.__name__, attrib) -def applyAllAttributes(guiObject, desktop, attributes): +def applyAllAttributes(guiObject, desktop, attributes, scale): for (attrib, value) in attributes: - applySingleAttribute(guiObject, desktop, attrib, value) + applySingleAttribute(guiObject, desktop, attrib, value, scale) def loadSingleSkinData(desktop, skin, path_prefix): """loads skin data like colors, windowstyle etc.""" @@ -305,8 +305,8 @@ def loadSingleSkinData(desktop, skin, path_prefix): for title in windowstyle.findall("title"): get_attr = title.attrib.get - offset = parseSize(get_attr("offset")) - font = parseFont(get_attr("font")) + offset = parseSize(get_attr("offset"), ((1,1),(1,1))) + font = parseFont(get_attr("font"), ((1,1),(1,1))) style.setTitleFont(font); style.setTitleOffset(offset) -- 2.30.2