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

@ -752,13 +752,16 @@ Tutorials
The *Tutorials* menu is to support the set of LAMMPS tutorials for The *Tutorials* menu is to support the set of LAMMPS tutorials for
beginners and intermediate LAMMPS users documented in (:ref:`Gravelle1 beginners and intermediate LAMMPS users documented in (:ref:`Gravelle1
<Gravelle1>`). From the drop down menu you can select which of the eight <Gravelle1>`). From the drop down menu you can select which of the
currently available tutorial sessions you want to start and then will be eight currently available tutorial sessions you want to start and then
taken to a 'wizard' dialog where you can choose in which folder you want will be taken to a 'wizard' dialog where you can choose in which folder
to work, whether you want that folder to be cleared, and also whether you want to work, whether you want that folder to be wiped from *any*
you want to download the solutions files (can be large). The dialog files, whether you want to download the solutions files (which can be
will then start downloading the files requested and load the first input large) to a ``solution`` sub-folder, and whether you want the
file for the selected session into LAMMPS-GUI. corresponding tutorial's online version opened in your web browser. The
dialog will then start downloading the files requested (download
progress is reported in the status line) and load the first input file
for the selected session into LAMMPS-GUI.
About About
^^^^^ ^^^^^

View File

@ -60,6 +60,8 @@
Change working directory to user's home dir if initial directory is "/" or the Application folder 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 preferences option to set https proxy, if not already set via environment variable
Add option to visualize molecules defined through the molecule command 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> </description>
</release> </release>
<release version="1.6.12" timestamp="1734890080"> <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 " "created if necessary and LAMMPS-GUI will download the files required for the "
"tutorial. If selected, an existing directory may be cleared from old " "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 " "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)); .arg(ntutorial));
label->setWordWrap(true); label->setWordWrap(true);
@ -1657,6 +1657,7 @@ QWizardPage *LammpsGui::tutorial_directory(const int ntutorial)
auto *solval = new QCheckBox; auto *solval = new QCheckBox;
auto *purgelabel = new QLabel("Remove existing files from directory"); auto *purgelabel = new QLabel("Remove existing files from directory");
auto *sollabel = new QLabel("Download solutions"); auto *sollabel = new QLabel("Download solutions");
purgeval->setCheckState(Qt::Unchecked); purgeval->setCheckState(Qt::Unchecked);
purgeval->setObjectName("t_dirpurge"); purgeval->setObjectName("t_dirpurge");
solval->setCheckState(Qt::Unchecked); solval->setCheckState(Qt::Unchecked);
@ -1668,6 +1669,18 @@ QWizardPage *LammpsGui::tutorial_directory(const int ntutorial)
grid->setColumnStretch(0, 0); grid->setColumnStretch(0, 0);
grid->setColumnStretch(1, 100); 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( auto *label2 = new QLabel(
QString("<hr width=\"33%\">\n<p align=\"center\">Click on " QString("<hr width=\"33%\">\n<p align=\"center\">Click on "
"the \"Finish\" button to complete the setup and start the download.</p>")); "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/" "geturl https://raw.githubusercontent.com/lammpstutorials/"
"lammpstutorials-article/refs/heads/main/files/tutorial%1/%2 output %2 verify no"; "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; constexpr int BUFLEN = 1024;
char errorbuf[BUFLEN]; char errorbuf[BUFLEN];
@ -2023,6 +2037,36 @@ void LammpsGui::setup_tutorial(int tutno, const QString &dir, bool purgedir, boo
QDir directory(dir); QDir directory(dir);
directory.cd(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 (purgedir) purge_directory(dir);
if (getsolution) directory.mkpath("solution"); if (getsolution) directory.mkpath("solution");
@ -2138,10 +2182,14 @@ void TutorialWizard::accept()
auto *dirname = findChild<QLineEdit *>("t_directory"); auto *dirname = findChild<QLineEdit *>("t_directory");
auto *dirpurge = findChild<QCheckBox *>("t_dirpurge"); auto *dirpurge = findChild<QCheckBox *>("t_dirpurge");
auto *getsol = findChild<QCheckBox *>("t_getsolution"); auto *getsol = findChild<QCheckBox *>("t_getsolution");
auto *webopen = findChild<QCheckBox *>("t_webopen");
bool purgedir = false; bool purgedir = false;
bool getsolution = false; bool getsolution = false;
bool openwebpage = false;
QString curdir; QString curdir;
if (webopen) openwebpage = (webopen->checkState() == Qt::Checked);
// create and populate directory. // create and populate directory.
if (dirname) { if (dirname) {
QDir directory; QDir directory;
@ -2165,7 +2213,7 @@ void TutorialWizard::accept()
LammpsGui *main = nullptr; LammpsGui *main = nullptr;
for (QWidget *widget : QApplication::topLevelWidgets()) for (QWidget *widget : QApplication::topLevelWidgets())
if (widget->objectName() == "LammpsGui") main = dynamic_cast<LammpsGui *>(widget); 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); void setFont(const QFont &newfont);
QWizardPage *tutorial_intro(const int ntutorial, const QString &infotext); QWizardPage *tutorial_intro(const int ntutorial, const QString &infotext);
QWizardPage *tutorial_directory(const int ntutorial); 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(); void purge_inspect_list();
bool eventFilter(QObject *watched, QEvent *event) override; bool eventFilter(QObject *watched, QEvent *event) override;