[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/lib/kross
From: Sebastian Sauer <mail () dipe ! org>
Date: 2005-12-17 1:03:55
Message-ID: 1134781435.767790.26153.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 489065 by sebsauer:
- Let ScriptAction handle it's own enable/disable.
- On python exception display a more detailed traceback to the outer world.
M +5 -0 api/exception.cpp
M +5 -0 api/exception.h
M +5 -2 main/scriptaction.cpp
M +0 -2 main/scriptguiclient.cpp
M +20 -9 python/pythonscript.cpp
M +1 -1 python/pythonscript.h
--- trunk/koffice/lib/kross/api/exception.cpp #489064:489065
@@ -59,6 +59,11 @@
return m_trace;
}
+void Exception::setTrace(const QString& tracemessage)
+{
+ m_trace = tracemessage;
+}
+
long Exception::getLineNo() const
{
return m_lineno;
--- trunk/koffice/lib/kross/api/exception.h #489064:489065
@@ -90,6 +90,11 @@
const QString& getTrace() const;
/**
+ * Set a more detailed tracemessage.
+ */
+ void setTrace(const QString& tracemessage);
+
+ /**
* \return the line number in the scripting code
* where the exception got thrown or -1 if there
* was no line number defined.
--- trunk/koffice/lib/kross/main/scriptaction.cpp #489064:489065
@@ -52,6 +52,7 @@
setName( name );
setText( text.isEmpty() ? name : text );
+ setEnabled(false);
d->scriptcontainer = Manager::scriptManager()->getScriptContainer(name);
}
@@ -83,9 +84,10 @@
d->scriptcontainer = Manager::scriptManager()->getScriptContainer(name);
QString interpreter = element.attribute("interpreter");
- if(! interpreter.isNull()) {
+ if(interpreter.isNull())
+ setEnabled(false);
+ else
setInterpreterName( interpreter );
- }
if(file.isNull()) {
setCode( element.text().stripWhiteSpace() );
@@ -132,6 +134,7 @@
void ScriptAction::setInterpreterName(const QString& name)
{
+ setEnabled( Manager::scriptManager()->hasInterpreterInfo(name) );
d->scriptcontainer->setInterpreterName(name);
}
--- trunk/koffice/lib/kross/main/scriptguiclient.cpp #489064:489065
@@ -144,8 +144,6 @@
if(node.nodeName() == "ScriptAction") {
ScriptAction* action = new ScriptAction( node.toElement() );
- if(! Manager::scriptManager()->hasInterpreterInfo( \
action->getInterpreterName() ) )
- action->setEnabled(false); // disable action if the interpreter \
isn't supported. d->scriptactions.append( action );
d->scriptextensions->insert( action );
connect(action, SIGNAL( failed(const QString&, const QString&) ),
--- trunk/koffice/lib/kross/python/pythonscript.cpp #489064:489065
@@ -162,9 +162,9 @@
}
catch(Py::Exception& e) {
QString err = Py::value(e).as_string().c_str();
- long lineno = getLineNo(e);
+ Kross::Api::Exception::Ptr exception = toException( QString("Failed to \
compile python code: %1").arg(err) ); e.clear(); // exception is handled. clear it \
now.
- throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(QString("Failed \
to compile python code: %1").arg(err), lineno) ); + throw exception;
}
}
@@ -181,10 +181,11 @@
d->m_classes.clear();
}
-long PythonScript::getLineNo(Py::Exception& /*exception*/)
+Kross::Api::Exception::Ptr PythonScript::toException(const QString& error)
{
PyObject *type, *value, *traceback;
PyObject *lineobj = 0;
+ Py::List tblist;
PyErr_Fetch(&type, &value, &traceback);
Py_FlushLine();
@@ -199,7 +200,7 @@
Py::Callable tbfunc(tbdict.getItem("format_tb"));
Py::Tuple args(1);
args.setItem(0, Py::Object(traceback));
- Py::List tblist = tbfunc.apply(args);
+ tblist = tbfunc.apply(args);
uint length = tblist.length();
for(Py::List::size_type i = 0; i < length; ++i)
kdDebug() << Py::Object(tblist[i]).as_string().c_str() << endl;
@@ -207,7 +208,7 @@
catch(Py::Exception& e) {
QString err = Py::value(e).as_string().c_str();
e.clear(); // exception is handled. clear it now.
- kdWarning() << QString("Kross::Python::PythonScript::getLineNo() Failed \
to fetch a traceback: %1").arg(err) << endl; + kdWarning() << \
QString("Kross::Python::PythonScript::toException() Failed to fetch a traceback: \
%1").arg(err) << endl; }
}
@@ -223,7 +224,15 @@
line = long(Py::Long(o)) - 1; // python linecount starts with 1..
}
- return line;
+ QStringList tb;
+ uint tblength = tblist.length();
+ for(Py::List::size_type i = 0; i < tblength; ++i)
+ tb.append( Py::Object(tblist[i]).as_string().c_str() );
+
+ Kross::Api::Exception::Ptr exception = new Kross::Api::Exception(error, line);;
+ if(tb.count() > 0)
+ exception->setTrace( tb.join("\n") );
+ return exception;
}
const QStringList& PythonScript::getFunctionNames()
@@ -337,14 +346,16 @@
if(errobj.ptr() == Py_None) // at least string-exceptions have there \
errormessage in the type-object errobj = Py::type(e);
QString err = errobj.as_string().c_str();
- long lineno = getLineNo(e);
+
+ Kross::Api::Exception::Ptr exception = toException( QString("Failed to \
execute python code: %1").arg(err) ); e.clear(); // exception is handled. clear it \
now.
- setException( new Kross::Api::Exception(QString("Failed to execute \
python code: %1").arg(err), lineno) ); + setException( exception );
}
catch(Py::Exception& e) {
QString err = Py::value(e).as_string().c_str();
+ Kross::Api::Exception::Ptr exception = toException( QString("Failed to \
execute python code: %1").arg(err) ); e.clear(); // exception is handled. clear it \
now.
- setException( new Kross::Api::Exception(QString("Failed to execute \
python code: %1").arg(err)) ); + setException( exception );
}
}
catch(Kross::Api::Exception::Ptr e) {
--- trunk/koffice/lib/kross/python/pythonscript.h #489064:489065
@@ -85,7 +85,7 @@
void initialize();
void finalize();
- long getLineNo(Py::Exception&);
+ Kross::Api::Exception::Ptr toException(const QString& error);
};
}}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic