add checkbox to automatically open tutorial website, if available

This commit is contained in:
Axel Kohlmeyer
2025-04-12 06:49:44 -04:00
parent d0c3564216
commit 1ad2df84d8
4 changed files with 65 additions and 11 deletions

View File

@ -60,6 +60,8 @@
Change working directory to user's home dir if initial directory is "/" or the Application folder
Add preferences option to set https proxy, if not already set via environment variable
Add option to visualize molecules defined through the molecule command
Add text fields for editing plot title and axis labels for charts
Add option to automatically open tutorial websites (enabled by default)
</description>
</release>
<release version="1.6.12" timestamp="1734890080">

View File

@ -1617,7 +1617,7 @@ QWizardPage *LammpsGui::tutorial_directory(const int ntutorial)
"created if necessary and LAMMPS-GUI will download the files required for the "
"tutorial. If selected, an existing directory may be cleared from old "
"files.</p>\n<p>Available files of the tutorial solution may be downloaded to a "
"sub-folder \"solution\", if requested.</p>\n")
"sub-folder called \"solution\", if requested.</p>\n")
.arg(ntutorial));
label->setWordWrap(true);
@ -1657,6 +1657,7 @@ QWizardPage *LammpsGui::tutorial_directory(const int ntutorial)
auto *solval = new QCheckBox;
auto *purgelabel = new QLabel("Remove existing files from directory");
auto *sollabel = new QLabel("Download solutions");
purgeval->setCheckState(Qt::Unchecked);
purgeval->setObjectName("t_dirpurge");
solval->setCheckState(Qt::Unchecked);
@ -1668,6 +1669,18 @@ QWizardPage *LammpsGui::tutorial_directory(const int ntutorial)
grid->setColumnStretch(0, 0);
grid->setColumnStretch(1, 100);
// we have tutorials 1 to 7 currently available online
QCheckBox *webval = nullptr;
if ((ntutorial > 0) && (ntutorial < 8)) {
grid->addWidget(new QLabel, 2, 0, 1, 2, Qt::AlignVCenter);
webval = new QCheckBox;
webval->setCheckState(Qt::Checked);
webval->setObjectName("t_webopen");
grid->addWidget(webval, 3, 0, Qt::AlignVCenter);
grid->addWidget(new QLabel("Open tutorial webpage in web browser"), 3, 1, Qt::AlignVCenter);
}
auto *label2 = new QLabel(
QString("<hr width=\"33%\">\n<p align=\"center\">Click on "
"the \"Finish\" button to complete the setup and start the download.</p>"));
@ -2008,7 +2021,8 @@ static const QString geturl =
"geturl https://raw.githubusercontent.com/lammpstutorials/"
"lammpstutorials-article/refs/heads/main/files/tutorial%1/%2 output %2 verify no";
void LammpsGui::setup_tutorial(int tutno, const QString &dir, bool purgedir, bool getsolution)
void LammpsGui::setup_tutorial(int tutno, const QString &dir, bool purgedir, bool getsolution,
bool openwebpage)
{
constexpr int BUFLEN = 1024;
char errorbuf[BUFLEN];
@ -2023,6 +2037,36 @@ void LammpsGui::setup_tutorial(int tutno, const QString &dir, bool purgedir, boo
QDir directory(dir);
directory.cd(dir);
if (openwebpage) {
QString weburl = "https://lammpstutorials.github.io/sphinx/build/html/tutorial%1/%2.html";
switch (tutno) {
case 1:
weburl = weburl.arg(tutno).arg("lennard-jones-fluid");
break;
case 2:
weburl = weburl.arg(tutno).arg("breaking-a-carbon-nanotube");
break;
case 3:
weburl = weburl.arg(tutno).arg("polymer-in-water");
break;
case 4:
weburl = weburl.arg(tutno).arg("nanosheard-electrolyte");
break;
case 5:
weburl = weburl.arg(tutno).arg("reactive-silicon-dioxide");
break;
case 6:
weburl = weburl.arg(tutno).arg("water-adsorption-in-silica");
break;
case 7:
weburl = weburl.arg(tutno).arg("free-energy-calculation");
break;
default:
weburl = "https://lammpstutorials.github.io/";
}
QDesktopServices::openUrl(QUrl(weburl));
}
if (purgedir) purge_directory(dir);
if (getsolution) directory.mkpath("solution");
@ -2138,10 +2182,14 @@ void TutorialWizard::accept()
auto *dirname = findChild<QLineEdit *>("t_directory");
auto *dirpurge = findChild<QCheckBox *>("t_dirpurge");
auto *getsol = findChild<QCheckBox *>("t_getsolution");
auto *webopen = findChild<QCheckBox *>("t_webopen");
bool purgedir = false;
bool getsolution = false;
bool openwebpage = false;
QString curdir;
if (webopen) openwebpage = (webopen->checkState() == Qt::Checked);
// create and populate directory.
if (dirname) {
QDir directory;
@ -2165,7 +2213,7 @@ void TutorialWizard::accept()
LammpsGui *main = nullptr;
for (QWidget *widget : QApplication::topLevelWidgets())
if (widget->objectName() == "LammpsGui") main = dynamic_cast<LammpsGui *>(widget);
if (main) main->setup_tutorial(_ntutorial, curdir, purgedir, getsolution);
if (main) main->setup_tutorial(_ntutorial, curdir, purgedir, getsolution, openwebpage);
}
}

View File

@ -85,7 +85,8 @@ protected:
void setFont(const QFont &newfont);
QWizardPage *tutorial_intro(const int ntutorial, const QString &infotext);
QWizardPage *tutorial_directory(const int ntutorial);
void setup_tutorial(int ntutorial, const QString &dir, bool purgedir, bool getsolution);
void setup_tutorial(int ntutorial, const QString &dir, bool purgedir, bool getsolution,
bool openwebpage);
void purge_inspect_list();
bool eventFilter(QObject *watched, QEvent *event) override;