X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b87bfdb7f9ba0e7c0963586965a1ef0b53905d5f..db679b8c836e69c111cdc31e62cf92cebe4f938f:/wxPython/src/_filesys.i?ds=sidebyside diff --git a/wxPython/src/_filesys.i b/wxPython/src/_filesys.i index 08b30074f2..d02c4d8748 100644 --- a/wxPython/src/_filesys.i +++ b/wxPython/src/_filesys.i @@ -27,8 +27,8 @@ class wxFSFile : public wxObject { public: %pythonAppend wxFSFile - "self.thisown = 0 # It will normally be deleted by the user of the wxFileSystem"; - + "self.thisown = 0 # It will normally be deleted by the user of the wx.FileSystem"; + wxFSFile(wxInputStream *stream, const wxString& loc, const wxString& mimetype, const wxString& anchor, wxDateTime modif); @@ -88,7 +88,8 @@ IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext -%name(CPPFileSystemHandler) class wxFileSystemHandler //: public wxObject +%rename(CPPFileSystemHandler) wxFileSystemHandler; +class wxFileSystemHandler //: public wxObject { public: //wxFileSystemHandler(); @@ -96,7 +97,8 @@ public: -%name(FileSystemHandler) class wxPyFileSystemHandler : public wxFileSystemHandler +%rename(FileSystemHandler) wxPyFileSystemHandler; +class wxPyFileSystemHandler : public wxFileSystemHandler { public: %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)"; @@ -127,7 +129,7 @@ public: wxFileSystem(); ~wxFileSystem(); - void ChangePathTo(const wxString& location, bool is_dir = False); + void ChangePathTo(const wxString& location, bool is_dir = false); wxString GetPath(); %newobject OpenFile; @@ -143,19 +145,16 @@ public: static wxString FileNameToURL(const wxString& filename); // Returns the native path for a file URL - //static wxFileName URLToFileName(const wxString& url); *** See below + //static wxFileName URLToFileName(const wxString& url); + %extend { + static wxString URLToFileName(const wxString& url) { + wxFileName fname = wxFileSystem::URLToFileName(url); + return fname.GetFullPath(); + } + } }; -// Returns the native path for a file URL -wxString wxFileSystem_URLToFileName(const wxString& url); -%{ - wxString wxFileSystem_URLToFileName(const wxString& url) { - wxFileName fname = wxFileSystem::URLToFileName(url); - return fname.GetFullPath(); - } -%} - //--------------------------------------------------------------------------- @@ -201,24 +200,40 @@ public: void __wxMemoryFSHandler_AddFile_Data(const wxString& filename, PyObject* data) { - wxMemoryFSHandler::AddFile(filename, - // TODO: Verify data type - (void*)PyString_AsString(data), - (size_t)PyString_Size(data)); + if (! PyString_Check(data)) { + wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError, + "Expected string object")); + return; + } + + wxPyBlock_t blocked = wxPyBeginBlockThreads(); + void* ptr = (void*)PyString_AsString(data); + size_t size = PyString_Size(data); + wxPyEndBlockThreads(blocked); + + wxMemoryFSHandler::AddFile(filename, ptr, size); } %} // case switch for overloading %pythoncode { -def MemoryFSHandler_AddFile(filename, a, b=''): - if isinstance(a, wx.Image): - __wxMemoryFSHandler_AddFile_wxImage(filename, a, b) - elif isinstance(a, wx.Bitmap): - __wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b) - elif type(a) == str: - __wxMemoryFSHandler_AddFile_Data(filename, a) - else: raise TypeError, 'wx.Image, wx.Bitmap or string expected' +def MemoryFSHandler_AddFile(filename, dataItem, imgType=-1): + """ + Add 'file' to the memory filesystem. The dataItem parameter can + either be a `wx.Bitmap`, `wx.Image` or a string that can contain + arbitrary data. If a bitmap or image is used then the imgType + parameter should specify what kind of image file it should be + written as, wx.BITMAP_TYPE_PNG, etc. + """ + if isinstance(dataItem, wx.Image): + __wxMemoryFSHandler_AddFile_wxImage(filename, dataItem, imgType) + elif isinstance(dataItem, wx.Bitmap): + __wxMemoryFSHandler_AddFile_wxBitmap(filename, dataItem, imgType) + elif type(dataItem) == str: + __wxMemoryFSHandler_AddFile_Data(filename, dataItem) + else: + raise TypeError, 'wx.Image, wx.Bitmap or string expected' }