[Tutor] (no subject)
Tim Golden
Tim.Golden at viacom-outdoor.co.uk
Fri Nov 24 15:49:57 CET 2006
[Gardner, Dean]
| I was wondering if anyone knew how to control the desktop
| resolution via python.
|
| What I ideally need is a small app that will swap resolution
| between 1600*1200 and 1280*1024
OK. Had a bit of time to look into this. The following code
snippet is (hopefully) fairly self-explanatory, the only
exception being the mild shenanigans one has to go through
to pick a display mode. Let's assume your two "keys" are:
Depth: 32
Freq: 70
Width: 1600 <-> 1280
Height: 1200 <-> 1024
First, find your display modes:
<code>
import os, sys
import win32api
import win32con
import pywintypes
display_modes = {}
n = 0
while True:
try:
devmode = win32api.EnumDisplaySettings (None, n)
except pywintypes.error:
break
else:
key = (
devmode.BitsPerPel,
devmode.PelsWidth,
devmode.PelsHeight,
devmode.DisplayFrequency
)
display_modes[key] = devmode
n += 1
</code>
You now have a dictionary [display_modes], keyed on the
height, width and depth needed. All you have to do to
switch is something like this:
<code>
mode_required = (32, 1600, 1280, 70)
devmode = display_modes[mode_required]
win32api.ChangeDisplaySettings (devmode, 0)
#
# ... time passes
#
mode_required = (32, 1280, 1024, 70)
devmode = display_modes[mode_required]
win32api.ChangeDisplaySettings (devmode, 0)
</code>
and so on. Obviously, this is *very* bare bones, (and untested)
but it should get you started.
TJG
________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
More information about the Tutor
mailing list