PyEdit is sufficiently powerful and robust to have served as the primary tool for coding
most of the examples in this book.
PyEdit supports all the usual mouse and keyboard text-editing operations: cut and
paste, search and replace, open and save, undo and redo, and so on. But really, PyEdit
is a bit more than just another text editor—it is designed to be used as both a program
and a library component, and it can be run in a variety of roles:
Standalone mode
As a standalone text-editor program, with or without the name of a file to be edited
passed in on the command line. In this mode, PyEdit is roughly like other text-
editing utility programs (e.g., Notepad on Windows), but it also provides advanced
functions such as running Python program code being edited, changing fonts and
colors, “grep” threaded external file search, a multiple window interface, and so
on. More important, because it is coded in Python, PyEdit is easy to customize,
and it runs portably on Windows, X Windows, and Macintosh.
Pop-up mode
Within a new pop-up window, allowing an arbitrary number of copies to appear
as pop ups at once in a program. Because state information is stored in class in-
stance attributes, each PyEdit object created operates independently. In this mode
and the next, PyEdit serves as a library object for use in other scripts, not as a canned
application. For example, Chapter 14’s PyMailGUI employs PyEdit in pop-up
mode to view email attachments and raw text, and both PyMailGUI and the pre-
ceding chapter’s PyDemos display source code files this way.
Embedded mode
As an attached component, to provide a text-editing widget for other GUIs. When
attached, PyEdit uses a frame-based menu and can optionally disable some of its
menu options for an embedded role. For instance, PyView (later in this chapter)
uses PyEdit in embedded mode this way to serve as a note editor for photos, and
PyMailGUI (in Chapter 14) attaches it to get an email text editor for free.
While such mixed-mode behavior may sound complicated to implement, most of
PyEdit’s modes are a natural byproduct of coding GUIs with the class-based techniques
we’ve seen in the last four chapters.
Running PyEdit
PyEdit sports lots of features, and the best way to learn how it works is to test-drive it
for yourself—you can run it by starting the main file textEditor.py, by running files
textEditorNoConsole.pyw or pyedit.pyw to suppress a console window on Windows,
or from the PyDemos and PyGadgets launcher bars described at the end of Chap-
ter 10 (the launchers themselves live in the top level of the book examples directory
tree). To give you a sampling of PyEdit’s interfaces, Figure 11-1 shows the main
PyEdit: A Text Editor Program/Object | 675