X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/8138d67d47307c7e438166b9c9cac5992e4929a5..a01b52be8469eb9fd10d2f31870d7d9970c5d974:/lib/python/Components/Pixmap.py diff --git a/lib/python/Components/Pixmap.py b/lib/python/Components/Pixmap.py index 48eec237..02eeb870 100644 --- a/lib/python/Components/Pixmap.py +++ b/lib/python/Components/Pixmap.py @@ -1,78 +1,115 @@ -import skin -from GUIComponent import * +from ConditionalWidget import ConditionalWidget +from GUIComponent import GUIComponent -from enigma import * +from enigma import ePixmap, eTimer -class Pixmap(GUIComponent): - """Pixmap can be used for components which diplay a pixmap""" - - SHOWN = 0 - HIDDEN = 1 - - def __init__(self): - GUIComponent.__init__(self) - self.instance = None - self.state = self.SHOWN - - def GUIcreate(self, parent): - self.instance = self.createWidget(parent) - - def GUIdelete(self): - self.removeWidget(self.instance) - self.instance = None - - def getePixmap(self, parent): - #pixmap = ePixmap(parent) - #pixmap.setPixmapFromFile(self.filename) - return ePixmap(parent) - - def createWidget(self, parent): - return self.getePixmap(parent) - - def removeWidget(self, w): - pass - - def showPixmap(self): - print "Show pixmap" - self.state = self.SHOWN - self.instance.show() +from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE +from os import path +from skin import loadPixmap - def hidePixmap(self): - print "Hide pixmap" - self.state = self.HIDDEN - self.instance.hide() - - def removeWidget(self, instance): - pass +class Pixmap(GUIComponent): + GUI_WIDGET = ePixmap -class PixmapConditional(Pixmap): +class PixmapConditional(ConditionalWidget, Pixmap): def __init__(self, withTimer = True): + ConditionalWidget.__init__(self) Pixmap.__init__(self) + +class MovingPixmap(Pixmap): + def __init__(self): + Pixmap.__init__(self) + + self.moving = False - self.setConnect(None) + # TODO: get real values + self.x = 0.0 + self.y = 0.0 - if (withTimer): - self.conditionCheckTimer = eTimer() - self.conditionCheckTimer.timeout.get().append(self.update) - self.conditionCheckTimer.start(1000) + self.clearPath() - def setConnect(self, conditionalFunction): - self.conditionalFunction = conditionalFunction + self.moveTimer = eTimer() + self.moveTimer.callback.append(self.doMove) + + def clearPath(self, repeated = False): + if (self.moving): + self.moving = False + self.moveTimer.stop() + + self.path = [] + self.currDest = 0 + self.repeated = repeated - def activateCondition(self, condition): - if (condition): - if (self.state == self.HIDDEN): - self.showPixmap() - else: - if (self.state == self.SHOWN): - self.hidePixmap() + def addMovePoint(self, x, y, time = 20): + self.path.append((x, y, time)) + + def moveTo(self, x, y, time = 20): + self.clearPath() + self.addMovePoint(x, y, time) + + def startMoving(self): + if not self.moving: + self.time = self.path[self.currDest][2] + self.stepX = (self.path[self.currDest][0] - self.x) / float(self.time) + self.stepY = (self.path[self.currDest][1] - self.y) / float(self.time) - def update(self): - if (self.conditionalFunction != None): - try: - self.conditionalFunction() # check, if the conditionalfunction is still valid - except: - self.conditionalFunction = None - self.activateCondition(False) + self.moving = True + self.moveTimer.start(100) - self.activateCondition(self.conditionalFunction()) + def stopMoving(self): + self.moving = False + self.moveTimer.stop() + + def doMove(self): + self.x += self.stepX + self.y += self.stepY + self.time -= 1 + try: + self.move(int(self.x), int(self.y)) + except: # moving not possible... widget not there any more... stop moving + self.stopMoving() + + if (self.time == 0): + self.currDest += 1 + self.moveTimer.stop() + self.moving = False + if (self.currDest >= len(self.path)): # end of path + if (self.repeated): + self.currDest = 0 + self.moving = False + self.startMoving() + else: + self.moving = False + self.startMoving() + +class MultiPixmap(Pixmap): + def __init__(self): + Pixmap.__init__(self) + self.pixmaps = [] + + def applySkin(self, desktop, screen): + if self.skinAttributes is not None: + skin_path_prefix = getattr(screen, "skin_path", path) + pixmap = None + attribs = [ ] + for (attrib, value) in self.skinAttributes: + if attrib == "pixmaps": + pixmaps = value.split(',') + for pixmap in pixmaps: + self.pixmaps.append(loadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, pixmap, path_prefix=skin_path_prefix), desktop) ) + if not pixmap: + pixmap = resolveFilename(SCOPE_SKIN_IMAGE, pixmaps[0], path_prefix=skin_path_prefix) + elif attrib == "pixmap": + pixmap = resolveFilename(SCOPE_SKIN_IMAGE, value, path_prefix=skin_path_prefix) + else: + attribs.append((attrib,value)) + if pixmap: + attribs.append(("pixmap", pixmap)) + self.skinAttributes = attribs + return GUIComponent.applySkin(self, desktop, screen) + + def setPixmapNum(self, x): + if self.instance: + if len(self.pixmaps) > x: + self.instance.setPixmap(self.pixmaps[x]) + else: + print "setPixmapNum(%d) failed! defined pixmaps:" %(x), self.pixmaps