Skip to content

Commit dd2b536

Browse files
authored
Fix SystemParametersInfo demo (#2666)
1 parent e319b77 commit dd2b536

File tree

1 file changed

+18
-36
lines changed

1 file changed

+18
-36
lines changed

win32/Demos/SystemParametersInfo.py

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import win32con
77
import win32gui
88

9-
## some of these tests will fail for systems prior to XP
10-
119
for pname in (
1210
## Set actions all take an unsigned int in pvParam
1311
"SPI_GETMOUSESPEED",
@@ -24,10 +22,7 @@
2422
"SPI_GETMOUSEHOVERTIME",
2523
"SPI_GETSCREENSAVETIMEOUT",
2624
"SPI_GETMENUSHOWDELAY",
27-
"SPI_GETLOWPOWERTIMEOUT",
28-
"SPI_GETPOWEROFFTIMEOUT",
2925
"SPI_GETBORDER",
30-
## below are winxp only:
3126
"SPI_GETFONTSMOOTHINGCONTRAST",
3227
"SPI_GETFONTSMOOTHINGTYPE",
3328
"SPI_GETFOCUSBORDERHEIGHT",
@@ -39,21 +34,23 @@
3934
cset = getattr(win32con, pname.replace("_GET", "_SET"))
4035
orig_value = win32gui.SystemParametersInfo(cget)
4136
print("\toriginal setting:", orig_value)
42-
win32gui.SystemParametersInfo(cset, orig_value + 1)
37+
# Some values are clamped to an upper bound
38+
# (like SPI_SETKEYBOARDDELAY, SPI_SETKEYBOARDSPEED, SPI_SETMOUSESPEED)
39+
# SPI_SETMOUSESPEED specifically ranges [0-3]
40+
# https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa#SPI_SETKEYBOARDDELAY
41+
# Some values won't accept 0
42+
new_value = orig_value + (1 if orig_value < 2 else -1)
43+
win32gui.SystemParametersInfo(cset, new_value)
4344
new_value = win32gui.SystemParametersInfo(cget)
4445
print("\tnew value:", new_value)
45-
# On Vista, some of these values seem to be ignored. So only "fail" if
46-
# the new value isn't what we set or the original
47-
if new_value != orig_value + 1:
48-
assert new_value == orig_value
49-
print(f"Strange - setting {pname} seems to have been ignored")
46+
assert new_value != orig_value
5047
win32gui.SystemParametersInfo(cset, orig_value)
5148
assert win32gui.SystemParametersInfo(cget) == orig_value
5249

5350

54-
# these take a boolean value in pvParam
5551
# change to opposite, check that it was changed and change back
5652
for pname in (
53+
# these take a boolean value in pvParam
5754
"SPI_GETFLATMENU",
5855
"SPI_GETDROPSHADOW",
5956
"SPI_GETKEYBOARDCUES",
@@ -70,44 +67,29 @@
7067
"SPI_GETUIEFFECTS",
7168
"SPI_GETACTIVEWINDOWTRACKING",
7269
"SPI_GETACTIVEWNDTRKZORDER",
73-
):
74-
print(pname)
75-
cget = getattr(win32con, pname)
76-
cset = getattr(win32con, pname.replace("_GET", "_SET"))
77-
orig_value = win32gui.SystemParametersInfo(cget)
78-
print(orig_value)
79-
win32gui.SystemParametersInfo(cset, not orig_value)
80-
new_value = win32gui.SystemParametersInfo(cget)
81-
print(new_value)
82-
assert orig_value != new_value
83-
win32gui.SystemParametersInfo(cset, orig_value)
84-
assert win32gui.SystemParametersInfo(cget) == orig_value
85-
86-
87-
# these take a boolean in uiParam
88-
# could combine with above section now that SystemParametersInfo only takes a single parameter
89-
for pname in (
70+
# these take a boolean in uiParam
9071
"SPI_GETFONTSMOOTHING",
9172
"SPI_GETICONTITLEWRAP",
9273
"SPI_GETBEEP",
9374
"SPI_GETBLOCKSENDINPUTRESETS",
9475
"SPI_GETKEYBOARDPREF",
95-
"SPI_GETSCREENSAVEACTIVE",
9676
"SPI_GETMENUDROPALIGNMENT",
9777
"SPI_GETDRAGFULLWINDOWS",
9878
"SPI_GETSHOWIMEUI",
79+
# Can be changed, but will always return True,
80+
# so don't include in demo since we can't know the value to revert
81+
# https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa#SPI_GETSCREENSAVEACTIVE
82+
# "SPI_GETSCREENSAVEACTIVE",
9983
):
84+
print(pname)
10085
cget = getattr(win32con, pname)
10186
cset = getattr(win32con, pname.replace("_GET", "_SET"))
10287
orig_value = win32gui.SystemParametersInfo(cget)
88+
print(orig_value)
10389
win32gui.SystemParametersInfo(cset, not orig_value)
10490
new_value = win32gui.SystemParametersInfo(cget)
105-
# Some of these also can't be changed (eg, SPI_GETSCREENSAVEACTIVE) so
106-
# don't actually get upset.
107-
if orig_value != new_value:
108-
print("successfully toggled", pname, "from", orig_value, "to", new_value)
109-
else:
110-
print("couldn't toggle", pname, "from", orig_value)
91+
print(new_value)
92+
assert orig_value != new_value
11193
win32gui.SystemParametersInfo(cset, orig_value)
11294
assert win32gui.SystemParametersInfo(cget) == orig_value
11395

0 commit comments

Comments
 (0)