add possibility to remove timers in epglist
[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                 self.skin = Console.skin
15                 Screen.__init__(self, session)
16
17                 self.finishedCallback = finishedCallback
18                 self.closeOnSuccess = closeOnSuccess
19
20                 self["text"] = ScrollLabel("")
21                 self["actions"] = ActionMap(["WizardActions", "DirectionActions"], 
22                 {
23                         "ok": self.cancel,
24                         "back": self.cancel,
25                         "up": self["text"].pageUp,
26                         "down": self["text"].pageDown
27                 }, -1)
28                 
29                 self.cmdlist = cmdlist
30                 self.newtitle = title
31                 
32                 self.onShown.append(self.updateTitle)
33                 
34                 self.container = eConsoleAppContainer()
35                 self.run = 0
36                 self.container.appClosed.append(self.runFinished)
37                 self.container.dataAvail.append(self.dataAvail)
38                 self.onLayoutFinish.append(self.startRun) # dont start before gui is finished
39
40         def updateTitle(self):
41                 self.setTitle(self.newtitle)
42
43         def startRun(self):
44                 self["text"].setText(_("Execution Progress:") + "\n\n")
45                 print "Console: executing in run", self.run, " the command:", self.cmdlist[self.run]
46                 if self.container.execute(self.cmdlist[self.run]): #start of container application failed...
47                         self.runFinished(-1) # so we must call runFinished manual
48
49         def runFinished(self, retval):
50                 self.run += 1
51                 if self.run != len(self.cmdlist):
52                         if self.container.execute(self.cmdlist[self.run]): #start of container application failed...
53                                 self.runFinished(-1) # so we must call runFinished manual
54                 else:
55                         str = self["text"].getText()
56                         str += _("Execution finished!!");
57                         self["text"].setText(str)
58                         self["text"].lastPage()
59                         if self.finishedCallback is not None:
60                                 self.finishedCallback()
61                         if not retval and self.closeOnSuccess:
62                                 self.cancel()
63
64         def cancel(self):
65                 if self.run == len(self.cmdlist):
66                         self.close()
67                         self.container.appClosed.remove(self.runFinished)
68                         self.container.dataAvail.remove(self.dataAvail)
69
70         def dataAvail(self, str):
71                 self["text"].setText(self["text"].getText() + str)