[Pythonmac-SIG] Accessing front window in IDE

Joseph J. Strout joe@strout.net
Fri, 8 Oct 1999 09:01:41 -0700


At 5:53 PM +0200 10/08/99, Jack Jansen wrote:

>Hmm, it would be nice to have a bit of an API for this that IDE extension
>scripts could use. If there was an easier interface than mucking around with
>the Window, PyEdit and waste internals that might prompt more people to write
>nifty little utilities.

That's a good point.  Seems like most of the time, you'd want to 
either change the text, or change the selection (e.g., if doing some 
sort of automatic search thing), or both.  That's pretty easy.

But then, what if somebody wants to write the "Reveal In Finder" 
script?  That requires access to the window path; text and selection 
range aren't enough.  So we add access to the path too; but what if 
there are other things we haven't thought of?

Still, I guess we could do better than the current state of things. 
Maybe something like this:

--------------------- hypothetical test code begins ---------------------
from FrontWinAPI import FrontWinAPI

# instantiate a front-window API object... automatically grabs text,
# selection range, path, etc.
win = FrontWinAPI()

# insert "Spam!" to the top, and also move the selection range accordingly
spam = "# Spam!\r"
win.text = spam + win.text
win.selStart = win.selStart + len(spam)
win.selEnd = win.selEnd + len(spam)

# that's it -- when win object dies, the front window is updated automagically
--------------------- hypothetical test code ends ---------------------

Is that the sort of thing you had in mind?

Cheers,
-- Joe

,------------------------------------------------------------------.
|    Joseph J. Strout           Biocomputing -- The Salk Institute |
|    joe@strout.net             http://www.strout.net              |
`------------------------------------------------------------------'