Wizard.py: hopefully fix async stuff
[enigma2.git] / lib / python / Screens / Console.py
index c2e1688d593f29a4db13c862af7d2190173d485b..b57f2400a5c21013928dad42715d7a1f2a9c5556 100644 (file)
@@ -7,14 +7,15 @@ class Console(Screen):
        #TODO move this to skin.xml
        skin = """
                <screen position="100,100" size="550,400" title="Command execution..." >
        #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>"""
                
                </screen>"""
                
-       def __init__(self, session, title = "Console", cmdlist = None, finishedCallback = 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.skin = Console.skin
                Screen.__init__(self, session)
 
                self.finishedCallback = finishedCallback
+               self.closeOnSuccess = closeOnSuccess
 
                self["text"] = ScrollLabel("")
                self["actions"] = ActionMap(["WizardActions", "DirectionActions"], 
 
                self["text"] = ScrollLabel("")
                self["actions"] = ActionMap(["WizardActions", "DirectionActions"], 
@@ -32,8 +33,8 @@ class Console(Screen):
                
                self.container = eConsoleAppContainer()
                self.run = 0
                
                self.container = eConsoleAppContainer()
                self.run = 0
-               self.container.appClosed.get().append(self.runFinished)
-               self.container.dataAvail.get().append(self.dataAvail)
+               self.container.appClosed.append(self.runFinished)
+               self.container.dataAvail.append(self.dataAvail)
                self.onLayoutFinish.append(self.startRun) # dont start before gui is finished
 
        def updateTitle(self):
                self.onLayoutFinish.append(self.startRun) # dont start before gui is finished
 
        def updateTitle(self):
@@ -42,22 +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]
        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):
 
        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()
                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()
        def cancel(self):
                if self.run == len(self.cmdlist):
                        self.close()
+                       self.container.appClosed.remove(self.runFinished)
+                       self.container.dataAvail.remove(self.dataAvail)
 
        def dataAvail(self, str):
                self["text"].setText(self["text"].getText() + str)
 
        def dataAvail(self, str):
                self["text"].setText(self["text"].getText() + str)