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.

splittst.py 2.8KB

1 year ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import commctrl
  2. import fontdemo
  3. import win32ui
  4. from pywin.mfc import docview, window
  5. # derive from CMDIChild. This does much work for us.
  6. class SplitterFrame(window.MDIChildWnd):
  7. def __init__(self):
  8. # call base CreateFrame
  9. self.images = None
  10. window.MDIChildWnd.__init__(self)
  11. def OnCreateClient(self, cp, context):
  12. splitter = win32ui.CreateSplitter()
  13. doc = context.doc
  14. frame_rect = self.GetWindowRect()
  15. size = ((frame_rect[2] - frame_rect[0]), (frame_rect[3] - frame_rect[1]) // 2)
  16. sub_size = (size[0] // 2, size[1])
  17. splitter.CreateStatic(self, 2, 1)
  18. self.v1 = win32ui.CreateEditView(doc)
  19. self.v2 = fontdemo.FontView(doc)
  20. # CListControl view
  21. self.v3 = win32ui.CreateListView(doc)
  22. sub_splitter = win32ui.CreateSplitter()
  23. # pass "splitter" so each view knows how to get to the others
  24. sub_splitter.CreateStatic(splitter, 1, 2)
  25. sub_splitter.CreateView(self.v1, 0, 0, (sub_size))
  26. sub_splitter.CreateView(self.v2, 0, 1, (0, 0)) # size ignored.
  27. splitter.SetRowInfo(0, size[1], 0)
  28. splitter.CreateView(self.v3, 1, 0, (0, 0)) # size ignored.
  29. # Setup items in the imagelist
  30. self.images = win32ui.CreateImageList(32, 32, 1, 5, 5)
  31. self.images.Add(win32ui.GetApp().LoadIcon(win32ui.IDR_MAINFRAME))
  32. self.images.Add(win32ui.GetApp().LoadIcon(win32ui.IDR_PYTHONCONTYPE))
  33. self.images.Add(win32ui.GetApp().LoadIcon(win32ui.IDR_TEXTTYPE))
  34. self.v3.SetImageList(self.images, commctrl.LVSIL_NORMAL)
  35. self.v3.InsertItem(0, "Icon 1", 0)
  36. self.v3.InsertItem(0, "Icon 2", 1)
  37. self.v3.InsertItem(0, "Icon 3", 2)
  38. # self.v3.Arrange(commctrl.LVA_DEFAULT) Hmmm - win95 aligns left always???
  39. return 1
  40. def OnDestroy(self, msg):
  41. window.MDIChildWnd.OnDestroy(self, msg)
  42. if self.images:
  43. self.images.DeleteImageList()
  44. self.images = None
  45. def InitialUpdateFrame(self, doc, makeVisible):
  46. self.v1.ReplaceSel("Hello from Edit Window 1")
  47. self.v1.SetModifiedFlag(0)
  48. class SampleTemplate(docview.DocTemplate):
  49. def __init__(self):
  50. docview.DocTemplate.__init__(
  51. self, win32ui.IDR_PYTHONTYPE, None, SplitterFrame, None
  52. )
  53. def InitialUpdateFrame(self, frame, doc, makeVisible):
  54. # print "frame is ", frame, frame._obj_
  55. # print "doc is ", doc, doc._obj_
  56. self._obj_.InitialUpdateFrame(frame, doc, makeVisible) # call default handler.
  57. frame.InitialUpdateFrame(doc, makeVisible)
  58. def demo():
  59. template = SampleTemplate()
  60. doc = template.OpenDocumentFile(None)
  61. doc.SetTitle("Splitter Demo")
  62. if __name__ == "__main__":
  63. import demoutils
  64. if demoutils.NeedGoodGUI():
  65. demo()