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] <mailto:[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]
    <mailto:python_inside_maya%[email protected]>.
    To post to this group, send email to
    [email protected]
    <mailto:[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.


Reply via email to