Pythonwin GUI Environment

This document describes the Pythonwin GUI environment. There are quite a few little features hidden away!

It has a discussion on the General Environment (including the Interactive Window and Menu and Toolbar), and the Command Line Arguments supported.

General Environment

Interactive Window

The Interactive Window is a little Python program which simulates the built-in Python interpreter. It is implemented in intpyapp.py (which in turn uses winout.py - a general purpose "output window".)

Pressing Enter

Whenever you press Enter, the interactive window has a look at the context, to try and decide what to do.

If the line is recognised as a "block" (ie, the first line starts with ">>> ", and the rest start with "… "), it checks to see if we are at the end of the window. If not, the block is copied to the end of the buffer - nothing is executed - enter must be pressed again to force execution.

If we are at the end of the buffer, it always attempts to execute the line. If Python indicates "unexpected end of file", then it assumes the block should continue, and emits the "… " for the next line.

If the line is recognised as part of a Python exception, then some special processing is done. If the line contains a filename and line number, it locates that file, and jumps to the offending line.

If the line is recognised as being an exception generated by COM (aka OLE), and the exception contains reference to a WinHelp file, the help topic is opened.

Menu and Toolbar

File Open/Close/Save/Print/etc.

All perform the obvious file operations. Pythonwin follows the standard MFC framework, and allows Python programs to plug-in support for other file types.

Locate File

Allows quick location of a Python scripts. Typing in the base name of a file will force a search of all the directories on sys.path, until a match is found.

To locate a module in a package, use a (back) slash instead of a dot - eg, to locate "win32com.client.dynamic", type in "win32com\client/dynamic"

Import Script

Imports or reloads a script - just like "import scriptname"/"reload(scriptname)" - (Pythonwin determines if the operation is an import or reload, It also handles "ni" modules with some success!)

If you select this (or use <Ctrl-I>) when a .py file is open, that file is saved and imported. If a current file can not be located, it will ask for a file to import via a File dialog.

If a syntax error occurs, the location will be moved to in the editor.

Run Script

Runs a script, as if the file was passed on the command line. A dialog is opened, asking the script name and arguments (unless the <Shift> key is held down)

Command Line Arguments

The following command line arguments are recognised. Note that these are implemented in "intpyapp.py", so should be pretty easy to change!

/run scriptname args

Runs the named script. Works just like "Python.exe scriptname args", except it is run in the GUI environment, and output goes to the interactive window.

/runargs scriptname args

As above, except the normal Pythonwin 'Run Script' dialog is shown.

/edit filename.py

Edits the filename. The /edit is currently optional, but in the future, the "default argument handling" may be changed.

/app specialscriptname args

Runs a special "application script". The application script can change the entire look and feel of a Pythonwin program - almost as much flexibility as the C++ programmer has when they first start their application). An example of this is "dlgapp.py" in the Pythonwin distribution.