MemoryFSHandler_AddFile updates

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29214 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn 2004-09-18 23:13:21 +00:00
parent debff7aa47
commit 7e6581d421

View File

@ -143,19 +143,16 @@ public:
static wxString FileNameToURL(const wxString& filename); static wxString FileNameToURL(const wxString& filename);
// Returns the native path for a file URL // 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 +198,40 @@ public:
void __wxMemoryFSHandler_AddFile_Data(const wxString& filename, void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
PyObject* data) { PyObject* data) {
wxMemoryFSHandler::AddFile(filename, if (! PyString_Check(data)) {
// TODO: Verify data type wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError,
(void*)PyString_AsString(data), "Expected string object"));
(size_t)PyString_Size(data)); return;
}
bool 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 // case switch for overloading
%pythoncode { %pythoncode {
def MemoryFSHandler_AddFile(filename, a, b=''): def MemoryFSHandler_AddFile(filename, dataItem, imgType=-1):
if isinstance(a, wx.Image): """
__wxMemoryFSHandler_AddFile_wxImage(filename, a, b) Add 'file' to the memory filesystem. The dataItem parameter can
elif isinstance(a, wx.Bitmap): either be a `wx.Bitmap`, `wx.Image` or a string that can contain
__wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b) arbitrary data. If a bitmap or image is used then the imgType
elif type(a) == str: parameter should specify what kind of image file it should be
__wxMemoryFSHandler_AddFile_Data(filename, a) written as, wx.BITMAP_TYPE_PNG, etc.
else: raise TypeError, 'wx.Image, wx.Bitmap or string expected' """
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'
} }