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 #include "../api/object.h"
00025 #include "../api/list.h"
00026 #include "../api/dict.h"
00027 #include "../api/class.h"
00028 
00029 #include <qstring.h>
00030 #include <qstringlist.h>
00031 #include <qvaluelist.h>
00032 #include <qvaluevector.h>
00033 #include <qmap.h>
00034 #include <qvariant.h>
00035 
00036 namespace Kross { namespace Python {
00037 
00038     // Forward declaration.
00039     class PythonScript;
00040 
00047     class PythonExtension : public Py::PythonExtension<PythonExtension>
00048     {
00049             friend class PythonScript;
00050             friend class PythonObject;
00051             friend class PythonModule;
00052 
00053         public:
00054 
00061             explicit PythonExtension(Kross::Api::Object::Ptr object);
00062 
00066             virtual ~PythonExtension();
00067 
00074             virtual Py::Object str();
00075 
00082             virtual Py::Object repr();
00083 
00095             virtual Py::Object getattr(const char* name);
00096 
00097             //virtual Py::Object getattr_methods(const char* name);
00098             //virtual int setattr(const char* name, const Py::Object& value);
00099 
00100         private:
00101 
00108             static Kross::Api::List::Ptr toObject(const Py::Tuple& tuple);
00109 
00116             static Kross::Api::List::Ptr toObject(const Py::List& list);
00117 
00124             static Kross::Api::Dict::Ptr toObject(const Py::Dict& dict);
00125 
00132             static Kross::Api::Object::Ptr toObject(const Py::Object& object);
00133 
00142             static const Py::Object toPyObject(const QString& s);
00143 
00150             static const Py::List toPyObject(const QStringList& list);
00151 
00158             static const Py::Dict toPyObject(const QMap<QString, QVariant>& map);
00159 
00166             static const Py::List toPyObject(const QValueList<QVariant>& list);
00167 
00174             static const Py::Object toPyObject(const QVariant& variant);
00175 
00182             static const Py::Object toPyObject(Kross::Api::Object::Ptr object);
00183 
00190             static const Py::Tuple toPyTuple(Kross::Api::List::Ptr list);
00191 
00193             Kross::Api::Object::Ptr m_object;
00194 
00199             Py::MethodDefExt<PythonExtension>* m_proxymethod;
00200 
00213             static PyObject* proxyhandler(PyObject* _self_and_name_tuple, PyObject* _args);
00214     };
00215 
00216 }}
00217 
00218 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys