Enabling Code Completion in an embedded Python Interpreter

后端 未结 4 2102
青春惊慌失措
青春惊慌失措 2020-12-28 23:20

I have got a PyQT widget interpreter working, the code picked up from here is as follows:

import os
import re
import sys
import code

from PyQt4.QtGui impo         


        
4条回答
  •  悲哀的现实
    2020-12-28 23:53

    If you want to save yourself some time - take a look at spyderlib, it contains a widget that embeds an interactive Python interpreter with some interaction sugar such as code completion. The bits of specific interest are

    • spyderlib/widgets/sourcecode/codeeditor.py
    • spyderlib/shell.py
    • spyderlib/editor.py
    • spyderlib/widgets/externalshell/pythonshell.py
    • spyderlib/utiils/module_completion.py
    • spyderlib/plugins/externalconsole.py
    • spyderlib/plugins/console.py
    • spyderlib/plugins/editor.py

    The only caveat I have with spyderlib is that you can't just use that doodad on it's own - somewhere I have a version I extracted that contains the bare minimum of support modules needed to run. If you run into the same problem I did regarding the bloat send me a msg and I'll check my stuff into github for you to grab.

    I also seem to remember there's an Qt based interactive Python interpreter widget that is used in NumPy or SciPy - I think it originally came from the ipython project however. It's pretty nice because it actually splits the interpeter from the execution of code - so if your code crashes, your interpreter doesn't crash with it. But, in that case you can't modify the Pythonic contents of other threads.. The spyderlib version can work both ways.

提交回复
热议问题