remove debug
[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.get().append(self.runFinished)
37                 self.container.dataAvail.get().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                         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.get().remove(self.runFinished)
67                         self.container.dataAvail.get().remove(self.dataAvail)
68
69         def dataAvail(self, str):
70                 self["text"].setText(self["text"].getText() + str)