Today is the first time I've used Python, so I'm sure this'll be an easy question.
I need to convert this Python script from a command line application: webkit2png. The end result will be a URL that returns an image of the webpage passed into it as a querystring param. I've achieved this on Windows with .NET and IE, Gecko and WebKit, but now need to do the same for Safari on OS X.
I think I've got it converted, but unfortunately I'm running into a problem running the script from Apache on OS X:
app = AppKit.NSApplication.sharedApplication()
# create an app delegate
delegate = AppDelegate.alloc().init()
AppKit.NSApp().setDelegate_(delegate)
# create a window
rect = Foundation.NSMakeRect(0,0,100,100)
win = AppKit.NSWindow.alloc()
win.initWithContentRect_styleMask_backing_defer_ (rect,
AppKit.NSBorderlessWindowMask, 2, 0)
The error is thrown on the final line "initWithContentRect...". The error I see is:
<class 'objc.error'>: NSInternalInconsistencyException - Error (1002) creating CGSWindow
args = ('NSInternalInconsistencyException - Error (1002) creating CGSWindow',)
message = 'NSInternalInconsistencyException - Error (1002) creating CGSWindow'
name = u'NSInternalInconsistencyException'
If I run the script on the command line (after removing the CGI stuff), it runs perfectly.
Here's the libraries I'm importing:
import cgi
import cgitb; cgitb.enable() # for troubleshooting
import sys
try:
import Foundation
import WebKit
import AppKit
import objc
except ImportError:
print "Cannot find pyobjc library files. Are you sure it is installed?"
sys.exit()