I have a python code that ta开发者_StackOverflowkes measurements off of a HP LCR Meter and collects the data for us in various ways. I recently created a GUI for imputing initial conditions for employees not comfortable modifying variables in the code. Everything works except for 1 thing. WE use the latest python xy so python version 2.6.6 with pyqt and spyder on a windows 7 PC.
Normally we would open the code in spyder. But opening spyder takes a while and my supervisor liked the ability to just double click on the file which opens the GUI with a python console window to print errors and various information as you would see in spyder.
As can be seen in the screen shots provided, there is a initial machine setup mode for setting up the device to be scanned by the LCR Meter and there are two user inputs that the code prompts. On spyder it prints these prompts nicely in the console but in the python console opened without spyder it continuously prints QCoreApplication::exec: The event loop is already running
Weird thing is you can still just push enter twice as normal and the code will run like normal. But its going to be confusing to basically everyone but me.
Does anyone know why this would be happening?
Here are the pictures of the output
Here is the code that prompts the input.
lcr = visa.instrument('GPIB::17')
#clear the instrument
lcr.write('*RST;*CLS')
#enable operation complete notification
lcr.write('*OPC')
if parallel:
lcr.write('FUNC:IMP CPG') #Parallel capacitance, conductance model
else:
lcr.write('FUNC:IMP CSRS') #Series capacitance, resistance model
lcr.write('APER '+integration+','+averages)
lcr.write('OUTP:HPOW ON')
lcr.write('OUTP:DC:ISOL OFF')
lcr.write('VOLT '+vac)
lcr.write('TRIG:SOUR BUS')
if zero == True:
#set open correction parameters
lcr.write('DISP:PAGE CSET')
lcr.write('CORR:LENG 1')
lcr.write('CORR:METH SING')
lcr.write('CORR:LOAD CPG')
lcr.write('CORR:USE 10')
lcr.write('CORR:SPOT1:STATE ON')
lcr.write('CORR:SPOT2:STATE OFF')
lcr.write('CORR:SPOT3:STATE OFF')
lcr.write('CORR:SPOT1:FREQ '+frequency)
#perform open correction -> unprobe device\
raw_input('Unprobe DUT and press ENTER to continue...')
lcr.write('CORR:SPOT1:OPEN')
lcr.write('CORR:OPEN:STATE ON')
lcr.write('DISP:PAGE MEAS')
#poll lcr to determine measurment state
lcr.write('*OPC?')
done = lcr.read()
while done == 0:
lcr.write('*OPC?')
done = lcr.read()
time.sleep(0.5)
#reprobe device
raw_input('Probe DUT, then press ENTER')
lcr.write('FREQ '+frequency)
The Prompts are the two raw_input()
.
Reason why you get continuous messages in your console, is that system logs use same output-stream than your app.
Spyder is nice program, which just embeds IPython or Python(backup) console in QT window, you can use similar solution - just use Qt4 to draw window, which includes IPython console
What you need to do is this(source):
def embed_ipython(window):
"wrapper funcs - works < IPython 0.11"
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed(user_ns = dict(w = window))
ipshell()
Here ‘window’ is a central object of some kind that you want to expose to IPython (to manipulate, test various methods, etc).
GUI app initialization would be like this:
if __name__ == "__main__":
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
window = QtGui.QMainWindow()
window.show()
embed_ipython(window)
sys.exit(app.exec_())
Some additional readings:
- QT4 tutorial: http://zetcode.com/tutorials/pyqt4/firstprograms/
- Similar topic - how to embed python console: How to embed a Python interpreter in a PyQT widget
- IPython and QT console: http://ipython.org/ipython-doc/dev/interactive/qtconsole.html
精彩评论