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.

progressbar.py 2.4KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #
  2. # Progress bar control example
  3. #
  4. # PyCProgressCtrl encapsulates the MFC CProgressCtrl class. To use it,
  5. # you:
  6. #
  7. # - Create the control with win32ui.CreateProgressCtrl()
  8. # - Create the control window with PyCProgressCtrl.CreateWindow()
  9. # - Initialize the range if you want it to be other than (0, 100) using
  10. # PyCProgressCtrl.SetRange()
  11. # - Either:
  12. # - Set the step size with PyCProgressCtrl.SetStep(), and
  13. # - Increment using PyCProgressCtrl.StepIt()
  14. # or:
  15. # - Set the amount completed using PyCProgressCtrl.SetPos()
  16. #
  17. # Example and progress bar code courtesy of KDL Technologies, Ltd., Hong Kong SAR, China.
  18. #
  19. import win32con
  20. import win32ui
  21. from pywin.mfc import dialog
  22. def MakeDlgTemplate():
  23. style = (
  24. win32con.DS_MODALFRAME
  25. | win32con.WS_POPUP
  26. | win32con.WS_VISIBLE
  27. | win32con.WS_CAPTION
  28. | win32con.WS_SYSMENU
  29. | win32con.DS_SETFONT
  30. )
  31. cs = win32con.WS_CHILD | win32con.WS_VISIBLE
  32. w = 215
  33. h = 36
  34. dlg = [
  35. [
  36. "Progress bar control example",
  37. (0, 0, w, h),
  38. style,
  39. None,
  40. (8, "MS Sans Serif"),
  41. ],
  42. ]
  43. s = win32con.WS_TABSTOP | cs
  44. dlg.append(
  45. [
  46. 128,
  47. "Tick",
  48. win32con.IDOK,
  49. (10, h - 18, 50, 14),
  50. s | win32con.BS_DEFPUSHBUTTON,
  51. ]
  52. )
  53. dlg.append(
  54. [
  55. 128,
  56. "Cancel",
  57. win32con.IDCANCEL,
  58. (w - 60, h - 18, 50, 14),
  59. s | win32con.BS_PUSHBUTTON,
  60. ]
  61. )
  62. return dlg
  63. class TestDialog(dialog.Dialog):
  64. def OnInitDialog(self):
  65. rc = dialog.Dialog.OnInitDialog(self)
  66. self.pbar = win32ui.CreateProgressCtrl()
  67. self.pbar.CreateWindow(
  68. win32con.WS_CHILD | win32con.WS_VISIBLE, (10, 10, 310, 24), self, 1001
  69. )
  70. # self.pbar.SetStep (5)
  71. self.progress = 0
  72. self.pincr = 5
  73. return rc
  74. def OnOK(self):
  75. # NB: StepIt wraps at the end if you increment past the upper limit!
  76. # self.pbar.StepIt()
  77. self.progress = self.progress + self.pincr
  78. if self.progress > 100:
  79. self.progress = 100
  80. if self.progress <= 100:
  81. self.pbar.SetPos(self.progress)
  82. def demo(modal=0):
  83. d = TestDialog(MakeDlgTemplate())
  84. if modal:
  85. d.DoModal()
  86. else:
  87. d.CreateWindow()
  88. if __name__ == "__main__":
  89. demo(1)