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.

createwin.py 2.4KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #
  2. # Window creation example
  3. #
  4. # This example creates a minimal "control" that just fills in its
  5. # window with red. To make your own control, subclass Control and
  6. # write your own OnPaint() method. See PyCWnd.HookMessage for what
  7. # the parameters to OnPaint are.
  8. #
  9. import win32api
  10. import win32con
  11. import win32ui
  12. from pywin.mfc import dialog, window
  13. class Control(window.Wnd):
  14. """Generic control class"""
  15. def __init__(self):
  16. window.Wnd.__init__(self, win32ui.CreateWnd())
  17. def OnPaint(self):
  18. dc, paintStruct = self.BeginPaint()
  19. self.DoPaint(dc)
  20. self.EndPaint(paintStruct)
  21. def DoPaint(self, dc): # Override this!
  22. pass
  23. class RedBox(Control):
  24. def DoPaint(self, dc):
  25. dc.FillSolidRect(self.GetClientRect(), win32api.RGB(255, 0, 0))
  26. class RedBoxWithPie(RedBox):
  27. def DoPaint(self, dc):
  28. RedBox.DoPaint(self, dc)
  29. r = self.GetClientRect()
  30. dc.Pie(r[0], r[1], r[2], r[3], 0, 0, r[2], r[3] // 2)
  31. def MakeDlgTemplate():
  32. style = (
  33. win32con.DS_MODALFRAME
  34. | win32con.WS_POPUP
  35. | win32con.WS_VISIBLE
  36. | win32con.WS_CAPTION
  37. | win32con.WS_SYSMENU
  38. | win32con.DS_SETFONT
  39. )
  40. cs = win32con.WS_CHILD | win32con.WS_VISIBLE
  41. w = 64
  42. h = 64
  43. dlg = [
  44. ["Red box", (0, 0, w, h), style, None, (8, "MS Sans Serif")],
  45. ]
  46. s = win32con.WS_TABSTOP | cs
  47. dlg.append(
  48. [
  49. 128,
  50. "Cancel",
  51. win32con.IDCANCEL,
  52. (7, h - 18, 50, 14),
  53. s | win32con.BS_PUSHBUTTON,
  54. ]
  55. )
  56. return dlg
  57. class TestDialog(dialog.Dialog):
  58. def OnInitDialog(self):
  59. rc = dialog.Dialog.OnInitDialog(self)
  60. self.redbox = RedBox()
  61. self.redbox.CreateWindow(
  62. None,
  63. "RedBox",
  64. win32con.WS_CHILD | win32con.WS_VISIBLE,
  65. (5, 5, 90, 68),
  66. self,
  67. 1003,
  68. )
  69. return rc
  70. class TestPieDialog(dialog.Dialog):
  71. def OnInitDialog(self):
  72. rc = dialog.Dialog.OnInitDialog(self)
  73. self.control = RedBoxWithPie()
  74. self.control.CreateWindow(
  75. None,
  76. "RedBox with Pie",
  77. win32con.WS_CHILD | win32con.WS_VISIBLE,
  78. (5, 5, 90, 68),
  79. self,
  80. 1003,
  81. )
  82. def demo(modal=0):
  83. d = TestPieDialog(MakeDlgTemplate())
  84. if modal:
  85. d.DoModal()
  86. else:
  87. d.CreateWindow()
  88. if __name__ == "__main__":
  89. demo(1)