| 
6 | 6 | import win32con  | 
7 | 7 | import win32gui  | 
8 | 8 | 
 
  | 
9 |  | -## some of these tests will fail for systems prior to XP  | 
10 |  | - | 
11 | 9 | for pname in (  | 
12 | 10 |     ## Set actions all take an unsigned int in pvParam  | 
13 | 11 |     "SPI_GETMOUSESPEED",  | 
 | 
24 | 22 |     "SPI_GETMOUSEHOVERTIME",  | 
25 | 23 |     "SPI_GETSCREENSAVETIMEOUT",  | 
26 | 24 |     "SPI_GETMENUSHOWDELAY",  | 
27 |  | -    "SPI_GETLOWPOWERTIMEOUT",  | 
28 |  | -    "SPI_GETPOWEROFFTIMEOUT",  | 
29 | 25 |     "SPI_GETBORDER",  | 
30 |  | -    ## below are winxp only:  | 
31 | 26 |     "SPI_GETFONTSMOOTHINGCONTRAST",  | 
32 | 27 |     "SPI_GETFONTSMOOTHINGTYPE",  | 
33 | 28 |     "SPI_GETFOCUSBORDERHEIGHT",  | 
 | 
39 | 34 |     cset = getattr(win32con, pname.replace("_GET", "_SET"))  | 
40 | 35 |     orig_value = win32gui.SystemParametersInfo(cget)  | 
41 | 36 |     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)  | 
43 | 44 |     new_value = win32gui.SystemParametersInfo(cget)  | 
44 | 45 |     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  | 
50 | 47 |     win32gui.SystemParametersInfo(cset, orig_value)  | 
51 | 48 |     assert win32gui.SystemParametersInfo(cget) == orig_value  | 
52 | 49 | 
 
  | 
53 | 50 | 
 
  | 
54 |  | -# these take a boolean value in pvParam  | 
55 | 51 | # change to opposite, check that it was changed and change back  | 
56 | 52 | for pname in (  | 
 | 53 | +    # these take a boolean value in pvParam  | 
57 | 54 |     "SPI_GETFLATMENU",  | 
58 | 55 |     "SPI_GETDROPSHADOW",  | 
59 | 56 |     "SPI_GETKEYBOARDCUES",  | 
 | 
70 | 67 |     "SPI_GETUIEFFECTS",  | 
71 | 68 |     "SPI_GETACTIVEWINDOWTRACKING",  | 
72 | 69 |     "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  | 
90 | 71 |     "SPI_GETFONTSMOOTHING",  | 
91 | 72 |     "SPI_GETICONTITLEWRAP",  | 
92 | 73 |     "SPI_GETBEEP",  | 
93 | 74 |     "SPI_GETBLOCKSENDINPUTRESETS",  | 
94 | 75 |     "SPI_GETKEYBOARDPREF",  | 
95 |  | -    "SPI_GETSCREENSAVEACTIVE",  | 
96 | 76 |     "SPI_GETMENUDROPALIGNMENT",  | 
97 | 77 |     "SPI_GETDRAGFULLWINDOWS",  | 
98 | 78 |     "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",  | 
99 | 83 | ):  | 
 | 84 | +    print(pname)  | 
100 | 85 |     cget = getattr(win32con, pname)  | 
101 | 86 |     cset = getattr(win32con, pname.replace("_GET", "_SET"))  | 
102 | 87 |     orig_value = win32gui.SystemParametersInfo(cget)  | 
 | 88 | +    print(orig_value)  | 
103 | 89 |     win32gui.SystemParametersInfo(cset, not orig_value)  | 
104 | 90 |     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  | 
111 | 93 |     win32gui.SystemParametersInfo(cset, orig_value)  | 
112 | 94 |     assert win32gui.SystemParametersInfo(cget) == orig_value  | 
113 | 95 | 
 
  | 
 | 
0 commit comments