1

I have developed a PyQt4 application for analysing delimited log files containing numeric data. Is there any way to easily add something like a 'console' to the application so that users can access objects and data created from the application and perform (type) arbitrary commands (using SciPy and NumPy?).

Vanush Vee
  • 426
  • 1
  • 3
  • 14
  • See this question: http://stackoverflow.com/questions/2758159/how-to-embed-a-python-interpreter-in-a-pyqt-widget – jdi Oct 12 '11 at 00:55

3 Answers3

2
import code

code.InteractiveInterpreter(local=locals())

Spawn the interpreter with the appropriate local variables. You probably don't want to spawn an interactive console (which you can also do) because you won't be able to do any other kinds of processing in your GUI application (though maybe you can get away with this if you use threads). Instead, you can allow the user to type in commands in some textbox, and send them to the interpreter object.

Alternatively, perhaps there is some way to make code.InteractiveConsole (not InteractiveInterpreter) thread-happy.

ninjagecko
  • 88,546
  • 24
  • 137
  • 145
2

How about embedding IPython into your application?

http://ipython.org/ipython-doc/stable/interactive/reference.html#embedding

JoshAdel
  • 66,734
  • 27
  • 141
  • 140
0

Append -i to the end of the she-bang. Like this

#!/bin/python2.7 -i
''' you code here '''

After the script finishes, there remains an interactive python.

Ade YU
  • 2,292
  • 3
  • 18
  • 28