This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Python not handling cText
Type: Stage:
Components: macOS Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: jackjansen Nosy List: jackjansen, robinsiebler
Priority: normal Keywords:

Created on 2002-08-22 20:44 by robinsiebler, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
HelloWorld.sit robinsiebler, 2002-09-11 19:57 Use this file instead
Messages (9)
msg12104 - (view) Author: Robin Siebler (robinsiebler) Date: 2002-08-22 20:44
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.
msg12105 - (view) Author: Robin Siebler (robinsiebler) Date: 2002-08-22 20:48
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)))
msg12106 - (view) Author: Jack Jansen (jackjansen) * (Python committer) Date: 2002-09-11 15:02
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?
msg12107 - (view) Author: Robin Siebler (robinsiebler) Date: 2002-09-11 18:01
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.
msg12108 - (view) Author: Robin Siebler (robinsiebler) Date: 2002-09-11 18:37
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.
msg12109 - (view) Author: Robin Siebler (robinsiebler) Date: 2002-09-11 18:38
Logged In: YES 
user_id=572605

Oops!  I forgot to check the stupid (and unneccessary) checkbox.
msg12110 - (view) Author: Robin Siebler (robinsiebler) Date: 2002-09-11 19:57
Logged In: YES 
user_id=572605

I left out the python script.  I will upload a new file
msg12111 - (view) Author: Jack Jansen (jackjansen) * (Python committer) Date: 2002-09-11 21:56
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.
msg12112 - (view) Author: Jack Jansen (jackjansen) * (Python committer) Date: 2002-09-12 20:30
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".
History
Date User Action Args
2022-04-10 16:05:36adminsetgithub: 37072
2002-08-22 20:44:55robinsieblercreate