Skip to content

Instantly share code, notes, and snippets.

@rcarmo
Created September 20, 2011 16:48
Show Gist options
  • Save rcarmo/1229627 to your computer and use it in GitHub Desktop.
Save rcarmo/1229627 to your computer and use it in GitHub Desktop.
Fullscreen webkit or PDF windows across any number of displays
from Quartz import *
from AppKit import *
from Foundation import *
import WebKit
import objc
import time
windows = {}
views = {}
def main():
app = NSApplication.sharedApplication()
app.setPresentationOptions_(NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationAutoHideDock)
NSCursor.setHiddenUntilMouseMoves_(YES)
screens = NSScreen.screens()
NSMenu.setMenuBarVisible_(False)
for screen in screens:
win = NSWindow.alloc()
rect = Foundation.NSMakeRect(0,0,0,0)
win.initWithContentRect_styleMask_backing_defer_(rect, NSBorderlessWindowMask, NSBackingStoreBuffered, False)
win.setFrame_display_animate_(screen.frame(), YES, YES)
win.makeKeyAndOrderFront_(None)
pdfview = PDFView.alloc()
pdfview.initWithFrame_(screen.frame())
pdfview.setDisplayMode_(kPDFDisplaySinglePage)
pdfview.setDisplayBox_(kPDFDisplayBoxMediaBox)
pdfview.setBackgroundColor_(NSColor.blackColor())
pdfview.setAutoScales_(True)
doc = PDFDocument.alloc()
docurl = NSURL.URLWithString_("file:///tmp/test.pdf")
doc.initWithURL_(docurl)
pdfview.setDocument_(doc)
width = screen.frame().size.width
height = screen.frame().size.height
win.setContentView_(pdfview)
windows[screen] = win
views[screen] = pdfview
# this is the basic mechanism for going to the next page
if pdfview.canGoToNextPage:
pdfview.goToNextPage_(None)
app.run()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment