]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/src/pyistream.h
   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 
  21 // list class for return list of strings, e.g. readlines() 
  22 WX_DECLARE_LIST(wxString
, wxStringPtrList
); 
  25 // C++ class wxPyInputStream to act as base for python class wxInputStream 
  26 // You can use it in python like a python file object. 
  27 class wxPyInputStream 
{ 
  29     // underlying wxInputStream 
  30     wxInputStream
* m_wxis
; 
  33     wxPyInputStream(wxInputStream
* wxis
) : m_wxis(wxis
) {} 
  36     // python file object interface for input files (most of it) 
  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); 
  49       void truncate(int size=-1); 
  50       void write(wxString data); 
  51       void writelines(wxStringPtrList); 
  57 // This is a wxInputStream that wraps a Python file-like 
  58 // object and calls the Python methods as needed. 
  59 class wxPyCBInputStream 
: public wxInputStream 
{ 
  62     virtual size_t GetSize() const; 
  65     static wxPyCBInputStream
* create(PyObject 
*py
, bool block
=TRUE
); 
  68     // can only be created via the factory 
  69     wxPyCBInputStream(PyObject 
*r
, PyObject 
*s
, PyObject 
*t
, bool block
); 
  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; 
  78     static PyObject
* getMethod(PyObject
* py
, char* name
); 
  86 //----------------------------------------------------------------------