[Python-bugs-list] [ python-Bugs-598981 ] Python not handling cText

noreply@sourceforge.net noreply@sourceforge.net
Thu, 12 Sep 2002 13:30:20 -0700


Bugs item #598981, was opened at 2002-08-22 22:44
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=598981&group_id=5470

Category: Macintosh
Group: Platform-specific
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: Robin Siebler (robinsiebler)
Assigned to: Jack Jansen (jackjansen)
Summary: Python not handling cText

Initial Comment:
I have the following AppleScript which I have also converted 
to Python:

tell application "CodeWarrior IDE"
    activate
    open file file1
    disassemble file file2
    set xText to (get text of document 1)
end tell

I had some difficulty converting the last command into 
Python, but the below should work (or so I have been told):

import CodeWarrior, time

cw = CodeWarrior.CodeWarrior(start=1)
time.sleep(5)
cw.activate()
cw.open(file1)
cw.disassemble_file(file2)
time.sleep(5)
xtext = app('CodeWarrior IDE').document[1].text

However, instead of the text that I expect, xtext is equal to 
'app('CodeWarrior IDE').document[1].text.all'

Bill Fancher looked at CodeWarrior and said that it is 
returning cText which is not being handled by Python.

----------------------------------------------------------------------

>Comment By: Jack Jansen (jackjansen)
Date: 2002-09-12 22:30

Message:
Logged In: YES 
user_id=45365

As Bill Fancher explained this turns out to be an ideosyncracy in CodeWarrior (and possibly other TextEdit-related programs). The text of the window is actually multiple text runs. In this case there's only one, so the correct lines in Python to grab the text of the window is
txt = cw.get(CodeWarrior.editor_document(1).text(1))

AppleScript apparently has a workaround for this situation, but I think that for now I'll flag this as "won't fix".


----------------------------------------------------------------------

Comment By: Jack Jansen (jackjansen)
Date: 2002-09-11 23:56

Message:
Logged In: YES 
user_id=45365

I removed the "disassemble file" bit and did that manually (it indeed doesn't work in CW7) and ran the Python script under the debugger.

The strange thing is that the reply AppleEvent indeed does not have a "----" item (this is the return value), so cw.get() is "right" in returning None. (Note that the problem sketched by Bill Fancher, missing support for cText, would have shown up differently: you would have gotten an aetypes.Unknown('ctxt', data) object back).

If you want to see this for yourself run the script under the debugger. The last line, by the way, should be "text = cw.get(CodeWarrior.text(CodeWarrior.document(1)))"

After the aesend() call in cw.get() you'll see there's no ---- argument.

I vaguely remember about there being a second protocol for send replies to AppleEvents (maybe especially for big replies?) but a quick look through the documentation hasn't revealed anything. I'll ask on the SIG whether anyone has any ideas.


----------------------------------------------------------------------

Comment By: Robin Siebler (robinsiebler)
Date: 2002-09-11 21:57

Message:
Logged In: YES 
user_id=572605

I left out the python script.  I will upload a new file

----------------------------------------------------------------------

Comment By: Robin Siebler (robinsiebler)
Date: 2002-09-11 20:38

Message:
Logged In: YES 
user_id=572605

Oops!  I forgot to check the stupid (and unneccessary) checkbox.

----------------------------------------------------------------------

Comment By: Robin Siebler (robinsiebler)
Date: 2002-09-11 20:37

Message:
Logged In: YES 
user_id=572605

Here is a project, applescript and python script.  You will have to 
change the paths in the script to wherever you place the project.  
Also, there is a bug in the last line of the python script because I 
can't remember the exact syntax I had to use to capture the text 
from CodeWarrior.  Maybe you will have better luck than me.

----------------------------------------------------------------------

Comment By: Robin Siebler (robinsiebler)
Date: 2002-09-11 20:01

Message:
Logged In: YES 
user_id=572605

I will create a project and attach it, however, you cannot use 
CodeWarrior IDE 4.2.5 because there is are bugs in it that have 
to do with AppleEvents.  You have to use v 5.0 of the IDE.

----------------------------------------------------------------------

Comment By: Jack Jansen (jackjansen)
Date: 2002-09-11 17:02

Message:
Logged In: YES 
user_id=45365

Robin,
you have to give a more complete example. I can get neither the applescript nor the Python program to work. I've filled in valid filenames for file1 and file2, but the Applescript keeps giving the error "CodeWarrior IDE 4.2.5 got an error: Bad name for file. some object".

Could you maybe create a sample soucre file (plus project?) and the real AppleScript you used, and pack it all up?

----------------------------------------------------------------------

Comment By: Robin Siebler (robinsiebler)
Date: 2002-08-22 22:48

Message:
Logged In: YES 
user_id=572605

I made a typo:
    xtext = app('CodeWarrior IDE').document[1].text 
should be:
    xtext = cw.get(CodeWarrior.text(CodeWarrior.document(1)))


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=598981&group_id=5470