deliver service events only to last created class which is based on
[enigma2.git] / lib / python / Screens / Console.py
index 98c373d5c2e94895449324654ddea8ee1a16354e..0ceba3ec106808ee290055040aa0fb43127a65ef 100644 (file)
@@ -1,19 +1,22 @@
 from enigma import eConsoleAppContainer
 from Screens.Screen import Screen
-from Components.ActionMap import ActionMap, NumberActionMap
+from Components.ActionMap import ActionMap
 from Components.ScrollLabel import ScrollLabel
 
 class Console(Screen):
        #TODO move this to skin.xml
        skin = """
                <screen position="100,100" size="550,400" title="Command execution..." >
-                       <widget name="text" position="0,0" size="550,400" font="Regular;15" />
+                       <widget name="text" position="0,0" size="550,400" font="Console;14" />
                </screen>"""
                
-       def __init__(self, session, title = "Console", cmdlist = None):
+       def __init__(self, session, title = "Console", cmdlist = None, finishedCallback = None, closeOnSuccess = False):
                self.skin = Console.skin
                Screen.__init__(self, session)
 
+               self.finishedCallback = finishedCallback
+               self.closeOnSuccess = closeOnSuccess
+
                self["text"] = ScrollLabel("")
                self["actions"] = ActionMap(["WizardActions", "DirectionActions"], 
                {
@@ -40,20 +43,28 @@ class Console(Screen):
        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])
+               if self.container.execute(self.cmdlist[self.run]): #start of container application failed...
+                       self.runFinished(-1) # so we must call runFinished manual
 
        def runFinished(self, retval):
                self.run += 1
                if self.run != len(self.cmdlist):
-                       self.container.execute(self.cmdlist[self.run])
+                       if self.container.execute(self.cmdlist[self.run]): #start of container application failed...
+                               self.runFinished(-1) # so we must call runFinished manual
                else:
                        str = self["text"].getText()
                        str += _("Execution finished!!");
                        self["text"].setText(str)
-                       
+                       if self.finishedCallback is not None:
+                               self.finishedCallback()
+                       if not retval and self.closeOnSuccess:
+                               self.cancel()
+
        def cancel(self):
                if self.run == len(self.cmdlist):
                        self.close()
+                       self.container.appClosed.get().remove(self.runFinished)
+                       self.container.dataAvail.get().remove(self.dataAvail)
 
        def dataAvail(self, str):
                self["text"].setText(self["text"].getText() + str)