Commit 6fb6620b authored by Sebastian Sauer's avatar Sebastian Sauer
Browse files

* renamed "Export to HTML" => "HTML Export".

* some more work to prepare scripting functions.


svn path=/trunk/koffice/; revision=601149
parent 5b1e9bda
......@@ -46,6 +46,8 @@ namespace Kross {
QHash< QString, QPointer<ActionCollection> > collections;
QStringList collectionnames;
QString text;
Private(ActionCollection* const p) : parent(p) {}
};
......@@ -56,6 +58,7 @@ ActionCollection::ActionCollection(const QString& name, ActionCollection* parent
, d( new Private(parent) )
{
setObjectName(name);
d->text = name;
if( d->parent )
d->parent->registerCollection(this);
}
......@@ -67,6 +70,9 @@ ActionCollection::~ActionCollection()
delete d;
}
QString ActionCollection::text() const { return d->text; }
void ActionCollection::setText(const QString& text) { d->text = text; }
ActionCollection* ActionCollection::parentCollection() const
{
return d->parent;
......@@ -125,9 +131,12 @@ bool ActionCollection::readXml(const QDomElement& element, const QDir& directory
if( elem.tagName() == "collection") {
const QString name = elem.attribute("name");
const QString text = elem.attribute("text");
ActionCollection* c = d->collections.contains(name) ? d->collections[name] : 0;
if( ! c )
c = new ActionCollection(name, this);
if( ! text.isNull() )
c->setText(text);
if( ! c->readXml(elem) )
ok = false;
}
......@@ -234,7 +243,7 @@ bool ActionCollection::readXmlFile(const QString& file)
bool ActionCollection::readXmlResource(const QByteArray& resource, const QString& filer)
{
//filer = KApplication::kApplication()->objectName() + "/scripts/*/*.rc";
//filer = KApplication::kApplication()->objectName() + "/scripts/*.rc";
QStringList files = KGlobal::dirs()->findAllResources(resource, filer);
//files.sort();
bool ok = true;
......@@ -259,6 +268,8 @@ QDomElement ActionCollection::writeXml()
QDomElement element = document.createElement("collection");
if( ! objectName().isNull() )
element.setAttribute("name", objectName());
if( ! text().isNull() && text() != objectName() )
element.setAttribute("text", text());
foreach(QString name, d->collectionnames) {
ActionCollection* c = d->collections[name];
......
......@@ -61,6 +61,16 @@ namespace Kross {
*/
virtual ~ActionCollection();
/**
* \return the display text
*/
QString text() const;
/**
* Set the display text to \p text .
*/
void setText(const QString& text);
/**
* \return the parent \a ActionCollection instance this
* \collection is child of or NULL oif this collection
......
......@@ -88,7 +88,7 @@ GUIClient::GUIClient(KXMLGUIClient* guiclient, QWidget* parent)
// try to read the main ActionCollection.
QByteArray partname = d->guiclient->instance()->instanceName(); //KApplication::kApplication()->objectName()
Manager::self().actionCollection()->readXmlResource("data", partname + "/scripts/*/*.rc");
Manager::self().actionCollection()->readXmlResource("data", partname + "/scripts/*.rc");
}
GUIClient::~GUIClient()
......
......@@ -23,7 +23,8 @@
#include <QWidget>
#include <QMetaMethod>
#include <qvarlengtharray.h>
#include <QSignalSpy>
#include <QVarLengthArray>
using namespace Kross;
......@@ -79,6 +80,16 @@ PythonExtension::PythonExtension(QObject* object)
behaviors().supportSequenceType();
behaviors().supportMappingType();
add_varargs_method("__name__", &PythonExtension::getObjectName, "Return the objectName.");
add_varargs_method("__class__", &PythonExtension::getClassName, "Return the className.");
//add_varargs_method("__classinfos__", &PythonExtension::getClassInfos, "Return a list of key,value-tuples of class informations.");
add_varargs_method("__signals__", &PythonExtension::getSignalNames, "Return list of signal names.");
add_varargs_method("__slots__", &PythonExtension::getSlotNames, "Return list of slot names.");
add_varargs_method("__properties__", &PythonExtension::getPropertyNames, "Return list of property names.");
//add_varargs_method("__toPointer__", &PythonExtension::toPointer, "Return the void* pointer of the QObject.");
//add_varargs_method("__fromPointer__", &PythonExtension::fromPointer, "Set the QObject* to the passed void* pointer.");
//add_varargs_method("__connect__", &PythonExtension::doConnect, "Connect signal with python function.");
d->proxymethod = new Py::MethodDefExt<PythonExtension>(
"", // methodname, not needed cause we use the method only internaly.
0, // method that should handle the callback, not needed cause proxyhandler will handle it.
......@@ -159,23 +170,6 @@ Py::Object PythonExtension::getattr(const char* n)
return d->membernames;
//if(strcmp(n,"__dict__") == 0)
// return PythonType<QStringList>::toPyObject( QStringList() );
if(strcmp(n,"__name__") == 0)
return PythonType<QString>::toPyObject( d->object->objectName() );
if(strcmp(n,"__class__") == 0)
return PythonType<QString>::toPyObject( d->object->metaObject()->className() );
/*
if(strcmp(n,"__toPointer__") == 0) {
PyObject* qobjectptr = PyLong_FromVoidPtr( (void*) d->object.data() );
//PyObject* o = Py_BuildValue ("N", mw);
return Py::asObject( qobjectptr );
//PythonPyQtExtension* pyqtextension = new PythonPyQtExtension(self, args);
//return pyqtextension;
}
if(strcmp(n,"__fromPointer__") == 0) {
QObject* object = dynamic_cast< QObject* >(PyLong_AsVoidPtr( args[0] ));
}
*/
}
// look if the attribute is a method
......@@ -250,6 +244,105 @@ int PythonExtension::setattr(const char* n, const Py::Object& value)
return Py::PythonExtension<PythonExtension>::setattr(n, value);
}
Py::Object PythonExtension::getObjectName(const Py::Tuple&)
{
return PythonType<QString>::toPyObject( d->object->objectName() );
}
Py::Object PythonExtension::getClassName(const Py::Tuple&)
{
return PythonType<QString>::toPyObject( d->object->metaObject()->className() );
}
Py::Object PythonExtension::getSignalNames(const Py::Tuple&)
{
Py::List list;
const QMetaObject* metaobject = d->object->metaObject();
const int count = metaobject->methodCount();
for(int i = 0; i < count; ++i) {
QMetaMethod m = metaobject->method(i);
if( m.methodType() == QMetaMethod::Signal)
list.append( Py::String(m.signature()) );
}
return list;
}
Py::Object PythonExtension::getSlotNames(const Py::Tuple&)
{
Py::List list;
const QMetaObject* metaobject = d->object->metaObject();
const int count = metaobject->methodCount();
for(int i = 0; i < count; ++i) {
QMetaMethod m = metaobject->method(i);
if( m.methodType() == QMetaMethod::Slot)
list.append( Py::String(m.signature()) );
}
return list;
}
Py::Object PythonExtension::getPropertyNames(const Py::Tuple&)
{
Py::List list;
const QMetaObject* metaobject = d->object->metaObject();
const int count = metaobject->propertyCount();
for(int i = 0; i < count; ++i)
list.append( Py::String(metaobject->property(i).name()) );
return list;
}
/*
Py::Object PythonExtension::toPointer(const Py::Tuple&)
{
PyObject* qobjectptr = PyLong_FromVoidPtr( (void*) d->object.data() );
//PyObject* o = Py_BuildValue ("N", mw);
return Py::asObject( qobjectptr );
//PythonPyQtExtension* pyqtextension = new PythonPyQtExtension(self, args);
//return pyqtextension;
}
Py::Object PythonExtension::toPointer(fromPointer(const Py::Tuple&)
{
QObject* object = dynamic_cast< QObject* >(PyLong_AsVoidPtr( args[0] ));
}
*/
#if 0
Py::Object PythonExtension::doConnect(const Py::Tuple& args)
{
if( args.size() < 2 ) {
Py::AttributeError("The connect-method expects at least 2 arguments.");
return PythonType<bool>::toPyObject(false);
}
QByteArray signalname = PythonType<QByteArray>::toVariant( args[0] );
krossdebug( QString("====================================> signalname=%1 typeName=%2").arg(signalname).arg(args[1].type().as_string().c_str()) );
if( args[1].isCallable() ) {
Py::Callable funcobject(args[1]);
QVariantList args = d->signalspy.takeFirst();
Py::Object result = d->callable.apply( PythonType<QVariantList,Py::Tuple>::toPyObject(args) );
//connect(d->object, "2" + signalname, , SIGNAL(handleEmitted));
//QSignalSpy spy(d->object, signalname);
/*
COMPARE(spy.count(), 1); // make sure the signal was emitted exactly one time
QVariantList arguments = spy.takeFirst(); // take the first signal
VERIFY(arguments.at(0).toBool() == true); // verify the first argument
*/
//TODO
}
else {
Py::AttributeError("The connect-method expects as second argument something that is callable (e.g. a function).");
return PythonType<bool>::toPyObject(false);
}
return PythonType<bool>::toPyObject(true);
}
#endif
PyObject* PythonExtension::proxyhandler(PyObject *_self_and_name_tuple, PyObject *args)
{
try {
......@@ -470,4 +563,3 @@ int PythonExtension::mapping_ass_subscript(const Py::Object& obj1, const Py::Obj
{
throw Py::RuntimeError( QString("Unsupported: PythonExtension::mapping_ass_subscript %1 %2").arg(obj1.as_string().c_str()).arg(obj2.as_string().c_str()).toLatin1().constData() );
}
......@@ -32,6 +32,7 @@
namespace Kross {
// Forward declaration.
class PythonExtension;
class PythonScript;
/**
......@@ -99,6 +100,23 @@ namespace Kross {
/// \internal d-pointer instance.
Private* const d;
/// Return the objectName.
Py::Object getObjectName(const Py::Tuple&);
/// Return the className.
Py::Object getClassName(const Py::Tuple&);
/// Return list of signal names.
Py::Object getSignalNames(const Py::Tuple&);
/// Return list of slot names.
Py::Object getSlotNames(const Py::Tuple&);
/// Return list of property names.
Py::Object getPropertyNames(const Py::Tuple&);
//Py::Object toPointer(const Py::Tuple&);
//Py::Object fromPointer(const Py::Tuple&);
/// Connect signal with python function.
Py::Object doConnect(const Py::Tuple&);
/**
* The static proxy-handler which will be used to dispatch
* a call to our \a PythonExtension instance and redirect
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment