1.3.1 Qwt4.iqt

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

Module Qwt4.iqt enables you to:

When Python has the GNU readline module, the Qwt4.iqt module 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.

When Python does not have the GNU readline module, the Qwt4.iqt module uses the techniques suggested on the PyQt mailing list and implemented in PyQt-4.3 (and later).

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 file loads the modules readline and rlcompleter. Then, it configures readline for tab-completion and history saving and cleans up the global namespace. Finally, it loads the modules numpy, scipy, qt, Qwt4.iqt, Qwt4.Qwt and Qwt4.qplt:

# Set your PYTHONSTARTUP environment variable to $HOME/.pythonrc.py
#
# inspired by:
# http://opag.ca/wiki/OpagCode/OpagSnippets

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, readline=readline):
    readline.write_history_file(historyPath)

register(save_history)

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

# Tries to import NumPy  and SciPy
try:
    import numpy as np
    import scipy as sp
    sp.pkgload()
except ImportError:
    pass

# Tries to import qt, Qwt4.iqt, Qwt4.Qwt and Qwt4.qplt
try:
    import qt
    import Qwt4.iqt
    import Qwt4.Qwt as qwt
    import Qwt4.qplt as qplt
except ImportError:
    pass

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