Commit da51ee0f authored by Minh Ngo's avatar Minh Ngo
Browse files

Separate configuration for Python 2 & Python 3 b..

..ackends.

BUG: 343010
parent e4b62733
......@@ -8,8 +8,6 @@ set( PythonBackend_SRCS
pythonextensions.cpp
)
kconfig_add_kcfg_files(PythonBackend_SRCS settings.kcfgc)
qt5_add_resources(PythonBackend_RSCS python.qrc)
ki18n_wrap_ui(PythonBackend_SRCS settings.ui)
......@@ -22,6 +20,5 @@ target_link_libraries(cantor_pythonbackend
KF5::ConfigGui)
install(TARGETS cantor_pythonbackend DESTINATION ${INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES pythonbackend.kcfg DESTINATION ${KCFG_INSTALL_DIR})
#install(FILES keywords.xml DESTINATION ${DATA_INSTALL_DIR}/cantor/pythonbackend)
#install(DIRECTORY . DESTINATION ${DATA_INSTALL_DIR}/cantor/pythonbackend FILES_MATCHING PATTERN "*.py")
\ No newline at end of file
......@@ -19,10 +19,8 @@
*/
#include "pythonbackend.h"
#include "pythonsession.h"
#include "pythonextensions.h"
#include "settings.h"
#include "ui_settings.h"
#include <QDebug>
......@@ -62,9 +60,4 @@ QWidget* PythonBackend::settingsWidget(QWidget* parent) const
return widget;
}
KConfigSkeleton* PythonBackend::config() const
{
return PythonSettings::self();
}
#include "pythonbackend.moc"
......@@ -33,7 +33,7 @@ class CANTOR_EXPORT PythonBackend : public Cantor::Backend
Cantor::Backend::Capabilities capabilities() const;
QWidget* settingsWidget(QWidget* parent) const;
KConfigSkeleton* config() const;
virtual KConfigSkeleton* config() const = 0;
};
......
......@@ -52,9 +52,9 @@ void PythonExpression::evaluate()
PythonSession* pythonSession = dynamic_cast<PythonSession*>(session());
qDebug() << PythonSettings::integratePlots() << command().contains(QLatin1String("show()"));
qDebug() << pythonSession->integratePlots() << command().contains(QLatin1String("show()"));
if((PythonSettings::integratePlots()) && (command().contains(QLatin1String("show()")))){
if((pythonSession->integratePlots()) && (command().contains(QLatin1String("show()")))){
qDebug() << "Preparing export figures property";
......
......@@ -37,7 +37,6 @@
#include <KDirWatch>
#include <settings.h>
#include <defaultvariablemodel.h>
#include <string>
......@@ -59,7 +58,7 @@ void PythonSession::login()
{
qDebug()<<"login";
if(PythonSettings::integratePlots())
if(integratePlots())
{
qDebug() << "integratePlots";
......@@ -83,8 +82,9 @@ void PythonSession::login()
QObject::connect(m_watch, SIGNAL(created(QString)), SLOT(plotFileChanged(QString)));
}
if(!PythonSettings::self()->autorunScripts().isEmpty()){
QString autorunScripts = PythonSettings::self()->autorunScripts().join(QLatin1String("\n"));
const QStringList& scripts = autorunScripts();
if(!scripts.isEmpty()){
QString autorunScripts = scripts.join(QLatin1String("\n"));
getPythonCommandOutput(autorunScripts);
}
......
......@@ -53,6 +53,9 @@ class CANTOR_EXPORT PythonSession : public Cantor::Session
virtual QSyntaxHighlighter* syntaxHighlighter(QObject* parent);
virtual QAbstractItemModel* variableModel();
virtual bool integratePlots() const = 0;
virtual QStringList autorunScripts() const = 0;
public Q_SLOTS:
void readOutput(PythonExpression* expr, const QString& commandProcessing);
void plotFileChanged(const QString& filename);
......
......@@ -3,6 +3,8 @@ set( Python2Backend_SRCS
python2session.cpp
)
kconfig_add_kcfg_files(Python2Backend_SRCS settings.kcfgc)
if(MSVC)
# ssize_t is typedef'd in both kdewin and python headers, this prevents using the kdewin one
add_definitions(-D_SSIZE_T_DEFINED)
......@@ -26,3 +28,4 @@ add_test(NAME testpython2 COMMAND testpython2)
install(FILES cantor_python2.knsrc DESTINATION ${CONFIG_INSTALL_DIR})
install(FILES python2backend.desktop DESTINATION ${SERVICES_INSTALL_DIR}/cantor)
install(TARGETS cantor_python2backend DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES python2backend.kcfg DESTINATION ${KCFG_INSTALL_DIR})
\ No newline at end of file
......@@ -19,11 +19,11 @@
*/
#include "python2backend.h"
#include <klocalizedstring.h>
#include "python2session.h"
#include "cantor_macros.h"
#include "settings.h"
#include <klocalizedstring.h>
Python2Backend::Python2Backend(QObject* parent, const QList<QVariant> args)
: PythonBackend(parent, args)
......@@ -60,6 +60,11 @@ QString Python2Backend::description() const
"<p>This backend supports Python 2.</p>");
}
KConfigSkeleton* Python2Backend::config() const
{
return PythonSettings::self();
}
K_EXPORT_CANTOR_PLUGIN(python2backend, Python2Backend)
#include "python2backend.moc"
\ No newline at end of file
......@@ -34,6 +34,8 @@ class Python2Backend : public PythonBackend
QString id() const;
KUrl helpUrl() const;
QString description() const;
KConfigSkeleton* config() const;
};
#endif
\ No newline at end of file
......@@ -4,7 +4,7 @@
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="cantorrc"/>
<group name="PythonBackend">
<group name="Python2Backend">
<entry name="integratePlots" type="Bool">
<label>Integrate Plots into the Worksheet</label>
<default>false</default>
......
......@@ -19,6 +19,7 @@
*/
#include "python2session.h"
#include "settings.h"
#include <Python.h>
......@@ -60,4 +61,14 @@ QString Python2Session::getError() const
QString Python2Session::pyObjectToQString(PyObject* obj) const
{
return QString::fromLocal8Bit(PyString_AsString(obj));
}
bool Python2Session::integratePlots() const
{
return PythonSettings::integratePlots();
}
QStringList Python2Session::autorunScripts() const
{
return PythonSettings::autorunScripts();
}
\ No newline at end of file
......@@ -33,6 +33,9 @@ class Python2Session : public PythonSession
void login();
bool integratePlots() const;
QStringList autorunScripts() const;
private:
void runPythonCommand(const QString& command) const;
QString getOutput() const;
......
File=pythonbackend.kcfg
File=python2backend.kcfg
ClassName=PythonSettings
Singleton=true
......@@ -3,6 +3,8 @@ set( Python3Backend_SRCS
python3session.cpp
)
kconfig_add_kcfg_files(Python3Backend_SRCS settings.kcfgc)
add_library(cantor_python3backend MODULE ${Python3Backend_SRCS})
target_link_libraries(cantor_python3backend
cantorlibs
......@@ -12,6 +14,7 @@ target_link_libraries(cantor_python3backend
install(FILES cantor_python3.knsrc DESTINATION ${CONFIG_INSTALL_DIR})
install(FILES python3backend.desktop DESTINATION ${SERVICES_INSTALL_DIR}/cantor)
install(TARGETS cantor_python3backend DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES python3backend.kcfg DESTINATION ${KCFG_INSTALL_DIR})
add_subdirectory(python3server)
add_subdirectory(tests)
\ No newline at end of file
......@@ -19,11 +19,11 @@
*/
#include "python3backend.h"
#include <klocalizedstring.h>
#include "python3session.h"
#include "cantor_macros.h"
#include "settings.h"
#include <klocalizedstring.h>
Python3Backend::Python3Backend(QObject* parent, const QList<QVariant> args)
: PythonBackend(parent, args)
......@@ -53,6 +53,11 @@ QString Python3Backend::description() const
"<p>This backend supports Python 3.</p>");
}
KConfigSkeleton* Python3Backend::config() const
{
return PythonSettings::self();
}
K_EXPORT_CANTOR_PLUGIN(python3backend, Python3Backend)
#include "python3backend.moc"
\ No newline at end of file
......@@ -33,6 +33,8 @@ class Python3Backend : public PythonBackend
QString id() const;
KUrl helpUrl() const;
QString description() const;
KConfigSkeleton* config() const;
};
#endif
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="cantorrc"/>
<group name="Python3Backend">
<entry name="integratePlots" type="Bool">
<label>Integrate Plots into the Worksheet</label>
<default>false</default>
</entry>
<entry name="autorunScripts" type="StringList">
<label>List of scripts to autorun at the beginning of session</label>
</entry>
</group>
</kcfg>
......@@ -19,6 +19,7 @@
*/
#include "python3session.h"
#include "settings.h"
#include <QDebug>
#include <QDBusConnection>
......@@ -116,4 +117,14 @@ QString Python3Session::getError() const
return reply.value();
return reply.error().message();
}
bool Python3Session::integratePlots() const
{
return PythonSettings::integratePlots();
}
QStringList Python3Session::autorunScripts() const
{
return PythonSettings::autorunScripts();
}
\ No newline at end of file
......@@ -34,6 +34,9 @@ class Python3Session : public PythonSession
void logout();
void interrupt();
bool integratePlots() const;
QStringList autorunScripts() const;
private:
void runPythonCommand(const QString& command) const;
QString getOutput() const;
......
File=python3backend.kcfg
ClassName=PythonSettings
Singleton=true
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