add background file eraser class for asynchronous file deletion
[enigma2.git] / lib / python / Screens / Console.py
1 from enigma import eConsoleAppContainer
2 from Screens.Screen import Screen
3 from Components.ActionMap import ActionMap, NumberActionMap
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="Regular;15" />
11                 </screen>"""
12                 
13         def __init__(self, session, title = "Console", cmdlist = None):
14                 self.skin = Console.skin
15                 Screen.__init__(self, session)
16
17                 self["text"] = ScrollLabel("")
18                 self["actions"] = ActionMap(["WizardActions", "DirectionActions"], 
19                 {
20                         "ok": self.cancel,
21                         "back": self.cancel,
22                         "up": self["text"].pageUp,
23                         "down": self["text"].pageDown
24                 }, -1)
25                 
26                 self.cmdlist = cmdlist
27                 self.newtitle = title
28                 
29                 self.onShown.append(self.updateTitle)
30                 
31                 self.container = eConsoleAppContainer()
32                 self.run = 0
33                 self.container.appClosed.get().append(self.runFinished)
34                 self.container.dataAvail.get().append(self.dataAvail)
35                 self.onLayoutFinish.append(self.startRun) # dont start before gui is finished
36
37         def updateTitle(self):
38                 self.setTitle(self.newtitle)
39
40         def startRun(self):
41                 self["text"].setText(_("Execution Progress:") + "\n\n")
42                 print "Console: executing in run", self.run, " the command:", self.cmdlist[self.run]
43                 self.container.execute(self.cmdlist[self.run])
44
45         def runFinished(self, retval):
46                 self.run += 1
47                 if self.run != len(self.cmdlist):
48                         self.container.execute(self.cmdlist[self.run])
49                 else:
50                         str = self["text"].getText()
51                         str += _("Execution finished!!");
52                         self["text"].setText(str)
53                         
54         def cancel(self):
55                 if self.run == len(self.cmdlist):
56                         self.close()
57
58         def dataAvail(self, str):
59                 self["text"].setText(self["text"].getText() + str)