Commit 783a4e91 authored by Sylvain Thery's avatar Sylvain Thery

upgrade python recording

parent dad3b8ae
...@@ -96,7 +96,10 @@ void Plugin::pythonRecording(QString slotName, QString returned, T1 param1) ...@@ -96,7 +96,10 @@ void Plugin::pythonRecording(QString slotName, QString returned, T1 param1)
if (rec) if (rec)
{ {
if (!returned.isEmpty()) if (!returned.isEmpty())
{
m_schnapps->pythonVarDeclare(returned);
*rec << returned << " = "; *rec << returned << " = ";
}
*rec << this->getName() << "." << slotName << "(" << pyR_stringify(param1) << ");" << endl; *rec << this->getName() << "." << slotName << "(" << pyR_stringify(param1) << ");" << endl;
} }
} }
...@@ -108,7 +111,10 @@ void Plugin::pythonRecording(QString slotName, QString returned, T1 param1, T2 p ...@@ -108,7 +111,10 @@ void Plugin::pythonRecording(QString slotName, QString returned, T1 param1, T2 p
if (rec) if (rec)
{ {
if (!returned.isEmpty()) if (!returned.isEmpty())
{
m_schnapps->pythonVarDeclare(returned);
*rec << returned << " = "; *rec << returned << " = ";
}
*rec << this->getName() << "." << slotName << "(" << pyR_stringify(param1) << ", " << pyR_stringify(param2) << ");" << endl; *rec << this->getName() << "." << slotName << "(" << pyR_stringify(param1) << ", " << pyR_stringify(param2) << ");" << endl;
} }
} }
...@@ -120,7 +126,10 @@ void Plugin::pythonRecording(QString slotName, QString returned, T1 param1, T2 p ...@@ -120,7 +126,10 @@ void Plugin::pythonRecording(QString slotName, QString returned, T1 param1, T2 p
if (rec) if (rec)
{ {
if (!returned.isEmpty()) if (!returned.isEmpty())
{
m_schnapps->pythonVarDeclare(returned);
*rec << returned << " = "; *rec << returned << " = ";
}
*rec << this->getName() << "." << slotName << "(" << pyR_stringify(param1) << ", " << pyR_stringify(param2) << ", " << pyR_stringify(param3) << ");" << endl; *rec << this->getName() << "." << slotName << "(" << pyR_stringify(param1) << ", " << pyR_stringify(param2) << ", " << pyR_stringify(param3) << ");" << endl;
} }
} }
...@@ -133,7 +142,10 @@ void Plugin::pythonRecording(QString slotName, QString returned, T1 param1, T2 p ...@@ -133,7 +142,10 @@ void Plugin::pythonRecording(QString slotName, QString returned, T1 param1, T2 p
if (rec) if (rec)
{ {
if (!returned.isEmpty()) if (!returned.isEmpty())
{
m_schnapps->pythonVarDeclare(returned);
*rec << returned << " = "; *rec << returned << " = ";
}
*rec << this->getName() << "." << slotName << "(" << pyR_stringify(param1) << ", " << pyR_stringify(param2) << ", " << pyR_stringify(param3) << ", " << pyR_stringify(param4) << ");" << endl; *rec << this->getName() << "." << slotName << "(" << pyR_stringify(param1) << ", " << pyR_stringify(param2) << ", " << pyR_stringify(param3) << ", " << pyR_stringify(param4) << ");" << endl;
} }
} }
...@@ -145,7 +157,10 @@ void Plugin::pythonRecording(QString slotName, QString returned, T1 param1, T2 p ...@@ -145,7 +157,10 @@ void Plugin::pythonRecording(QString slotName, QString returned, T1 param1, T2 p
if (rec) if (rec)
{ {
if (!returned.isEmpty()) if (!returned.isEmpty())
{
m_schnapps->pythonVarDeclare(returned);
*rec << returned << " = "; *rec << returned << " = ";
}
*rec << this->getName() << "." << slotName << "(" << pyR_stringify(param1) << ", " << pyR_stringify(param2) << ", "; *rec << this->getName() << "." << slotName << "(" << pyR_stringify(param1) << ", " << pyR_stringify(param2) << ", ";
*rec << pyR_stringify(param3) << ", " << pyR_stringify(param4) << ", " << pyR_stringify(param5) << ");" << endl; *rec << pyR_stringify(param3) << ", " << pyR_stringify(param4) << ", " << pyR_stringify(param5) << ");" << endl;
} }
...@@ -159,7 +174,10 @@ void Plugin::pythonRecording(QString slotName, QString returned, T1 param1, T2 p ...@@ -159,7 +174,10 @@ void Plugin::pythonRecording(QString slotName, QString returned, T1 param1, T2 p
if (rec) if (rec)
{ {
if (!returned.isEmpty()) if (!returned.isEmpty())
{
m_schnapps->pythonVarDeclare(returned);
*rec << returned << " = "; *rec << returned << " = ";
}
*rec << this->getName() << "." << slotName << "(" << pyR_stringify(param1) << ", " << pyR_stringify(param2) << ", "; *rec << this->getName() << "." << slotName << "(" << pyR_stringify(param1) << ", " << pyR_stringify(param2) << ", ";
*rec << pyR_stringify(param3) << ", " << pyR_stringify(param4) << ", " << pyR_stringify(param5) << ", " << pyR_stringify(param6) << ");" << endl; *rec << pyR_stringify(param3) << ", " << pyR_stringify(param4) << ", " << pyR_stringify(param5) << ", " << pyR_stringify(param6) << ");" << endl;
} }
...@@ -174,7 +192,10 @@ void Plugin::pythonRecording(QString slotName, QString returned, T1 param1, T2 p ...@@ -174,7 +192,10 @@ void Plugin::pythonRecording(QString slotName, QString returned, T1 param1, T2 p
if (rec) if (rec)
{ {
if (!returned.isEmpty()) if (!returned.isEmpty())
{
m_schnapps->pythonVarDeclare(returned);
*rec << returned << " = "; *rec << returned << " = ";
}
*rec << this->getName() << "." << slotName << "(" << pyR_stringify(param1) << ", " << pyR_stringify(param2) << ", "; *rec << this->getName() << "." << slotName << "(" << pyR_stringify(param1) << ", " << pyR_stringify(param2) << ", ";
*rec << pyR_stringify(param3) << ", " << pyR_stringify(param4) << ", " << pyR_stringify(param5) << ", "; *rec << pyR_stringify(param3) << ", " << pyR_stringify(param4) << ", " << pyR_stringify(param5) << ", ";
*rec << pyR_stringify(param6) << ", " << pyR_stringify(param7) << ", " << pyR_stringify(param8) << ", "; *rec << pyR_stringify(param6) << ", " << pyR_stringify(param7) << ", " << pyR_stringify(param8) << ", ";
......
...@@ -156,6 +156,8 @@ private slots: ...@@ -156,6 +156,8 @@ private slots:
protected: protected:
QTextStream* m_pyRecording; QTextStream* m_pyRecording;
QFile* m_pyRecFile; QFile* m_pyRecFile;
QList<QString> m_pyVarNames;
QString m_pyBuffer;
private slots: private slots:
void beginPyRecording(); void beginPyRecording();
...@@ -164,7 +166,8 @@ private slots: ...@@ -164,7 +166,8 @@ private slots:
public: public:
inline QTextStream* pythonStreamRecorder() { return m_pyRecording; } inline QTextStream* pythonStreamRecorder() { return m_pyRecording; }
inline void pythonVarDeclare(const QString& var) { m_pyVarNames.push_back(var); }
inline void pythonVarsClear() { m_pyVarNames.clear(); }
signals: signals:
void cameraAdded(Camera* camera); void cameraAdded(Camera* camera);
......
...@@ -839,7 +839,11 @@ void SCHNApps::beginPyRecording() ...@@ -839,7 +839,11 @@ void SCHNApps::beginPyRecording()
if (m_pyRecording != NULL) // WRITE & CLOSE if (m_pyRecording != NULL) // WRITE & CLOSE
{ {
QTextStream out(m_pyRecFile); QTextStream out(m_pyRecFile);
out << m_pyRecording->readAll(); foreach(QString var, m_pyVarNames)
{
m_pyBuffer.replace("\"" + var + "\"", var + ".getName()");
}
out << m_pyBuffer << endl;
m_pyRecFile->close(); m_pyRecFile->close();
delete m_pyRecording; delete m_pyRecording;
...@@ -856,7 +860,10 @@ void SCHNApps::beginPyRecording() ...@@ -856,7 +860,10 @@ void SCHNApps::beginPyRecording()
m_pyRecFile = new QFile(fileName); m_pyRecFile = new QFile(fileName);
if (!m_pyRecFile->open(QIODevice::WriteOnly | QIODevice::Text)) if (!m_pyRecFile->open(QIODevice::WriteOnly | QIODevice::Text))
return; return;
m_pyRecording = new QTextStream(m_pyRecFile);
m_pyBuffer.clear();
m_pyRecording = new QTextStream(&m_pyBuffer);
foreach(View *v, m_views) foreach(View *v, m_views)
*m_pyRecording << v->getName() << " = schnapps.getView(\"" << v->getName() << "\");" << endl; *m_pyRecording << v->getName() << " = schnapps.getView(\"" << v->getName() << "\");" << endl;
...@@ -865,6 +872,7 @@ void SCHNApps::beginPyRecording() ...@@ -865,6 +872,7 @@ void SCHNApps::beginPyRecording()
*m_pyRecording << m->getName() << " = schnapps.getMap(\"" << m->getName() << "\");" << endl; *m_pyRecording << m->getName() << " = schnapps.getMap(\"" << m->getName() << "\");" << endl;
statusbar->showMessage(QString(" Recording python in ") + fileName); statusbar->showMessage(QString(" Recording python in ") + fileName);
pythonVarsClear();
} }
else else
{ {
...@@ -880,7 +888,11 @@ void SCHNApps::appendPyRecording() ...@@ -880,7 +888,11 @@ void SCHNApps::appendPyRecording()
if (m_pyRecording != NULL) // WRITE & CLOSE if (m_pyRecording != NULL) // WRITE & CLOSE
{ {
QTextStream out(m_pyRecFile); QTextStream out(m_pyRecFile);
out << m_pyRecording->readAll(); foreach(QString var, m_pyVarNames)
{
m_pyBuffer.replace("\"" + var + "\"", var + ".getName()");
}
out << m_pyBuffer << endl;
m_pyRecFile->close(); m_pyRecFile->close();
delete m_pyRecording; delete m_pyRecording;
...@@ -897,15 +909,22 @@ void SCHNApps::appendPyRecording() ...@@ -897,15 +909,22 @@ void SCHNApps::appendPyRecording()
m_pyRecFile = new QFile(fileName); m_pyRecFile = new QFile(fileName);
if (!m_pyRecFile->open(QIODevice::Append | QIODevice::Text)) if (!m_pyRecFile->open(QIODevice::Append | QIODevice::Text))
return; return;
m_pyRecording = new QTextStream(m_pyRecFile);
m_pyBuffer.clear();
m_pyRecording = new QTextStream(&m_pyBuffer);
pythonVarsClear();
foreach(View *v, m_views) foreach(View *v, m_views)
*m_pyRecording << v->getName() << " = schnapps.getView(\"" << v->getName() << "\");" << endl; *m_pyRecording << v->getName() << " = schnapps.getView(\"" << v->getName() << "\");" << endl;
foreach(MapHandlerGen *m, m_maps) foreach(MapHandlerGen *m, m_maps)
*m_pyRecording << m->getName() << " = schnapps.getMap(\"" << m->getName() << "\");" << endl; {
*m_pyRecording << m->getName() << " = schnapps.getMap(\"" << m->getName() << "\"); #replace by = previous_var if appending" << endl;
pythonVarDeclare(m->getName());
}
statusbar->showMessage(QString(" Append recording python in ") + fileName); statusbar->showMessage(QString(" Append recording python in ") + fileName);
} }
else else
{ {
......
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