root/trunk/RBSkinning/RBSkinning/wxTools/winUtils.py

Revision 591, 2.7 kB (checked in by sholloway, 6 years ago)

*** empty log message ***

Line 
1 #!/usr/bin/env python
2 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 ##~ License
4 ##~
5 ##- The RuneBlade Foundation library is intended to ease some
6 ##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.)
7 ##- applications, while providing the flexibility to modularly change the
8 ##- architecture. Enjoy.
9 ##~
10 ##~ Copyright (C) 2002  TechGame Networks, LLC.
11 ##~
12 ##~ This library is free software; you can redistribute it and/or
13 ##~ modify it under the terms of the BSD style License as found in the
14 ##~ LICENSE file included with this distribution.
15 ##~
16 ##~ TechGame Networks, LLC can be reached at:
17 ##~ 3578 E. Hartsel Drive #211
18 ##~ Colorado Springs, Colorado, USA, 80920
19 ##~
20 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21
22 """Microsoft Windows specific calls.
23
24 Highly dependent upon ctypes and struct modules.
25
26 Note: Hack warning!  Only bit twiddlers will like this stuff.  ;)
27 """
28
29 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30 #~ Imports
31 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32
33 import ctypes
34 import struct
35
36 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 #~ Definitions
38 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39
40 def ChangeDisplaySettings(xres=None, yres=None, BitsPerPixel=None):
41     """Changes the display resolution and bit depth on Windows.
42     """
43
44     DM_BITSPERPEL = 0x00040000
45     DM_PELSWIDTH = 0x00080000
46     DM_PELSHEIGHT = 0x00100000
47     CDS_FULLSCREEN = 0x00000004
48     SIZEOF_DEVMODE = 148
49
50     user32 = ctypes.WinDLL('user32.dll')
51     DevModeData = struct.calcsize("32BHH") * '\x00'
52     DevModeData += struct.pack("H", SIZEOF_DEVMODE)
53     DevModeData += struct.calcsize("H") * '\x00'
54     dwFields = (xres and DM_PELSWIDTH or 0) | (yres and DM_PELSHEIGHT or 0) | (BitsPerPixel and DM_BITSPERPEL or 0)
55     DevModeData += struct.pack("L", dwFields)
56     DevModeData += struct.calcsize("l9h32BHL") * '\x00'
57     DevModeData += struct.pack("LLL", BitsPerPixel or 0, xres or 0, yres or 0)
58     DevModeData += struct.calcsize("8L") * '\x00'
59     result = user32.ChangeDisplaySettingsA(DevModeData, CDS_FULLSCREEN)
60     return result == 0
61
62 SetResolution = ChangeDisplaySettings
63
64 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65
66 def GlobalMemoryStatus():
67     buf = '\x00' * 32
68     kernel32 = ctypes.WinDLL('kernel32')
69     kernel32.GlobalMemoryStatus(buf)
70     rtuple = struct.unpack('8L', buf)
71     result = {}
72     result['MemoryLoad'] = rtuple[1]   # [0] is len
73     result['TotalPhysical'] = rtuple[2]
74     result['AvailablePhysical'] = rtuple[3]
75     result['TotalPageFile'] = rtuple[4]
76     result['AvailablePageFile'] = rtuple[5]
77     result['TotalVirtual'] = rtuple[6]
78     result['AvailableVirtual'] = rtuple[7]
79     return result
80
Note: See TracBrowser for help on using the browser.