MacPython stuff
This is a loose collection of stuff I've made specifically for MacPython.
General Instructions
The Python files below must be saved as standard Macintosh text files, with Mac line endings. Unfortunately, some browsers feel the need to save them with Unix line endings. This is easily fixed with a text conversion utility, such as Cyclone (set the input type to "ISO/Western Latin-1", and the output encoding to "Macintosh/Western"; and in the Preferences, check "Remember last used encoding settings" and "Change line breaks to match output standard", and set the custom creator to "Pide"). There are many other tools which can convert line endings, but Cyclone is free and fast once you have it configured.
So the general procedure is to save the files below as source, then drop them on Cyclone (or your preferred conversion tool) to fix the line endings.
Printing Patch
This file patches PythonIDEMain.py and PyEdit.py to add printing support to the IDE. The printouts have 65 lines per page (in Profont 9, at least), with line numbers shown in gray to the left of each line.
Directions:
- Make sure you're using MacPython 1.5.2c1. I can't guarantee this will work on other versions (though it might).
- Download PatchUtils.py and PrintingPatch.py. Put
them into the same directory.
- Run PrintingPatch.py (either with the IDE, or with PythonInterpreter).
- Quit the IDE (if running), find BuildIDE.py (in Python 1.5.2c1:Mac:Tools:IDE), and double-click that.
That's it! If you re-run the patch, it will note that it's been applied before, and ask whether you want to restore from backup -- you should say yes, unless you've applied some other patches or customizations you don't want to lose. As long as you're willing to restore from backup, you can muck with the patch file and re-apply it as often as you wish.
Advanced Editor Patch
This file patches PyEdit.py to add several advanced features: syntax coloring,
function look-up, and more comin' later. Actually it only patches PyEdit.py a little bit; most of the real new functionality is implemented by a new "PyAdvancedEditor" module.
Directions:
- Make sure you're using MacPython 1.5.2c1. I can't guarantee this will work on other versions (though it might).
- Download PyAdvancedEditor.py, and put it into Python 1.5.2c1:Mac:Tools:IDE.
- Download PatchUtils.py and AdvancedEditorPatch.py. Put
them together into some working directory (the Desktop, whatever).
- Run AdvancedEditorPatch.py (either with the IDE, or with PythonInterpreter).
- Quit the IDE (if running), find BuildIDE.py (in Python 1.5.2c1:Mac:Tools:IDE), and double-click that.
That's it! If you re-run the patch, it will note that it's been applied before, and ask whether you want to restore from backup -- you should say yes, unless you've applied some other patches or customizations you don't want to lose.
Though both this one and the Printing Patch both affect PyEdit.py, you should be able to use them both together (or either one alone).
Syntax Coloring: This feature highlights keywords, strings, comments, etc. in various colors and styles. A new menu command in the pop-up menu above the vertical scrollbar lets you turn this on and off. This feature is still a work in progress; and has several limitations:
- It can get confused when multi-line strings are involved. If that happens, just turn coloring off and back on; that should fix it. (In the future we may have a command key to do this more quickly.)
- It assumes you have Profont installed, and want to use it. I can't imagine why you wouldn't, but if it's a problem let me know and we'll talk.
Function Look-up: This feature looks for doc strings for a function or class when you type a question mark ("?") after the function name in an editor window. For example, go into any IDE editor window at type "string?". The string.__doc__ will be printed to the output window. It also works for functions, e.g. "string.strip?". When the query is successful, the question mark is absorbed (not entered into the editor). If you really need to type the question mark after a known function, you'll have to type it first after a space, and then delete the space.
Better Chunking: The standard WASTE word-finding function isn't very appropriate for Python code; it breaks on underscores, doesn't break on periods, etc. AdvancedEditor gives you more Python-savvy chunks of text when you double-click. In addition, you can double-click a grouping character (a parenthesis, square bracket, curly brace, or quotation mark) to select the entire range delimited by that character. Note that the finding of quoted strings may not work correctly when triple-quoted strings are involved.
Option Click -- Function Look-up: This feature looks up the function or class name you option-click on, without moving the cursor.
Command Click -- Insert Chunk: When you command-click, the chunk of text at the location clicked is copied to the current cursor location. It's equivalent to double-clicking, doing a Copy, putting the cursor back to its previous location, and Paste (except that the clipboard is not modified). Because it uses the same chunking algorithm as double-clicking, this works nicely with grouping characters (like parentheses) too.
Command+Option -- Launch URL: by holding the command and option keys while clicking on a URL in the source code, the URL will be launched by Internet Config. This is equivalent to a command-click in the default IDE editor.
Note that the modifier key mappings are defined at the top of PyAdvancedEditor.py in a simple dictionary, so feel free to customize these to taste.
http://www.strout.net/info/coding/python/mac/index.html
Last Updated:
10/04/99
. . . . . .
webmaster@strout.net