Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 555d70e2 authored by Nikita Sirgienko's avatar Nikita Sirgienko

[R, Maxima, Octave, Python] Add option to enable/disable Variable Management....

[R, Maxima, Octave, Python] Add option to enable/disable Variable Management. Also don't parse variables value, when management disabled
parent bab221e2
......@@ -65,10 +65,15 @@ Cantor::Session* RBackend::createSession()
Cantor::Backend::Capabilities RBackend::capabilities() const
{
qDebug()<<"Requesting capabilities of RSession";
return Cantor::Backend::InteractiveMode |
Cantor::Backend::SyntaxHighlighting |
Cantor::Backend::Completion |
Cantor::Backend::VariableManagement;
Cantor::Backend::Capabilities cap=
SyntaxHighlighting|
Completion |
InteractiveMode;
if (RServerSettings::variableManagement())
cap |= VariableManagement;
return cap;
}
bool RBackend::requirementsFullfilled() const
......
......@@ -429,7 +429,7 @@ void RServer::listSymbols()
if (Rf_isFunction(value))
funcs << name;
else
else if (RServerSettings::variableManagement())
{
int convertStatus;
SEXP valueAsString = PROTECT(R_tryEval(lang2(install("toString"),value),nullptr,&convertStatus));
......@@ -439,6 +439,8 @@ void RServer::listSymbols()
values << QString::fromUtf8(translateCharUTF8(asChar(valueAsString)));
}
}
else
vars << name;
}
UNPROTECT(1);
......
......@@ -12,6 +12,10 @@
<label>Integrate Plots into the Worksheet</label>
<default>true</default>
</entry>
<entry name="variableManagement" type="Bool">
<label>Enable Variable Management</label>
<default>true</default>
</entry>
<entry name="autorunScripts" type="StringList">
<label>List of scripts to autorun at the beginning of session</label>
</entry>
......
......@@ -36,8 +36,13 @@ void RVariableModel::update()
void RVariableModel::parseResult(const QStringList& names, const QStringList& values, const QStringList& funcs)
{
QList<Variable> vars;
for (int i = 0; i < names.size(); i++)
vars.append(Variable{names[i], values[i]});
if (!values.isEmpty()) // Variables management disabled
for (int i = 0; i < names.size(); i++)
vars.append(Variable{names[i], values[i]});
else
for (int i = 0; i < names.size(); i++)
vars.append(Variable{names[i], QString()});
setVariables(vars);
// Handle functions
......
......@@ -32,6 +32,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_variableManagement">
<property name="toolTip">
<string>Let Cantor follow the creation/destruction of variables</string>
</property>
<property name="text">
<string>Enable Variable Management</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox">
<property name="title">
......
......@@ -28,6 +28,8 @@
#include <QDebug>
#include <KLocalizedString>
#include "settings.h"
//command used to inspect a maxima variable. %1 is the name of that variable
const QString MaximaVariableModel::inspectCommand=QLatin1String(":lisp($disp $%1)");
const QString MaximaVariableModel::variableInspectCommand=QLatin1String(":lisp(cantor-inspect $%1)");
......@@ -111,10 +113,13 @@ QList<Cantor::DefaultVariableModel::Variable> parse(MaximaExpression* expr)
//nameString = "[a,b]"
//variableString = "\n1\n\"-cantor-value-separator-\"\n2\n\"-cantor-value-separator-\"\n($A $B)"
variableNames = namesString.split(QLatin1Char(','));
valuesString = text.mid(nameIndex+1).trimmed();
valuesString = valuesString.remove(QLatin1String("\n")); //lists with many elements have line breaks, remove them
variableValues = valuesString.split(QLatin1String("\"-cantor-value-separator-\""));
hasValues = variableValues.isEmpty();
if (MaximaSettings::self()->variableManagement())
{
valuesString = text.mid(nameIndex+1).trimmed();
valuesString = valuesString.remove(QLatin1String("\n")); //lists with many elements have line breaks, remove them
variableValues = valuesString.split(QLatin1String("\"-cantor-value-separator-\""));
hasValues = variableValues.isEmpty();
}
}
qDebug()<<variableNames;
......
......@@ -52,7 +52,13 @@ QString OctaveBackend::version() const
Cantor::Backend::Capabilities OctaveBackend::capabilities() const
{
return SyntaxHighlighting | Completion | SyntaxHelp | VariableManagement;
Cantor::Backend::Capabilities cap=
SyntaxHighlighting|
Completion |
SyntaxHelp;
if (OctaveSettings::self()->variableManagement())
cap |= VariableManagement;
return cap;
}
Cantor::Session* OctaveBackend::createSession()
......
......@@ -17,6 +17,10 @@
<label>Integrate Plots into the Worksheet</label>
<default>true</default>
</entry>
<entry name="variableManagement" type="Bool">
<label>Enable Variable Management</label>
<default>true</default>
</entry>
<entry name="autorunScripts" type="StringList">
<label>List of scripts to autorun at the beginning of session</label>
</entry>
......
......@@ -24,6 +24,8 @@
#include <QDebug>
#include "settings.h"
using namespace Cantor;
OctaveVariableModel::OctaveVariableModel(OctaveSession* session):
......@@ -72,7 +74,9 @@ void OctaveVariableModel::parseNewVariables(Expression::Status status)
{
line = line.trimmed();
const QString& name = line.section(QLatin1String("\n"), 0, 0);
const QString& value = line.section(QLatin1String("\n"), 1);
QString value;
if (OctaveSettings::self()->variableManagement())
value = line.section(QLatin1String("\n"), 1);
vars << Variable{name, value};
}
......
......@@ -46,6 +46,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_variableManagement">
<property name="toolTip">
<string>Let Cantor follow the creation/destruction of variables</string>
</property>
<property name="text">
<string>Enable Variable Management</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox">
<property name="title">
......
......@@ -42,16 +42,6 @@ PythonBackend::~PythonBackend()
qDebug()<<"Destroying PythonBackend";
}
Cantor::Backend::Capabilities PythonBackend::capabilities() const
{
qDebug()<<"Requesting capabilities of PythonSession";
return Cantor::Backend::SyntaxHighlighting |
Cantor::Backend::Completion |
Cantor::Backend::SyntaxHelp |
Cantor::Backend::VariableManagement;
}
QWidget* PythonBackend::settingsWidget(QWidget* parent) const
{
QWidget* widget=new QWidget(parent);
......
......@@ -31,10 +31,10 @@ class CANTOR_PYTHONBACKEND_EXPORT PythonBackend : public Cantor::Backend
explicit PythonBackend(QObject* parent = nullptr, const QList<QVariant>& args = QList<QVariant>());
~PythonBackend() override;
Cantor::Backend::Capabilities capabilities() const override;
QWidget* settingsWidget(QWidget* parent) const override;
KConfigSkeleton* config() const override = 0;
Cantor::Backend::Capabilities capabilities() const override = 0;
};
......
......@@ -144,7 +144,7 @@ void PythonServer::setFilePath(const QString& path)
PyRun_SimpleString(("__file__ = '"+path.toStdString()+"'").c_str());
}
QString PythonServer::variables() const
QString PythonServer::variables(bool parseValue) const
{
// FIXME: This code allows get full form of numpy array, but for big arrays it's could cause performonce problems
// especially for displaying in variables panel
......@@ -191,7 +191,10 @@ QString PythonServer::variables() const
if (PyType_Check(value))
continue;
const QString& valueString = pyObjectToQString(PyObject_Repr(value));
QString valueString;
if (parseValue)
valueString = pyObjectToQString(PyObject_Repr(value));
vars.append(keyString + QChar(31) + valueString);
}
......
......@@ -38,7 +38,7 @@ class PythonServer : public QObject
Q_SCRIPTABLE void runPythonCommand(const QString& command) const;
Q_SCRIPTABLE QString getOutput() const;
Q_SCRIPTABLE QString getError() const;
Q_SCRIPTABLE QString variables() const;
Q_SCRIPTABLE QString variables(bool parseValue) const;
private:
PyObject* m_pModule;
......
......@@ -53,6 +53,7 @@ class CANTOR_PYTHONBACKEND_EXPORT PythonSession : public Cantor::Session
virtual bool integratePlots() const = 0;
virtual QStringList autorunScripts() const = 0;
virtual bool variableManagement() const = 0;
private:
PythonVariableModel* m_variableModel;
......
......@@ -45,7 +45,8 @@ void PythonVariableModel::update()
if (!m_pIface)
return;
const QString& data = QDBusReply<QString>(m_pIface->call(QString::fromLatin1("variables"))).value();
bool variableManagement = static_cast<PythonSession*>(session())->variableManagement();
const QString& data = QDBusReply<QString>(m_pIface->call(QString::fromLatin1("variables"), variableManagement)).value();
const QStringList& records = data.split(QChar(30), QString::SkipEmptyParts);
QList<Variable> variables;
......
......@@ -31,6 +31,16 @@
<string>Integrate Plots in Worksheet</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_variableManagement">
<property name="toolTip">
<string>Let Cantor follow the creation/destruction of variables</string>
</property>
<property name="text">
<string>Enable Variable Management</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox">
......
......@@ -53,6 +53,21 @@ QString Python2Backend::version() const
return QLatin1String("2.7");
}
Cantor::Backend::Capabilities Python2Backend::capabilities() const
{
qDebug()<<"Requesting capabilities of Python3Session";
Backend::Capabilities cap =
Cantor::Backend::SyntaxHighlighting |
Cantor::Backend::Completion |
Cantor::Backend::SyntaxHelp;
if(PythonSettings::variableManagement())
cap |= Cantor::Backend::VariableManagement;
return cap;
}
QUrl Python2Backend::helpUrl() const
{
const QUrl& localDoc = PythonSettings::self()->localDoc();
......
......@@ -33,6 +33,7 @@ class Python2Backend : public PythonBackend
QString id() const override;
QString version() const override;
Cantor::Backend::Capabilities capabilities() const override;
QUrl helpUrl() const override;
QString description() const override;
......
......@@ -12,6 +12,10 @@
<label>Integrate Plots into the Worksheet</label>
<default>false</default>
</entry>
<entry name="variableManagement" type="Bool">
<label>Enable Variable Management</label>
<default>true</default>
</entry>
<entry name="autorunScripts" type="StringList">
<label>List of scripts to autorun at the beginning of session</label>
</entry>
......
......@@ -44,3 +44,8 @@ QStringList Python2Session::autorunScripts() const
{
return PythonSettings::autorunScripts();
}
bool Python2Session::variableManagement() const
{
return PythonSettings::variableManagement();
}
......@@ -30,6 +30,7 @@ class Python2Session : public PythonSession
bool integratePlots() const override;
QStringList autorunScripts() const override;
bool variableManagement() const override;
};
#endif
......@@ -46,6 +46,21 @@ QString Python3Backend::version() const
return QLatin1String("3.6");
}
Cantor::Backend::Capabilities Python3Backend::capabilities() const
{
qDebug()<<"Requesting capabilities of Python3Session";
Backend::Capabilities cap =
Cantor::Backend::SyntaxHighlighting |
Cantor::Backend::Completion |
Cantor::Backend::SyntaxHelp;
if(PythonSettings::variableManagement())
cap |= Cantor::Backend::VariableManagement;
return cap;
}
QUrl Python3Backend::helpUrl() const
{
const QUrl& localDoc = PythonSettings::self()->localDoc();
......
......@@ -32,6 +32,7 @@ class Python3Backend : public PythonBackend
QString id() const override;
QString version() const override;
Cantor::Backend::Capabilities capabilities() const override;
QUrl helpUrl() const override;
QString description() const override;
......
......@@ -12,6 +12,10 @@
<label>Integrate Plots into the Worksheet</label>
<default>false</default>
</entry>
<entry name="variableManagement" type="Bool">
<label>Enable Variable Management</label>
<default>true</default>
</entry>
<entry name="autorunScripts" type="StringList">
<label>List of scripts to autorun at the beginning of session</label>
</entry>
......
......@@ -35,3 +35,9 @@ QStringList Python3Session::autorunScripts() const
{
return PythonSettings::autorunScripts();
}
bool Python3Session::variableManagement() const
{
return PythonSettings::variableManagement();
}
......@@ -30,6 +30,7 @@ class Python3Session : public PythonSession
bool integratePlots() const override;
QStringList autorunScripts() const override;
bool variableManagement() const override;
};
#endif
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