Merge remote branch 'origin/bug_348_dvdburn_residenttask'
[enigma2.git] / lib / python / Screens / Console.py
1 from enigma import eConsoleAppContainer
2 from Screens.Screen import Screen
3 from Components.ActionMap import ActionMap
4 from Components.ScrollLabel import ScrollLabel
5
6 class Console(Screen):
7         #TODO move this to skin.xml
8         skin = """
9                 <screen position="100,100" size="550,400" title="Command execution..." >
10                         <widget name="text" position="0,0" size="550,400" font="Console;14" />
11                 </screen>"""
12                 
13         def __init__(self, session, title = "Console", cmdlist = None, finishedCallback = None, closeOnSuccess = False):
14                 Screen.__init__(self, session)
15
16                 self.finishedCallback = finishedCallback
17                 self.closeOnSuccess = closeOnSuccess
18
19                 self["text"] = ScrollLabel("")
20                 self["actions"] = ActionMap(["WizardActions", "DirectionActions"], 
21                 {
22                         "ok": self.cancel,
23                         "back": self.cancel,
24                         "up": self["text"].pageUp,
25                         "down": self["text"].pageDown
26                 }, -1)
27                 
28                 self.cmdlist = cmdlist
29                 self.newtitle = title
30                 
31                 self.onShown.append(self.updateTitle)
32                 
33                 self.container = eConsoleAppContainer()
34                 self.run = 0
35                 self.container.appClosed.append(self.runFinished)
36                 self.container.dataAvail.append(self.dataAvail)
37                 self.onLayoutFinish.append(self.startRun) # dont start before gui is finished
38
39         def updateTitle(self):
40                 self.setTitle(self.newtitle)
41
42         def startRun(self):
43                 self["text"].setText(_("Execution Progress:") + "\n\n")
44                 print "Console: executing in run", self.run, " the command:", self.cmdlist[self.run]
45                 if self.container.execute(self.cmdlist[self.run]): #start of container application failed...
46                         self.runFinished(-1) # so we must call runFinished manual
47
48         def runFinished(self, retval):
49                 self.run += 1
50                 if self.run != len(self.cmdlist):
51                         if self.container.execute(self.cmdlist[self.run]): #start of container application failed...
52                                 self.runFinished(-1) # so we must call runFinished manual
53                 else:
54                         str = self["text"].getText()
55                         str += _("Execution finished!!");
56                         self["text"].setText(str)
57                         self["text"].lastPage()
58                         if self.finishedCallback is not None:
59                                 self.finishedCallback()
60                         if not retval and self.closeOnSuccess:
61                                 self.cancel()
62
63         def cancel(self):
64                 if self.run == len(self.cmdlist):
65                         self.close()
66                         self.container.appClosed.remove(self.runFinished)
67                         self.container.dataAvail.remove(self.dataAvail)
68
69         def dataAvail(self, str):
70                 self["text"].setText(self["text"].getText() + str)