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.

toolbar.py 3.1KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # Demo of ToolBars
  2. # Shows the toolbar control.
  3. # Demos how to make custom tooltips, etc.
  4. import commctrl
  5. import win32api
  6. import win32con
  7. import win32ui
  8. from pywin.mfc import afxres, docview, window
  9. class GenericFrame(window.MDIChildWnd):
  10. def OnCreateClient(self, cp, context):
  11. # handlers for toolbar buttons
  12. self.HookCommand(self.OnPrevious, 401)
  13. self.HookCommand(self.OnNext, 402)
  14. # Its not necessary for us to hook both of these - the
  15. # common controls should fall-back all by themselves.
  16. # Indeed, given we hook TTN_NEEDTEXTW, commctrl.TTN_NEEDTEXTA
  17. # will not be called.
  18. self.HookNotify(self.GetTTText, commctrl.TTN_NEEDTEXT)
  19. self.HookNotify(self.GetTTText, commctrl.TTN_NEEDTEXTW)
  20. # parent = win32ui.GetMainFrame()
  21. parent = self
  22. style = (
  23. win32con.WS_CHILD
  24. | win32con.WS_VISIBLE
  25. | afxres.CBRS_SIZE_DYNAMIC
  26. | afxres.CBRS_TOP
  27. | afxres.CBRS_TOOLTIPS
  28. | afxres.CBRS_FLYBY
  29. )
  30. buttons = (win32ui.ID_APP_ABOUT, win32ui.ID_VIEW_INTERACTIVE)
  31. bitmap = win32ui.IDB_BROWSER_HIER
  32. tbid = 0xE840
  33. self.toolbar = tb = win32ui.CreateToolBar(parent, style, tbid)
  34. tb.LoadBitmap(bitmap)
  35. tb.SetButtons(buttons)
  36. tb.EnableDocking(afxres.CBRS_ALIGN_ANY)
  37. tb.SetWindowText("Test")
  38. parent.EnableDocking(afxres.CBRS_ALIGN_ANY)
  39. parent.DockControlBar(tb)
  40. parent.LoadBarState("ToolbarTest")
  41. window.MDIChildWnd.OnCreateClient(self, cp, context)
  42. return 1
  43. def OnDestroy(self, msg):
  44. self.SaveBarState("ToolbarTest")
  45. def GetTTText(self, std, extra):
  46. (hwndFrom, idFrom, code) = std
  47. text, hinst, flags = extra
  48. if flags & commctrl.TTF_IDISHWND:
  49. return # Not handled
  50. if idFrom == win32ui.ID_APP_ABOUT:
  51. # our 'extra' return value needs to be the following
  52. # entries from a NMTTDISPINFO[W] struct:
  53. # (szText, hinst, uFlags). None means 'don't change
  54. # the value'
  55. return 0, ("It works!", None, None)
  56. return None # not handled.
  57. def GetMessageString(self, id):
  58. if id == win32ui.ID_APP_ABOUT:
  59. return "Dialog Test\nTest"
  60. else:
  61. return self._obj_.GetMessageString(id)
  62. def OnSize(self, params):
  63. print("OnSize called with ", params)
  64. def OnNext(self, id, cmd):
  65. print("OnNext called")
  66. def OnPrevious(self, id, cmd):
  67. print("OnPrevious called")
  68. msg = """\
  69. This toolbar was dynamically created.\r
  70. \r
  71. The first item's tooltips is provided by Python code.\r
  72. \r
  73. (Dont close the window with the toolbar in a floating state - it may not re-appear!)\r
  74. """
  75. def test():
  76. template = docview.DocTemplate(
  77. win32ui.IDR_PYTHONTYPE, None, GenericFrame, docview.EditView
  78. )
  79. doc = template.OpenDocumentFile(None)
  80. doc.SetTitle("Toolbar Test")
  81. view = doc.GetFirstView()
  82. view.SetWindowText(msg)
  83. if __name__ == "__main__":
  84. import demoutils
  85. if demoutils.NeedGoodGUI():
  86. test()