- 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
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
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):
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)
+import skin
+
class GUIComponent:
""" GUI component """
-
+
def __init__(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)
from GUIComponent import *
+from skin import applyAllAttributes
class GUISkin:
+ __module__ = __name__
+
def __init__(self):
+ self.onLayoutFinish = [ ]
pass
-
- def createGUIScreen(self, parent):
+
+ def createGUIScreen(self, parent, desktop):
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()
- 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 produceHTML(self):
return "<h2>" + self.getText() + "</h2>\n"
- def createWidget(self, parent, skindata):
+ def createWidget(self, parent):
g = eLabel(parent)
return g
return self.getText()
# GUI:
- def createWidget(self, parent, skindata):
+ def createWidget(self, parent):
return eLabel(parent)
+ def getSize(self):
+ s = self.instance.calculateSize()
+ return (s.width(), s.height())
+
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)
# 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
GUIComponent.__init__(self)
VariableValue.__init__(self)
- def createWidget(self, parent, skindata):
+ def createWidget(self, parent):
g = eSlider(parent)
g.setRange(0, 100)
return g
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)
-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
-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
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)
+import skin
+
class VariableText:
"""VariableText can be used for components which have a variable text, based on any widget with setText call"""
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):
+import skin
+
class VariableValue:
"""VariableValue can be used for components which have a variable value (like eSlider), based on any widget with setValue call"""
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):
GUIComponent.__init__(self)
VariableValue.__init__(self)
- def createWidget(self, parent, skindata):
+ def createWidget(self, parent):
g = eSlider(parent)
g.setRange(0, 100)
return g
from Components.ServiceName import ServiceName
from Components.EventInfo import EventInfo
+from Screens.MessageBox import MessageBox
+
from enigma import *
import time
"hide": self.hide,
"toggleShow": self.toggleShow
})
- self["okbutton"] = Button("mainMenu", [self.mainMenu])
+# self["okbutton"] = Button("mainMenu", [self.mainMenu])
self["CurrentTime"] = Clock()
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)
from xml.dom import EMPTY_NAMESPACE
from skin import elementsWithTag
+from Tools import XMLTools
+
# some screens
def doGlobal(screen):
screen["clock"] = Clock()
</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)
self.session.open(clockDisplay, Clock())
def okbuttonClick(self):
+ print "okbuttonClick"
selection = self["menu"].getCurrent()
selection[1]()
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:
--- /dev/null
+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
+ })
+
__all__ = ["ChannelSelection", "ClockDisplay", "ConfigMenu",
- "InfoBar", "Menu", "ScartLoopThrough", "Screen", "ServiceScan",
+ "InfoBar", "MessageBox", "Menu", "ScartLoopThrough", "Screen", "ServiceScan",
"TimerEdit"]
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
+
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.
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):
print sys.getrefcount(self.currentDialog)
del self.currentDialog.instance
- dump(self.currentDialog)
+# dump(self.currentDialog)
del self.currentDialog
self.popCurrent()
return screen(self, *arguments)
def instantiateDialog(self, screen, *arguments):
+ # create dialog
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)
-
+ applyAllAttributes(dlg.instance, self.desktop, dlg.skinAttributes)
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):
import xml.dom.minidom
from xml.dom import EMPTY_NAMESPACE
-from Tools.XMLTools import elementsWithTag
+from Tools.XMLTools import elementsWithTag, mergeText
colorNames = dict()
<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>
<screen name="ScartLoopThrough" position="0,0" size="720,576">
</screen>
<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>
+ <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):
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)
# 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:
- guiObject.setHAlign(
- { "left": guiObject.alignLeft,
- "center": guiObject.alignCenter,
- "right": guiObject.alignRight,
- "block": guiObject.alignBlock
- }[value])
+ fv = eWindow.__dict__[f]
+ guiObject.setFlag(fv)
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..."
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
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"):
# 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 + "'!")
- applyAttributes(guiObject, widget, desktop)
+ collectAttributes(attributes, 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":
- guiObject = eLabel(screen.instance)
+ w.widget = eLabel
elif widget.tagName == "ePixmap":
- guiObject = ePixmap(screen.instance)
+ w.widget = ePixmap
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)