From fa7423d185e5f0009afc8ca4e90b7186fadaec08 Mon Sep 17 00:00:00 2001 From: Sam Pfeiffer Date: Sun, 2 Apr 2023 20:51:09 +1000 Subject: [PATCH] Introduce environment variables to skip dialogs to automate PlotJuggler usage Introduce the environment variables: PLOTJUGGLER_ACCEPT_PREVIOUSLY_USED_STREAMING_PLUGIN=1 to skip the dialog 'Start the previously used streaming plugin?' PLOTJUGGLER_CHOOSE_EMPTY_PLACEHOLDERS_ON_MISSING_TIMESERIES=1 to skip the dialog 'One or more timeseries in the layout haven't been loaded yet, What do you want to do?' Note that there is a sibling commit in plotjuggler-ros-plugins to skip the ROS topic selection dialog. This is a workaround for https://github.com/facontidavide/PlotJuggler/issues/201 (passing commandline flags would require a lot of changes) --- README.md | 8 ++++++++ plotjuggler_app/mainwindow.cpp | 29 +++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 086029d37..9df0794d2 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,14 @@ Note that this also affect the desktop launcher. You can find find the detailed instructions here: [COMPILE.md](COMPILE.md). +## Auto start previously used streaming plugin +When loading a layout that includes a streaming plugin, PlotJuggler asks `Start the previously used streaming plugin?`, in order to automatically +click on `Yes`, you can set the environment variable: `PLOTJUGGLER_ACCEPT_PREVIOUSLY_USED_STREAMING_PLUGIN=1` and this dialog will be skipped. + +## Automatically choose 'Create empty placeholders' when data from a layout is missing +When loading a layout some timeseries may be missing, PlotJuggler may ask `One or more timeseries in the layout haven't been loaded yet, What do you want to do?`, with the options: `Remove curves from plots` and `Create empty placeholders`. To automate choosing `Create empty placeholders` you can set the environment variable: `PLOTJUGGLER_CHOOSE_EMPTY_PLACEHOLDERS_ON_MISSING_TIMESERIES=1` and the dialog will be skipped chosing that option. + + # Sponsorship and commercial support PlotJuggler required a lot of work to be developed; my goal is to build the most diff --git a/plotjuggler_app/mainwindow.cpp b/plotjuggler_app/mainwindow.cpp index 1a81975f2..d9ee32e71 100644 --- a/plotjuggler_app/mainwindow.cpp +++ b/plotjuggler_app/mainwindow.cpp @@ -1071,8 +1071,20 @@ void MainWindow::checkAllCurvesFromLayout(const QDomElement& root) QPushButton* buttonPlaceholder = msgBox.addButton(tr("Create empty placeholders"), QMessageBox::YesRole); msgBox.setDefaultButton(buttonPlaceholder); - msgBox.exec(); - if (msgBox.clickedButton() == buttonPlaceholder) + + const char* env_var = std::getenv("PLOTJUGGLER_CHOOSE_EMPTY_PLACEHOLDERS_ON_MISSING_TIMESERIES"); + bool skip_msg_box = (env_var != nullptr && env_var[0] == '1'); + if(skip_msg_box){ + qDebug() << "Environment variable PLOTJUGGLER_CHOOSE_EMPTY_PLACEHOLDERS_ON_MISSING_TIMESERIES set." + << " Skipping dialog.\n"; + // To enable the user to choose manually in the future + setenv("PLOTJUGGLER_CHOOSE_EMPTY_PLACEHOLDERS_ON_MISSING_TIMESERIES", "0", 1); + } + if (!skip_msg_box){ + msgBox.exec(); + } + + if (skip_msg_box || msgBox.clickedButton() == buttonPlaceholder) { for (auto& name : missing_curves) { @@ -2059,9 +2071,18 @@ bool MainWindow::loadLayoutFromFile(QString filename) QPushButton* yes = msgBox.addButton(tr("Yes"), QMessageBox::YesRole); QPushButton* no = msgBox.addButton(tr("No"), QMessageBox::RejectRole); msgBox.setDefaultButton(yes); - msgBox.exec(); - if (msgBox.clickedButton() == yes) + const char* env_var = std::getenv("PLOTJUGGLER_ACCEPT_PREVIOUSLY_USED_STREAMING_PLUGIN"); + bool skip_msg_box = (env_var != nullptr && env_var[0] == '1'); + if (skip_msg_box){ + qDebug() << "Environment variable PLOTJUGGLER_ACCEPT_PREVIOUSLY_USED_STREAMING_PLUGIN set." + << " Skipping dialog.\n"; + } + else{ + msgBox.exec(); + } + + if (skip_msg_box || msgBox.clickedButton() == yes) { if (_data_streamer.count(streamer_name) != 0) {