bug fix and improve on Setup New Exp panel

This commit is contained in:
Ryan Tang 2023-04-14 13:14:10 -04:00
parent 66c7211d7a
commit b916295a4d

View File

@ -1674,6 +1674,7 @@ void MainWindow::SetupNewExpPanel(){
QPushButton *bnChangeBranch = new QPushButton("Change", &dialog); QPushButton *bnChangeBranch = new QPushButton("Change", &dialog);
layout->addWidget(bnChangeBranch, rowID, 3); layout->addWidget(bnChangeBranch, rowID, 3);
bnChangeBranch->setAutoDefault(false);
connect(bnChangeBranch, &QPushButton::clicked, this, [=](){ this->ChangeExperiment(cb->currentText()); }); connect(bnChangeBranch, &QPushButton::clicked, this, [=](){ this->ChangeExperiment(cb->currentText()); });
connect(bnChangeBranch, &QPushButton::clicked, &dialog, &QDialog::accept); connect(bnChangeBranch, &QPushButton::clicked, &dialog, &QDialog::accept);
@ -1684,9 +1685,11 @@ void MainWindow::SetupNewExpPanel(){
}else{ }else{
for( int i = 0; i < branches.size(); i++){ for( int i = 0; i < branches.size(); i++){
if( i == bID ) continue; if( i == bID ) continue;
if( branches[i].contains("HEAD")) continue;
if( branches[i].contains(presentBranch)) continue;
cb->addItem(branches[i].remove(" ")); cb->addItem(branches[i].remove(" "));
} }
if ( branches.size() == 1) { if ( cb->count() == 0) {
cb->setEnabled(false); cb->setEnabled(false);
cb->addItem("no other branch"); cb->addItem("no other branch");
bnChangeBranch->setEnabled(false); bnChangeBranch->setEnabled(false);
@ -1694,10 +1697,10 @@ void MainWindow::SetupNewExpPanel(){
} }
connect(cbUseGit, &QCheckBox::clicked, this, [=](){ connect(cbUseGit, &QCheckBox::clicked, this, [=](){
if( branches.size() > 1 ) cb->setEnabled(cbUseGit->isChecked()); if( cb->count() > 1 ) {
}); cb->setEnabled(cbUseGit->isChecked());
connect(cbUseGit, &QCheckBox::clicked, this, [=](){ bnChangeBranch->setEnabled(cbUseGit->isChecked());
if(branches.size() > 1 ) bnChangeBranch->setEnabled(cbUseGit->isChecked()); }
}); });
//------- type existing or new experiment //------- type existing or new experiment
@ -1708,15 +1711,28 @@ void MainWindow::SetupNewExpPanel(){
QLineEdit * newExp = new QLineEdit("type and Enter", &dialog); QLineEdit * newExp = new QLineEdit("type and Enter", &dialog);
layout->addWidget(newExp, rowID, 1, 1, 2); layout->addWidget(newExp, rowID, 1, 1, 2);
//newExp->setFocus();
QPushButton *button1 = new QPushButton("Create", &dialog); QPushButton *bnCreateNewExp = new QPushButton("Create", &dialog);
layout->addWidget(button1, rowID, 3); layout->addWidget(bnCreateNewExp, rowID, 3);
button1->setEnabled(false); bnCreateNewExp->setEnabled(false);
bnCreateNewExp->setAutoDefault(false);
connect(newExp, &QLineEdit::textChanged, this, [=](){ newExp->setStyleSheet("color : green;");}); connect(newExp, &QLineEdit::textChanged, this, [=](){
connect(newExp, &QLineEdit::returnPressed, this, [=](){ if( newExp->text() != "") { newExp->setStyleSheet(""); button1->setEnabled(true);}}); newExp->setStyleSheet("color : blue;");
connect(button1, &QPushButton::clicked, this, [=](){ this->CreateNewExperiment(newExp->text());}); if( newExp->text() == "") bnCreateNewExp->setEnabled(false);
connect(button1, &QPushButton::clicked, &dialog, &QDialog::accept); });
connect(newExp, &QLineEdit::returnPressed, this, [=](){
if( newExp->text() != "") {
newExp->setStyleSheet("");
bnCreateNewExp->setEnabled(true);
}
});
connect(bnCreateNewExp, &QPushButton::clicked, this, [=](){ this->CreateNewExperiment(newExp->text());});
connect(bnCreateNewExp, &QPushButton::clicked, &dialog, &QDialog::accept);
//----- diable all possible actions //----- diable all possible actions
//?---- don't know why isGitExist && !isCleanGit does not work //?---- don't know why isGitExist && !isCleanGit does not work
@ -1726,12 +1742,13 @@ void MainWindow::SetupNewExpPanel(){
cb->setEnabled(false); cb->setEnabled(false);
bnChangeBranch->setEnabled(false); bnChangeBranch->setEnabled(false);
newExp->setEnabled(false); newExp->setEnabled(false);
button1->setEnabled(false); bnCreateNewExp->setEnabled(false);
} }
} }
//--------- cancel //--------- cancel
rowID ++; rowID ++;
QPushButton *bnCancel = new QPushButton("Cancel", &dialog); QPushButton *bnCancel = new QPushButton("Cancel", &dialog);
bnCancel->setAutoDefault(false);
layout->addWidget(bnCancel, rowID, 0, 1, 4); layout->addWidget(bnCancel, rowID, 0, 1, 4);
connect(bnCancel, &QPushButton::clicked, this, [=](){this->LogMsg("Cancel <b>New/Change/Reload Exp</b>");}); connect(bnCancel, &QPushButton::clicked, this, [=](){this->LogMsg("Cancel <b>New/Change/Reload Exp</b>");});
connect(bnCancel, &QPushButton::clicked, &dialog, &QDialog::reject); connect(bnCancel, &QPushButton::clicked, &dialog, &QDialog::reject);
@ -1804,6 +1821,7 @@ bool MainWindow::LoadExpSettings(){
void MainWindow::CreateNewExperiment(const QString newExpName){ void MainWindow::CreateNewExperiment(const QString newExpName){
LogMsg("======================================");
LogMsg("Creating new Exp. : <font style=\"color: red;\">" + newExpName + "</font>"); LogMsg("Creating new Exp. : <font style=\"color: red;\">" + newExpName + "</font>");
expName = newExpName; expName = newExpName;
@ -1841,10 +1859,27 @@ void MainWindow::CreateNewExperiment(const QString newExpName){
git.start("git", QStringList() << "commit" << "-m" << "initial commit."); git.start("git", QStringList() << "commit" << "-m" << "initial commit.");
git.waitForFinished(); git.waitForFinished();
LogMsg("Commit branch : <b>" + newExpName + "</b> as \"initial commit\""); LogMsg("Commit branch : <b>" + expName + "</b> as \"initial commit\"");
//check if remote exist, if exist, push to remote
git.start("git", QStringList() << "remote" );
git.waitForFinished();
QString haha = QString::fromLocal8Bit(git.readAllStandardOutput());
if( haha != ""){
git.start("git", QStringList() << "push" << "--set-upstream" << haha.remove('\n') << expName);
git.waitForFinished();
qDebug() << QString::fromLocal8Bit(git.readAllStandardOutput());
LogMsg("Pushed new branch : <b>" + expName + "</b> to remote repositiory.");
} }
CheckElog(); }
//CheckElog();
logMsgHTMLMode = true;
LogMsg("<font style=\"color red;\"> !!!! Please Create a new Elog with name <b>" + newExpName + "</b>. </font>");
leRawDataPath->setText(rawDataFolder); leRawDataPath->setText(rawDataFolder);
leExpName->setText(expName); leExpName->setText(expName);
@ -1861,21 +1896,26 @@ void MainWindow::CreateNewExperiment(const QString newExpName){
influx->WriteData(DatabaseName.toStdString()); influx->WriteData(DatabaseName.toStdString());
} }
} }
void MainWindow::ChangeExperiment(const QString newExpName){ void MainWindow::ChangeExperiment(const QString newExpName){
//@---- git must exist. expName = newExpName;
if( newExpName.contains("remotes")){
QStringList haha = newExpName.split('/');
expName = haha.last();
}
//@---- git must exist.
QProcess git; QProcess git;
git.setWorkingDirectory(analysisPath); git.setWorkingDirectory(analysisPath);
git.start("git", QStringList() << "checkout" << newExpName); git.start("git", QStringList() << "checkout" << expName);
git.waitForFinished(); git.waitForFinished();
LogMsg("Swicted to branch : <b>" + newExpName + "</b>");
expName = newExpName; LogMsg("=============================================");
LogMsg("Swicted to branch : <b>" + expName + "</b>");
CreateRawDataFolderAndLink(); CreateRawDataFolderAndLink();
LoadExpSettings(); LoadExpSettings();
@ -1915,7 +1955,7 @@ void MainWindow::CreateRawDataFolderAndLink(){
QDir dir; QDir dir;
if( !dir.exists(rawDataFolder)){ if( !dir.exists(rawDataFolder)){
if( dir.mkdir(rawDataFolder)){ if( dir.mkdir(rawDataFolder)){
LogMsg("<b>" + rawDataFolder + "</b> created." ); LogMsg("Created folder <b>" + rawDataFolder + "</b> for storing raw data." );
}else{ }else{
LogMsg("<font style=\"color:red;\"><b>" + rawDataFolder + "</b> cannot be created. Access right problem? </font>" ); LogMsg("<font style=\"color:red;\"><b>" + rawDataFolder + "</b> cannot be created. Access right problem? </font>" );
} }
@ -1924,11 +1964,11 @@ void MainWindow::CreateRawDataFolderAndLink(){
} }
//----- create root data folder //----- create root data folder
rootDataFolder = rootDataFolder + "/" + expName; rootDataFolder = rootDataPath + "/" + expName;
QDir rootDir; QDir rootDir;
if( !rootDir.exists(rootDataFolder)) { if( !rootDir.exists(rootDataFolder)) {
if( rootDir.mkdir(rootDataFolder) ){ if( rootDir.mkdir(rootDataFolder) ){
LogMsg("Created folder " + rootDataFolder + " for storing root files"); LogMsg("Created folder <b>" + rootDataFolder + "</b> for storing root files.");
}else{ }else{
LogMsg("<font style=\"color:red;\"><b>" + rootDataFolder + "</b> cannot be created. Access right problem? </font>" ); LogMsg("<font style=\"color:red;\"><b>" + rootDataFolder + "</b> cannot be created. Access right problem? </font>" );
} }
@ -1954,6 +1994,7 @@ void MainWindow::CreateRawDataFolderAndLink(){
if( file.exists(linkName)) { if( file.exists(linkName)) {
file.remove(linkName); file.remove(linkName);
LogMsg("removing existing Link");
} }
if (file.link(rawDataFolder, linkName)) { if (file.link(rawDataFolder, linkName)) {
@ -1962,9 +2003,10 @@ void MainWindow::CreateRawDataFolderAndLink(){
LogMsg("<font style=\"color:red;\">Symbolic link <b>" + linkName +"</b> -> " + rawDataFolder + " cannot be created. </font>"); LogMsg("<font style=\"color:red;\">Symbolic link <b>" + linkName +"</b> -> " + rawDataFolder + " cannot be created. </font>");
} }
linkName = analysisPath + "root_data"; linkName = analysisPath + "/root_data";
if( file.exists(linkName)) { if( file.exists(linkName)) {
file.remove(linkName); file.remove(linkName);
LogMsg("removing existing Link");
} }
if (file.link(rawDataFolder, linkName)) { if (file.link(rawDataFolder, linkName)) {