lib

pythonextension.h

00001 /***************************************************************************
00002  * pythonextension.h
00003  * This file is part of the KDE project
00004  * copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org)
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this program; see the file COPYING.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  ***************************************************************************/
00019 
00020 #ifndef KROSS_PYTHON_EXTENSION_H
00021 #define KROSS_PYTHON_EXTENSION_H
00022 
00023 #include "pythonconfig.h"
00024 
00025 #include "../api/object.h"
00026 #include "../api/list.h"
00027 #include "../api/dict.h"
00028 #include "../api/class.h"
00029 
00030 #include <qstring.h>
00031 #include <qstringlist.h>
00032 #include <qvaluelist.h>
00033 #include <qvaluevector.h>
00034 #include <qmap.h>
00035 #include <qvariant.h>
00036 
00037 namespace Kross { namespace Python {
00038 
00039     // Forward declaration.
00040     class PythonScript;
00041 
00048     class PythonExtension : public Py::PythonExtension<PythonExtension>
00049     {
00050             friend class PythonScript;
00051             friend class PythonObject;
00052             friend class PythonModule;
00053 
00054         public:
00055 
00062             explicit PythonExtension(Kross::Api::Object::Ptr object);
00063 
00067             virtual ~PythonExtension();
00068 
00069 #if 0
00070 
00076             virtual Py::Object str();
00077 
00084             virtual Py::Object repr();
00085 #endif
00086 
00098             virtual Py::Object getattr(const char* name);
00099 
00100             //virtual Py::Object getattr_methods(const char* name);
00101             //virtual int setattr(const char* name, const Py::Object& value);
00102 
00103         private:
00104 
00111             static Kross::Api::List::Ptr toObject(const Py::Tuple& tuple);
00112 
00119             static Kross::Api::List::Ptr toObject(const Py::List& list);
00120 
00127             static Kross::Api::Dict::Ptr toObject(const Py::Dict& dict);
00128 
00135             static Kross::Api::Object::Ptr toObject(const Py::Object& object);
00136 
00145             static const Py::Object toPyObject(const QString& s);
00146 
00153             static const Py::List toPyObject(const QStringList& list);
00154 
00161             static const Py::Dict toPyObject(const QMap<QString, QVariant>& map);
00162 
00169             static const Py::List toPyObject(const QValueList<QVariant>& list);
00170 
00177             static const Py::Object toPyObject(const QVariant& variant);
00178 
00185             static const Py::Object toPyObject(Kross::Api::Object::Ptr object);
00186 
00193             static const Py::Tuple toPyTuple(Kross::Api::List::Ptr list);
00194 
00196             Kross::Api::Object::Ptr m_object;
00197 
00202             Py::MethodDefExt<PythonExtension>* m_proxymethod;
00203 
00216             static PyObject* proxyhandler(PyObject* _self_and_name_tuple, PyObject* _args);
00217     };
00218 
00219 }}
00220 
00221 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys