views:

50

answers:

2

Is there a equatable bit of code to GetSystemMetrics in win32api, for Ubuntu? I need to get the monitors width and height in pixels.

+1  A: 

I can suggest a few approaches that can be used. I have not used the xlib version though.

1) xlib ( X client library for Python programs), if available on your system. You can look at "Display" methods and properties : python-xlib.sourceforge

2) On Ubuntu, you could do the following to get the screen resolution:

   xrandr  | grep \* | cut -d' ' -f4

3) You can use subprocess python module, to run the above command and extract the information

import subprocess
output = subprocess.Popen('xrandr | grep "\*" | cut -d" " -f4',shell=True, stdout=subprocess.PIPE).communicate()[0]
print output

Let me know, if this was helpful to you.

pyfunc
+2  A: 

I assume you're a GUI toolkit. Why else would you be interested in the screen dimensions?

Check out gtk.gdk.screen_width() and gtk.gdk.screen_height() from PyGTK. Something similar should be available for QT.

loevborg
With wxPython, it would be the GetDisplaySize method: http://xoomer.virgilio.it/infinity77/wxPython/wxFunctions.html?highlight=getdisplaysize#GetDisplaySize
Mark
Thanks, I'm currently re-configuring some of my programs to run in Ubuntu. I'm switching out all the Win specific functions.
Anteater7171