Whoops, you are starting your QProcess twice:
101: self.proc.start(command)
106: QtCore.QTimer.singleShot(100, partial(self.proc.start, command))
And also you aren't making use of that partial callback...
def dataReady(self, proc):
# make sure you are first converting the QByteArray
# to a string, and then stripping the string.
out = str(proc.readAllStandardOutput())
self.log.append(out.strip())
...
def export(self):
...
# probably dont need to save it as a member
# but pass it a parent
proc = QtCore.QProcess(self)
# connect signals first
proc.started.connect(self.started)
proc.readyReadStandardOutput.connect(partial(self.dataReady, proc))
proc.finished.connect(self.finished)
# start
proc.start(command)
On Tue, Mar 19, 2013 at 9:36 AM, Ricardo Viana <[email protected]> wrote:
> Thanks. i m trying Qprocess now.
> i can get the started and finished feedback. but nothing in between... :(
>
> i even changed from avconv to ffmpeg to see if its something w the command.
> maybe its something to do with the stdout from the command line app!?!?
>
> here is the latest.
>
> https://gist.github.com/RicardoViana/5190548
>
>
>
>
>
>
> On 03/18/2013 07:57 PM, Justin Israel wrote:
>
> This works fine as a test, when I change these lines:
>
> command = 'for i in {1..5}; do echo $i; sleep 1; done'
> self.proc=subprocess.Popen(command, shell=True,
> stdout=subprocess.PIPE)
>
> Also, you can just connect the button right to the slot:
>
> saveFile = QtGui.QPushButton('Export')
> saveFile.clicked.connect(self.export)
>
> Now here is a down side of the subprocess approach. What if the
> application takes a while to print a line? That means your application will
> still hang on that line, then process events, then wait on another line. I
> still think you should explore the QProcess approach.
>
>
>
>
> On Mar 19, 2013, at 8:06 AM, Ricardo Viana wrote:
>
> Thanks for the help man. Learning quite a lot of python just by joining
> this group.
>
> here is the link:
>
> https://gist.github.com/RicardoViana/5189872
>
>
> cheers
> Ricardo Viana
>
>
> On 03/18/2013 06:53 PM, Justin Israel wrote:
>
> Can you post a full example on pastsbin or gist? It sounds like something
> is happening before the event loop.
> Also for subprocess, you should pass the command as a list so you don't
> need shell=True
>
> command=["avconv", "-i", self.inputFile, "-b",
> self.bitRatesList[self.bitRate.currentIndex()], "-s",
> self.sizeList[self.sizeSel.cur rentIndex()], self.outputFile]
>
> Generally though, I think the QProcess approach is more robust as it plays
> nicely with the event loop.
>
> With the qtimer then reason I was using it plus a 100 ms timeout was to
> have the callback placed into the event loop and run after the app had
> fully started and signals would work. In a real case, the process would
> probably get started by some action in your running app. Like a button
> press or a response to some signal.
> On Mar 18, 2013 11:00 PM, "Ricardo Viana" <[email protected]> wrote:
>
>> Thank you very much for the help Justin.
>>
>> i followed your code on gist.
>>
>> here is what i have now:
>>
>> -----code----
>>
>>
>> def timer(self):
>> QtCore.QTimer.singleShot(100,self.export)
>>
>>
>>
>> def export(self):
>> self.log.append("started")
>>
>> self.proc=subprocess.Popen("avconv -i %s -b %s -s %s %s"
>> %(self.inputFile,self.bitRatesList[self.bitRate.currentIndex()],
>>
>> self.sizeList[self.sizeSel.currentIndex()],self.outputFile),shell=True,stdout=subprocess.PIPE)
>> while True:
>> output=self.proc.stdout.readline()
>> if not output:
>> break
>> QtGui.qApp.processEvents()
>> self.log.append(output.strip())
>>
>>
>>
>>
>> -----code----
>>
>>
>> what is happening is the following. The self.log.append("started") only
>> shows when the subprocess terminates and it should be the
>> other way around. Also i can't append the output.strip to the
>> QTextBrowser(self.log) i have. it shows nicely on the terminal but not in
>> the GUI.
>>
>> Another thing i can't figure is why i have to say to subprocess ->
>> Shell=True. In your code you don't have it. but if i run it that way
>> i get an error :
>>
>> File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
>> raise child_exception
>> OSError: [Errno 2] No such file or directory
>>
>>
>>
>>
>>
>>
>> On 03/16/2013 03:29 AM, Justin Israel wrote:
>>
>>> QProcess has signals that indicate when new data is ready to read from
>>> your process, allowing to to get line updates. Also, in your example, you
>>> are going to be blocking the event loop with your for loop.
>>>
>>> I put together an example of each of those for you here:
>>> https://gist.github.com/justinfx/5174795
>>>
>>> The first example shows how to monitor the QProcess for new output
>>>
>>> The second shows how to use subprocess in a way that you can loop over
>>> the output, but still pump the event loop. If your lines are being emitted
>>> quickly you probably don't need to make the call for every loop, but rather
>>> you could call on on every 10 lines...or 100 lines.. or whatever is
>>> appropriate to give your main gui thread a chance to process the pending
>>> events:
>>>
>>> i.e.
>>>
>>> i = 0
>>> while True:
>>> line = process.stdout.readline()
>>> if not line:
>>> break
>>>
>>> # process line
>>>
>>> # process event loop every 10 lines
>>> if i % 10 == 0:
>>> QtGui.qApp.processEvents()
>>> i +=1
>>>
>>>
>>> -- justin
>>>
>>>
>>>
>>> On Thursday, March 7, 2013 5:22:19 AM UTC+13, olheiros wrote:
>>>
>>>> Hi Fellas!
>>>>
>>>>
>>>>
>>>> i'm trying to build my own video converter gui on a Linux. Using Pyqt4.
>>>>
>>>> I'm using avconv command line converter.
>>>>
>>>>
>>>>
>>>> I have setup all parameters and it is working fine.
>>>>
>>>>
>>>>
>>>> The thing is i would like to have some kind of progress feedback.
>>>>
>>>> Does anyone know how to retrieve the command line feedback so
>>>>
>>>> i can hook it to some kind of expression to drive the QProgressBar?
>>>>
>>>>
>>>>
>>>> thank you very much
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> ////////////////////////////////////
>>>>
>>>> Ricardo Viana
>>>>
>>>> VFX Generalist
>>>>
>>>
>>
>> --
>> ////////////////////////////////////
>> Ricardo Viana
>> VFX Generalist
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
>
> --
> ////////////////////////////////////
> Ricardo Viana
> VFX Generalist
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
>
> --
> ////////////////////////////////////
> Ricardo Viana
> VFX Generalist
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.