]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/pyistream.h
Updated note about wxSTC using wxPopupWindow
[wxWidgets.git] / wxPython / src / pyistream.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: pyistream.h
3// Purpose: Classes for managing wxInputStream <--> Python streams
4//
5// Author: Robin Dunn
6//
7// Created: 25-Sept-2000
8// RCS-ID: $Id$
9// Copyright: (c) 2000 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13#ifndef __PYISTREAM__
14#define __PYISTREAM__
15
16
17//----------------------------------------------------------------------
18// Handling of wxInputStreams by Joerg Baumann
19// See stream.i for implementations
20
21// list class for return list of strings, e.g. readlines()
22WX_DECLARE_LIST(wxString, wxStringPtrList);
23
24
25// C++ class wxPyInputStream to act as base for python class wxInputStream
26// You can use it in python like a python file object.
27class wxPyInputStream {
28public:
29 // underlying wxInputStream
30 wxInputStream* m_wxis;
31
32public:
33 wxPyInputStream(wxInputStream* wxis) : m_wxis(wxis) {}
34 ~wxPyInputStream();
35
36 // python file object interface for input files (most of it)
37 void close();
38 void flush();
39 bool eof();
40 PyObject* read(int size=-1);
41 PyObject* readline(int size=-1);
42 PyObject* readlines(int sizehint=-1);
43 void seek(int offset, int whence=0);
44 int tell();
45
46 /* do these later?
47 bool isatty();
48 int fileno();
49 void truncate(int size=-1);
50 void write(wxString data);
51 void writelines(wxStringPtrList);
52 */
53};
54
55
56
57// This is a wxInputStream that wraps a Python file-like
58// object and calls the Python methods as needed.
59class wxPyCBInputStream : public wxInputStream {
60public:
61 ~wxPyCBInputStream();
62 virtual size_t GetSize() const;
63
64 // factory function
65 static wxPyCBInputStream* create(PyObject *py, bool block=TRUE);
66
67protected:
68 // can only be created via the factory
69 wxPyCBInputStream(PyObject *r, PyObject *s, PyObject *t, bool block);
70
71 // wxStreamBase methods
72 virtual size_t OnSysRead(void *buffer, size_t bufsize);
73 virtual size_t OnSysWrite(const void *buffer, size_t bufsize);
74 virtual off_t OnSysSeek(off_t off, wxSeekMode mode);
75 virtual off_t OnSysTell() const;
76
77 // helper
78 static PyObject* getMethod(PyObject* py, char* name);
79
80 PyObject* m_read;
81 PyObject* m_seek;
82 PyObject* m_tell;
83 bool m_block;
84};
85
86//----------------------------------------------------------------------
87#endif