Re: [Pythonmac-SIG] TKinter problem

2005-10-26 Thread Mark Asbach
Hi Toby,

> Tkinter command I get a "no display name and no $DISPLAY environment
> variable" error, e.g.

obviously, you are using a version of Tkinter that relies on the X11  
Window environment. Just start your python code from apple's / 
Applications/Utilities/X11.app or one of the open source X11 window  
servers for OS X.

Yours, Mark
-
   Dipl.-Ing. Mark Asbach  Tel +49 (0)241 80-27677
   Institute of Communications Engineering Fax +49 (0)241 80-22196
   RWTH Aachen University, Germany  http://www.ient.rwth-aachen.de



___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


[Pythonmac-SIG] [q] Help with choosing "right" python port

2005-10-26 Thread Neal Carpenter
Title: [Pythonmac-SIG] [q] Help with choosing "right"
python port


The problem: From within IDLE, I type:

from turtle import *
reset()

I then get a small window, titled tk, and a new 'console'
window. When I move the cursor to either of these I get a spinning
rainbow disk, and am unable to enlarge the tk window. This does not
happen when I use Terminal.

I want to use IDLE (for ease of use) and turtle graphics (for
motivation) to teach programming to my 6th, 7th, and 8th graders. Am I
doing something wrong? Is this a problem with IDLE? Is there a fix or
a work-around? (I'm very new to Python myself and have warned my
students that I'll be learning it from them, as they learn from
me.)

Also, what is the 'Console' window for? I've tried typing in it
only to get error messages.

This started while I was using Jack Jensen's IDLE, and Tiger's
built-in Python (2.3.5?); I've spent most of the day searching for a
solution and came upon your name in Pythonmac-SIG. So I got to your
site, downloaded and ran 2.4.1 and the TigerPython24Fix, only to find
that the exact same thing still happens - import turtle stuff, invoke
any turtle word, and find a small window that 'works' (the turtle
moves around, on command) but that cannot be enlarged (still the
swirling rainbow disk).

Thanks for your time - any help would be greatly
appreciated.

-- 

Stay in Touch!

Neal
Carpenter 
Search for the Eternal.
[EMAIL PROTECTED]    Find it ... In the
Search.

___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] obj in MacPython and Appscript

2005-10-26 Thread has
Zhi Peng wrote:
 
>When I used appscript, I often try to print out the object or string while I 
>debug the program. For example:
>cs = app('TextEdit').documents[1].paragraphs[1]
>print cs
>I assumed that cs should be anObject of paragraphs.
>But it print out as
> 
>app('TextEdit').documents[1].paragraphs[1]
> 
>instead of specific python object.

In fact, this is a specific python object, just not the one you expected. It's 
an instance of appscript's Specifier class, which represents a first-class 
query identifying the first paragraph of the first document of the TextEdit 
application. Run 'print type(cs)' to see this. Like a lot of Python objects, 
Specifier instances use their __repr__ method to return a meaningful 
representation of itself ("app('TextEdit').documents[1].paragraphs[1] ") rather 
than a literal one (""). What it doesn't 
do is resolve this query itself a-la AppleScript's "implicit get"; you have to 
command it to do so yourself.

Please bear in mind that appscript is mostly just a big lump of OO-like 
syntactic sugar atop a procedural+query driven API, and the rules by which it 
operates are not the same as either AppleScript's (for application scripting) 
or Python's (for object-oriented programming). This point is made in the 
appscript manual, although I'm still trying to find a big enough font to 
display it in. ;)


>If one would like to get the actual
>reference of the paragraphs[1] object, what should I do? Anyone knew?
>if one uses following, it may get sth for 'TextEdit'
>app('TextEdit').documents[1].paragraphs[1].get()
> 
>But some other application does not have 'get' for documents[1] or
>paragraphs[1]. In this case, is there way that I can catch the object?

Not all applications bother to list get() and set() commands in their 
terminology documentation, but as long as they have an object model they will 
respond to these commands - where necessary, appscript will provide default 
definitions.


>For example, in Adobe InDesign CS2, I could have
> 
> 
>cs = app('Adobe InDesign CS2')
>doc=cs.open("mydoc.indd") <--- just example
>doc = cs.active_document
>page = doc.pages[1]
>print page  <- this does not show object

As stated above, it will show you the representation of the Specifier instance 
assigned to the 'page' variable.


>anObject=page.get()  <- this may raise exception
 
This should work, assuming that you do actually have an active document with at 
least one page in it, and ID doesn't have any bugs that prevent it resolving 
that reference correctly. That said, I do remember ID's dictionary being 
particularly warty with respect to get() and set(), defining both standard AND 
non-standard versions of these commands. I can't remember how well older 
versions of appscript resolved this problem, and I don't have a copy of ID here 
to test on, but the latest version will correctly disambiguate things by 
appending underscores to the non-standard definitions so they appear as get_() 
and set_(), allowing the standard get() and set() to be used as normal.

The source distribution is at 
 if you 
want to remove your existing installation (which I assume was created by 
Appscript Installer, which is a couple releases behind) and build a fresh 
installation from scratch. Sorry it's such a pain in the butt, but I will get 
an up-to-date binary installer done at some point; it's just a matter of 
finding the time, etc.


>2. By the way, I get a little confused with following command
>application.make(...) -- Make a new element

'make' is often one of the worst-documented commands that application scripters 
will encounter, so you're by no means alone in your confusion. Go file a 
feature request for better documentation with the application's developer, and 
meantime get used to figuring it out by asking other users, pulling apart any 
sample scripts you can find, and plain old trial-and-error.


>[new=Type] -- The class of the item to be created
>[at=InsertionRef] -- The location at which to insert the item
>[with_data=Record] -- The initial data for the item
>[with_properties=Record] -- Initial values for properties of the new object
>Result: Reference -- The new object(s)
>
>I guess that 'new' may be sth like new=text_frame or new=document

That should read:

new=k.text_frame

or:

new=k.document

since all Apple Event Manager-defined types and application-defined 
types/classes exist as attributes of the k namespace.


>at=cs.documents[1].sth
>What was the with_data=Record and with_properties? 
 
The 'with_properties' parameter allows you to specify initial values for some 
or [depending on the application] all of the properties of the object being 
created. For example:

app('TextEdit').documents.end.make(
new=k.document,
with_properties={k.text: 'Hello World'})

will create a new document in TextEdit and set its text property to 'He

Re: [Pythonmac-SIG] [q] Help with choosing "right" python port

2005-10-26 Thread Kent Quirk
Title: [Pythonmac-SIG] [q] Help with choosing "right" python port








The thing to realize is that IDLE is a TK
application…and so is the turtle graphics. They conflict. There are
apparently workarounds, but I’m not a TK weenie. There’s some
information here:

 

http://rlai.cs.ualberta.ca/RLAI/RLsoftware/PythonLinks.html

 

Consider teaching kids to use a text
editor instead of typing things into IDLE. They can write and save programs and
run them pretty easily. SubEthaEdit is free for noncommercial use and could
even let kids collaborate on writing programs together from separate machines.

 

Try this program, for example:

 

import turtle 

import random

 

turtle.reset()

 

turtle.down()

for i in
xrange(100):

   
dist = random.randint(5, 15)

   
angle = random.randint(-135, 135)

   
turtle.forward(dist)

   
turtle.right(angle)

turtle.up()

 

Save it into a .py file, then run python
on it. 

 

Once you get a decent editor set up, it’s
a lot easier and more scalable than monkeying with IDLE anyway.

 

You might also consider something like
PyGame, depending on the sophistication and interests of your students.

 

 Kent


 









From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Neal Carpenter
Sent: Sunday, October 23, 2005
4:22 PM
To: pythonmac-sig@python.org
Subject: [Pythonmac-SIG] [q] Help
with choosing "right" python port



 



The problem: From within IDLE, I type:

from turtle import *
reset()





I then get a small window,
titled tk, and a new 'console' window. When I move the cursor to either of
these I get a spinning rainbow disk, and am unable to enlarge the tk window.
This does not happen when I use Terminal.





 





I want to use IDLE (for ease of use) and turtle graphics (for
motivation) to teach programming to my 6th, 7th, and 8th graders. Am I doing
something wrong? Is this a problem with IDLE? Is there a fix or a work-around?
(I'm very new to Python myself and have warned my students that I'll be
learning it from them, as they learn from me.)





 





Also, what is the 'Console' window for? I've tried typing in it only to
get error messages.





 





This started while I was using Jack Jensen's IDLE, and Tiger's built-in
Python (2.3.5?); I've spent most of the day searching for a solution and came
upon your name in Pythonmac-SIG. So I got to your site, downloaded and ran
2.4.1 and the TigerPython24Fix, only to find that the exact same thing still
happens - import turtle stuff, invoke any turtle word, and find a small window
that 'works' (the turtle moves around, on command) but that cannot be enlarged
(still the swirling rainbow disk).





 





Thanks for your time - any help would be greatly appreciated.





 



-- 



Stay in Touch!

Neal
Carpenter 
Search for the Eternal.
[EMAIL PROTECTED]   
Find it ... In the Search.








___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] [OT] Quicktime/Buffer API

2005-10-26 Thread Chris Barker
michael ferraro wrote:
> I need to eliminate any copies of a PixMaps used
> by  a Quicktime Movie that I am texture mapping
> with OpenGL.  I have built an extension in "C" but
> I am a bit unclear as to how to "circumvent" the the
> copy done by Py_BuildValue.
> 
> I was wondering if any one has any experience
> or advice on how to approach this. Is the Buffer
> Object/API the right way to go? or is there
> another approach

What form is the data in in your c code? A pointer to simple C array?

If so, the buffer object could work, or you could build a NumPy array. I 
think PyOpenGL can work with them natively. If you want to got hat 
route, the situation is pretty confusing as there are now three (count 
'em three!) implementations, Numeric, numarray, and the new SciPy.base. 
I'd go with whatever PyOpenGL supports, or, if you have the option, and 
can tolerate beta code, Scipy.base. With any luck it will be the next 
generation NumPy.

http://numeric.scipy.org/

SciPy.base has also introduced  a new "array protocol/interface", which 
I think has been back ported to both Numeric and numarray:

http://numeric.scipy.org/array_interface.html

This was designed with just this kind of use in mind.

-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer

NOAA/OR&R/HAZMAT (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

[EMAIL PROTECTED]
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] [OT] Quicktime/Buffer API

2005-10-26 Thread michael ferraro
The data is a simple unsigned char *
so thanks for the leads.


M


On Oct 26, 2005, at 1:02 PM, Chris Barker wrote:

> michael ferraro wrote:
>
>> I need to eliminate any copies of a PixMaps used
>> by  a Quicktime Movie that I am texture mapping
>> with OpenGL.  I have built an extension in "C" but
>> I am a bit unclear as to how to "circumvent" the the
>> copy done by Py_BuildValue.
>>
>> I was wondering if any one has any experience
>> or advice on how to approach this. Is the Buffer
>> Object/API the right way to go? or is there
>> another approach
>>
>
> What form is the data in in your c code? A pointer to simple C array?
>
> If so, the buffer object could work, or you could build a NumPy  
> array. I
> think PyOpenGL can work with them natively. If you want to got hat
> route, the situation is pretty confusing as there are now three (count
> 'em three!) implementations, Numeric, numarray, and the new  
> SciPy.base.
> I'd go with whatever PyOpenGL supports, or, if you have the option,  
> and
> can tolerate beta code, Scipy.base. With any luck it will be the next
> generation NumPy.
>
> http://numeric.scipy.org/
>
> SciPy.base has also introduced  a new "array protocol/interface",  
> which
> I think has been back ported to both Numeric and numarray:
>
> http://numeric.scipy.org/array_interface.html
>
> This was designed with just this kind of use in mind.
>
> -Chris
>
>
>
> -- 
> Christopher Barker, Ph.D.
> Oceanographer
>
> NOAA/OR&R/HAZMAT (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115   (206) 526-6317   main reception
>
> [EMAIL PROTECTED]
> ___
> Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig
>

___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


[Pythonmac-SIG] get reference

2005-10-26 Thread Zhi Peng
Hi! All 

First of all, Thanks for all your answers for my
qestions. 

1. In appscript commands set, I often see something
like 

reference.bring_to_front()
reference.extract_label()
application.open()
...
etc

Application can accept all commands it should accept
and respond to the commands. 

I knew the 'application" is 'app("Adobe InDesign
CS2")' but what is the reference? I assume it is
anObject or python object. How could we get the
reference? Because all we get is something with type
appscript.specifier.specifier. It seems not an Object
as Has's mail mentioned. With the specifier, one may
not be able to send commands to it. 
For example, 
page = app("Adobe InDesign
CS2").open("filename").pages[0]

This 'page' is not a reference, which can not accept
any command that page object should accept.

Is there any way that I can convert or get the
reference or object instead of specifier?  I would
like to hold that reference object.

Thanks 

  



__ 
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] get reference

2005-10-26 Thread has
Zhi Peng wrote:

>page = app("Adobe InDesign
>CS2").open("filename").pages[0]
>
>This 'page' is not a reference,

It is, although it's an invalid one as elements must be 1-indexed, not 
0-indexed.

has
-- 
http://freespace.virgin.net/hamish.sanderson/
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] [q] Help with choosing "right" python port

2005-10-26 Thread Chris Barker
Kent Quirk wrote:
> The thing to realize is that IDLE is a TK application...and so is the
> turtle graphics. They conflict.

Huh? I thought you could run TK apps form IDLE, and indeed that the 
newer IDLE ran the app in separate process, just to avoid this kind of 
problem!

However, IDLE and TkInter have never been all that well supported on 
OS-X, so I agree:

> Consider teaching kids to use a text editor instead of typing things
> into IDLE.

TextWrangler is another freely available option. PyOxide would be great, 
if it's bug-free enough to be generally usable. I haven't checked it out 
for while, nor heard reports. there are also a number of cross-platform 
options: Dr. Python, SPE, etc. I think the SPE developer just got some 
funding to make SPE work better on OS-X, so that's promising.

Also check out PythonCard, which I think includes a version of Turtle 
graphics as well.

-Chris

-- 
Christopher Barker, Ph.D.
Oceanographer

NOAA/OR&R/HAZMAT (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

[EMAIL PROTECTED]
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] [OT] Quicktime/Buffer API

2005-10-26 Thread Chris Barker
michael ferraro wrote:
> The data is a simple unsigned char *

Thats just what NumPy's ArrayFromDimsAndData() (or something like that) 
expects. However, one issue is that if you don't copy the data, then 
it's hard to have Python manage the garbage collection, you need to 
figure out how (and when!) to free it yourself.

-Chris
-- 
Christopher Barker, Ph.D.
Oceanographer

NOAA/OR&R/HAZMAT (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

[EMAIL PROTECTED]
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] get reference

2005-10-26 Thread Zhi Peng
Yes. When I run TextEdit, it works with following code


from appscript import * 
textedit=app('TextEdit')
textedit.activate()
textedit.documents.end.make(new=k.document)
textedit.documents[1].text.set("TEXT STRING")
print textedit.documents[1].text.get()


It works well. But with app('Adobe InDesign CS2'), it
does not work well. All application can accept the
commands but not the reference such as 

cs = app("Adobe InDesign CS2")
cs.activate()   - works
cs.open("filepath_with_name")   --- works
doc = cs.documents[0]  works 
page = doc[1]   works 
textframe=page.textframes[1]  --- works 
textframe.contents.set("HELLO") -- not work
textframe.contents="HELLO"  -- not work 
textframe.contents.get() -- not work 

contents is a property of textframe with r/w


I wonder if I missed something since I get only a
small __init__.py file while I used pythonw
getsuitmodule.py for Adobe InDesign CS2. But same
command applied to TextEdit and Finder, iTune, I get a
few big file include __init__.py. 




--- has <[EMAIL PROTECTED]> wrote:

> Zhi Peng wrote:
> 
> >page = app("Adobe InDesign
> >CS2").open("filename").pages[0]
> >
> >This 'page' is not a reference,
> 
> It is, although it's an invalid one as elements must
> be 1-indexed, not 0-indexed.
> 
> has
> -- 
> http://freespace.virgin.net/hamish.sanderson/
> ___
> Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
>
http://mail.python.org/mailman/listinfo/pythonmac-sig
> 





__ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


[Pythonmac-SIG] apple script and MacPython code

2005-10-26 Thread Zhi Peng
Hi! All 
 
I strongly believe that MacPython can be used to write similar code to perform Applescript code functions. I try to find corresponding MacPython code for apple script. For example following adobe apple script code 
 
tell application "Adobe InDesign CS2"
    set myDoc to make document
tell myDoc 
    tell page 1 
    set myTextFrame to make text frame 
    set geometric bounds of myTextFrame to {"6p0","6p0","18p0","18p0"}
    set contents of myTextFrame to "HELLO"
   end tell
    end tell
end tell 
 
I can run this script and set text frame on ID document. Now the questions are: 
1. we can create MacPython obj say cs = app("Adobe InDesign CS2")
2. Then from cs we could have myDoc=cs.open(filename)
    How do we make a new document by using MacPython code??
    From appscript help, we can get some description like : 
 
    application.make(...)  make new element
    [new=Type]   The class of the item to be created 
    [at =InsertionRef] The location at which to insert the item 
    [with_data=record] --- the initialial data for the item
    [with_properties=Record] -- Initialial value for the properties of the new object 
    result reference
 
    The question is "Do I need fill all 4 paramters in order to create a item?" I kew the type could be k.document, etc. 
    On Adobe InDesign manual, there is no make method for application, I wonder if application will accept the commands. 
 
3. I can write something like 
 
 cs.active_document.pages[1].text_frames[1]
 
   and execute it without error. 
 
   But how can one get the information from 
    cs.active_document.pages[1].text_frames[1].contents
   here cs is app("Adobe InDesign CS2")
 
 
  If I print cs.active_document.pages[1].text_frames[1].contents, it should print out empty string or some string based on content. But it print out 
 app("Adobe InDesign CS2").active_document.pages[1].text_frames[1].contents
 
 
 
   In TextEdit, we can use get() and set(). I do not know what command one needs to send cs.active_document.pages[1].text_frames[1].contents
 
in order to get the information. 
 
Thanks for all your help. __Do You Yahoo!?Tired of spam?  Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] get reference

2005-10-26 Thread has
Zhi Peng wrote:

>But with app('Adobe InDesign CS2'), it
>does not work well. All application can accept the
>commands but not the reference such as
>
>cs = app("Adobe InDesign CS2")
>cs.activate()   - works
>cs.open("filepath_with_name")   --- works
>doc = cs.documents[0]  works

Shouldn't work, because elements of application objects are always 1-indexed. 
(It's not impossible that a scriptable app might try to 'helpfully' interpret a 
0 index rather than just flagging it as an error, but I'm not aware of any that 
do.) However, note that a bad reference won't raise an error until you actually 
use it in a command, at which point the application will raise an Apple event 
error of [usually] type -1728 which appscript reports as a CommandError.


>page = doc[1]   works

I think you meant 'page = doc.pages[1]'


>textframe.contents="HELLO"  -- not work

Not supported.


The following should work, assuming it's semantically correct and identifies an 
existing object:

cs.documents[1].pages[1].textframes[1].contents.set("HELLO")

If it doesn't, check the AppleScript equivalent just to make sure that it works:

tell application "Adobe InDesign CS2"
set contents of textframe 1 of page 1 of document 1 to "HELLO"
end tell

Then tell me what version of appscript you're using and post a traceback so I 
can see what the error actually is. Like I say, it may just be that you need to 
upgrade to the latest version of appscript, though I'd like to make sure it's 
not something else.


>I wonder if I missed something since I get only a
>small __init__.py file while I used pythonw
>getsuitmodule.py for Adobe InDesign CS2. But same
>command applied to TextEdit and Finder, iTune, I get a
>few big file include __init__.py.

I wouldn't know about that. gensuitemodule has always been rather flaky and 
clumsy; however, appscript has no connection to it or aetools/aepack/aetypes.

has
-- 
http://freespace.virgin.net/hamish.sanderson/
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] get reference

2005-10-26 Thread Zhi Peng
Hi! 'Has" 

First of all, thank you very much for your help. 

tell application "Adobe InDesign CS2" 
   set contents of text frame 1 of page 1 of document
1 to "Hello"
end tell 

works well. (textframe -> text frame in adobe)

But Corresponding MacPython code does not work well
where I used appscript 1.1 (3.7 MB). Should I use
other version of Appscript? 

Following is the information I used debug. 


>
/Users/zpeng/Documents/projects/set_text_frame.py(44)?()
->
cs.documents[1].pages[1].text_frames[1].contents.set("set
the frame")
(Pdb) n
CommandError:
appscript.CommandError(app(u'/Applications/Adobe
InDesign CS2/Adobe InDesign
CS2.app').documents[1...ext_frames[1].contents.set,
(('set the frame',), {}), )
>
/Users/zpeng/Documents/projects/set_text_frame.py(44)?()
->
cs.documents[1].pages[1].text_frames[1].contents.set("set
the frame")
(Pdb)
cs.documents[1].pages[1].text_frames[1].contents.get()
(Pdb) print
cs.documents[1].pages[1].text_frames[1].contents.get()
None






But it is much better than that before. 


Regards 

Zhi 






--- has <[EMAIL PROTECTED]> wrote:

> Zhi Peng wrote:
> 
> >But with app('Adobe InDesign CS2'), it
> >does not work well. All application can accept the
> >commands but not the reference such as
> >
> >cs = app("Adobe InDesign CS2")
> >cs.activate()   - works
> >cs.open("filepath_with_name")   --- works
> >doc = cs.documents[0]  works
> 
> Shouldn't work, because elements of application
> objects are always 1-indexed. (It's not impossible
> that a scriptable app might try to 'helpfully'
> interpret a 0 index rather than just flagging it as
> an error, but I'm not aware of any that do.)
> However, note that a bad reference won't raise an
> error until you actually use it in a command, at
> which point the application will raise an Apple
> event error of [usually] type -1728 which appscript
> reports as a CommandError.
> 
> 
> >page = doc[1]  
> works
> 
> I think you meant 'page = doc.pages[1]'
> 
> 
> >textframe.contents="HELLO"  -- not work
> 
> Not supported.
> 
> 
> The following should work, assuming it's
> semantically correct and identifies an existing
> object:
> 
>
cs.documents[1].pages[1].textframes[1].contents.set("HELLO")
> 
> If it doesn't, check the AppleScript equivalent just
> to make sure that it works:
> 
> tell application "Adobe InDesign CS2"
>   set contents of textframe 1 of page 1 of document 1
> to "HELLO"
> end tell
> 
> Then tell me what version of appscript you're using
> and post a traceback so I can see what the error
> actually is. Like I say, it may just be that you
> need to upgrade to the latest version of appscript,
> though I'd like to make sure it's not something
> else.
> 
> 
> >I wonder if I missed something since I get only a
> >small __init__.py file while I used pythonw
> >getsuitmodule.py for Adobe InDesign CS2. But same
> >command applied to TextEdit and Finder, iTune, I
> get a
> >few big file include __init__.py.
> 
> I wouldn't know about that. gensuitemodule has
> always been rather flaky and clumsy; however,
> appscript has no connection to it or
> aetools/aepack/aetypes.
> 
> has
> -- 
> http://freespace.virgin.net/hamish.sanderson/
> ___
> Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
>
http://mail.python.org/mailman/listinfo/pythonmac-sig
> 





__ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] apple script and MacPython code

2005-10-26 Thread has
Zhi Peng wrote:

>I strongly believe that MacPython can be used to write similar code to perform 
>Applescript code functions. I try to find corresponding MacPython code for 
>apple script. For example following adobe apple script code
> 
>tell application "Adobe InDesign CS2"
>set myDoc to make document
>tell myDoc
>tell page 1
>set myTextFrame to make text frame
>set geometric bounds of myTextFrame to {"6p0","6p0","18p0","18p0"}
>set contents of myTextFrame to "HELLO"
>   end tell
>end tell
>end tell

Python equivalent:

#!/usr/bin/pythonw
from appscript import *

id = app("Adobe InDesign CS2")
myDoc = id.make(new=k.document)
myTextFrame = id.make(new=k.text_frame, at=myDoc.pages[1])
myTextFrame.geometric_bounds.set(["6p0","6p0","18p0","18p0"])
myTextFrame.contents.set("HELLO")


>I can run this script and set text frame on ID document. Now the questions are:
>1. we can create MacPython obj say cs = app("Adobe InDesign CS2")
>2. Then from cs we could have myDoc=cs.open(filename)
>How do we make a new document by using MacPython code??
>From appscript help, we can get some description like :
> 
>application.make(...)  make new element
>[new=Type]   The class of the item to be created
>[at =InsertionRef] The location at which to insert the item
>[with_data=record] --- the initialial data for the item
>[with_properties=Record] -- Initialial value for the properties of the new 
> object
>result reference
> 
>The question is "Do I need fill all 4 paramters in order to create a item?"

You supply the same parameters as you would if you were using AppleScript.


>On Adobe InDesign manual, there is no make method for application, I 
> wonder if application will accept the commands.

All commands are ultimately handled by the application object. Both AppleScript 
and appscript allow various bits of syntactic jiggery-pokery to make it look 
like you're sending a command to other objects, e.g.

tell application "TextEdit"
tell document 1
set text to "hello"
end tell
end tell


app('TextEdit').documents[1].text.set('hello')


but these are merely convenience forms and under the surface both languages 
translate this to (pseudocode):

application("TextEdit").set(
root.elementByIndex('document', 1).property('text'),
to="hello")

This stuff is explained in the appscript manual, so if you've not read it 
already then now's a good time to do so. If you have trouble understanding the 
manual, please let me know what's missing or unclear so I can improve it for 
the next release.


>3. I can write something like
> 
> cs.active_document.pages[1].text_frames[1]
> 
>   and execute it without error.
> 
>   But how can one get the information from
>cs.active_document.pages[1].text_frames[1].contents
>   here cs is app("Adobe InDesign CS2")
> 
> 
>  If I print cs.active_document.pages[1].text_frames[1].contents, it should 
> print out empty string or some string based on content.

No, it won't. This is covered in the manual, and I've just explained it again 
in the 'get references' thread. You're making incorrect assumptions based on 
your prior knowledge of how AppleScript and/or Python OOP references work. 
Regardless of any visual similarity, appscript references are NOT the same 
thing and they *follow their own, well-defined rules*.

Appscript's rules regarding get() and set() are logical and consistent and work 
well in practice [1], but you do need to learn those rules in order to use it 
effectively, otherwise you'll just confuse the heck out of yourself. (FWIW, 
you're not the first person to make this mistake and you'll no doubt be the 
last, but I am working on making the documentation clearer about this issue.)

has

p.s. Please keep further discussion of your get() and set() problems with 
InDesign to the existing 'get references' thread to avoid confusion.

-

[1] In fact, it's impossible for appscript to do 'implicit gets' a-la 
AppleScript due to the way the Python interpreter operates. AppleScript manages 
to pull such tricks only through deep magic that runs throughout the core 
language, but there's no way I'm hacking Python's bytecode interpreter to 
emulate it.
-- 
http://freespace.virgin.net/hamish.sanderson/
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] get reference

2005-10-26 Thread has
Zhi Peng wrote:

>But Corresponding MacPython code does not work well
>where I used appscript 1.1 (3.7 MB). Should I use
>other version of Appscript?

Probably would be a good idea. If you're on Panther you'll need to build it 
from scratch, I'm afraid, though I can supply binaries for Jaguar and Tiger. (I 
should have a copy of Panther next month.)


>Following is the information I used debug.
>
>
>(Pdb) n
>CommandError:
>appscript.CommandError(app(u'/Applications/Adobe
>InDesign CS2/Adobe InDesign
>CS2.app').documents[1...ext_frames[1].contents.set,
>(('set the frame',), {}), instance at 0x13fd0d0>)

Wouldn't mind knowing a bit more about the TypeError within that CommandError, 
if you could get its string representation instead; e.g.:

try:
cs.documents[1].pages[1].text_frames[1].contents.set("set the 
frame")
except Exception, e:
print str(e)

Thanks,

has
-- 
http://freespace.virgin.net/hamish.sanderson/
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] get reference

2005-10-26 Thread Zhi Peng

Hi! "Has" 
I run the MacPython script, the only error is in the
set geometric_bounds as following where I used
appscript 1.1. It seems better than previous version. 
Thanks 

zhi-pengs-power-mac-g5:~/Documents/projects zpeng$
pythonw has.py >error.txt
Traceback (most recent call last):
  File "has.py", line 14, in ?
   
myTextFrame.geometric_bounds.set(["6p0","6p0","18p0","18p0"])
  File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/appscript/specifier.py",
line 179, in __call__
raise CommandError(self, (args, kargs), e)
appscript.specifier.CommandError: Too many direct
arguments.
Failed command: app(u'/Applications/Adobe
InDesign CS2/Adobe InDesign
CS2.app').documents[u'Untitled-1'].spreads.ID(146).pages.ID(151).text_frames.ID(179).geometric_bounds.set(['6p0',
'6p0', '18p0', '18p0'])
zhi-pengs-power-mac-g5:~/Documents/projects zpeng$ vi
error.txt


--- Zhi Peng <[EMAIL PROTECTED]> wrote:

> Hi! 'Has" 
> 
> First of all, thank you very much for your help. 
> 
> tell application "Adobe InDesign CS2" 
>set contents of text frame 1 of page 1 of
> document
> 1 to "Hello"
> end tell 
> 
> works well. (textframe -> text frame in adobe)
> 
> But Corresponding MacPython code does not work well
> where I used appscript 1.1 (3.7 MB). Should I use
> other version of Appscript? 
> 
> Following is the information I used debug. 
> 
> 
> >
>
/Users/zpeng/Documents/projects/set_text_frame.py(44)?()
> ->
>
cs.documents[1].pages[1].text_frames[1].contents.set("set
> the frame")
> (Pdb) n
> CommandError:
> appscript.CommandError(app(u'/Applications/Adobe
> InDesign CS2/Adobe InDesign
> CS2.app').documents[1...ext_frames[1].contents.set,
> (('set the frame',), {}),  instance at 0x13fd0d0>)
> >
>
/Users/zpeng/Documents/projects/set_text_frame.py(44)?()
> ->
>
cs.documents[1].pages[1].text_frames[1].contents.set("set
> the frame")
> (Pdb)
>
cs.documents[1].pages[1].text_frames[1].contents.get()
> (Pdb) print
>
cs.documents[1].pages[1].text_frames[1].contents.get()
> None
> 
> 
> 
> 
> 
> 
> But it is much better than that before. 
> 
> 
> Regards 
> 
> Zhi 
> 
> 
> 
> 
> 
> 
> --- has <[EMAIL PROTECTED]> wrote:
> 
> > Zhi Peng wrote:
> > 
> > >But with app('Adobe InDesign CS2'), it
> > >does not work well. All application can accept
> the
> > >commands but not the reference such as
> > >
> > >cs = app("Adobe InDesign CS2")
> > >cs.activate()   - works
> > >cs.open("filepath_with_name")   --- works
> > >doc = cs.documents[0]  works
> > 
> > Shouldn't work, because elements of application
> > objects are always 1-indexed. (It's not impossible
> > that a scriptable app might try to 'helpfully'
> > interpret a 0 index rather than just flagging it
> as
> > an error, but I'm not aware of any that do.)
> > However, note that a bad reference won't raise an
> > error until you actually use it in a command, at
> > which point the application will raise an Apple
> > event error of [usually] type -1728 which
> appscript
> > reports as a CommandError.
> > 
> > 
> > >page = doc[1]  
> > works
> > 
> > I think you meant 'page = doc.pages[1]'
> > 
> > 
> > >textframe.contents="HELLO"  -- not work
> > 
> > Not supported.
> > 
> > 
> > The following should work, assuming it's
> > semantically correct and identifies an existing
> > object:
> > 
> >
>
cs.documents[1].pages[1].textframes[1].contents.set("HELLO")
> > 
> > If it doesn't, check the AppleScript equivalent
> just
> > to make sure that it works:
> > 
> > tell application "Adobe InDesign CS2"
> > set contents of textframe 1 of page 1 of document
> 1
> > to "HELLO"
> > end tell
> > 
> > Then tell me what version of appscript you're
> using
> > and post a traceback so I can see what the error
> > actually is. Like I say, it may just be that you
> > need to upgrade to the latest version of
> appscript,
> > though I'd like to make sure it's not something
> > else.
> > 
> > 
> > >I wonder if I missed something since I get only a
> > >small __init__.py file while I used pythonw
> > >getsuitmodule.py for Adobe InDesign CS2. But same
> > >command applied to TextEdit and Finder, iTune, I
> > get a
> > >few big file include __init__.py.
> > 
> > I wouldn't know about that. gensuitemodule has
> > always been rather flaky and clumsy; however,
> > appscript has no connection to it or
> > aetools/aepack/aetypes.
> > 
> > has
> > -- 
> > http://freespace.virgin.net/hamish.sanderson/
> > ___
> > Pythonmac-SIG maillist  - 
> Pythonmac-SIG@python.org
> >
>
http://mail.python.org/mailman/listinfo/pythonmac-sig
> > 
> 
> 
> 
>   
>   
> __ 
> Yahoo! Mail - PC Magazine Editors' Choice 2005 
> http://mail.yahoo.com
> ___
> Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
>
http://mail.python.org/mailman/listinfo/pythonm

Re: [Pythonmac-SIG] get reference

2005-10-26 Thread has
Zhi Peng wrote:
 
>Traceback (most recent call last):
>
>appscript.specifier.CommandError: Too many direct
>arguments.
>Failed command: app(u'/Applications/Adobe
>InDesign CS2/Adobe InDesign
>CS2.app').documents[u'Untitled-1'].spreads.ID(146).pages.ID(151).text_frames.ID(179).geometric_bounds.set(['6p0',
>'6p0', '18p0', '18p0'])

Yep, it's the non-standard 'get' and 'set' definitions in ID's stupid 
dictionary causing the problem. The latest version of appscript takes care of 
this, so you shouldn't have any problems using get() and set() once you upgrade.

has
-- 
http://freespace.virgin.net/hamish.sanderson/
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] get reference

2005-10-26 Thread Zhi Peng
Has, thanks a lot for your help. 

I use Tiger Mac 10.4.  Could I ask you, is it possible
for me to get new version or binary version? As I run
the MacPython script, it now can make new document and
make new textframe which place a small rectangle on
the left coner of the document created. It might be
better if using 
myTextFrame1= id.make(new=k.text_frame,
at=myDoc.pages[1],
with_data=["6p0","6p0","38p0","38p0"],
with_properties=geometric_bounds)

But I am not sure if it is in right form for both
with_data and with_properties. Anyone knew? 

The error message is as following. 




> /Users/zpeng/Documents/projects/has.py(15)?()
->
myTextFrame.geometric_bounds.set(["6p0","6p0","18p0","18p0"])
(Pdb) n
CommandError:
appscript.CommandError(app(u'/Applications/Adobe
InDesign CS2/Adobe InDesign
CS2.app').documents[u..._bounds.set, ((['6p0', '6p0',
'18p0', '18p0'],), {}), )
> /Users/zpeng/Documents/projects/has.py(15)?()
->
myTextFrame.geometric_bounds.set(["6p0","6p0","18p0","18p0"])
(Pdb) n
> /Users/zpeng/Documents/projects/has.py(16)?()
-> except Exception, e:
(Pdb) n
> /Users/zpeng/Documents/projects/has.py(17)?()
-> print str(e)
(Pdb) n
Too many direct arguments.
Failed command: app(u'/Applications/Adobe
InDesign CS2/Adobe InDesign
CS2.app').documents[u'Untitled-2'].spreads.ID(146).pages.ID(151).text_frames.ID(179).geometric_bounds.set(['6p0',
'6p0', '18p0', '18p0'])
> /Users/zpeng/Documents/projects/has.py(19)?()
-> myTextFrame.contents.set("InDesign Doc")
(Pdb) n
CommandError:
appscript.CommandError(app(u'/Applications/Adobe
InDesign CS2/Adobe InDesign
CS2.app').documents[u...frames.ID(179).contents.set,
(('InDesign Doc',), {}), )
> /Users/zpeng/Documents/projects/has.py(19)?()
-> myTextFrame.contents.set("InDesign Doc")
(Pdb) n



Zhi 


 

--- has <[EMAIL PROTECTED]> wrote:

> Zhi Peng wrote:
> 
> >But Corresponding MacPython code does not work well
> >where I used appscript 1.1 (3.7 MB). Should I use
> >other version of Appscript?
> 
> Probably would be a good idea. If you're on Panther
> you'll need to build it from scratch, I'm afraid,
> though I can supply binaries for Jaguar and Tiger.
> (I should have a copy of Panther next month.)
> 
> 
> >Following is the information I used debug.
> >
> >
> >(Pdb) n
> >CommandError:
> >appscript.CommandError(app(u'/Applications/Adobe
> >InDesign CS2/Adobe InDesign
> >CS2.app').documents[1...ext_frames[1].contents.set,
> >(('set the frame',), {}),  >instance at 0x13fd0d0>)
> 
> Wouldn't mind knowing a bit more about the TypeError
> within that CommandError, if you could get its
> string representation instead; e.g.:
> 
>   try:
>   
>
cs.documents[1].pages[1].text_frames[1].contents.set("set
> the frame")
>   except Exception, e:
>   print str(e)
> 
> Thanks,
> 
> has
> -- 
> http://freespace.virgin.net/hamish.sanderson/
> ___
> Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
>
http://mail.python.org/mailman/listinfo/pythonmac-sig
> 




__ 
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] get reference

2005-10-26 Thread has
Zhi Peng wrote:

>I use Tiger Mac 10.4.  Could I ask you, is it possible
>for me to get new version or binary version?

I can email you the binary files direct if you want. Save you having to built 
it yourself, which is a bit of a chore.


>As I run
>the MacPython script, it now can make new document and
>make new textframe which place a small rectangle on
>the left coner of the document created. It might be
>better if using
>myTextFrame1= id.make(new=k.text_frame,
>at=myDoc.pages[1],
>with_data=["6p0","6p0","38p0","38p0"],
>with_properties=geometric_bounds)
>
>But I am not sure if it is in right form for both
>with_data and with_properties. Anyone knew?

You do it the same as you would in AppleScript, which I'm assuming is:

myTextFrame1= id.make(
new=k.text_frame,
at=myDoc.pages[1],
with_properties={
k.geometric_bounds: ["6p0","6p0","38p0","38p0"]
}
)


has
-- 
http://freespace.virgin.net/hamish.sanderson/
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] get reference

2005-10-26 Thread Zhi Peng
Hi! Has 

Thanks a lot for your help. You may email me the
binary version if possible. 

It makes sense to use new code for mytextFrame. I will
try that too. 

regards 

Zhi 


--- has <[EMAIL PROTECTED]> wrote:

> Zhi Peng wrote:
> 
> >I use Tiger Mac 10.4.  Could I ask you, is it
> possible
> >for me to get new version or binary version?
> 
> I can email you the binary files direct if you want.
> Save you having to built it yourself, which is a bit
> of a chore.
> 
> 
> >As I run
> >the MacPython script, it now can make new document
> and
> >make new textframe which place a small rectangle on
> >the left coner of the document created. It might be
> >better if using
> >myTextFrame1= id.make(new=k.text_frame,
> >at=myDoc.pages[1],
> >with_data=["6p0","6p0","38p0","38p0"],
> >with_properties=geometric_bounds)
> >
> >But I am not sure if it is in right form for both
> >with_data and with_properties. Anyone knew?
> 
> You do it the same as you would in AppleScript,
> which I'm assuming is:
> 
> myTextFrame1= id.make(
> new=k.text_frame,
> at=myDoc.pages[1],
> with_properties={
> k.geometric_bounds:
> ["6p0","6p0","38p0","38p0"]
> }
> )
> 
> 
> has
> -- 
> http://freespace.virgin.net/hamish.sanderson/
> ___
> Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
>
http://mail.python.org/mailman/listinfo/pythonmac-sig
> 





__ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


[Pythonmac-SIG] embedded C in MacPython

2005-10-26 Thread Zhi Peng
Hi! All 
 
I has some small program in C which is compiled as .so library in Linux and I can directly import name_of_lib.so as a module from python when I run it on Linux. It looks same if I just see them from Terminal window on Mac. Did anyone compile any C code as library called by MacPython or from C code calling MacPython using Py_RunSimpleString or similar commands?  Thanks 
 
 
Zhi   
		 Yahoo! FareChase - Search multiple travel sites in one click.

 

 ___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig