splittst.py 2.5 KB

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