1.3.1 iqt

Warning: The module iqt will not work with a MSVC-compiled Python, because it has no readline module.

The programming style imposed by PyQt (and other GUI toolkit wrappers) is to create an application instance with some widgets and to enter into an event loop that locks you from the Python command line interpreter.

Module iqt enables you to:

Module iqt works by hooking qApp->processEvents() on the event hook of the readline module. The GNU readline library closes the event loop by calling qApp->processEvent() at a maximum rate of 10 times per second while reading your keyboard input.

To see how iqt works, play with ICompass.py by running

python -i ICompass.py
or
python ICompass.py
or
ipython ICompass.py

My .pythonrc.py:

  1. sets up a tab for completion (use a single space to indent Python code),
  2. reads the history of the previous session, if it exists,
  3. sets up history saving on exit,
  4. cleans up the global name space,
  5. tries to make the PyQt and PyQwt widgets usable from the command line,
  6. tries to import SciPy, PyQt and Qwt,
  7. sets up the SciPy help for tab completion: help(scipy.optimize.leastsq).
and the code reads:
# Set your PYTHONSTARTUP environment variable to $HOME/.pythonrc.py
#
# inspired by:
# http://opag.ca/wiki/OpagSnippets?action=highlight&value=pythonrc

from atexit import register
from os import path
import readline
import rlcompleter

# Sets up a tab for completion (use a single space to indent Python code).
readline.parse_and_bind('tab: complete')

historyPath = path.expanduser(' /.python_history')
readline.set_history_length(1000)

# Reads the history of the previous session, if it exists.
if path.exists(historyPath):
    readline.read_history_file(historyPath)

# Sets up history saving on exit.
def save_history(historyPath=historyPath):
    import readline
    # why fails the next line to see the global readline?
    readline.write_history_file(historyPath)

register(save_history)

# Cleans up the global name space.
del register, path, readline, rlcompleter, historyPath, save_history

# Tries to make the PyQt and PyQwt widgets usable from the command line.
try:
    import iqt
    del iqt
except ImportError:
    pass

# Tries to import SciPy, PyQt and Qwt.
try:
    from scipy import *
    from qt import *
    from qwt import *
except ImportError:
    pass

# Sets up the SciPy help for tab completion: help(scipy.optimize.leastsq).
try:
    import scipy
except ImportError:
    pass

# Local Variables: ***
# mode: python ***
# End: ***