Screen's resolution

Hi all,

I need to change the screen's resolution. I suspect it must be done via
some python's module. Any clues?

Thanks in advance,
Ilia Kats

Ilia Kats wrote:

Hi all,

I need to change the screen's resolution. I suspect it must be done via
some python's module. Any clues?

Thanks in advance,
Ilia Kats

I don't know what platform you are on, but this code might prove useful to other people writing Windows applications. I dervied this in a severe bit-twiddling-twitch from the Microsoft documentation and ctypes/struct. It has been tested on Windows 2000 and XP, but should work on others from what I remember of the documentation.

···

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Imports
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

import ctypes
import struct

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Definitions
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

def ChangeDisplaySettings(xres=None, yres=None, BitsPerPixel=None):
    """Changes the display resolution and bit depth on Windows."""

    DM_BITSPERPEL = 0x00040000
    DM_PELSWIDTH = 0x00080000
    DM_PELSHEIGHT = 0x00100000
    CDS_FULLSCREEN = 0x00000004
    SIZEOF_DEVMODE = 148

    user32 = ctypes.WinDLL('user32.dll')
    DevModeData = struct.calcsize("32BHH") * '\x00'
    DevModeData += struct.pack("H", SIZEOF_DEVMODE)
    DevModeData += struct.calcsize("H") * '\x00'
    dwFields = (xres and DM_PELSWIDTH or 0) | (yres and DM_PELSHEIGHT or 0) | (BitsPerPixel and DM_BITSPERPEL or 0)
    DevModeData += struct.pack("L", dwFields)
    DevModeData += struct.calcsize("l9h32BHL") * '\x00'
    DevModeData += struct.pack("LLL", BitsPerPixel or 0, xres or 0, yres or 0)
    DevModeData += struct.calcsize("8L") * '\x00'
    result = user32.ChangeDisplaySettingsA(DevModeData, CDS_FULLSCREEN)
    return result == 0 # success if zero, some failure otherwise

Shane Holloway wrote:

Ilia Kats wrote:

>Hi all,
>
>I need to change the screen's resolution. I suspect it must be done via
>some python's module. Any clues?
>
>Thanks in advance,
>Ilia Kats
>
>

I don't know what platform you are on, but this code might prove useful
to other people writing Windows applications. I dervied this in a
severe bit-twiddling-twitch from the Microsoft documentation and
ctypes/struct. It has been tested on Windows 2000 and XP, but should
work on others from what I remember of the documentation.

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Imports
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

import ctypes
import struct

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Definitions
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

def ChangeDisplaySettings(xres=None, yres=None, BitsPerPixel=None):
    """Changes the display resolution and bit depth on Windows."""

    DM_BITSPERPEL = 0x00040000
    DM_PELSWIDTH = 0x00080000
    DM_PELSHEIGHT = 0x00100000
    CDS_FULLSCREEN = 0x00000004
    SIZEOF_DEVMODE = 148

    user32 = ctypes.WinDLL('user32.dll')
    DevModeData = struct.calcsize("32BHH") * '\x00'
    DevModeData += struct.pack("H", SIZEOF_DEVMODE)
    DevModeData += struct.calcsize("H") * '\x00'
    dwFields = (xres and DM_PELSWIDTH or 0) | (yres and DM_PELSHEIGHT or
0) | (BitsPerPixel and DM_BITSPERPEL or 0)
    DevModeData += struct.pack("L", dwFields)
    DevModeData += struct.calcsize("l9h32BHL") * '\x00'
    DevModeData += struct.pack("LLL", BitsPerPixel or 0, xres or 0, yres
or 0)
    DevModeData += struct.calcsize("8L") * '\x00'
    result = user32.ChangeDisplaySettingsA(DevModeData, CDS_FULLSCREEN)
    return result == 0 # success if zero, some failure otherwise

Can I achieve the same thing without using ctypes module, but via some
win32xxx module? It would be nice, if there is a way to do this without
installing additional modules.

I've stumbled across a theme problem on wxGTK:

I have a dialog box which uses wxStaticBoxSizers. Having just installed
Ximian's XD2 desktop, I find that the wxStaticText labels inside my
wxStaticBoxSizer disappear when I use Ximian's Industrial gtk2 theme.
Everything looks fine with other themes however.

Is there a fix for this from wxPython? I.e. can I override the gtk theme
settings? I can't reproduce the effect using either gtk-1.2 or gtk-2 in
Glade, so I don't really know where the problem is.

This problem is evident using both wxGTK-2.4.0.7 and wxGTK-2.4.1.2, on
both RH8.0 and RH9.0 (both with XD2 installed). Two small images
illustrating the point and some example code attached.

thanks,
Bryan

Bryan Cole
Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge CB4 0WG, United Kingdom.
tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382

BlueCurve.png

Industrial.png

testTheme.py (3.8 KB)

hi all,
is it possible with win32 after closing excel having a message dialogue in
python that is saying the application is closed??
i have the program now with excel running under python2.2, but the section
for closing excel within python is still the problem. as said before i would
like a dialogue in python when this is happening. anyone?

Stephan

excel in python.txt (5.31 KB)

bryan cole wrote:

I've stumbled across a theme problem on wxGTK:

I have a dialog box which uses wxStaticBoxSizers. Having just installed
Ximian's XD2 desktop, I find that the wxStaticText labels inside my
wxStaticBoxSizer disappear when I use Ximian's Industrial gtk2 theme.
Everything looks fine with other themes however.

Is there a fix for this from wxPython? I.e. can I override the gtk theme
settings?

No, not from wxPython.

I can't reproduce the effect using either gtk-1.2 or gtk-2 in
Glade, so I don't really know where the problem is.

This problem is evident using both wxGTK-2.4.0.7 and wxGTK-2.4.1.2, on
both RH8.0 and RH9.0 (both with XD2 installed). Two small images
illustrating the point and some example code attached.

It works fine here using the Geramik theme, with both gtk 1.2.x and gtk 2.x

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Ilia Kats wrote:

Can I achieve the same thing without using ctypes module, but via some
win32xxx module? It would be nice, if there is a way to do this without
installing additional modules.

Sorry Ilia, I missed your response. To my knowledge, the requisite call, "ChangeDisplaySettings", is not in win32all, so the answer is no. That was why I wrote it with ctypes... :frowning:

Ilia Kats wrote:

Can I achieve the same thing without using ctypes module, but via some
win32xxx module? It would be nice, if there is a way to do this without
installing additional modules.

Sorry Ilia, I missed your response. To my knowledge, the requisite call, "ChangeDisplaySettings", is not in win32all, so the answer is no. That was why I wrote it with ctypes... :frowning:

Shane Holloway wrote:

Ilia Kats wrote:
> Can I achieve the same thing without using ctypes module, but via some
> win32xxx module? It would be nice, if there is a way to do this without
> installing additional modules.

Sorry Ilia, I missed your response. To my knowledge, the requisite call,

"ChangeDisplaySettings", is not in win32all,

so the answer is no. That was why I wrote it with ctypes... :frowning:

Ok. I got it working with ctypes. Thanks.

Thanks for looking at this, Robin.

I guess I'll have to use another theme then!
thanks,
Bryan

···

On Sat, 2003-06-28 at 17:36, Robin Dunn wrote:

bryan cole wrote:
> I've stumbled across a theme problem on wxGTK:
>
> I have a dialog box which uses wxStaticBoxSizers. Having just installed
> Ximian's XD2 desktop, I find that the wxStaticText labels inside my
> wxStaticBoxSizer disappear when I use Ximian's Industrial gtk2 theme.
> Everything looks fine with other themes however.
>
> Is there a fix for this from wxPython? I.e. can I override the gtk theme
> settings?

No, not from wxPython.

> illustrating the point and some example code attached.

It works fine here using the Geramik theme, with both gtk 1.2.x and gtk 2.x

--
Bryan Cole
Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge CB4 0WG, United Kingdom.
tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382