- skins are now loaded first and applied later
authorFelix Domke <tmbinc@elitedvb.net>
Fri, 8 Jul 2005 16:41:35 +0000 (16:41 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Fri, 8 Jul 2005 16:41:35 +0000 (16:41 +0000)
 - this allows use skin information to build special eWidgets, depending on skin
 - add "applet"-feature: code which is executed from skin
 - example: centering of messagebox

24 files changed:
lib/python/Components/Button.py
lib/python/Components/Clock.py
lib/python/Components/ConfigList.py
lib/python/Components/GUIComponent.py
lib/python/Components/GUISkin.py
lib/python/Components/Header.py
lib/python/Components/Label.py
lib/python/Components/MenuList.py
lib/python/Components/PerServiceDisplay.py
lib/python/Components/ProgressBar.py
lib/python/Components/ServiceList.py
lib/python/Components/TextInput.py
lib/python/Components/TimeInput.py
lib/python/Components/TimerList.py
lib/python/Components/VariableText.py
lib/python/Components/VariableValue.py
lib/python/Components/VolumeBar.py
lib/python/Screens/InfoBar.py
lib/python/Screens/Menu.py
lib/python/Screens/MessageBox.py [new file with mode: 0644]
lib/python/Screens/__init__.py
lib/python/Tools/XMLTools.py
mytest.py
skin.py

index d773b2c10d16c2b81213f9a12969e28e0e0b7e1c..d9226b6dbeaf516a9d1e2ad928cc7c1805fe7149 100644 (file)
@@ -29,7 +29,7 @@ class Button(HTMLComponent, GUIComponent, VariableText):
                return "<input type=\"submit\" text=\"" + self.getText() + "\">\n"
 
 # GUI:
                return "<input type=\"submit\" text=\"" + self.getText() + "\">\n"
 
 # GUI:
-       def createWidget(self, parent, skindata):
+       def createWidget(self, parent):
                g = eButton(parent)
                g.selected.get().append(self.push)
                return g
                g = eButton(parent)
                g.selected.get().append(self.push)
                return g
index 36e06942251a9bcfb017cd43223eed37c32504e5..3beed551dc0c92e9bb34b848fd7a88daa8697088 100644 (file)
@@ -24,7 +24,7 @@ class Clock(HTMLComponent, GUIComponent, VariableText):
                self.setText("%2d:%02d:%02d" % (t[3], t[4], t[5]))
 
 # realisierung als GUI
                self.setText("%2d:%02d:%02d" % (t[3], t[4], t[5]))
 
 # realisierung als GUI
-       def createWidget(self, parent, skindata):
+       def createWidget(self, parent):
                return eLabel(parent)
 
        def removeWidget(self, w):
                return eLabel(parent)
 
        def removeWidget(self, w):
index a2bdcb0b3ce532003260ea88b8ed397e0af35fdb..35ea093c0b5235c8aa7a1ec89fba7a0cd20cbef9 100644 (file)
@@ -22,7 +22,7 @@ class ConfigList(HTMLComponent, GUIComponent):
        def invalidateCurrent(self):
                self.l.invalidateEntry(self.l.getCurrentSelectionIndex())
        
        def invalidateCurrent(self):
                self.l.invalidateEntry(self.l.getCurrentSelectionIndex())
        
-       def GUIcreate(self, parent, skindata):
+       def GUIcreate(self, parent):
                self.instance = eListbox(parent)
                self.instance.setContent(self.l)
        
                self.instance = eListbox(parent)
                self.instance.setContent(self.l)
        
index bcd99d245e86fc32fb9a08e5b09b5d7c993d14ad..fee9341c558876846c95106957239c1454abc93d 100644 (file)
@@ -1,12 +1,17 @@
+import skin
+
 class GUIComponent:
        """ GUI component """
 class GUIComponent:
        """ GUI component """
-
+       
        def __init__(self):
                pass
        def __init__(self):
                pass
-               
+       
        def execBegin(self):
                pass
        
        def execEnd(self):
                pass
        def execBegin(self):
                pass
        
        def execEnd(self):
                pass
-
+       
+       # this works only with normal widgets - if you don't have self.instance, override this.
+       def applySkin(self, desktop):
+               skin.applyAllAttributes(self.instance, desktop, self.skinAttributes)
index b918e90881e26d9f74a19d83ac8e98021095dd36..982cce317dbd74325727ceb8ad80b2e8db6df78d 100644 (file)
@@ -1,65 +1,31 @@
 from GUIComponent import *
 from GUIComponent import *
+from skin import applyAllAttributes
 
 class GUISkin:
 
 class GUISkin:
+       __module__ = __name__
+
        def __init__(self):
        def __init__(self):
+               self.onLayoutFinish = [ ]
                pass
                pass
-       
-       def createGUIScreen(self, parent):
+
+       def createGUIScreen(self, parent, desktop):
                for (name, val) in self.items():
                        if isinstance(val, GUIComponent):
                for (name, val) in self.items():
                        if isinstance(val, GUIComponent):
-                               val.GUIcreate(parent, None)
-       
+                               val.GUIcreate(parent)
+                               val.applySkin(desktop)
+
+               for w in self.additionalWidgets:
+                       w.instance = w.widget(parent)
+                       w.instance.thisown = 0
+                       applyAllAttributes(w.instance, desktop, w.skinAttributes)
+               
+               for f in self.onLayoutFinish:
+                       exec(f) in globals(), locals()
+
        def deleteGUIScreen(self):
                for (name, val) in self.items():
                        if isinstance(val, GUIComponent):
                                val.GUIdelete()
        def deleteGUIScreen(self):
                for (name, val) in self.items():
                        if isinstance(val, GUIComponent):
                                val.GUIdelete()
-                       try:
-                               val.fix()
-                       except:
-                               pass
-                       
-                       # DIESER KOMMENTAR IST NUTZLOS UND MITTLERWEILE VERALTET! (glaub ich)
-                       # BITTE NICHT LESEN!
-                       # note: you'll probably run into this assert. if this happens, don't panic!
-                       # yes, it's evil. I told you that programming in python is just fun, and 
-                       # suddently, you have to care about things you don't even know.
-                       #
-                       # but calm down, the solution is easy, at least on paper:
-                       #
-                       # Each Component, which is a GUIComponent, owns references to each
-                       # instantiated eWidget (namely in screen.data[name]["instance"], in case
-                       # you care.)
-                       # on deleteGUIscreen, all eWidget *must* (!) be deleted (otherwise,
-                       # well, problems appear. I don't want to go into details too much,
-                       # but this would be a memory leak anyway.)
-                       # The assert beyond checks for that. It asserts that the corresponding
-                       # eWidget is about to be removed (i.e., that the refcount becomes 0 after
-                       # running deleteGUIscreen).
-                       # (You might wonder why the refcount is checked for 2 and not for 1 or 0 -
-                       # one reference is still hold by the local variable 'w', another one is
-                       # hold be the function argument to sys.getrefcount itself. So only if it's
-                       # 2 at this point, the object will be destroyed after leaving deleteGUIscreen.)
-                       #
-                       # Now, how to fix this problem? You're holding a reference somewhere. (References
-                       # can only be hold from Python, as eWidget itself isn't related to the c++
-                       # way of having refcounted objects. So it must be in python.)
-                       #
-                       # It could be possible that you're calling deleteGUIscreen trough a call of
-                       # a PSignal. For example, you could try to call screen.doClose() in response
-                       # to a Button::click. This will fail. (It wouldn't work anyway, as you would
-                       # remove a dialog while running it. It never worked - enigma1 just set a 
-                       # per-mainloop variable on eWidget::close() to leave the exec()...)
-                       # That's why Session supports delayed closes. Just call Session.close() and
-                       # it will work.
-                       #
-                       # Another reason is that you just stored the data["instance"] somewhere. or
-                       # added it into a notifier list and didn't removed it.
-                       #
-                       # If you can't help yourself, just ask me. I'll be glad to help you out.
-                       # Sorry for not keeping this code foolproof. I really wanted to archive
-                       # that, but here I failed miserably. All I could do was to add this assert.
-#                      assert sys.getrefcount(w) == 2, "too many refs hold to " + str(w)
-       
+
        def close(self):
                self.deleteGUIScreen()
        def close(self):
                self.deleteGUIScreen()
-
index 3ff6ab32c910ca0489f00d7d2e5a652677df0202..9f7be60edb26042109d0d0bf2781f7f8e32adb69 100644 (file)
@@ -14,7 +14,7 @@ class Header(HTMLComponent, GUIComponent, VariableText):
        def produceHTML(self):
                return "<h2>" + self.getText() + "</h2>\n"
 
        def produceHTML(self):
                return "<h2>" + self.getText() + "</h2>\n"
 
-       def createWidget(self, parent, skindata):
+       def createWidget(self, parent):
                g = eLabel(parent)
                return g
 
                g = eLabel(parent)
                return g
 
index 609c6deb5822232eb6fa3a7bcead6ac2aa8ee25c..7402d722f0b925a6688131271f01d99887bd8d91 100644 (file)
@@ -15,6 +15,10 @@ class Label(HTMLComponent, GUIComponent, VariableText):
                return self.getText()
 
 # GUI:
                return self.getText()
 
 # GUI:
-       def createWidget(self, parent, skindata):
+       def createWidget(self, parent):
                return eLabel(parent)
        
                return eLabel(parent)
        
+       def getSize(self):
+               s = self.instance.calculateSize()
+               return (s.width(), s.height())
+
index 90cd3286e837afa78cba119f7959f2bb34bb8637..6fb33540de20cf13491a60368dbc2977d3daafc9 100644 (file)
@@ -12,7 +12,7 @@ class MenuList(HTMLComponent, GUIComponent):
        def getCurrent(self):
                return self.l.getCurrentSelection()
        
        def getCurrent(self):
                return self.l.getCurrentSelection()
        
-       def GUIcreate(self, parent, skindata):
+       def GUIcreate(self, parent):
                self.instance = eListbox(parent)
                self.instance.setContent(self.l)
        
                self.instance = eListbox(parent)
                self.instance.setContent(self.l)
        
index bd94318e119c688c7c1d58eaa466b5752e72808f..eab1e08618cb4ff7bd430187df4e557b97868101 100644 (file)
@@ -23,7 +23,7 @@ class PerServiceDisplay(GUIComponent, VariableText):
                        # call handler
                        self.eventmap[ev]()
        
                        # call handler
                        self.eventmap[ev]()
        
-       def createWidget(self, parent, skindata):
+       def createWidget(self, parent):
                # by default, we use a label to display our data.
                g = eLabel(parent)
                return g
                # by default, we use a label to display our data.
                g = eLabel(parent)
                return g
index 0ae4868ac367f51a72f7516c1f7e632e583d1fa7..68824d5a1cb460319fe7afda9f6cb2218b06092f 100644 (file)
@@ -10,7 +10,7 @@ class ProgressBar(HTMLComponent, GUIComponent, VariableValue):
                GUIComponent.__init__(self)
                VariableValue.__init__(self)
 
                GUIComponent.__init__(self)
                VariableValue.__init__(self)
 
-       def createWidget(self, parent, skindata):
+       def createWidget(self, parent):
                g = eSlider(parent)
                g.setRange(0, 100)
                return g
                g = eSlider(parent)
                g.setRange(0, 100)
                return g
index b1bd217069f6c131a26736876104177248267269..1aa3d487fd62c810ddc62b2a365a381752c2c661 100644 (file)
@@ -19,7 +19,7 @@ class ServiceList(HTMLComponent, GUIComponent):
        def moveDown(self):
                self.instance.moveSelection(self.instance.moveDown)
 
        def moveDown(self):
                self.instance.moveSelection(self.instance.moveDown)
 
-       def GUIcreate(self, parent, skindata):
+       def GUIcreate(self, parent):
                self.instance = eListbox(parent)
                self.instance.setContent(self.l)
        
                self.instance = eListbox(parent)
                self.instance.setContent(self.l)
        
index 98b440c5bd604cf4d2032ed7f2cb17ca228efb78..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,31 +0,0 @@
-from HTMLComponent import *
-from GUIComponent import *
-
-from tools import CONNECT, DISCONNECT
-
-from enigma import eInput, eInputContentString
-
-class TextInput(HTMLComponent, GUIComponent):
-       def __init__(self):
-               GUIComponent.__init__(self)
-               self.content = eInputContentString()
-
-       def contentChanged(self):
-               print "content changed to %s!" % (self.getText())
-       
-       def getText(self):
-               return self.content.getText()
-       
-       def setText(self, text):
-               # TODO :  support unicode!
-               self.content.setText(str(text))
-       
-       def GUIcreate(self, parent, skindata):
-               self.instance = eInput(parent)
-               CONNECT(self.instance.changed, self.contentChanged)
-               self.instance.setContent(self.content)
-       
-       def GUIdelete(self):
-               DISCONNECT(self.instance.changed, self.contentChanged)
-               self.instance.setContent(None)
-               self.instance = None
index c520fdf5ce86b6ea20d9dd4d404afadae0e94bc7..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,18 +0,0 @@
-from HTMLComponent import *
-from GUIComponent import *
-from VariableText import *
-
-from enigma import eInput, eInputContentNumber
-
-class TimeInput(HTMLComponent, GUIComponent):
-       def __init__(self):
-               GUIComponent.__init__(self)
-               self.content = eInputContentNumber(12, 0, 15)
-       
-       def GUIcreate(self, parent, skindata):
-               self.instance = eInput(parent)
-               self.instance.setContent(self.content)
-       
-       def GUIdelete(self):
-               self.instance.setContent(None)
-               self.instance = None
index 9ef7cc4b400e91924173154ed156e4d8026acbe6..18c5cb134a250c5973944130ce7366afc23538df 100644 (file)
@@ -45,7 +45,7 @@ class TimerList(HTMLComponent, GUIComponent):
        def getCurrent(self):
                return self.l.getCurrentSelection()
        
        def getCurrent(self):
                return self.l.getCurrentSelection()
        
-       def GUIcreate(self, parent, skindata):
+       def GUIcreate(self, parent):
                self.instance = eListbox(parent)
                self.instance.setContent(self.l)
                self.instance.setItemHeight(50)
                self.instance = eListbox(parent)
                self.instance.setContent(self.l)
                self.instance.setItemHeight(50)
index 694355e7fa7bd7d5c6099eebfe2941b494105c58..76dc201a4e6b5804c2a22362a2144b24857f37a0 100644 (file)
@@ -1,3 +1,5 @@
+import skin
+
 class VariableText:
        """VariableText can be used for components which have a variable text, based on any widget with setText call"""
        
 class VariableText:
        """VariableText can be used for components which have a variable text, based on any widget with setText call"""
        
@@ -13,8 +15,8 @@ class VariableText:
        def getText(self):
                return self.message
        
        def getText(self):
                return self.message
        
-       def GUIcreate(self, parent, skindata):
-               self.instance = self.createWidget(parent, skindata)
+       def GUIcreate(self, parent):
+               self.instance = self.createWidget(parent)
                self.instance.setText(self.message)
        
        def GUIdelete(self):
                self.instance.setText(self.message)
        
        def GUIdelete(self):
index c94218fe7e0515c35614cfa0747747b24cd71353..8f0cef4c5ecc415f966554075ba3a6405e4208c7 100644 (file)
@@ -1,3 +1,5 @@
+import skin
+
 class VariableValue:
        """VariableValue can be used for components which have a variable value (like eSlider), based on any widget with setValue call"""
        
 class VariableValue:
        """VariableValue can be used for components which have a variable value (like eSlider), based on any widget with setValue call"""
        
@@ -13,8 +15,8 @@ class VariableValue:
        def getValue(self):
                return self.value
                
        def getValue(self):
                return self.value
                
-       def GUIcreate(self, parent, skindata):
-               self.instance = self.createWidget(parent, skindata)
+       def GUIcreate(self, parent):
+               self.instance = self.createWidget(parent)
                self.instance.setValue(self.value)
        
        def GUIdelete(self):
                self.instance.setValue(self.value)
        
        def GUIdelete(self):
index 6eace42c3f7ea9ceeb98a13f8b119ff1806c062f..a6da59803af99b1bcc4a652e8a60d3eaa0a294e3 100644 (file)
@@ -8,7 +8,7 @@ class VolumeBar(HTMLComponent, GUIComponent, VariableValue):
                GUIComponent.__init__(self)
                VariableValue.__init__(self)
 
                GUIComponent.__init__(self)
                VariableValue.__init__(self)
 
-       def createWidget(self, parent, skindata):
+       def createWidget(self, parent):
                g = eSlider(parent)
                g.setRange(0, 100)
                return g
                g = eSlider(parent)
                g.setRange(0, 100)
                return g
index 5112a00d0f2a579357fc4bc34ec072fa2de95b1f..ee09e5771fbb2ea691c84959e3af2670b435e6d4 100644 (file)
@@ -6,6 +6,8 @@ from Components.Button import Button
 from Components.ServiceName import ServiceName
 from Components.EventInfo import EventInfo
 
 from Components.ServiceName import ServiceName
 from Components.EventInfo import EventInfo
 
+from Screens.MessageBox import MessageBox
+
 from enigma import *
 
 import time
 from enigma import *
 
 import time
@@ -31,7 +33,7 @@ class InfoBar(Screen):
                                "hide": self.hide,
                                "toggleShow": self.toggleShow
                        })
                                "hide": self.hide,
                                "toggleShow": self.toggleShow
                        })
-               self["okbutton"] = Button("mainMenu", [self.mainMenu])
+#              self["okbutton"] = Button("mainMenu", [self.mainMenu])
                
                self["CurrentTime"] = Clock()
                
                
                self["CurrentTime"] = Clock()
                
@@ -77,6 +79,9 @@ class InfoBar(Screen):
                self.servicelist.zap()
                
        def instantRecord(self):
                self.servicelist.zap()
                
        def instantRecord(self):
+               self.session.open(MessageBox, "this would be an instant recording! do you really know what you're doing?!")
+               return
+       
                if self.recording != None:
                        print "remove entry"
                        self.session.nav.RecordTimer.removeEntry(self.recording)
                if self.recording != None:
                        print "remove entry"
                        self.session.nav.RecordTimer.removeEntry(self.recording)
index c3809318d2111f3215b578660b13dc0bcc494344..3b54577ee468077cdc4aa5a637f4e48675aae49a 100644 (file)
@@ -19,6 +19,8 @@ import xml.dom.minidom
 from xml.dom import EMPTY_NAMESPACE
 from skin import elementsWithTag
 
 from xml.dom import EMPTY_NAMESPACE
 from skin import elementsWithTag
 
+from Tools import XMLTools
+
 # some screens
 def doGlobal(screen):
        screen["clock"] = Clock()
 # some screens
 def doGlobal(screen):
        screen["clock"] = Clock()
@@ -74,13 +76,6 @@ mdom = xml.dom.minidom.parseString(
                </menu>
        </menu>""")
 
                </menu>
        </menu>""")
 
-def getText(nodelist):
-       rc = ""
-       for node in nodelist:
-               if node.nodeType == node.TEXT_NODE:
-                       rc = rc + node.data
-       return rc
-
 def getValbyAttr(x, attr):
        for p in range(x.attributes.length):
                a = x.attributes.item(p)
 def getValbyAttr(x, attr):
        for p in range(x.attributes.length):
                a = x.attributes.item(p)
@@ -159,6 +154,7 @@ class Menu(Screen):
                self.session.open(clockDisplay, Clock())
 
        def okbuttonClick(self):
                self.session.open(clockDisplay, Clock())
 
        def okbuttonClick(self):
+               print "okbuttonClick"
                selection = self["menu"].getCurrent()
                selection[1]()
 
                selection = self["menu"].getCurrent()
                selection[1]()
 
@@ -178,7 +174,7 @@ class Menu(Screen):
        def addItem(self, destList, node):
                ItemText = getValbyAttr(node, "text")
                if ItemText != "":                                                                                                                                      #check for name
        def addItem(self, destList, node):
                ItemText = getValbyAttr(node, "text")
                if ItemText != "":                                                                                                                                      #check for name
-                       b = getText(node.childNodes)
+                       b = XMLTools.mergeText(node.childNodes)
                        if b != "":                                                                                                                                                             #check for function
                                destList.append((ItemText,boundFunction(self.evalText,b)))
                        else:
                        if b != "":                                                                                                                                                             #check for function
                                destList.append((ItemText,boundFunction(self.evalText,b)))
                        else:
diff --git a/lib/python/Screens/MessageBox.py b/lib/python/Screens/MessageBox.py
new file mode 100644 (file)
index 0000000..bb6318b
--- /dev/null
@@ -0,0 +1,15 @@
+from Screen import Screen
+from Components.ActionMap import ActionMap
+from Components.Label import Label
+
+class MessageBox(Screen):
+       def __init__(self, session, text):
+               Screen.__init__(self, session)
+               
+               self["text"] = Label(text)
+
+               self["actions"] = ActionMap(["OkCancelActions"], 
+                       {
+                               "cancel": self.close
+                       })
+
index fbd2c173647d65246d39a320768a3bab37c3ca1e..c91f5f5766524dc7efc95a1668a51fd81b688c76 100644 (file)
@@ -1,4 +1,4 @@
 __all__ = ["ChannelSelection", "ClockDisplay", "ConfigMenu", 
 __all__ = ["ChannelSelection", "ClockDisplay", "ConfigMenu", 
-       "InfoBar", "Menu", "ScartLoopThrough", "Screen", "ServiceScan",
+       "InfoBar", "MessageBox", "Menu", "ScartLoopThrough", "Screen", "ServiceScan",
        "TimerEdit"]
 
        "TimerEdit"]
 
index aaab4677f4887dcbaea4ac5f48d12ef2a4053718..05513622d839ef39dd755cfe229b326cd05cb8a9 100644 (file)
@@ -15,3 +15,11 @@ def elementsWithTag(el, tag):
                        continue
                if tag(x.tagName):
                        yield x
                        continue
                if tag(x.tagName):
                        yield x
+
+def mergeText(nodelist):
+       rc = ""
+       for node in nodelist:
+               if node.nodeType == node.TEXT_NODE:
+                       rc = rc + node.data
+       return rc
+
index d6cfb1a2d81823618ce2e3b6230a24294aefc094..01db6e65c263e949306c3d56ef919a907b054a74 100644 (file)
--- a/mytest.py
+++ b/mytest.py
@@ -10,7 +10,7 @@ import ServiceReference
 
 from Navigation import Navigation
 
 
 from Navigation import Navigation
 
-from skin import applyGUIskin
+from skin import readSkin, applyAllAttributes
 
 # A screen is a function which instanciates all components of a screen into a temporary component.
 # Thus, the global stuff is a screen, too.
 
 # A screen is a function which instanciates all components of a screen into a temporary component.
 # Thus, the global stuff is a screen, too.
@@ -54,8 +54,8 @@ html = HTMLOutputDevice()
 
 class GUIOutputDevice(OutputDevice):
        parent = None
 
 class GUIOutputDevice(OutputDevice):
        parent = None
-       def create(self, comp):
-               comp.createGUIScreen(self.parent)
+       def create(self, comp, desktop):
+               comp.createGUIScreen(self.parent, desktop)
 
 class Session:
        def __init__(self):
 
 class Session:
        def __init__(self):
@@ -75,7 +75,7 @@ class Session:
                
                        print sys.getrefcount(self.currentDialog)
                        del self.currentDialog.instance
                
                        print sys.getrefcount(self.currentDialog)
                        del self.currentDialog.instance
-                       dump(self.currentDialog)
+#                      dump(self.currentDialog)
                        del self.currentDialog
                
                self.popCurrent()
                        del self.currentDialog
                
                self.popCurrent()
@@ -93,16 +93,20 @@ class Session:
                return screen(self, *arguments)
        
        def instantiateDialog(self, screen, *arguments):
                return screen(self, *arguments)
        
        def instantiateDialog(self, screen, *arguments):
+               # create dialog
                dlg = self.create(screen, arguments)
                dlg = self.create(screen, arguments)
+               
+               # read skin data
+               readSkin(dlg, None, dlg.skinName, self.desktop)
+
+               # create GUI view of this dialog
                assert self.desktop != None
                dlg.instance = eWindow(self.desktop)
                assert self.desktop != None
                dlg.instance = eWindow(self.desktop)
-
+               applyAllAttributes(dlg.instance, self.desktop, dlg.skinAttributes)
                gui = GUIOutputDevice()
                gui.parent = dlg.instance
                gui = GUIOutputDevice()
                gui.parent = dlg.instance
-               gui.create(dlg)
-
-               applyGUIskin(dlg, None, dlg.skinName, self.desktop)
-               
+               gui.create(dlg, self.desktop)
+               
                return dlg
         
        def pushCurrent(self):
                return dlg
         
        def pushCurrent(self):
diff --git a/skin.py b/skin.py
index bc4931fbd34c3a6694c75ecf254973e9c413947f..5706507618e2f2d056f8695a0392af1875dcdf99 100644 (file)
--- a/skin.py
+++ b/skin.py
@@ -2,7 +2,7 @@ from enigma import *
 import xml.dom.minidom
 from xml.dom import EMPTY_NAMESPACE
 
 import xml.dom.minidom
 from xml.dom import EMPTY_NAMESPACE
 
-from Tools.XMLTools import elementsWithTag
+from Tools.XMLTools import elementsWithTag, mergeText
 
 colorNames = dict()
 
 
 colorNames = dict()
 
@@ -46,11 +46,12 @@ dom = xml.dom.minidom.parseString(
                                <pixmap pos="bpBottom"      filename="data/b_w_b.png"  />
                                <pixmap pos="bpBottomRight" filename="data/b_w_br.png" />
                        </borderset>
                                <pixmap pos="bpBottom"      filename="data/b_w_b.png"  />
                                <pixmap pos="bpBottomRight" filename="data/b_w_br.png" />
                        </borderset>
-               </windowstyle>
+               </windowstyle> """ """
                <screen name="Menu" position="300,100" size="300,300" title="real main menu">
 <!--                   <widget name="okbutton" position="10,190" size="280,50" font="Arial;20" valign="center" halign="center" />-->
                        <widget name="title" position="10,10" size="280,20" />
                        <widget name="menu" position="10,30" size="280,200" />
                <screen name="Menu" position="300,100" size="300,300" title="real main menu">
 <!--                   <widget name="okbutton" position="10,190" size="280,50" font="Arial;20" valign="center" halign="center" />-->
                        <widget name="title" position="10,10" size="280,20" />
                        <widget name="menu" position="10,30" size="280,200" />
+                       
                </screen>
                <screen name="ScartLoopThrough" position="0,0" size="720,576">
                </screen>
                </screen>
                <screen name="ScartLoopThrough" position="0,0" size="720,576">
                </screen>
@@ -104,13 +105,38 @@ dom = xml.dom.minidom.parseString(
                        <widget name="scan_state" position="10,60" size="280,30" />
                </screen>
                <screen name="TimerEdit" position="70,100" size="590,335" title="Timer Edit">
                        <widget name="scan_state" position="10,60" size="280,30" />
                </screen>
                <screen name="TimerEdit" position="70,100" size="590,335" title="Timer Edit">
-                       <widget name="description" position="10,10" size="580,40" font="Arial;25"/>
-                       <widget name="lbegin" position="405,102" size="103,30" font="Arial;25" />
-                       <widget name="lend" position="405,158" size="103,30" font="Arial;25" />
+                       <widget name="description" position="10,10" size="580,40" font="Arial;25" />
+                       <widget name="lbegin" position="405,102" size="103,30" font="Arial;25" foregroundColor="red" />
+                       <widget name="lend" position="405,158" size="103,30" font="Arial;25" foregroundColor="green" />
                        <widget name="begin" position="508,105" size="72,35" font="Arial;25" />
                        <widget name="end" position="508,150" size="72,35" font="Arial;25" />
                        <widget name="apply" position="10,240" size="250,35" />
                </screen>
                        <widget name="begin" position="508,105" size="72,35" font="Arial;25" />
                        <widget name="end" position="508,150" size="72,35" font="Arial;25" />
                        <widget name="apply" position="10,240" size="250,35" />
                </screen>
+               <screen name="MessageBox" position="0,300" size="720,10" title="Message">
+                       <widget name="text" position="0,0" size="500,0" font="Arial;25" />
+                       <applet type="onLayoutFinish">
+# this should be factored out into some helper code, but currently demonstrated applets.
+from enigma import eSize, ePoint
+
+orgwidth = self.instance.size().width()
+orgpos = self.instance.position()
+textsize = self["text"].getSize()
+
+# y size still must be fixed in font stuff...
+textsize = (textsize[0], textsize[1] + 20)
+wsize = (textsize[0] + 20, textsize[1] + 20)
+
+# resize 
+self.instance.resize(eSize(*wsize))
+
+# resize label
+self["text"].instance.resize(eSize(*textsize))
+
+# center window
+newwidth = wsize[0]
+self.instance.move(ePoint(orgpos.x() + (orgwidth - newwidth)/2, orgpos.y()))
+                       </applet>
+               </screen>
        </skin>""")
 
 def parsePosition(str):
        </skin>""")
 
 def parsePosition(str):
@@ -133,7 +159,7 @@ def parseColor(str):
                        raise ("color '%s' must be #aarrggbb or valid named color" % (str))
        return gRGB(int(str[1:], 0x10))
 
                        raise ("color '%s' must be #aarrggbb or valid named color" % (str))
        return gRGB(int(str[1:], 0x10))
 
-def applyAttributes(guiObject, node, desktop):
+def collectAttributes(skinAttributes, node):
        # walk all attributes
        for p in range(node.attributes.length):
                a = node.attributes.item(p)
        # walk all attributes
        for p in range(node.attributes.length):
                a = node.attributes.item(p)
@@ -144,60 +170,70 @@ def applyAttributes(guiObject, node, desktop):
                # TODO: localization? as in e1?
                value = str(a.value)
                
                # TODO: localization? as in e1?
                value = str(a.value)
                
-               # and set attributes
-               try:
-                       if attrib == 'position':
-                               guiObject.move(parsePosition(value))
-                       elif attrib == 'size':
-                               guiObject.resize(parseSize(value))
-                       elif attrib == 'title':
-                               guiObject.setTitle(value)
-                       elif attrib == 'text':
-                               guiObject.setText(value)
-                       elif attrib == 'font':
-                               guiObject.setFont(parseFont(value))
-                       elif attrib == "pixmap":
-                               ptr = gPixmapPtr()
-                               if loadPNG(ptr, value):
-                                       raise "loading PNG failed!"
-                               x = ptr
-                               ptr = ptr.__deref__()
-                               desktop.makeCompatiblePixmap(ptr)
-                               guiObject.setPixmap(ptr)
-#                              guiObject.setPixmapFromFile(value)
-                       elif attrib == "valign":
-                               try:
-                                       guiObject.setVAlign(
-                                               { "top": guiObject.alignTop,
-                                                       "center": guiObject.alignCenter,
-                                                       "bottom": guiObject.alignBottom
-                                               }[value])
-                               except KeyError:
-                                       print "valign must be either top, center or bottom!"
-                       elif attrib == "halign":
+               skinAttributes[attrib] = value
+
+def applySingleAttribute(guiObject, desktop, attrib, value):           
+       # and set attributes
+       try:
+               if attrib == 'position':
+                       guiObject.move(parsePosition(value))
+               elif attrib == 'size':
+                       guiObject.resize(parseSize(value))
+               elif attrib == 'title':
+                       guiObject.setTitle(value)
+               elif attrib == 'text':
+                       guiObject.setText(value)
+               elif attrib == 'font':
+                       guiObject.setFont(parseFont(value))
+               elif attrib == "pixmap":
+                       ptr = gPixmapPtr()
+                       if loadPNG(ptr, value):
+                               raise "loading PNG failed!"
+                       x = ptr
+                       ptr = ptr.__deref__()
+                       desktop.makeCompatiblePixmap(ptr)
+                       guiObject.setPixmap(ptr)
+                       # guiObject.setPixmapFromFile(value)
+               elif attrib == "valign":
+                       try:
+                               guiObject.setVAlign(
+                                       { "top": guiObject.alignTop,
+                                               "center": guiObject.alignCenter,
+                                               "bottom": guiObject.alignBottom
+                                       }[value])
+                       except KeyError:
+                               print "valign must be either top, center or bottom!"
+               elif attrib == "halign":
+                       try:
+                               guiObject.setHAlign(
+                                       { "left": guiObject.alignLeft,
+                                               "center": guiObject.alignCenter,
+                                               "right": guiObject.alignRight,
+                                               "block": guiObject.alignBlock
+                                       }[value])
+                       except KeyError:
+                               print "halign must be either left, center, right or block!"
+               elif attrib == "flags":
+                       flags = value.split(',')
+                       for f in flags:
                                try:
                                try:
-                                       guiObject.setHAlign(
-                                               { "left": guiObject.alignLeft,
-                                                       "center": guiObject.alignCenter,
-                                                       "right": guiObject.alignRight,
-                                                       "block": guiObject.alignBlock
-                                               }[value])
+                                       fv = eWindow.__dict__[f]
+                                       guiObject.setFlag(fv)
                                except KeyError:
                                except KeyError:
-                                       print "halign must be either left, center, right or block!"
-                       elif attrib == "flags":
-                               flags = value.split(',')
-                               for f in flags:
-                                       try:
-                                               fv = eWindow.__dict__[f]
-                                               guiObject.setFlag(fv)
-                                       except KeyError:
-                                               print "illegal flag %s!" % f
-                       elif attrib == "backgroundColor":
-                               guiObject.setBackgroundColor(parseColor(value))
-                       elif attrib != 'name':
-                               print "unsupported attribute " + attrib + "=" + value
-               except AttributeError:
-                       print "widget %s (%s) doesn't support attribute %s!" % ("", guiObject.__class__.__name__, attrib)
+                                       print "illegal flag %s!" % f
+               elif attrib == "backgroundColor":
+                       guiObject.setBackgroundColor(parseColor(value))
+               elif attrib == "foregroundColor":
+                       guiObject.setForegroundColor(parseColor(value))
+               elif attrib != 'name':
+                       print "unsupported attribute " + attrib + "=" + value
+       except int:
+# AttributeError:
+               print "widget %s (%s) doesn't support attribute %s!" % ("", guiObject.__class__.__name__, attrib)
+
+def applyAllAttributes(guiObject, desktop, attributes):
+       for (attrib, value) in attributes.items():
+               applySingleAttribute(guiObject, desktop, attrib, value)
 
 def loadSkin(desktop):
        print "loading skin..."
 
 def loadSkin(desktop):
        print "loading skin..."
@@ -249,7 +285,7 @@ def loadSkin(desktop):
                eWindowStyleManager.getInstance(x)
                x.setStyle(style)
 
                eWindowStyleManager.getInstance(x)
                x.setStyle(style)
 
-def applyGUIskin(screen, skin, name, desktop):
+def readSkin(screen, skin, name, desktop):
        myscreen = None
        
        # first, find the corresponding screen element
        myscreen = None
        
        # first, find the corresponding screen element
@@ -261,8 +297,11 @@ def applyGUIskin(screen, skin, name, desktop):
        del skin
        
        assert myscreen != None, "no skin for screen '" + name + "' found!"
        del skin
        
        assert myscreen != None, "no skin for screen '" + name + "' found!"
+
+       screen.skinAttributes = { }     
+       collectAttributes(screen.skinAttributes, myscreen)
        
        
-       applyAttributes(screen.instance, myscreen, desktop)
+       screen.additionalWidgets = [ ]
        
        # now walk all widgets
        for widget in elementsWithTag(myscreen.childNodes, "widget"):
        
        # now walk all widgets
        for widget in elementsWithTag(myscreen.childNodes, "widget"):
@@ -273,20 +312,43 @@ def applyGUIskin(screen, skin, name, desktop):
                
                # get corresponding gui object
                try:
                
                # get corresponding gui object
                try:
-                       guiObject = screen[wname].instance
+                       attributes = screen[wname].skinAttributes = { }
                except:
                        raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!")
                
                except:
                        raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!")
                
-               applyAttributes(guiObject, widget, desktop)
+               collectAttributes(attributes, widget)
 
        # now walk additional objects
        for widget in elementsWithTag(myscreen.childNodes, lambda x: x != "widget"):
 
        # now walk additional objects
        for widget in elementsWithTag(myscreen.childNodes, lambda x: x != "widget"):
+               if widget.tagName == "applet":
+                       codeText = mergeText(widget.childNodes).strip()
+                       type = widget.getAttribute('type')
+
+                       code = compile(codeText, "skin applet", "exec")
+                       
+                       if type == "onLayoutFinish":
+                               screen.onLayoutFinish.append(code)
+                       else:
+                               raise str("applet type '%s' unknown!" % type)
+                       
+                       continue
+               
+               class additionalWidget:
+                       pass
+               
+               w = additionalWidget()
+               
                if widget.tagName == "eLabel":
                if widget.tagName == "eLabel":
-                       guiObject = eLabel(screen.instance)
+                       w.widget = eLabel
                elif widget.tagName == "ePixmap":
                elif widget.tagName == "ePixmap":
-                       guiObject = ePixmap(screen.instance)
+                       w.widget = ePixmap
                else:
                        raise str("unsupported stuff : %s" % widget.tagName)
                
                else:
                        raise str("unsupported stuff : %s" % widget.tagName)
                
-               applyAttributes(guiObject, widget, desktop      )
-               guiObject.thisown = 0
+               w.skinAttributes = { }
+               collectAttributes(w.skinAttributes, widget)
+               
+               # applyAttributes(guiObject, widget, desktop)
+               # guiObject.thisown = 0
+               print screen.additionalWidgets
+               screen.additionalWidgets.append(w)