template.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import string
  2. import win32ui
  3. import win32api
  4. from pywin.mfc import docview
  5. import pywin.framework.window
  6. import os
  7. import frame
  8. ParentEditorTemplate=docview.DocTemplate
  9. class EditorTemplateBase(ParentEditorTemplate):
  10. def __init__(self, res=win32ui.IDR_TEXTTYPE, makeDoc=None, makeFrame=None, makeView=None):
  11. if makeFrame is None: makeFrame = frame.EditorFrame
  12. ParentEditorTemplate.__init__(self, res, makeDoc, makeFrame, makeView)
  13. def _CreateDocTemplate(self, resourceId):
  14. assert 0, "You must override this"
  15. def CreateWin32uiDocument(self):
  16. assert 0, "You must override this"
  17. def GetFileExtensions(self):
  18. return ".txt", ".py"
  19. def MatchDocType(self, fileName, fileType):
  20. doc = self.FindOpenDocument(fileName)
  21. if doc: return doc
  22. ext = os.path.splitext(fileName)[1].lower()
  23. if ext in self.GetFileExtensions():
  24. return win32ui.CDocTemplate_Confidence_yesAttemptNative
  25. return win32ui.CDocTemplate_Confidence_maybeAttemptForeign
  26. def InitialUpdateFrame(self, frame, doc, makeVisible=1):
  27. self._obj_.InitialUpdateFrame(frame, doc, makeVisible) # call default handler.
  28. doc._UpdateUIForState()
  29. def GetPythonPropertyPages(self):
  30. """Returns a list of property pages
  31. """
  32. import configui
  33. return [configui.EditorPropertyPage(), configui.EditorWhitespacePropertyPage()]
  34. def OpenDocumentFile(self, filename, bMakeVisible = 1):
  35. if filename is not None:
  36. try:
  37. path = os.path.split(filename)[0]
  38. # print "The editor is translating", `filename`,"to",
  39. filename = win32api.FindFiles(filename)[0][8]
  40. filename = os.path.join(path, filename)
  41. # print `filename`
  42. except (win32api.error, IndexError), details:
  43. pass
  44. # print "Couldnt get the full filename!", details
  45. return self._obj_.OpenDocumentFile(filename, bMakeVisible)