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.

win32rcparser_demo.py 2.7KB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # A demo of the win32rcparser module and using win32gui
  2. import os
  3. import commctrl
  4. import win32api
  5. import win32con
  6. import win32gui
  7. import win32rcparser
  8. this_dir = os.path.abspath(os.path.dirname(__file__))
  9. g_rcname = os.path.abspath(
  10. os.path.join(this_dir, "..", "test", "win32rcparser", "test.rc")
  11. )
  12. if not os.path.isfile(g_rcname):
  13. raise RuntimeError("Can't locate test.rc (should be at '%s')" % (g_rcname,))
  14. class DemoWindow:
  15. def __init__(self, dlg_template):
  16. self.dlg_template = dlg_template
  17. def CreateWindow(self):
  18. self._DoCreate(win32gui.CreateDialogIndirect)
  19. def DoModal(self):
  20. return self._DoCreate(win32gui.DialogBoxIndirect)
  21. def _DoCreate(self, fn):
  22. message_map = {
  23. win32con.WM_INITDIALOG: self.OnInitDialog,
  24. win32con.WM_CLOSE: self.OnClose,
  25. win32con.WM_DESTROY: self.OnDestroy,
  26. win32con.WM_COMMAND: self.OnCommand,
  27. }
  28. return fn(0, self.dlg_template, 0, message_map)
  29. def OnInitDialog(self, hwnd, msg, wparam, lparam):
  30. self.hwnd = hwnd
  31. # centre the dialog
  32. desktop = win32gui.GetDesktopWindow()
  33. l, t, r, b = win32gui.GetWindowRect(self.hwnd)
  34. dt_l, dt_t, dt_r, dt_b = win32gui.GetWindowRect(desktop)
  35. centre_x, centre_y = win32gui.ClientToScreen(
  36. desktop, ((dt_r - dt_l) // 2, (dt_b - dt_t) // 2)
  37. )
  38. win32gui.MoveWindow(
  39. hwnd, centre_x - (r // 2), centre_y - (b // 2), r - l, b - t, 0
  40. )
  41. def OnCommand(self, hwnd, msg, wparam, lparam):
  42. # Needed to make OK/Cancel work - no other controls are handled.
  43. id = win32api.LOWORD(wparam)
  44. if id in [win32con.IDOK, win32con.IDCANCEL]:
  45. win32gui.EndDialog(hwnd, id)
  46. def OnClose(self, hwnd, msg, wparam, lparam):
  47. win32gui.EndDialog(hwnd, 0)
  48. def OnDestroy(self, hwnd, msg, wparam, lparam):
  49. pass
  50. def DemoModal():
  51. # Load the .rc file.
  52. resources = win32rcparser.Parse(g_rcname)
  53. for id, ddef in resources.dialogs.items():
  54. print("Displaying dialog", id)
  55. w = DemoWindow(ddef)
  56. w.DoModal()
  57. if __name__ == "__main__":
  58. flags = 0
  59. for flag in """ICC_DATE_CLASSES ICC_ANIMATE_CLASS ICC_ANIMATE_CLASS
  60. ICC_BAR_CLASSES ICC_COOL_CLASSES ICC_DATE_CLASSES
  61. ICC_HOTKEY_CLASS ICC_INTERNET_CLASSES ICC_LISTVIEW_CLASSES
  62. ICC_PAGESCROLLER_CLASS ICC_PROGRESS_CLASS ICC_TAB_CLASSES
  63. ICC_TREEVIEW_CLASSES ICC_UPDOWN_CLASS ICC_USEREX_CLASSES
  64. ICC_WIN95_CLASSES """.split():
  65. flags |= getattr(commctrl, flag)
  66. win32gui.InitCommonControlsEx(flags)
  67. # Need to do this go get rich-edit working.
  68. win32api.LoadLibrary("riched20.dll")
  69. DemoModal()