wxFileSystem

Has anyone documented the uses of wxFileSystem classes in wxPython? I've
been getting nowhere with them and would be grateful for any examples.

George Jansen wrote:

Has anyone documented the uses of wxFileSystem classes in wxPython? I've
been getting nowhere with them and would be grateful for any examples.

The only places it is used in wxPython are in wxHTML and XRC. Each is able to read files from a wxFileSystem, which may be real files, URLs or a virtual in memory file system.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

There are 2 aspects to using wxFileSystem:

1. Using it to retrieve data
2. Creating a custom filesystem

I use it with a custom filesystem to retrieve data
out of the Zope object database. I subclass
wxFileSystemHandler and provide the methods
required by that class. After creating the subclass
I add it to the set of filesystem handlers with the following
code at the end of the file (i.e., at module scope).

handler=ZODB_FS()
wxFileSystem_AddHandler(handler)

I'm not enclosing the code for the subclass
because you probably don't need to create a
subclass and the code is so specific to what
I am doing that it would probably be
really opaque.

ANYWAY...
Then I can use a wxFileSystem instance to
read from either a file (with the path
prefaced with 'file:') or from the
database (with the path prefaced with
'db:'), like this operation which can
read an XML file out of either the
database or a disk file:

        fs = wxFileSystem()
        f = fs.OpenFile(fileName)
        result = 0
        if f:
            result = 1
            stream = f.GetStream()
            data = stream.read()
            try:
                xml.parsers.expat.ParserCreate().Parse(data)
            except xml.parsers.expat.ExpatError,v:
                result = 0
                self.msgCache.append('Parsing Error:\n %s' % v)
                
            stream.close()
            del f

        del fs

Obviously there's a lot of stuff pertaining to the xml parser left out here.
The key things are:

stream = f.GetStream()
and
data = stream.read()

I also use wxHTML, and since that uses wxFileSystem to load
data, it can now seamlessly load from a disk file, from the net, or
from the database. It's pretty neat and not all that hard to do.
Even if you don't need a custom filesystem it's pretty convenient.

It's also instructive to look at the source for wxHTML and see
how that works when loading data.

HTH

···

#--------------------------------
Jeff Sasmor
jeff@sasmor.com
----- Original Message -----
From: "George Jansen" <GJANSEN@aflcio.org>
To: <wxPython-users@lists.wxwindows.org>
Sent: Wednesday, February 12, 2003 4:52 PM
Subject: [wxPython-users] wxFileSystem

Has anyone documented the uses of wxFileSystem classes in wxPython? I've
been getting nowhere with them and would be grateful for any examples.

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org