Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SystemParametersInfo.py 7.8KB

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