prepare for skin updating and scaling
authorFelix Domke <tmbinc@elitedvb.net>
Wed, 23 Apr 2008 11:32:18 +0000 (11:32 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Wed, 23 Apr 2008 11:32:18 +0000 (11:32 +0000)
lib/python/Components/GUIComponent.py
lib/python/Components/GUISkin.py
lib/python/Components/Renderer/Picon.py
lib/python/Components/Renderer/Pig.py
lib/python/Components/ScrollLabel.py
lib/python/Components/ServiceList.py
mytest.py
skin.py

index a3b1b9e198dea2830af46ebb46259344e90b202a..b67937e4cac0f0f9f16ac6474670e1f84bab13a6 100644 (file)
@@ -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)
 
index ce4d397d07df59f8808498f45ee5eed8b6808c2b..9eb4a80b3b80321f480763b4c9357a81192a523e 100644 (file)
@@ -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)
index ca934c8e8acaab098054e1300c3b6491395ce904..de19c9aaf3cc555b1fff8f9555abf94f29447a6c 100644 (file)
@@ -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
 
index 99488e4a242c48b80f443c1d712e285c26014b86..23e1393df0c87cbddace7a4b8bdb189f58018a8f 100644 (file)
@@ -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
 
index 253353bb4d5c120bcf863862e77391aee97fc1ec..46d22abc6451c2ebb3878d777a6c4e305b71178a 100644 (file)
@@ -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())
index ced4b0c3372ff580ac9b34a1b440a9fb80a20dab..059b890611ef03aa9f59474c8a9371dc3048fb8a 100644 (file)
@@ -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:
index 2597f8d6866452614ca553659c3e58bff87bb40c..baa481c28da639b2a71aec56f5a84fc962d97e7c 100644 (file)
--- 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 4f2260d64c5578b4d349777c44ecff56b9060cb9..8789e877cac291941b2a140f8d60effe0dc05d23 100644 (file)
--- 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)