X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dd9f7fea29e3f8bb61861f52984b7943512346ac..015131a1fd95d4fcfb2bbd660197ad5185cc8992:/wxPython/src/_filesys.i diff --git a/wxPython/src/_filesys.i b/wxPython/src/_filesys.i index feb4026650..fa76da3e68 100644 --- a/wxPython/src/_filesys.i +++ b/wxPython/src/_filesys.i @@ -26,16 +26,31 @@ class wxFSFile : public wxObject { public: + %typemap(out) wxFSFile*; // turn off this typemap + wxFSFile(wxInputStream *stream, const wxString& loc, const wxString& mimetype, const wxString& anchor, wxDateTime modif); + + // Turn it back on. + %typemap(out) wxFSFile* { $result = wxPyMake_wxObject($1, $owner); } + ~wxFSFile(); wxInputStream *GetStream(); + void DetachStream(); + const wxString& GetMimeType(); const wxString& GetLocation(); const wxString& GetAnchor(); wxDateTime GetModificationTime(); + + %property(Anchor, GetAnchor, doc="See `GetAnchor`"); + %property(Location, GetLocation, doc="See `GetLocation`"); + %property(MimeType, GetMimeType, doc="See `GetMimeType`"); + %property(ModificationTime, GetModificationTime, doc="See `GetModificationTime`"); + %property(Stream, GetStream, doc="See `GetStream`"); + }; @@ -84,24 +99,28 @@ IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext -%name(CPPFileSystemHandler) class wxFileSystemHandler //: public wxObject +%rename(CPPFileSystemHandler) wxFileSystemHandler; +class wxFileSystemHandler //: public wxObject { public: //wxFileSystemHandler(); + ~wxFileSystemHandler(); }; -%name(FileSystemHandler) class wxPyFileSystemHandler : public wxFileSystemHandler +%rename(FileSystemHandler) wxPyFileSystemHandler; +class wxPyFileSystemHandler : public wxFileSystemHandler { public: - %addtofunc wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)"; - + %pythonAppend wxPyFileSystemHandler setCallbackInfo(FileSystemHandler) + wxPyFileSystemHandler(); void _setCallbackInfo(PyObject* self, PyObject* _class); bool CanOpen(const wxString& location); + %newobject OpenFile; wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); wxString FindFirst(const wxString& spec, int flags = 0); wxString FindNext(); @@ -111,6 +130,12 @@ public: wxString GetAnchor(const wxString& location); wxString GetRightLocation(const wxString& location); wxString GetMimeTypeFromExt(const wxString& location); + + %property(Anchor, GetAnchor, doc="See `GetAnchor`"); + %property(LeftLocation, GetLeftLocation, doc="See `GetLeftLocation`"); + %property(MimeTypeFromExt, GetMimeTypeFromExt, doc="See `GetMimeTypeFromExt`"); + %property(Protocol, GetProtocol, doc="See `GetProtocol`"); + %property(RightLocation, GetRightLocation, doc="See `GetRightLocation`"); }; @@ -119,37 +144,50 @@ public: class wxFileSystem : public wxObject { public: + // turn off this typemap + %typemap(out) wxFileSystem*; + wxFileSystem(); ~wxFileSystem(); - void ChangePathTo(const wxString& location, bool is_dir = False); + // Turn it back on again + %typemap(out) wxFileSystem* { $result = wxPyMake_wxObject($1, $owner); } + + void ChangePathTo(const wxString& location, bool is_dir = false); wxString GetPath(); + %newobject OpenFile; wxFSFile* OpenFile(const wxString& location); wxString FindFirst(const wxString& spec, int flags = 0); wxString FindNext(); + %disownarg(wxFileSystemHandler *handler); static void AddHandler(wxFileSystemHandler *handler); + %cleardisown(wxFileSystemHandler *handler); + + // Removes FS handler + %newobject RemoveHandler; + static wxFileSystemHandler* RemoveHandler(wxFileSystemHandler *handler); + static void CleanUpHandlers(); // Returns the file URL for a native path 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(); + } + } + + %property(Path, GetPath, doc="See `GetPath`"); }; -// 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(); - } -%} - //--------------------------------------------------------------------------- @@ -157,6 +195,7 @@ class wxInternetFSHandler : public wxFileSystemHandler { public: wxInternetFSHandler(); bool CanOpen(const wxString& location); + %newobject OpenFile; wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); }; @@ -168,6 +207,7 @@ public: wxZipFSHandler(); bool CanOpen(const wxString& location); + %newobject OpenFile; wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); wxString FindFirst(const wxString& spec, int flags = 0); wxString FindNext(); @@ -193,24 +233,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' } @@ -223,8 +279,9 @@ public: // Add a file to the memory FS %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) } - + bool CanOpen(const wxString& location); + %newobject OpenFile; wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); wxString FindFirst(const wxString& spec, int flags = 0); virtual wxString FindNext();