from enigma import eConsoleAppContainer from Screens.Screen import Screen from Components.ActionMap import ActionMap, NumberActionMap from Components.ScrollLabel import ScrollLabel class Console(Screen): #TODO move this to skin.xml skin = """ """ def __init__(self, session, title = "Console", cmdlist = None, finishedCallback = None): self.skin = Console.skin Screen.__init__(self, session) self.finishedCallback = finishedCallback self["text"] = ScrollLabel("") self["actions"] = ActionMap(["WizardActions", "DirectionActions"], { "ok": self.cancel, "back": self.cancel, "up": self["text"].pageUp, "down": self["text"].pageDown }, -1) self.cmdlist = cmdlist self.newtitle = title self.onShown.append(self.updateTitle) self.container = eConsoleAppContainer() self.run = 0 self.container.appClosed.get().append(self.runFinished) self.container.dataAvail.get().append(self.dataAvail) self.onLayoutFinish.append(self.startRun) # dont start before gui is finished def updateTitle(self): self.setTitle(self.newtitle) def startRun(self): self["text"].setText(_("Execution Progress:") + "\n\n") print "Console: executing in run", self.run, " the command:", self.cmdlist[self.run] self.container.execute(self.cmdlist[self.run]) def runFinished(self, retval): self.run += 1 if self.run != len(self.cmdlist): self.container.execute(self.cmdlist[self.run]) else: str = self["text"].getText() str += _("Execution finished!!"); self["text"].setText(str) if self.finishedCallback is not None: self.finishedCallback() def cancel(self): if self.run == len(self.cmdlist): self.close() def dataAvail(self, str): self["text"].setText(self["text"].getText() + str)