SystemParametersInfo.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import win32gui, win32con, win32api, time, os, glob
  2. ## some of these tests will fail for systems prior to XP
  3. for pname in(
  4. ## Set actions all take an unsigned int in pvParam
  5. "SPI_GETMOUSESPEED", "SPI_GETACTIVEWNDTRKTIMEOUT", "SPI_GETCARETWIDTH",
  6. "SPI_GETFOREGROUNDFLASHCOUNT", "SPI_GETFOREGROUNDLOCKTIMEOUT",
  7. ## Set actions all take an unsigned int in uiParam
  8. "SPI_GETWHEELSCROLLLINES", "SPI_GETKEYBOARDDELAY",
  9. "SPI_GETKEYBOARDSPEED",
  10. "SPI_GETMOUSEHOVERHEIGHT", "SPI_GETMOUSEHOVERWIDTH",
  11. "SPI_GETMOUSEHOVERTIME", "SPI_GETSCREENSAVETIMEOUT", "SPI_GETMENUSHOWDELAY",
  12. "SPI_GETLOWPOWERTIMEOUT", "SPI_GETPOWEROFFTIMEOUT", "SPI_GETBORDER",
  13. ## below are winxp only:
  14. "SPI_GETFONTSMOOTHINGCONTRAST", "SPI_GETFONTSMOOTHINGTYPE", "SPI_GETFOCUSBORDERHEIGHT",
  15. "SPI_GETFOCUSBORDERWIDTH", "SPI_GETMOUSECLICKLOCKTIME"):
  16. print(pname)
  17. cget=getattr(win32con,pname)
  18. cset=getattr(win32con,pname.replace('_GET','_SET'))
  19. orig_value=win32gui.SystemParametersInfo(cget)
  20. print('\toriginal setting:',orig_value)
  21. win32gui.SystemParametersInfo(cset, orig_value+1)
  22. new_value=win32gui.SystemParametersInfo(cget)
  23. print('\tnew value:',new_value)
  24. # On Vista, some of these values seem to be ignored. So only "fail" if
  25. # the new value isn't what we set or the original
  26. if new_value!=orig_value+1:
  27. assert new_value == orig_value
  28. print("Strange - setting %s seems to have been ignored" % (pname,))
  29. win32gui.SystemParametersInfo(cset, orig_value)
  30. assert win32gui.SystemParametersInfo(cget)==orig_value
  31. # these take a boolean value in pvParam
  32. # change to opposite, check that it was changed and change back
  33. for pname in ("SPI_GETFLATMENU","SPI_GETDROPSHADOW","SPI_GETKEYBOARDCUES","SPI_GETMENUFADE",
  34. "SPI_GETCOMBOBOXANIMATION", "SPI_GETCURSORSHADOW", "SPI_GETGRADIENTCAPTIONS", "SPI_GETHOTTRACKING",
  35. "SPI_GETLISTBOXSMOOTHSCROLLING", "SPI_GETMENUANIMATION", "SPI_GETSELECTIONFADE",
  36. "SPI_GETTOOLTIPANIMATION", "SPI_GETTOOLTIPFADE", "SPI_GETUIEFFECTS", "SPI_GETACTIVEWINDOWTRACKING",
  37. "SPI_GETACTIVEWNDTRKZORDER"):
  38. print(pname)
  39. cget=getattr(win32con,pname)
  40. cset=getattr(win32con,pname.replace('_GET','_SET'))
  41. orig_value=win32gui.SystemParametersInfo(cget)
  42. print(orig_value)
  43. win32gui.SystemParametersInfo(cset, not orig_value)
  44. new_value=win32gui.SystemParametersInfo(cget)
  45. print(new_value)
  46. assert orig_value!=new_value
  47. win32gui.SystemParametersInfo(cset, orig_value)
  48. assert win32gui.SystemParametersInfo(cget)==orig_value
  49. # these take a boolean in uiParam
  50. # could combine with above section now that SystemParametersInfo only takes a single parameter
  51. for pname in ("SPI_GETFONTSMOOTHING","SPI_GETICONTITLEWRAP","SPI_GETBEEP","SPI_GETBLOCKSENDINPUTRESETS",
  52. "SPI_GETKEYBOARDPREF","SPI_GETSCREENSAVEACTIVE","SPI_GETMENUDROPALIGNMENT",
  53. "SPI_GETDRAGFULLWINDOWS", "SPI_GETSHOWIMEUI"):
  54. cget=getattr(win32con,pname)
  55. cset=getattr(win32con,pname.replace('_GET','_SET'))
  56. orig_value=win32gui.SystemParametersInfo(cget)
  57. win32gui.SystemParametersInfo(cset, not orig_value)
  58. new_value=win32gui.SystemParametersInfo(cget)
  59. # Some of these also can't be changed (eg, SPI_GETSCREENSAVEACTIVE) so
  60. # don't actually get upset.
  61. if orig_value!=new_value:
  62. print("successfully toggled", pname, "from", orig_value, "to", new_value)
  63. else:
  64. print("couldn't toggle", pname, "from", orig_value)
  65. win32gui.SystemParametersInfo(cset, orig_value)
  66. assert win32gui.SystemParametersInfo(cget)==orig_value
  67. print("SPI_GETICONTITLELOGFONT")
  68. lf=win32gui.SystemParametersInfo(win32con.SPI_GETICONTITLELOGFONT)
  69. orig_height=lf.lfHeight
  70. orig_italic=lf.lfItalic
  71. print('Height:', orig_height, 'Italic:',orig_italic)
  72. lf.lfHeight+=2
  73. lf.lfItalic=not lf.lfItalic
  74. win32gui.SystemParametersInfo(win32con.SPI_SETICONTITLELOGFONT, lf)
  75. new_lf=win32gui.SystemParametersInfo(win32con.SPI_GETICONTITLELOGFONT)
  76. print('New Height:', new_lf.lfHeight, 'New Italic:',new_lf.lfItalic)
  77. assert new_lf.lfHeight==orig_height+2
  78. assert new_lf.lfItalic!=orig_italic
  79. lf.lfHeight=orig_height
  80. lf.lfItalic=orig_italic
  81. win32gui.SystemParametersInfo(win32con.SPI_SETICONTITLELOGFONT, lf)
  82. new_lf=win32gui.SystemParametersInfo(win32con.SPI_GETICONTITLELOGFONT)
  83. assert new_lf.lfHeight==orig_height
  84. assert new_lf.lfItalic==orig_italic
  85. print("SPI_GETMOUSEHOVERWIDTH, SPI_GETMOUSEHOVERHEIGHT, SPI_GETMOUSEHOVERTIME")
  86. w=win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERWIDTH)
  87. h=win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERHEIGHT)
  88. t=win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERTIME)
  89. print('w,h,t:', w,h,t)
  90. win32gui.SystemParametersInfo(win32con.SPI_SETMOUSEHOVERWIDTH,w+1)
  91. win32gui.SystemParametersInfo(win32con.SPI_SETMOUSEHOVERHEIGHT,h+2)
  92. win32gui.SystemParametersInfo(win32con.SPI_SETMOUSEHOVERTIME,t+3)
  93. new_w=win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERWIDTH)
  94. new_h=win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERHEIGHT)
  95. new_t=win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERTIME)
  96. print('new w,h,t:', new_w, new_h, new_t)
  97. assert new_w==w+1
  98. assert new_h==h+2
  99. assert new_t==t+3
  100. win32gui.SystemParametersInfo(win32con.SPI_SETMOUSEHOVERWIDTH,w)
  101. win32gui.SystemParametersInfo(win32con.SPI_SETMOUSEHOVERHEIGHT,h)
  102. win32gui.SystemParametersInfo(win32con.SPI_SETMOUSEHOVERTIME,t)
  103. new_w=win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERWIDTH)
  104. new_h=win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERHEIGHT)
  105. new_t=win32gui.SystemParametersInfo(win32con.SPI_GETMOUSEHOVERTIME)
  106. assert new_w==w
  107. assert new_h==h
  108. assert new_t==t
  109. print("SPI_SETDOUBLECLKWIDTH, SPI_SETDOUBLECLKHEIGHT")
  110. x=win32api.GetSystemMetrics(win32con.SM_CXDOUBLECLK)
  111. y=win32api.GetSystemMetrics(win32con.SM_CYDOUBLECLK)
  112. print('x,y:', x, y)
  113. win32gui.SystemParametersInfo(win32con.SPI_SETDOUBLECLKWIDTH, x+1)
  114. win32gui.SystemParametersInfo(win32con.SPI_SETDOUBLECLKHEIGHT, y+2)
  115. new_x=win32api.GetSystemMetrics(win32con.SM_CXDOUBLECLK)
  116. new_y=win32api.GetSystemMetrics(win32con.SM_CYDOUBLECLK)
  117. print('new x,y:', new_x, new_y)
  118. assert new_x==x+1
  119. assert new_y==y+2
  120. win32gui.SystemParametersInfo(win32con.SPI_SETDOUBLECLKWIDTH, x)
  121. win32gui.SystemParametersInfo(win32con.SPI_SETDOUBLECLKHEIGHT, y)
  122. new_x=win32api.GetSystemMetrics(win32con.SM_CXDOUBLECLK)
  123. new_y=win32api.GetSystemMetrics(win32con.SM_CYDOUBLECLK)
  124. assert new_x==x
  125. assert new_y==y
  126. print("SPI_SETDRAGWIDTH, SPI_SETDRAGHEIGHT")
  127. dw=win32api.GetSystemMetrics(win32con.SM_CXDRAG)
  128. dh=win32api.GetSystemMetrics(win32con.SM_CYDRAG)
  129. print('dw,dh:', dw, dh)
  130. win32gui.SystemParametersInfo(win32con.SPI_SETDRAGWIDTH,dw+1)
  131. win32gui.SystemParametersInfo(win32con.SPI_SETDRAGHEIGHT,dh+2)
  132. new_dw=win32api.GetSystemMetrics(win32con.SM_CXDRAG)
  133. new_dh=win32api.GetSystemMetrics(win32con.SM_CYDRAG)
  134. print('new dw,dh:', new_dw, new_dh)
  135. assert new_dw==dw+1
  136. assert new_dh==dh+2
  137. win32gui.SystemParametersInfo(win32con.SPI_SETDRAGWIDTH,dw)
  138. win32gui.SystemParametersInfo(win32con.SPI_SETDRAGHEIGHT,dh)
  139. new_dw=win32api.GetSystemMetrics(win32con.SM_CXDRAG)
  140. new_dh=win32api.GetSystemMetrics(win32con.SM_CYDRAG)
  141. assert new_dw==dw
  142. assert new_dh==dh
  143. orig_wallpaper=win32gui.SystemParametersInfo(Action=win32con.SPI_GETDESKWALLPAPER)
  144. print('Original: ',orig_wallpaper)
  145. for bmp in glob.glob(os.path.join(os.environ['windir'],'*.bmp')):
  146. print(bmp)
  147. win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, Param=bmp)
  148. print(win32gui.SystemParametersInfo(Action=win32con.SPI_GETDESKWALLPAPER))
  149. time.sleep(1)
  150. win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, Param=orig_wallpaper)