MCPcopy Create free account
hub / github.com/mhammond/pywin32 / ui_edit_window_load_file

Function ui_edit_window_load_file

Pythonwin/win32view.cpp:759–800  ·  view source on GitHub ↗

@pymethod |PyCEditView|LoadFile|Loads a file into the view.

Source from the content-addressed store, hash-verified

757
758// @pymethod |PyCEditView|LoadFile|Loads a file into the view.
759static PyObject *
760ui_edit_window_load_file(PyObject *self, PyObject *args)
761{
762 USES_CONVERSION;
763 TCHAR *fileName;
764 PyObject *obfileName;
765 // @pyparm string|fileName||The name of the file to be loaded.
766 if (!PyArg_ParseTuple(args, "O:LoadFile", &obfileName))
767 return NULL;
768
769 CPythonEditView *pView;
770 if (!(pView=GetEditViewPtr(self)))
771 return NULL;
772 if (!PyWinObject_AsTCHAR(obfileName, &fileName, FALSE))
773 return NULL;
774 CFile file;
775 CFileException fe;
776 if (!file.Open(fileName, CFile::modeRead | CFile::shareDenyWrite, &fe)) {
777 PyWinObject_FreeTCHAR(fileName);
778 long errCode = fe.m_lOsError;
779 CString csMessage = GetAPIErrorString(errCode);
780 if (csMessage.GetLength()){
781 LPTSTR msg=csMessage.GetBuffer(csMessage.GetLength());
782 PyErr_SetString(PyExc_IOError, T2A(msg));
783 csMessage.ReleaseBuffer();
784 }
785 else
786 PyErr_SetString(PyExc_IOError, "Unknown IO error?");
787 return NULL;
788 }
789 PyWinObject_FreeTCHAR(fileName);
790
791 GUI_BGN_SAVE;
792 pView->DeleteContents();
793 CArchive loadArchive(&file, CArchive::load | CArchive::bNoFlushOnDelete);
794 TRY
795 {
796 pView->BeginWaitCursor();
797 pView->SerializeRaw(loadArchive); // load me
798 loadArchive.Close();
799 file.Close();
800 }
801 CATCH_ALL(e)
802 {
803 file.Abort(); // will not throw an exception

Callers

nothing calls this directly

Calls 6

GetEditViewPtrFunction · 0.85
GetAPIErrorStringFunction · 0.85
OpenMethod · 0.45
GetLengthMethod · 0.45
DeleteContentsMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected