I’m remaking that little AIR app I posted previously, but doing so in Python. I am using this as my first project to learn python and the QT classes. so far so good. I had a question before I get myself into a corner. I want the thing to be able to open up the command console for pc or terminal for mac for one, any ideas how to have python open a default app on a computer. The other thing(related to the tiltle of the post) is I want to be able to display the progress of your batch render through a progressBar, any clue as to pull that data from the batch render in through the console? I don’t care if it’s complicated or you just tell me the name of the method used and I will figure out the rest.
update: I found the subprocess module and got the Cmd console to pop up, so I guess I just need to know how talk to it
THIS WILL KEEP PRINTING THE OUTPUT ONLY IF IT CONTAINS %, BASICALY RETRIEVES THE OUTPUT
for i in range(2000):
output = proc.stdout.readline()
if output.__contains__("%"):
print output.rstrip()
#ALSO HANDLE THE % BAR OF THE PYQT UI HERE
outputSplit = output.split("%")[0]
lenSplit = len(outputSplit)-1
value = outputSplit[lenSplit-3] + outputSplit[lenSplit-2]
bar.setValue(int(value))
if output is "":
print "RENDER IS DONE!"
break
The above code prints this for me, ofc didn’t include it all!
JOB 0.4 progr: 71.6% rendered on Yasin-Dator.4
JOB 0.3 progr: 72.0% rendered on Yasin-Dator.3
JOB 0.4 progr: 72.3% rendered on Yasin-Dator.4
JOB 0.3 progr: 72.6% rendered on Yasin-Dator.3
JOB 0.4 progr: 73.0% rendered on Yasin-Dator.4
JOB 0.3 progr: 73.3% rendered on Yasin-Dator.3
Now for some PyQT magic, self explanatory I guess
from PyQt4 import QtCore, QtGui
import subprocess
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
bar = QtGui.QProgressBar()
bar.setRange(0, 100)
bar.setValue(50) #SETTINGS THIS TO 50 FOR EXAMPLE
bar.show()
#OPEN THE SUB PROCESS HERE
#............ insert code from above
#START LOOPING HERE
#........... insert code from above
sys.exit(app.exec_())
@ LoneWolf, i’m using python 3.1 and its giving me this error when I compile the code
Traceback (most recent call last):
File “C:/Users/Matt/Desktop/progress.pyw”, line 25, in <module>
if output.contains("%"):
TypeError: Type str doesn’t support the buffer API
Yeah Akira is right the above one is the correct way to do it don’t know why I didn’t think of that one xD //facepalm
Edit: Found a problem though, when you click something the application kinda goes into not responding mode and the progressbar stops where it was, untill the rendering is done… Not sure what the best way would be to fix this… someone with greater experience might be able to help ya
@LoneWolf - is that for loop with the range 2000 able to be substituted for a type of “listener”(i’ve been using actionScript too much) so that it only runs when there is an output from the console and not just checking 2000 times? Or is that really all you need to do?
It doesn’t loop 2000 times, I just put the 2000 value so it catches every message. What readline does is block execution untill it gets something from the process… I guess you would need something async… I haven’t played much with those type of stuff… Ill see if I have time to dig into it tonight
We ran across this problem in apps that have very verbose output. The most annoying thing is that no errors are actually thrown and the process doesn’t stop. It just sits there and does nothing.