.. include:: headings.inc .. _MemoryFSHandler: ========================================================================================================================================== |phoenix_title| **MemoryFSHandler** ========================================================================================================================================== This :ref:`FileSystem` handler can store arbitrary data in memory stream and make them accessible via an ``URL``. It is particularly suitable for storing bitmaps from resources or included ``XPM`` files so that they can be used with ``HTML``. Filenames are prefixed with ``"memory:"`` , e.g. ``"memory:myfile.html"`` . Example: :: def OnAbout(self, event): bcur = wx.BeginBusyCursor() wx.FileSystem.AddHandler(wx.MemoryFSHandler) wx.MemoryFSHandler.AddFile("logo.pcx", wx.Bitmap("logo.pcx", wx.BITMAP_TYPE_PCX)) wx.MemoryFSHandler.AddFile("about.htm", "About: " "") dlg = wx.Dialog(self, -1, _("About")) topsizer = wx.BoxSizer(wx.VERTICAL) html = wx.html.HtmlWindow(dlg, size=wx.Size(380, 160), style=wx.HW_SCROLLBAR_NEVER) html.SetBorders(0) html.LoadPage("memory:about.htm") html.SetSize(html.GetInternalRepresentation().GetWidth(), html.GetInternalRepresentation().GetHeight()) topsizer.Add(html, 1, wx.ALL, 10) topsizer.Add(wx.StaticLine(dlg, -1), 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 10) topsizer.Add(wx.Button(dlg, wx.ID_OK, "Ok"), 0, wx.ALL | wx.ALIGN_RIGHT, 15) dlg.SetAutoLayout(True) dlg.SetSizer(topsizer) topsizer.Fit(dlg) dlg.Centre() dlg.ShowModal() wx.MemoryFSHandler.RemoveFile("logo.pcx") wx.MemoryFSHandler.RemoveFile("about.htm") .. seealso:: :meth:`MemoryFSHandler.AddFileWithMimeType` | |class_hierarchy| Inheritance Diagram ===================================== Inheritance diagram for class **MemoryFSHandler** .. raw:: html

Inheritance diagram of MemoryFSHandler

| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~MemoryFSHandler.__init__` Constructor. :meth:`~MemoryFSHandler.AddFile` Adds a file to the list of the files stored in memory. :meth:`~MemoryFSHandler.AddFileWithMimeType` Like :meth:`AddFile` , but lets you explicitly specify added file's ``MIME`` type. :meth:`~MemoryFSHandler.RemoveFile` Removes a file from memory ``FS`` and frees the occupied memory. ================================================================================ ================================================================================ | |api| Class API =============== .. class:: MemoryFSHandler(FileSystemHandler) This FileSystem handler can store arbitrary data in memory stream and make them accessible via an ``URL``. **Possible constructors**:: MemoryFSHandler() .. method:: __init__(self) Constructor. .. staticmethod:: AddFile(*args, **kw) Adds a file to the list of the files stored in memory. Stored data (bitmap, text or raw data) will be copied into private memory stream and available under name ``"memory:"`` + `filename`. .. note:: you must use a `type` value (aka image format) that wxWidgets can save (e.g. ``JPG``, ``PNG``, see :ref:`Image` documentation)! .. seealso:: :meth:`AddFileWithMimeType` |overload| **Overloaded Implementations**: **~~~** **AddFile** `(filename, image, type)` :param `filename`: :type `filename`: string :param `image`: :type `image`: Image :param `type`: :type `type`: BitmapType **~~~** **AddFile** `(filename, bitmap, type)` :param `filename`: :type `filename`: string :param `bitmap`: :type `bitmap`: Bitmap :param `type`: :type `type`: BitmapType **~~~** .. staticmethod:: AddFileWithMimeType(*args, **kw) Like :meth:`AddFile` , but lets you explicitly specify added file's ``MIME`` type. This version should be used whenever you know the ``MIME`` type, because it makes accessing the files faster. .. versionadded:: 2.8.5 .. seealso:: :meth:`AddFile` |overload| **Overloaded Implementations**: **~~~** **AddFileWithMimeType** `(filename, textdata, mimetype)` :param `filename`: :type `filename`: string :param `textdata`: :type `textdata`: string :param `mimetype`: :type `mimetype`: string **~~~** **AddFileWithMimeType** `(filename, binarydata, size, mimetype)` :param `filename`: :type `filename`: string :param `binarydata`: :param `size`: :type `size`: int :param `mimetype`: :type `mimetype`: string **~~~** .. staticmethod:: RemoveFile(filename) Removes a file from memory ``FS`` and frees the occupied memory. :param `filename`: :type `filename`: string