frame.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # frame.py - The MDI frame window for an editor.
  2. import pywin.framework.window
  3. import win32ui
  4. import win32con
  5. import afxres
  6. import ModuleBrowser
  7. class EditorFrame(pywin.framework.window.MDIChildWnd):
  8. def OnCreateClient(self, cp, context):
  9. # Create the default view as specified by the template (ie, the editor view)
  10. view = context.template.MakeView(context.doc)
  11. # Create the browser view.
  12. browserView = ModuleBrowser.BrowserView(context.doc)
  13. view2 = context.template.MakeView(context.doc)
  14. splitter = win32ui.CreateSplitter()
  15. style = win32con.WS_CHILD | win32con.WS_VISIBLE
  16. splitter.CreateStatic (self, 1, 2, style, win32ui.AFX_IDW_PANE_FIRST)
  17. sub_splitter = self.sub_splitter = win32ui.CreateSplitter()
  18. sub_splitter.CreateStatic (splitter, 2, 1, style, win32ui.AFX_IDW_PANE_FIRST+1)
  19. # Note we must add the default view first, so that doc.GetFirstView() returns the editor view.
  20. sub_splitter.CreateView(view, 1, 0, (0,0))
  21. splitter.CreateView (browserView, 0, 0, (0,0))
  22. sub_splitter.CreateView(view2,0, 0, (0,0))
  23. ## print "First view is", context.doc.GetFirstView()
  24. ## print "Views are", view, view2, browserView
  25. ## print "Parents are", view.GetParent(), view2.GetParent(), browserView.GetParent()
  26. ## print "Splitter is", splitter
  27. ## print "sub splitter is", sub_splitter
  28. ## Old
  29. ## splitter.CreateStatic (self, 1, 2)
  30. ## splitter.CreateView(view, 0, 1, (0,0)) # size ignored.
  31. ## splitter.CreateView (browserView, 0, 0, (0, 0))
  32. # Restrict the size of the browser splitter (and we can avoid filling
  33. # it until it is shown)
  34. splitter.SetColumnInfo(0, 10, 20)
  35. # And the active view is our default view (so it gets initial focus)
  36. self.SetActiveView(view)
  37. def GetEditorView(self):
  38. # In a multi-view (eg, splitter) environment, get
  39. # an editor (ie, scintilla) view
  40. # Look for the splitter opened the most!
  41. if self.sub_splitter is None:
  42. return self.GetDlgItem(win32ui.AFX_IDW_PANE_FIRST)
  43. v1 = self.sub_splitter.GetPane(0,0)
  44. v2 = self.sub_splitter.GetPane(1,0)
  45. r1 = v1.GetWindowRect()
  46. r2 = v2.GetWindowRect()
  47. if r1[3]-r1[1] > r2[3]-r2[1]:
  48. return v1
  49. return v2
  50. def GetBrowserView(self):
  51. # XXX - should fix this :-)
  52. return self.GetActiveDocument().GetAllViews()[1]
  53. def OnClose(self):
  54. doc=self.GetActiveDocument()
  55. if not doc.SaveModified():
  56. ## Cancel button selected from Save dialog, do not actually close
  57. ## print 'close cancelled'
  58. return 0
  59. ## So the 'Save' dialog doesn't come up twice
  60. doc._obj_.SetModifiedFlag(False)
  61. # Must force the module browser to close itself here (OnDestroy for the view itself is too late!)
  62. self.sub_splitter = None # ensure no circles!
  63. self.GetBrowserView().DestroyBrowser()
  64. return self._obj_.OnClose()