Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
objdoc.py58 linesDownload Raw Back to Demos
1# This is a sample file, and shows the basic framework for using an "Object" based2# document, rather than a "filename" based document.3# This is referenced by the Pythonwin .html documentation.4 5# In the example below, the OpenObject() method is used instead of OpenDocumentFile,6# and all the core MFC document open functionality is retained.7 8import win32ui9from pywin.mfc import docview10 11 12class object_template(docview.DocTemplate):13    def __init__(self):14        docview.DocTemplate.__init__(self, None, None, None, object_view)15 16    def OpenObject(self, object):  # Use this instead of OpenDocumentFile.17        # Look for existing open document18        for doc in self.GetDocumentList():19            print("document is ", doc)20            if doc.object is object:21                doc.GetFirstView().ActivateFrame()22                return doc23        # not found - new one.24        doc = object_document(self, object)25        frame = self.CreateNewFrame(doc)26        doc.OnNewDocument()27        doc.SetTitle(str(object))28        self.InitialUpdateFrame(frame, doc)29        return doc30 31 32class object_document(docview.Document):33    def __init__(self, template, object):34        docview.Document.__init__(self, template)35        self.object = object36 37    def OnOpenDocument(self, name):38        raise RuntimeError("Should not be called if template strings set up correctly")39        return 040 41 42class object_view(docview.EditView):43    def OnInitialUpdate(self):44        self.ReplaceSel("Object is %s" % repr(self.GetDocument().object))45 46 47def demo():48    t = object_template()49    d = t.OpenObject(win32ui)50    return (t, d)51 52 53if __name__ == "__main__":54    import demoutils55 56    if demoutils.NeedGoodGUI():57        demo()58 
codekingpro/portable-devtools · Team Ai