123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- # document and view classes for MFC.
- import win32ui
- import win32con
- from . import object
- from . import window
- class View(window.Wnd):
- def __init__(self, initobj):
- window.Wnd.__init__(self, initobj)
- def OnInitialUpdate(self):
- pass
- # Simple control based views.
- class CtrlView(View):
- def __init__(self, doc, wndclass, style=0):
- View.__init__(self, win32ui.CreateCtrlView(doc, wndclass, style))
- class EditView(CtrlView):
- def __init__(self, doc):
- View.__init__(self, win32ui.CreateEditView(doc))
- class RichEditView(CtrlView):
- def __init__(self, doc):
- View.__init__(self, win32ui.CreateRichEditView(doc))
- class ListView(CtrlView):
- def __init__(self, doc):
- View.__init__(self, win32ui.CreateListView(doc))
- class TreeView(CtrlView):
- def __init__(self, doc):
- View.__init__(self, win32ui.CreateTreeView(doc))
- # Other more advanced views.
- class ScrollView(View):
- def __init__(self, doc):
- View.__init__(self, win32ui.CreateView(doc))
- class FormView(View):
- def __init__(self, doc, id):
- View.__init__(self, win32ui.CreateFormView(doc, id))
- class Document(object.CmdTarget):
- def __init__(self, template, docobj=None):
- if docobj is None:
- docobj = template.DoCreateDoc()
- object.CmdTarget.__init__(self, docobj)
- class RichEditDoc(object.CmdTarget):
- def __init__(self, template):
- object.CmdTarget.__init__(self, template.DoCreateRichEditDoc())
- class CreateContext:
- "A transient base class used as a CreateContext"
- def __init__(self, template, doc = None):
- self.template = template
- self.doc = doc
- def __del__(self):
- self.close()
- def close(self):
- self.doc = None
- self.template = None
- class DocTemplate(object.CmdTarget):
- def __init__(self, resourceId=None, MakeDocument=None, MakeFrame=None, MakeView=None):
- if resourceId is None: resourceId = win32ui.IDR_PYTHONTYPE
- object.CmdTarget.__init__(self, self._CreateDocTemplate(resourceId))
- self.MakeDocument=MakeDocument
- self.MakeFrame=MakeFrame
- self.MakeView=MakeView
- self._SetupSharedMenu_()
- def _SetupSharedMenu_(self):
- pass # to be overridden by each "app"
- def _CreateDocTemplate(self, resourceId):
- return win32ui.CreateDocTemplate(resourceId)
- def __del__(self):
- object.CmdTarget.__del__(self)
- def CreateCreateContext(self, doc=None):
- return CreateContext(self, doc)
- def CreateNewFrame(self, doc):
- makeFrame = self.MakeFrame
- if makeFrame is None: makeFrame = window.MDIChildWnd
- wnd = makeFrame()
- context = self.CreateCreateContext(doc)
- wnd.LoadFrame(self.GetResourceID(), -1, None, context) # triggers OnCreateClient...
- return wnd
- def CreateNewDocument(self):
- makeDocument = self.MakeDocument
- if makeDocument is None:
- makeDocument = Document
- return makeDocument(self)
- def CreateView(self, frame, context):
- makeView = self.MakeView
- if makeView is None: makeView = EditView
- view = makeView(context.doc)
- view.CreateWindow(frame)
- class RichEditDocTemplate(DocTemplate):
- def __init__(self, resourceId=None, MakeDocument=None, MakeFrame=None, MakeView=None):
- if MakeView is None: MakeView = RichEditView
- if MakeDocument is None: MakeDocument = RichEditDoc
- DocTemplate.__init__(self, resourceId, MakeDocument, MakeFrame, MakeView)
- def _CreateDocTemplate(self, resourceId):
- return win32ui.CreateRichEditDocTemplate(resourceId)
- def t():
- class FormTemplate(DocTemplate):
- def CreateView(self, frame, context):
- makeView = self.MakeView
- # view = FormView(context.doc, win32ui.IDD_PROPDEMO1)
- view = ListView(context.doc)
- view.CreateWindow(frame)
- t=FormTemplate()
- return t.OpenDocumentFile(None)
|