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.

dlgtest.py 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # A Demo of Pythonwin's Dialog and Property Page support.
  2. ###################
  3. #
  4. # First demo - use the built-in to Pythonwin "Tab Stop" dialog, but
  5. # customise it heavily.
  6. #
  7. # ID's for the tabstop dialog - out test.
  8. #
  9. import win32con
  10. import win32ui
  11. from pywin.mfc import dialog
  12. from win32con import IDCANCEL
  13. from win32ui import IDC_EDIT_TABS, IDC_PROMPT_TABS, IDD_SET_TABSTOPS
  14. class TestDialog(dialog.Dialog):
  15. def __init__(self, modal=1):
  16. dialog.Dialog.__init__(self, IDD_SET_TABSTOPS)
  17. self.counter = 0
  18. if modal:
  19. self.DoModal()
  20. else:
  21. self.CreateWindow()
  22. def OnInitDialog(self):
  23. # Set the caption of the dialog itself.
  24. self.SetWindowText("Used to be Tab Stops!")
  25. # Get a child control, remember it, and change its text.
  26. self.edit = self.GetDlgItem(IDC_EDIT_TABS) # the text box.
  27. self.edit.SetWindowText("Test")
  28. # Hook a Windows message for the dialog.
  29. self.edit.HookMessage(self.KillFocus, win32con.WM_KILLFOCUS)
  30. # Get the prompt control, and change its next.
  31. prompt = self.GetDlgItem(IDC_PROMPT_TABS) # the prompt box.
  32. prompt.SetWindowText("Prompt")
  33. # And the same for the button..
  34. cancel = self.GetDlgItem(IDCANCEL) # the cancel button
  35. cancel.SetWindowText("&Kill me")
  36. # And just for demonstration purposes, we hook the notify message for the dialog.
  37. # This allows us to be notified when the Edit Control text changes.
  38. self.HookCommand(self.OnNotify, IDC_EDIT_TABS)
  39. def OnNotify(self, controlid, code):
  40. if code == win32con.EN_CHANGE:
  41. print("Edit text changed!")
  42. return 1 # I handled this, so no need to call defaults!
  43. # kill focus for the edit box.
  44. # Simply increment the value in the text box.
  45. def KillFocus(self, msg):
  46. self.counter = self.counter + 1
  47. if self.edit != None:
  48. self.edit.SetWindowText(str(self.counter))
  49. # Called when the dialog box is terminating...
  50. def OnDestroy(self, msg):
  51. del self.edit
  52. del self.counter
  53. # A very simply Property Sheet.
  54. # We only make a new class for demonstration purposes.
  55. class TestSheet(dialog.PropertySheet):
  56. def __init__(self, title):
  57. dialog.PropertySheet.__init__(self, title)
  58. self.HookMessage(self.OnActivate, win32con.WM_ACTIVATE)
  59. def OnActivate(self, msg):
  60. pass
  61. # A very simply Property Page, which will be "owned" by the above
  62. # Property Sheet.
  63. # We create a new class, just so we can hook a control notification.
  64. class TestPage(dialog.PropertyPage):
  65. def OnInitDialog(self):
  66. # We use the HookNotify function to allow Python to respond to
  67. # Windows WM_NOTIFY messages.
  68. # In this case, we are interested in BN_CLICKED messages.
  69. self.HookNotify(self.OnNotify, win32con.BN_CLICKED)
  70. def OnNotify(self, std, extra):
  71. print("OnNotify", std, extra)
  72. # Some code that actually uses these objects.
  73. def demo(modal=0):
  74. TestDialog(modal)
  75. # property sheet/page demo
  76. ps = win32ui.CreatePropertySheet("Property Sheet/Page Demo")
  77. # Create a completely standard PropertyPage.
  78. page1 = win32ui.CreatePropertyPage(win32ui.IDD_PROPDEMO1)
  79. # Create our custom property page.
  80. page2 = TestPage(win32ui.IDD_PROPDEMO2)
  81. ps.AddPage(page1)
  82. ps.AddPage(page2)
  83. if modal:
  84. ps.DoModal()
  85. else:
  86. style = (
  87. win32con.WS_SYSMENU
  88. | win32con.WS_POPUP
  89. | win32con.WS_CAPTION
  90. | win32con.DS_MODALFRAME
  91. | win32con.WS_VISIBLE
  92. )
  93. styleex = win32con.WS_EX_DLGMODALFRAME | win32con.WS_EX_PALETTEWINDOW
  94. ps.CreateWindow(win32ui.GetMainFrame(), style, styleex)
  95. def test(modal=1):
  96. # dlg=dialog.Dialog(1010)
  97. # dlg.CreateWindow()
  98. # dlg.EndDialog(0)
  99. # del dlg
  100. # return
  101. # property sheet/page demo
  102. ps = TestSheet("Property Sheet/Page Demo")
  103. page1 = win32ui.CreatePropertyPage(win32ui.IDD_PROPDEMO1)
  104. page2 = win32ui.CreatePropertyPage(win32ui.IDD_PROPDEMO2)
  105. ps.AddPage(page1)
  106. ps.AddPage(page2)
  107. del page1
  108. del page2
  109. if modal:
  110. ps.DoModal()
  111. else:
  112. ps.CreateWindow(win32ui.GetMainFrame())
  113. return ps
  114. def d():
  115. dlg = win32ui.CreateDialog(win32ui.IDD_DEBUGGER)
  116. dlg.datalist.append((win32ui.IDC_DBG_RADIOSTACK, "radio"))
  117. print("data list is ", dlg.datalist)
  118. dlg.data["radio"] = 1
  119. dlg.DoModal()
  120. print(dlg.data["radio"])
  121. if __name__ == "__main__":
  122. demo(1)