regularize application startup. use Qt's command line parser support
This commit is contained in:
@ -40,7 +40,6 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QLocale>
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
#include <QProgressBar>
|
||||
@ -76,9 +75,6 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
||||
prefdialog(nullptr), lammpsstatus(nullptr), varwindow(nullptr), wizard(nullptr),
|
||||
runner(nullptr), is_running(false), run_counter(0)
|
||||
{
|
||||
// enforce using the plain ASCII C locale within the GUI.
|
||||
QLocale::setDefault(QLocale("C"));
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
// register QList<QString> only needed for Qt5
|
||||
qRegisterMetaTypeStreamOperators<QList<QString>>("QList<QString>");
|
||||
@ -95,14 +91,6 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
||||
if (current_dir == "/") current_dir = QDir::homePath();
|
||||
inspectList.clear();
|
||||
|
||||
#define stringify(x) myxstr(x)
|
||||
#define myxstr(x) #x
|
||||
QCoreApplication::setOrganizationName("The LAMMPS Developers");
|
||||
QCoreApplication::setOrganizationDomain("lammps.org");
|
||||
QCoreApplication::setApplicationName("LAMMPS-GUI - QT" stringify(QT_VERSION_MAJOR));
|
||||
#undef stringify
|
||||
#undef myxstr
|
||||
|
||||
// restore and initialize settings
|
||||
QSettings settings;
|
||||
|
||||
|
||||
@ -14,28 +14,42 @@
|
||||
#include "lammpsgui.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCommandLineOption>
|
||||
#include <QCommandLineParser>
|
||||
#include <QLocale>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#define stringify(x) myxstr(x)
|
||||
#define myxstr(x) #x
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
Q_INIT_RESOURCE(lammpsgui);
|
||||
QApplication app(argc, argv);
|
||||
// enforce using the plain ASCII C locale within the GUI.
|
||||
QLocale::setDefault(QLocale::c());
|
||||
QCoreApplication::setOrganizationName("The LAMMPS Developers");
|
||||
QCoreApplication::setOrganizationDomain("lammps.org");
|
||||
QCoreApplication::setApplicationName("LAMMPS-GUI - QT" stringify(QT_VERSION_MAJOR));
|
||||
QCoreApplication::setApplicationVersion(LAMMPS_GUI_VERSION);
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(
|
||||
"\nThis is LAMMPS-GUI v" LAMMPS_GUI_VERSION "\n"
|
||||
"\nA graphical editor for LAMMPS input files with syntax highlighting and\n"
|
||||
"auto-completion that can run LAMMPS directly. It has built-in capabilities\n"
|
||||
"for monitoring, visualization, plotting, and capturing console output.");
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
parser.addPositionalArgument("file", "The LAMMPS input file to open (optional).");
|
||||
parser.process(app); // this removes known arguments
|
||||
|
||||
const char *infile = nullptr;
|
||||
if (argc > 1) {
|
||||
infile = argv[1];
|
||||
if ((strcmp(infile, "-help") == 0) || (strcmp(infile, "-h") == 0)) {
|
||||
printf("This is LAMMPS-GUI version " LAMMPS_GUI_VERSION
|
||||
" using Qt version " QT_VERSION_STR "\n");
|
||||
printf("Usage: %s [-h|-help|<inputfile>]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > 1) infile = argv[1];
|
||||
LammpsGui w(nullptr, infile);
|
||||
w.show();
|
||||
return QApplication::exec();
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
|
||||
Reference in New Issue
Block a user