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