use platform abstractions from Qt library
This commit is contained in:
@ -2,8 +2,6 @@ LAMMPS-GUI TODO list:
|
|||||||
|
|
||||||
# Short term goals
|
# Short term goals
|
||||||
|
|
||||||
- use qgetenv, qputenv for portability
|
|
||||||
- use QFile/QDir/QFileInto for portable file and directory operations.
|
|
||||||
- write LAMMPS GUI Howto showing/explaining options -> simplify docs and readme
|
- write LAMMPS GUI Howto showing/explaining options -> simplify docs and readme
|
||||||
- rewrite syntax highlighting to be line oriented instead of word oriented.
|
- rewrite syntax highlighting to be line oriented instead of word oriented.
|
||||||
handle first part of line based on regular expressions, then advance and only highlight strings and numbers.
|
handle first part of line based on regular expressions, then advance and only highlight strings and numbers.
|
||||||
|
|||||||
@ -170,7 +170,7 @@ void ImageViewer::createImage()
|
|||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
QString dumpcmd = QString("write_dump ") + group + " image ";
|
QString dumpcmd = QString("write_dump ") + group + " image ";
|
||||||
QDir dumpdir = settings.value("tempdir").toString();
|
QDir dumpdir(QDir::tempPath());
|
||||||
QFile dumpfile(dumpdir.absoluteFilePath(filename + ".ppm"));
|
QFile dumpfile(dumpdir.absoluteFilePath(filename + ".ppm"));
|
||||||
dumpcmd += dumpfile.fileName();
|
dumpcmd += dumpfile.fileName();
|
||||||
|
|
||||||
|
|||||||
@ -55,6 +55,7 @@ private slots:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void createImage();
|
void createImage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createActions();
|
void createActions();
|
||||||
void updateActions();
|
void updateActions();
|
||||||
|
|||||||
@ -48,12 +48,6 @@
|
|||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#include <io.h>
|
|
||||||
#else
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const QString blank(" ");
|
static const QString blank(" ");
|
||||||
static constexpr int MAXRECENT = 5;
|
static constexpr int MAXRECENT = 5;
|
||||||
|
|
||||||
@ -114,35 +108,14 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
|||||||
#if defined(_OPENMP)
|
#if defined(_OPENMP)
|
||||||
// use maximum number of available threads unless OMP_NUM_THREADS was set
|
// use maximum number of available threads unless OMP_NUM_THREADS was set
|
||||||
int nthreads = settings.value("nthreads", omp_get_max_threads()).toInt();
|
int nthreads = settings.value("nthreads", omp_get_max_threads()).toInt();
|
||||||
#if _WIN32
|
if (!qEnvironmentVariableIsSet("OMP_NUM_THREADS")) {
|
||||||
if (!getenv("OMP_NUM_THREADS")) {
|
qputenv("OMP_NUM_THREADS", std::to_string(nthreads).c_str());
|
||||||
_putenv_s("OMP_NUM_THREADS", std::to_string(nthreads).c_str());
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
setenv("OMP_NUM_THREADS", std::to_string(nthreads).c_str(), 0);
|
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
int nthreads = settings.value("nthreads", 1).toInt();
|
int nthreads = settings.value("nthreads", 1).toInt();
|
||||||
#endif
|
#endif
|
||||||
settings.setValue("nthreads", QString::number(nthreads));
|
settings.setValue("nthreads", QString::number(nthreads));
|
||||||
|
|
||||||
const char *tmpdir = getenv("TMPDIR");
|
|
||||||
if (!tmpdir) tmpdir = getenv("TMP");
|
|
||||||
if (!tmpdir) tmpdir = getenv("TEMPDIR");
|
|
||||||
if (!tmpdir) tmpdir = getenv("TEMP");
|
|
||||||
#if _WIN32
|
|
||||||
if (!tmpdir) tmpdir = "C:\\Windows\\Temp";
|
|
||||||
#else
|
|
||||||
if (!tmpdir) tmpdir = "/tmp";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QFileInfo newtmp(settings.value("tempdir", QString(tmpdir)).toString());
|
|
||||||
if (newtmp.isDir() && newtmp.isWritable()) {
|
|
||||||
settings.setValue("tempdir", newtmp.filePath());
|
|
||||||
} else {
|
|
||||||
settings.setValue("tempdir", QString(tmpdir));
|
|
||||||
}
|
|
||||||
|
|
||||||
lammps_args.clear();
|
lammps_args.clear();
|
||||||
lammps_args.push_back(mystrdup("LAMMPS-GUI"));
|
lammps_args.push_back(mystrdup("LAMMPS-GUI"));
|
||||||
lammps_args.push_back(mystrdup("-log"));
|
lammps_args.push_back(mystrdup("-log"));
|
||||||
@ -666,12 +639,8 @@ void LammpsGui::run_buffer()
|
|||||||
logwindow->setWindowTitle("LAMMPS-GUI - Output from running LAMMPS on buffer - " +
|
logwindow->setWindowTitle("LAMMPS-GUI - Output from running LAMMPS on buffer - " +
|
||||||
current_file);
|
current_file);
|
||||||
logwindow->setWindowIcon(QIcon(":/lammps-icon-128x128.png"));
|
logwindow->setWindowIcon(QIcon(":/lammps-icon-128x128.png"));
|
||||||
#if (__APPLE__)
|
QFont text_font;
|
||||||
QFont text_font("Menlo");
|
text_font.fromString(settings.value("textfont", text_font.toString()).toString());
|
||||||
#else
|
|
||||||
QFont text_font(":/Monospace.ttf");
|
|
||||||
#endif
|
|
||||||
text_font.setStyleHint(QFont::TypeWriter);
|
|
||||||
logwindow->document()->setDefaultFont(text_font);
|
logwindow->document()->setDefaultFont(text_font);
|
||||||
logwindow->setLineWrapMode(LogWindow::NoWrap);
|
logwindow->setLineWrapMode(LogWindow::NoWrap);
|
||||||
logwindow->setMinimumSize(400, 300);
|
logwindow->setMinimumSize(400, 300);
|
||||||
|
|||||||
@ -99,11 +99,6 @@ void Preferences::accept()
|
|||||||
if (field)
|
if (field)
|
||||||
if (field->hasAcceptableInput()) settings->setValue("nthreads", field->text());
|
if (field->hasAcceptableInput()) settings->setValue("nthreads", field->text());
|
||||||
|
|
||||||
// store temp dir
|
|
||||||
field = tabWidget->findChild<QLineEdit *>("tmpedit");
|
|
||||||
if (field)
|
|
||||||
if (field->hasAcceptableInput()) settings->setValue("tempdir", field->text());
|
|
||||||
|
|
||||||
// store image width, height, zoom, and rendering settings
|
// store image width, height, zoom, and rendering settings
|
||||||
|
|
||||||
settings->beginGroup("snapshot");
|
settings->beginGroup("snapshot");
|
||||||
@ -173,17 +168,6 @@ GeneralTab::GeneralTab(QSettings *_settings, LammpsWrapper *_lammps, QWidget *pa
|
|||||||
pltr->setObjectName("chartreplace");
|
pltr->setObjectName("chartreplace");
|
||||||
pltr->setCheckState(settings->value("chartreplace", false).toBool() ? Qt::Checked
|
pltr->setCheckState(settings->value("chartreplace", false).toBool() ? Qt::Checked
|
||||||
: Qt::Unchecked);
|
: Qt::Unchecked);
|
||||||
#if !defined(__APPLE__)
|
|
||||||
auto *tmplabel = new QLabel("Scratch Folder:");
|
|
||||||
auto *tmpedit = new QLineEdit(settings->value("tempdir", ".").toString());
|
|
||||||
auto *tmpbrowse = new QPushButton("Browse...");
|
|
||||||
auto *tmplayout = new QHBoxLayout;
|
|
||||||
tmpedit->setObjectName("tmpedit");
|
|
||||||
tmplayout->addWidget(tmplabel);
|
|
||||||
tmplayout->addWidget(tmpedit);
|
|
||||||
tmplayout->addWidget(tmpbrowse);
|
|
||||||
connect(tmpbrowse, &QPushButton::released, this, &GeneralTab::newtmpfolder);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
||||||
auto *pluginlabel = new QLabel("Path to LAMMPS Shared Library File:");
|
auto *pluginlabel = new QLabel("Path to LAMMPS Shared Library File:");
|
||||||
@ -213,9 +197,6 @@ GeneralTab::GeneralTab(QSettings *_settings, LammpsWrapper *_lammps, QWidget *pa
|
|||||||
layout->addWidget(logr);
|
layout->addWidget(logr);
|
||||||
layout->addWidget(pltr);
|
layout->addWidget(pltr);
|
||||||
layout->addWidget(imgr);
|
layout->addWidget(imgr);
|
||||||
#if !defined(__APPLE__)
|
|
||||||
layout->addLayout(tmplayout);
|
|
||||||
#endif
|
|
||||||
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
||||||
layout->addWidget(pluginlabel);
|
layout->addWidget(pluginlabel);
|
||||||
layout->addLayout(pluginlayout);
|
layout->addLayout(pluginlayout);
|
||||||
@ -263,18 +244,6 @@ void GeneralTab::newtextfont()
|
|||||||
settings.setValue("textfont", font.toString());
|
settings.setValue("textfont", font.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeneralTab::newtmpfolder()
|
|
||||||
{
|
|
||||||
QLineEdit *field = findChild<QLineEdit *>("tmpedit");
|
|
||||||
QString tmpdir =
|
|
||||||
QFileDialog::getExistingDirectory(this, "Find Folder for Temporary Files", field->text());
|
|
||||||
|
|
||||||
if (!tmpdir.isEmpty()) {
|
|
||||||
QFileInfo newtmp(tmpdir);
|
|
||||||
if (newtmp.isDir() && newtmp.isWritable()) field->setText(tmpdir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GeneralTab::pluginpath()
|
void GeneralTab::pluginpath()
|
||||||
{
|
{
|
||||||
QLineEdit *field = findChild<QLineEdit *>("pluginedit");
|
QLineEdit *field = findChild<QLineEdit *>("pluginedit");
|
||||||
|
|||||||
@ -49,7 +49,6 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void pluginpath();
|
void pluginpath();
|
||||||
void newtmpfolder();
|
|
||||||
void newallfont();
|
void newallfont();
|
||||||
void newtextfont();
|
void newtextfont();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user