str = qt.QFileDialog.getExistingDirectory (self.txtOut.text(), self)
QFileDialog devuelve un directorio o una cadena vacía si se pulsa cancelar. A continuación se comprueba la cadena.
if str :
self.txtOut.setText ( str )
str = qt.QFileDialog.getExistingDirectory (self.txtOut.text(), self)
if str :
self.txtOut.setText ( str )
class Frm01 ( parentFrm01 ):
def __init__(self,parent = None,name = None,fl = 0):
#call parent's constructor
parentFrm01.__init__ (self,parent,name,fl)
Se crea un objeto QProcess y se le conecta a los slots
self.proc = QProcess ( self )
self.connect (self.proc,SIGNAL("readyReadStdout ()"),self.leidofromProcess )
self.connect (self.proc,SIGNAL("readyReadStderr ()"),self.leidofromProcess)
self.connect (self.proc,SIGNAL("processExited ()"),self.procesoTerminado)
def leidofromProcess(self):
self.textEdit1.append ( QString (self.proc.readStdout () ) )
self.textEdit1.append ( QString (self.proc.readStderr () ) )
#Lleva el cursor a la última linea
self.textEdit1.setContentsPos (0,self.textEdit1.contentsHeight() )
def procesoTerminado ( self ) :
#self.textEdit1.setContentsPos (0,0)
self.textEdit1.append ("Terminado")
def lanzar(self):
a = QStringList ()
a.append ("faad")
a.append ("s9.m4a")
self.proc.setArguments ( a )
#self.proc.addArgument ("faad")
#self.proc.addArgument ("s9.m4a")
if not self.proc.start () :
print "fallo"
def lanza2 ( self ) :
a = QStringList()
a.append ("ls")
a.append ("/")
a.append ("-l")
self.proc.setArguments ( a )
#self.proc.addArgument ( "ls" )
#self.proc.addArgument ( "/" )
#self.proc.addArgument ( "-l" )
if not self.proc.start () :
print "fallo"
def parar ( self ) :
print "terminando..."
self.proc.tryTerminate()
QTimer.singleShot(5000, self.proc, SLOT ("kill()") )
import sys
old_stdout = sys.stdout
sys.stdout = open("kk.log","w")
print"hola"
print"adios"
sys.stdout.close()
sys.stdout = old_stdout
print "ya esta"