Trying to write a python application that downloads images from an RSS feed, and makes a composite background. How do I get the current desktop resolution on Mac OS X (leopard?)
A:
As usual, using features that are binded to an OS is a very bad idea. There are hundred of portable libs in Python that give you access to that information. The first that comes to my mind is of course pygame :
import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((640,480), FULLSCREEN)
x, y = screen.get_size()
But I guess cocoa do just as good, and therefor wxpython or qt is your friend. I suppose on Windows you did something like this :
from win32api import GetSystemMetrics
width = GetSystemMetrics [0]
height = GetSystemMetrics [1]
Sure it's easier, but won't work on Mac, Linux, BSD, Solaris, and probably nor very later windows version.
e-satis
2009-08-15 10:01:06
+5
A:
With Pyobjc something like this should work. Pyobjc comes with Leopard.
from AppKit import NSScreen
print NSScreen.mainScreen().frame()
Koen Bok
2009-08-15 11:07:52
Well, ain't that easy
kch
2009-08-15 11:12:35
Well, thanks for making my rant seem pointless :D
Alan
2009-08-15 16:11:58
Yeah, pyobjc is quite something. And it's on every mac since Leopard. And remember when actually using this a lot of mac users have more then one screen. So account for that when needed. See Apple's docs on NSScreen for more info.
Koen Bok
2009-08-15 21:34:41