[Pythonmac-SIG] Python CoreGraphics script running in Applescript

2009-01-30 Thread Jim Skibbie
I have a script that needs to get the height and width dimensions of the
media box of a PDF using Applescript. In OS X 10.4, I was using the
following:

 set shellScript to python   quoted form of PythonPath POSIXThisFile
 set dims to every paragraph of (do shell script shellScript)


The PythonPath is a path to the below Python script and the POSIXThisFile is
the path to the PDF.

The response is two paragraphs where paragraph 1 is the width and paragraph
2 is the height.


HereĀ¹s the python script:

# step 1: import the required modules
import os, sys
from CoreGraphics import *

if len( sys.argv ) != 2:
print ERROR: useage: python example2.py pdf_filename
sys.exit(1)

# step 2: read the pdf file name from the command line arguments
pdf_filename = sys.argv[1]
pdf_name, ext = os.path.splitext( pdf_filename )

# step 3: create the input PDF document
provider = CGDataProviderCreateWithFilename( pdf_filename )
pdf = CGPDFDocumentCreateWithProvider( provider )
if pdf is None:
print ERROR reading PDF document - \r\n check that the supplied
filename points to a PDF file
sys.exit(1)

page_number = 1

page_rect = pdf.getMediaBox( page_number )
page_width = int(page_rect.getWidth())
page_height = int(page_rect.getHeight())

print %d \r\n%d % (page_width, page_height)


Under OS 10.5, this script now uses a deprecated function of CoreGraphics
and I get an error that says:


  Error: The function `CGPDFDocumentGetMediaBox' is obsolete and will be
 removed in an upcoming update. Unfortunately, this application, or a library
 it uses, is using this obsolete function, and is thereby contributing to an
 overall degradation of system performance. Please use `CGPDFPageGetBoxRect'
 instead.


Can anyone steer me in the right direction on how to work with the
CGPDFPageGetBoxRect function?

Thanks.
Jim

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


Re: [Pythonmac-SIG] Python CoreGraphics script running in Applescript

2009-01-30 Thread Bill Noon


On Jan 30, 2009, at 3:24 PM, Jim Skibbie wrote:
...

page_rect = pdf.getMediaBox( page_number )
page_width = int(page_rect.getWidth())
page_height = int(page_rect.getHeight())

print %d \r\n%d % (page_width, page_height)


Under OS 10.5, this script now uses a deprecated function of  
CoreGraphics and I get an error that says:



Error: The function `CGPDFDocumentGetMediaBox' is obsolete and  
will be removed in an upcoming update. Unfortunately, this  
application, or a library it uses, is using this obsolete  
function, and is thereby contributing to an overall degradation of  
system performance. Please use `CGPDFPageGetBoxRect' instead.



Can anyone steer me in the right direction on how to work with the  
CGPDFPageGetBoxRect function?


Thanks.
Jim


Jim -- Try the following:
page_rect = pdf.getPage(page_number).getBoxRect(page_number)

--Bill Noon

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


Re: [Pythonmac-SIG] appscript install error

2009-01-30 Thread has

Rajanikanth Jammalamadaka wrote:


I get this error when trying to install appscript from source on Mac
OS X(using python 2.6.1):

ld: in /Developer/SDKs/MacOSX10.4u.sdk/usr/local/lib/libPng.dylib,
file is not of required architecture for architecture ppc
collect2: ld returned 1 exit status
lipo: can't open input file:
/var/folders/1F/1FIgkp3qEImZWgJI447-qU+TFxI/-Tmp-//ccmr16bT.out (No
such file or directory)
error: command 'gcc' failed with exit status 1



Looks like you've installed an i386-only build of libPng in /usr/local/ 
bin, overriding the 4-way fat version included in OS X. Appscript  
builds as 32-bit fat by default, so when the linker tries to link in  
the PPC versions all the Carbon libraries it can't find the fat  
version of libPng that Carbon normally expects. The best solution  
would be to rebuild your custom libPng installation as 4-way fat,  
otherwise you'll run into the same problem when building other fat  
projects.


HTH

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

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


[Pythonmac-SIG] appscript rocket-in-dock preventing logout

2009-01-30 Thread Bill Janssen
We discussed this a bit last year, but with no resolution that I
remember.  I've got a situation where a Python program is preventing
logout/shutdown.  It's a script that just runs in an endless loop
watching what app I'm working with; when it sees one it knows (Preview,
MS Word, Safari, etc.) it uses appscript to ask the app what document
I'm looking at.  It then squirrels that document away in a journal so
that I've got a record of what I've been working with.

The basic control loop is something like this:

   while True:
  ... see what's running, and possibly what document ...
  time.sleep(1.0)

When I fire this up, it creates a Python rocket icon in the dock.  Not
great, but I can live with it.  But it also prevents logout and shutdown
from working -- I keep getting the message Logout has timed out because
the application Python has failed to quit.

Does anyone know what I've got to do to this script to keep it from
preventing logout?  For bonus points, what do I have to do to keep it
from putting the rocket in the dock?

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


[Pythonmac-SIG] pyobjc python3k languagebridge

2009-01-30 Thread Nehemiah Dacres
I have a few questions about Python Objective-C. First, how is
the development of python3 objective-C going?will python3.0 objective3 be
implimented with the Leopard scripting bridge?
Is PowerPC a target for these developments?

-- 

lalalalala! it's not broken because I can use it

http://linux.slashdot.org/comments.pl?sid=194281threshold=1commentsort=0mode=threadcid=15927703
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig