Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

docview.py 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # document and view classes for MFC.
  2. import win32ui
  3. from . import object, window
  4. class View(window.Wnd):
  5. def __init__(self, initobj):
  6. window.Wnd.__init__(self, initobj)
  7. def OnInitialUpdate(self):
  8. pass
  9. # Simple control based views.
  10. class CtrlView(View):
  11. def __init__(self, doc, wndclass, style=0):
  12. View.__init__(self, win32ui.CreateCtrlView(doc, wndclass, style))
  13. class EditView(CtrlView):
  14. def __init__(self, doc):
  15. View.__init__(self, win32ui.CreateEditView(doc))
  16. class RichEditView(CtrlView):
  17. def __init__(self, doc):
  18. View.__init__(self, win32ui.CreateRichEditView(doc))
  19. class ListView(CtrlView):
  20. def __init__(self, doc):
  21. View.__init__(self, win32ui.CreateListView(doc))
  22. class TreeView(CtrlView):
  23. def __init__(self, doc):
  24. View.__init__(self, win32ui.CreateTreeView(doc))
  25. # Other more advanced views.
  26. class ScrollView(View):
  27. def __init__(self, doc):
  28. View.__init__(self, win32ui.CreateView(doc))
  29. class FormView(View):
  30. def __init__(self, doc, id):
  31. View.__init__(self, win32ui.CreateFormView(doc, id))
  32. class Document(object.CmdTarget):
  33. def __init__(self, template, docobj=None):
  34. if docobj is None:
  35. docobj = template.DoCreateDoc()
  36. object.CmdTarget.__init__(self, docobj)
  37. class RichEditDoc(object.CmdTarget):
  38. def __init__(self, template):
  39. object.CmdTarget.__init__(self, template.DoCreateRichEditDoc())
  40. class CreateContext:
  41. "A transient base class used as a CreateContext"
  42. def __init__(self, template, doc=None):
  43. self.template = template
  44. self.doc = doc
  45. def __del__(self):
  46. self.close()
  47. def close(self):
  48. self.doc = None
  49. self.template = None
  50. class DocTemplate(object.CmdTarget):
  51. def __init__(
  52. self, resourceId=None, MakeDocument=None, MakeFrame=None, MakeView=None
  53. ):
  54. if resourceId is None:
  55. resourceId = win32ui.IDR_PYTHONTYPE
  56. object.CmdTarget.__init__(self, self._CreateDocTemplate(resourceId))
  57. self.MakeDocument = MakeDocument
  58. self.MakeFrame = MakeFrame
  59. self.MakeView = MakeView
  60. self._SetupSharedMenu_()
  61. def _SetupSharedMenu_(self):
  62. pass # to be overridden by each "app"
  63. def _CreateDocTemplate(self, resourceId):
  64. return win32ui.CreateDocTemplate(resourceId)
  65. def __del__(self):
  66. object.CmdTarget.__del__(self)
  67. def CreateCreateContext(self, doc=None):
  68. return CreateContext(self, doc)
  69. def CreateNewFrame(self, doc):
  70. makeFrame = self.MakeFrame
  71. if makeFrame is None:
  72. makeFrame = window.MDIChildWnd
  73. wnd = makeFrame()
  74. context = self.CreateCreateContext(doc)
  75. wnd.LoadFrame(
  76. self.GetResourceID(), -1, None, context
  77. ) # triggers OnCreateClient...
  78. return wnd
  79. def CreateNewDocument(self):
  80. makeDocument = self.MakeDocument
  81. if makeDocument is None:
  82. makeDocument = Document
  83. return makeDocument(self)
  84. def CreateView(self, frame, context):
  85. makeView = self.MakeView
  86. if makeView is None:
  87. makeView = EditView
  88. view = makeView(context.doc)
  89. view.CreateWindow(frame)
  90. class RichEditDocTemplate(DocTemplate):
  91. def __init__(
  92. self, resourceId=None, MakeDocument=None, MakeFrame=None, MakeView=None
  93. ):
  94. if MakeView is None:
  95. MakeView = RichEditView
  96. if MakeDocument is None:
  97. MakeDocument = RichEditDoc
  98. DocTemplate.__init__(self, resourceId, MakeDocument, MakeFrame, MakeView)
  99. def _CreateDocTemplate(self, resourceId):
  100. return win32ui.CreateRichEditDocTemplate(resourceId)
  101. def t():
  102. class FormTemplate(DocTemplate):
  103. def CreateView(self, frame, context):
  104. makeView = self.MakeView
  105. # view = FormView(context.doc, win32ui.IDD_PROPDEMO1)
  106. view = ListView(context.doc)
  107. view.CreateWindow(frame)
  108. t = FormTemplate()
  109. return t.OpenDocumentFile(None)