]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/include/wx/wxPython/pyistream.h
793315adafdb06437e9244df8c9d546ea6a573f0
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Classes for managing wxInputStream <--> Python streams
7 // Created: 25-Sept-2000
9 // Copyright: (c) 2000 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
17 //----------------------------------------------------------------------
18 // Handling of wxInputStreams by Joerg Baumann
19 // See stream.i for implementations
22 // C++ class wxPyInputStream to act as base for python class wxInputStream
23 // You can use it in python like a python file object.
24 class wxPyInputStream
{
26 // underlying wxInputStream
27 wxInputStream
* m_wxis
;
30 wxPyInputStream(wxInputStream
* wxis
) : m_wxis(wxis
) {}
33 // python file object interface for input files (most of it)
37 PyObject
* read(int size
=-1);
38 PyObject
* readline(int size
=-1);
39 PyObject
* readlines(int sizehint
=-1);
40 void seek(int offset
, int whence
=0);
46 void truncate(int size=-1);
47 void write(wxString data);
48 void writelines(wxStringPtrList);
51 // wxInputStream methods that may come in handy...
53 char Peek() { if (m_wxis
) return m_wxis
->Peek(); else return -1; }
54 char GetC() { if (m_wxis
) return m_wxis
->GetC(); else return -1; }
55 size_t LastRead() { if (m_wxis
) return m_wxis
->LastRead(); else return 0; }
56 bool CanRead() { if (m_wxis
) return m_wxis
->CanRead(); else return false; }
57 bool Eof() { if (m_wxis
) return m_wxis
->Eof(); else return false; }
58 bool Ungetch(char c
) { if (m_wxis
) return m_wxis
->Ungetch(c
); else return false; }
60 unsigned long SeekI(unsigned long pos
, wxSeekMode mode
)
61 { if (m_wxis
) return m_wxis
->SeekI(pos
, mode
); else return 0; }
62 unsigned long TellI() { if (m_wxis
) return m_wxis
->TellI(); else return 0; }
67 // This is a wxInputStream that wraps a Python file-like
68 // object and calls the Python methods as needed.
69 class wxPyCBInputStream
: public wxInputStream
{
72 virtual size_t GetSize() const;
75 static wxPyCBInputStream
* create(PyObject
*py
, bool block
=true);
78 // can only be created via the factory
79 wxPyCBInputStream(PyObject
*r
, PyObject
*s
, PyObject
*t
, bool block
);
81 // wxStreamBase methods
82 virtual size_t OnSysRead(void *buffer
, size_t bufsize
);
83 virtual size_t OnSysWrite(const void *buffer
, size_t bufsize
);
84 virtual wxFileOffset
OnSysSeek(wxFileOffset off
, wxSeekMode mode
);
85 virtual wxFileOffset
OnSysTell() const;
88 static PyObject
* getMethod(PyObject
* py
, char* name
);
96 //----------------------------------------------------------------------