From 55ff424a3e0333939e3a556e448ef7a0a38ca88a Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@uliege.be>
Date: Thu, 1 Oct 2020 18:11:09 +0200
Subject: [PATCH] run GUI in all tutorials if command line does not contain
 "-nopopup"

---
 tutorial/c++/t1.cpp    | 10 +++++++---
 tutorial/c++/t10.cpp   |  7 +++++--
 tutorial/c++/t11.cpp   |  5 ++++-
 tutorial/c++/t12.cpp   |  5 ++++-
 tutorial/c++/t13.cpp   |  7 +++++--
 tutorial/c++/t14.cpp   | 13 +++++++++----
 tutorial/c++/t15.cpp   |  5 +++++
 tutorial/c++/t16.cpp   |  6 ++++--
 tutorial/c++/t17.cpp   |  7 ++++++-
 tutorial/c++/t18.cpp   |  5 ++++-
 tutorial/c++/t19.cpp   |  7 ++++++-
 tutorial/c++/t2.cpp    |  7 ++++++-
 tutorial/c++/t20.cpp   |  8 +++++---
 tutorial/c++/t21.cpp   |  7 +++++--
 tutorial/c++/t3.cpp    |  5 +++--
 tutorial/c++/t4.cpp    |  7 +++----
 tutorial/c++/t5.cpp    |  7 +++++--
 tutorial/c++/t6.cpp    |  6 ++++++
 tutorial/c++/t7.cpp    |  5 ++---
 tutorial/c++/t8.cpp    |  9 ++++-----
 tutorial/c++/t9.cpp    |  7 +++----
 tutorial/c++/x2.cpp    |  5 ++++-
 tutorial/c++/x3.cpp    |  5 ++---
 tutorial/c++/x4.cpp    |  5 ++---
 tutorial/julia/t1.jl   |  4 ++++
 tutorial/julia/t10.jl  |  4 ++++
 tutorial/julia/t16.jl  |  4 ++++
 tutorial/julia/t2.jl   |  4 ++++
 tutorial/julia/t3.jl   |  5 +++++
 tutorial/julia/t4.jl   |  1 -
 tutorial/julia/t5.jl   |  5 ++++-
 tutorial/python/t1.py  |  9 ++++++---
 tutorial/python/t10.py |  4 +++-
 tutorial/python/t11.py |  5 ++++-
 tutorial/python/t12.py |  5 ++++-
 tutorial/python/t13.py |  5 ++++-
 tutorial/python/t14.py |  5 +++++
 tutorial/python/t15.py |  5 +++++
 tutorial/python/t16.py |  6 ++++--
 tutorial/python/t17.py |  5 ++++-
 tutorial/python/t18.py |  5 ++++-
 tutorial/python/t19.py |  7 ++++++-
 tutorial/python/t2.py  |  4 ++++
 tutorial/python/t20.py |  6 ++++--
 tutorial/python/t21.py |  5 ++++-
 tutorial/python/t3.py  |  5 +++--
 tutorial/python/t5.py  |  5 ++++-
 tutorial/python/t6.py  |  6 ++++++
 tutorial/python/t8.py  |  2 +-
 tutorial/python/t9.py  |  2 +-
 tutorial/python/x2.py  |  4 +++-
 51 files changed, 213 insertions(+), 74 deletions(-)

diff --git a/tutorial/c++/t1.cpp b/tutorial/c++/t1.cpp
index 8dcca235fe..9f9d902578 100644
--- a/tutorial/c++/t1.cpp
+++ b/tutorial/c++/t1.cpp
@@ -6,6 +6,8 @@
 //
 // -----------------------------------------------------------------------------
 
+#include <set>
+
 // The Gmsh C++ API is entirely defined in the `gmsh.h' header (which contains
 // the full documentation of all the functions in the API):
 #include <gmsh.h>
@@ -146,9 +148,11 @@ int main(int argc, char **argv)
   // the format explicitly, and just choose a filename with the `.msh2' or
   // `.msh4' extension.
 
-  // To visualize the model we could run the graphical user interface with:
-  //
-  // gmsh::fltk::run();
+  // To visualize the model we can run the graphical user interface with
+  // `gmsh::fltk::run()'. Here we run it only if the "-nopopup" is not provided
+  // in the command line arguments:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   // Note that starting with Gmsh 3.0, models can be built using other geometry
   // kernels than the default "built-in" kernel. To use the OpenCASCADE geometry
diff --git a/tutorial/c++/t10.cpp b/tutorial/c++/t10.cpp
index f539a1e68f..0525b0f403 100644
--- a/tutorial/c++/t10.cpp
+++ b/tutorial/c++/t10.cpp
@@ -10,8 +10,9 @@
 // (see `t1.cpp') or using a background mesh (see `t7.cpp'), you can use general
 // mesh size "Fields".
 
-#include <gmsh.h>
+#include <set>
 #include <sstream>
+#include <gmsh.h>
 
 int main(int argc, char **argv)
 {
@@ -146,7 +147,9 @@ int main(int argc, char **argv)
   gmsh::model::mesh::generate(2);
   gmsh::write("t10.msh");
 
-  // gmsh::fltk::run();
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
   return 0;
diff --git a/tutorial/c++/t11.cpp b/tutorial/c++/t11.cpp
index b3601fb530..b7c897f059 100644
--- a/tutorial/c++/t11.cpp
+++ b/tutorial/c++/t11.cpp
@@ -6,6 +6,7 @@
 //
 // -----------------------------------------------------------------------------
 
+#include <set>
 #include <gmsh.h>
 
 int main(int argc, char **argv)
@@ -91,7 +92,9 @@ int main(int argc, char **argv)
   // gmsh::option::setNumber("Mesh.SubdivisionAlgorithm", 1);
   // gmsh::model::mesh::refine();
 
-  // gmsh::fltk::run();
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
   return 0;
diff --git a/tutorial/c++/t12.cpp b/tutorial/c++/t12.cpp
index 9edc392425..f41656726f 100644
--- a/tutorial/c++/t12.cpp
+++ b/tutorial/c++/t12.cpp
@@ -6,6 +6,7 @@
 //
 // -----------------------------------------------------------------------------
 
+#include <set>
 #include <gmsh.h>
 
 // "Compound" meshing constraints allow to generate meshes across surface
@@ -92,7 +93,9 @@ int main(int argc, char **argv)
   gmsh::model::mesh::generate(2);
   gmsh::write("t12.msh");
 
-  // gmsh::fltk::run();
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
 
diff --git a/tutorial/c++/t13.cpp b/tutorial/c++/t13.cpp
index f162984b06..555f88286f 100644
--- a/tutorial/c++/t13.cpp
+++ b/tutorial/c++/t13.cpp
@@ -6,8 +6,9 @@
 //
 // -----------------------------------------------------------------------------
 
+#include <set>
+#include <cmath>
 #include <gmsh.h>
-#include <math.h>
 
 int main(int argc, char **argv)
 {
@@ -74,7 +75,9 @@ int main(int argc, char **argv)
 
   gmsh::model::mesh::generate(3);
 
-  // gmsh::fltk::run();
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
   return 0;
diff --git a/tutorial/c++/t14.cpp b/tutorial/c++/t14.cpp
index 7a73d8638d..daadafa7d4 100644
--- a/tutorial/c++/t14.cpp
+++ b/tutorial/c++/t14.cpp
@@ -10,9 +10,10 @@
 // (co)homology space bases using a mesh of a model.  The representative basis
 // chains are stored in the mesh as physical groups of Gmsh, one for each chain.
 
-#include <gmsh.h>
-#include <math.h>
+#include <set>
+#include <cmath>
 #include <algorithm>
+#include <gmsh.h>
 
 int main(int argc, char **argv)
 {
@@ -132,12 +133,16 @@ int main(int argc, char **argv)
   // Generate the mesh and perform the requested homology computations
   gmsh::model::mesh::generate(3);
 
-  gmsh::write("t14.msh");
-
   // For more information, see M. Pellikka, S. Suuriniemi, L. Kettunen and
   // C. Geuzaine. Homology and cohomology computation in finite element
   // modeling. SIAM Journal on Scientific Computing 35(5), pp. 1195-1214, 2013.
 
+  gmsh::write("t14.msh");
+
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
+
   gmsh::finalize();
   return 0;
 }
diff --git a/tutorial/c++/t15.cpp b/tutorial/c++/t15.cpp
index 0c5fa11c60..204d30c428 100644
--- a/tutorial/c++/t15.cpp
+++ b/tutorial/c++/t15.cpp
@@ -14,6 +14,7 @@
 // Embedding constraints allow to force a mesh to be conformal to other lower
 // dimensional entities.
 
+#include <set>
 #include <gmsh.h>
 
 int main(int argc, char **argv)
@@ -99,6 +100,10 @@ int main(int argc, char **argv)
 
   gmsh::write("t15.msh");
 
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
+
   gmsh::finalize();
   return 0;
 }
diff --git a/tutorial/c++/t16.cpp b/tutorial/c++/t16.cpp
index 1671404f8e..c258ae40b3 100644
--- a/tutorial/c++/t16.cpp
+++ b/tutorial/c++/t16.cpp
@@ -10,6 +10,7 @@
 // geometry kernel, starting with version 3 Gmsh allows you to directly use
 // alternative geometry kernels. Here we will use the OpenCASCADE kernel.
 
+#include <set>
 #include <iostream>
 #include <gmsh.h>
 
@@ -138,8 +139,9 @@ int main(int argc, char **argv)
   std::cout << "Logger has recorded " << log.size() << " lines" << std::endl;
   gmsh::logger::stop();
 
-  // Show the GUI:
-  // gmsh::fltk::run();
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
   return 0;
diff --git a/tutorial/c++/t17.cpp b/tutorial/c++/t17.cpp
index ed7e589211..53436db6d7 100644
--- a/tutorial/c++/t17.cpp
+++ b/tutorial/c++/t17.cpp
@@ -14,8 +14,9 @@
 // a square. One should use bamg as 2d mesh generator to enable anisotropic
 // meshes in 2D.
 
+#include <set>
+#include <cmath>
 #include <gmsh.h>
-#include <math.h>
 
 int main(int argc, char **argv)
 {
@@ -50,6 +51,10 @@ int main(int argc, char **argv)
 
   gmsh::write("t17.msh");
 
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
+
   gmsh::finalize();
   return 0;
 }
diff --git a/tutorial/c++/t18.cpp b/tutorial/c++/t18.cpp
index 84577988f2..e6c28e5b1a 100644
--- a/tutorial/c++/t18.cpp
+++ b/tutorial/c++/t18.cpp
@@ -8,6 +8,7 @@
 
 // Periodic meshing constraints can be imposed on surfaces and curves.
 
+#include <set>
 #include <algorithm>
 #include <gmsh.h>
 
@@ -138,7 +139,9 @@ int main(int argc, char **argv)
   gmsh::model::mesh::generate(3);
   gmsh::write("t18.msh");
 
-  // gmsh::fltk::run();
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
   return 0;
diff --git a/tutorial/c++/t19.cpp b/tutorial/c++/t19.cpp
index 44e15b6f26..ee02a783fd 100644
--- a/tutorial/c++/t19.cpp
+++ b/tutorial/c++/t19.cpp
@@ -9,6 +9,7 @@
 // The OpenCASCADE geometry kernel supports several useful features for solid
 // modelling.
 
+#include <set>
 #include <cmath>
 #include <cstdlib>
 #include <gmsh.h>
@@ -101,6 +102,10 @@ int main(int argc, char **argv)
   gmsh::model::mesh::generate(3);
   gmsh::write("t19.msh");
 
-  // gmsh::fltk::run();
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
+
+  gmsh::finalize();
   return 0;
 }
diff --git a/tutorial/c++/t2.cpp b/tutorial/c++/t2.cpp
index e115580619..4030abcf3c 100644
--- a/tutorial/c++/t2.cpp
+++ b/tutorial/c++/t2.cpp
@@ -6,8 +6,9 @@
 //
 // -----------------------------------------------------------------------------
 
+#include <set>
+#include <cmath>
 #include <gmsh.h>
-#include <math.h>
 
 int main(int argc, char **argv)
 {
@@ -164,6 +165,10 @@ int main(int argc, char **argv)
   // OpenCASCADE BRep file; or export an OpenCASCADE model as an Unrolled GEO
   // file.
 
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
+
   gmsh::finalize();
   return 0;
 }
diff --git a/tutorial/c++/t20.cpp b/tutorial/c++/t20.cpp
index 98fca4ec02..1eec46c04b 100644
--- a/tutorial/c++/t20.cpp
+++ b/tutorial/c++/t20.cpp
@@ -10,10 +10,11 @@
 // them. In this tutorial we will load a STEP geometry and partition it into
 // slices.
 
+#include <set>
 #include <cmath>
 #include <cstdlib>
-#include <gmsh.h>
 #include <algorithm>
+#include <gmsh.h>
 
 int main(int argc, char **argv)
 {
@@ -140,8 +141,9 @@ int main(int argc, char **argv)
   gmsh::model::mesh::generate(3);
   gmsh::write("t20.msh");
 
-  // Show the result:
-  // gmsh::fltk::run();
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
   return 0;
diff --git a/tutorial/c++/t21.cpp b/tutorial/c++/t21.cpp
index 54bd509856..36efbf093e 100644
--- a/tutorial/c++/t21.cpp
+++ b/tutorial/c++/t21.cpp
@@ -6,11 +6,12 @@
 //
 // -----------------------------------------------------------------------------
 
+#include <set>
 #include <cmath>
 #include <cstdlib>
-#include <gmsh.h>
 #include <algorithm>
 #include <iostream>
+#include <gmsh.h>
 
 // Gmsh can partition meshes using different algorithms, e.g. the graph
 // partitioner Metis or the `SimplePartition' plugin. For all the partitioning
@@ -129,7 +130,9 @@ int main(int argc, char **argv)
     }
   }
 
-  // gmsh::fltk::run();
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
   return 0;
diff --git a/tutorial/c++/t3.cpp b/tutorial/c++/t3.cpp
index 727cedd8bc..cf030e3431 100644
--- a/tutorial/c++/t3.cpp
+++ b/tutorial/c++/t3.cpp
@@ -6,6 +6,7 @@
 //
 // -----------------------------------------------------------------------------
 
+#include <set>
 #include <cmath>
 #include <gmsh.h>
 
@@ -93,8 +94,8 @@ int main(int argc, char **argv)
   gmsh::option::setColor("Geometry.Surfaces", r, g, b, a);
 
   // Launch the GUI to see the effects of the color changes:
-
-  // gmsh::fltk::run();
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   // When the GUI is launched, you can use the `Help->Current Options and
   // Workspace' menu to see the current values of all options. To save the
diff --git a/tutorial/c++/t4.cpp b/tutorial/c++/t4.cpp
index 54a2d67e72..f4326008f4 100644
--- a/tutorial/c++/t4.cpp
+++ b/tutorial/c++/t4.cpp
@@ -7,7 +7,7 @@
 // -----------------------------------------------------------------------------
 
 #include <set>
-#include <math.h>
+#include <cmath>
 #include <gmsh.h>
 
 double hypoth(double a, double b) { return sqrt(a * a + b * b); }
@@ -168,9 +168,8 @@ int main(int argc, char **argv)
   gmsh::write("t4.msh");
 
   // Launch the GUI to see the results:
-  std::set<std::string> args;
-  for(int i = 1; i < argc; i++) args.insert(argv[i]);
-  if(args.find("-nopopup") == args.end()) gmsh::fltk::run();
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
   return 0;
diff --git a/tutorial/c++/t5.cpp b/tutorial/c++/t5.cpp
index 8927ea6be9..a0330add24 100644
--- a/tutorial/c++/t5.cpp
+++ b/tutorial/c++/t5.cpp
@@ -6,8 +6,9 @@
 //
 // -----------------------------------------------------------------------------
 
-#include <gmsh.h>
+#include <set>
 #include <cstdio>
+#include <gmsh.h>
 
 void cheeseHole(double x, double y, double z, double r, double lc,
                 std::vector<int> &shells, std::vector<int> &volumes)
@@ -223,7 +224,9 @@ int main(int argc, char **argv)
   gmsh::model::mesh::generate(3);
   gmsh::write("t5.msh");
 
-  // gmsh::fltk::run();
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
 
diff --git a/tutorial/c++/t6.cpp b/tutorial/c++/t6.cpp
index bc19ac033b..152bea963b 100644
--- a/tutorial/c++/t6.cpp
+++ b/tutorial/c++/t6.cpp
@@ -6,6 +6,7 @@
 //
 // -----------------------------------------------------------------------------
 
+#include <set>
 #include <gmsh.h>
 
 int main(int argc, char **argv)
@@ -99,6 +100,11 @@ int main(int argc, char **argv)
   gmsh::model::geo::synchronize();
   gmsh::model::mesh::generate(2);
   gmsh::write("t6.msh");
+
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
+
   gmsh::finalize();
   return 0;
 }
diff --git a/tutorial/c++/t7.cpp b/tutorial/c++/t7.cpp
index 777a2db871..efe1f5a9c9 100644
--- a/tutorial/c++/t7.cpp
+++ b/tutorial/c++/t7.cpp
@@ -65,9 +65,8 @@ int main(int argc, char **argv)
   gmsh::write("t7.msh");
 
   // Launch the GUI to see the results:
-  std::set<std::string> args;
-  for(int i = 1; i < argc; i++) args.insert(argv[i]);
-  if(args.find("-nopopup") == args.end()) gmsh::fltk::run();
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
   return 0;
diff --git a/tutorial/c++/t8.cpp b/tutorial/c++/t8.cpp
index 8b445c95b6..9dd443e63c 100644
--- a/tutorial/c++/t8.cpp
+++ b/tutorial/c++/t8.cpp
@@ -72,10 +72,9 @@ int main(int argc, char **argv)
   gmsh::option::setNumber("General.Axes", 0);
   gmsh::option::setNumber("General.SmallAxes", 0);
 
-  // Show the GUI
-  std::set<std::string> args;
-  for(int i = 1; i < argc; i++) args.insert(argv[i]);
-  if(args.find("-nopopup") == args.end()) gmsh::fltk::initialize();
+  // Show the GUI:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::initialize();
 
   // We also set some options for each post-processing view:
   gmsh::option::setNumber("View[0].IntervalsType", 2);
@@ -164,7 +163,7 @@ int main(int argc, char **argv)
     }
   }
 
-  if(args.find("-nopopup") == args.end()) gmsh::fltk::run();
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
 
diff --git a/tutorial/c++/t9.cpp b/tutorial/c++/t9.cpp
index cab6ffdfd6..bef92ec1e2 100644
--- a/tutorial/c++/t9.cpp
+++ b/tutorial/c++/t9.cpp
@@ -75,10 +75,9 @@ int main(int argc, char **argv)
   gmsh::option::setNumber("View[1].IntervalsType", 2);
   gmsh::option::setNumber("View[2].IntervalsType", 2);
 
-  // show the GUI at the end
-  std::set<std::string> args;
-  for(int i = 1; i < argc; i++) args.insert(argv[i]);
-  if(args.find("-nopopup") == args.end()) gmsh::fltk::run();
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
   return 0;
diff --git a/tutorial/c++/x2.cpp b/tutorial/c++/x2.cpp
index a4749acc51..5c45ed719e 100644
--- a/tutorial/c++/x2.cpp
+++ b/tutorial/c++/x2.cpp
@@ -6,6 +6,7 @@
 //
 // -----------------------------------------------------------------------------
 
+#include <set>
 #include <iostream>
 #include <gmsh.h>
 
@@ -175,7 +176,9 @@ int main(int argc, char **argv)
   gmsh::model::mesh::generate(3);
   gmsh::write("x2.msh");
 
-  // gmsh::fltk::run();
+  // Launch the GUI to see the results:
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
   return 0;
diff --git a/tutorial/c++/x3.cpp b/tutorial/c++/x3.cpp
index 00009bfd46..d7e393acf5 100644
--- a/tutorial/c++/x3.cpp
+++ b/tutorial/c++/x3.cpp
@@ -164,9 +164,8 @@ int main(int argc, char **argv)
   gmsh::option::setNumber(v2 + ".MaxRecursionLevel", 5);
 
   // Launch the GUI to see the results:
-  std::set<std::string> args;
-  for(int i = 1; i < argc; i++) args.insert(argv[i]);
-  if(args.find("-nopopup") == args.end()) gmsh::fltk::run();
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
   return 0;
diff --git a/tutorial/c++/x4.cpp b/tutorial/c++/x4.cpp
index 96c3832943..e5fda981a9 100644
--- a/tutorial/c++/x4.cpp
+++ b/tutorial/c++/x4.cpp
@@ -92,9 +92,8 @@ int main(int argc, char **argv)
   gmsh::view::write(t2, "x4_t2.msh");
 
   // Launch the GUI to see the results:
-  std::set<std::string> args;
-  for(int i = 1; i < argc; i++) args.insert(argv[i]);
-  if(args.find("-nopopup") == args.end()) gmsh::fltk::run();
+  std::set<std::string> args(argv, argv + argc);
+  if(!args.count("-nopopup")) gmsh::fltk::run();
 
   gmsh::finalize();
   return 0;
diff --git a/tutorial/julia/t1.jl b/tutorial/julia/t1.jl
index de01e2a8b1..67e09e0dd0 100644
--- a/tutorial/julia/t1.jl
+++ b/tutorial/julia/t1.jl
@@ -35,4 +35,8 @@ gmsh.model.mesh.generate(2)
 
 gmsh.write("t1.msh")
 
+if !("-nopopup" in ARGS)
+    gmsh.fltk.run()
+end
+
 gmsh.finalize()
diff --git a/tutorial/julia/t10.jl b/tutorial/julia/t10.jl
index d9dd656aa8..830d32fad9 100644
--- a/tutorial/julia/t10.jl
+++ b/tutorial/julia/t10.jl
@@ -71,4 +71,8 @@ gmsh.option.setNumber("Mesh.CharacteristicLengthFromCurvature", 0)
 gmsh.model.mesh.generate(2)
 gmsh.write("t10.msh")
 
+if !("-nopopup" in ARGS)
+    gmsh.fltk.run()
+end
+
 gmsh.finalize()
diff --git a/tutorial/julia/t16.jl b/tutorial/julia/t16.jl
index 3ebf800ee1..f73e0cc6f7 100644
--- a/tutorial/julia/t16.jl
+++ b/tutorial/julia/t16.jl
@@ -45,4 +45,8 @@ gmsh.model.mesh.generate(3)
 
 gmsh.write("t16.msh")
 
+if !("-nopopup" in ARGS)
+    gmsh.fltk.run()
+end
+
 gmsh.finalize()
diff --git a/tutorial/julia/t2.jl b/tutorial/julia/t2.jl
index 62c24ace57..34bfcc2c31 100644
--- a/tutorial/julia/t2.jl
+++ b/tutorial/julia/t2.jl
@@ -88,4 +88,8 @@ gmsh.model.mesh.generate(3)
 
 gmsh.write("t2.msh")
 
+if !("-nopopup" in ARGS)
+    gmsh.fltk.run()
+end
+
 gmsh.finalize()
diff --git a/tutorial/julia/t3.jl b/tutorial/julia/t3.jl
index d5cf6d295c..f7430ca5e1 100644
--- a/tutorial/julia/t3.jl
+++ b/tutorial/julia/t3.jl
@@ -37,4 +37,9 @@ gmsh.model.addPhysicalGroup(3, [1, 2, ov[2][2]], 101)
 gmsh.model.geo.synchronize()
 gmsh.model.mesh.generate(3)
 gmsh.write("t3.msh")
+
+if !("-nopopup" in ARGS)
+    gmsh.fltk.run()
+end
+
 gmsh.finalize()
diff --git a/tutorial/julia/t4.jl b/tutorial/julia/t4.jl
index c62f272721..b05bf3ac3d 100644
--- a/tutorial/julia/t4.jl
+++ b/tutorial/julia/t4.jl
@@ -115,7 +115,6 @@ gmsh.model.mesh.generate(2)
 
 gmsh.write("t4.msh")
 
-# Launch the GUI to see the results:
 if !("-nopopup" in ARGS)
     gmsh.fltk.run()
 end
diff --git a/tutorial/julia/t5.jl b/tutorial/julia/t5.jl
index 7bbcbb5f63..61cfec1eed 100644
--- a/tutorial/julia/t5.jl
+++ b/tutorial/julia/t5.jl
@@ -122,9 +122,12 @@ gmsh.model.geo.addVolume(shells, 186);
 
 gmsh.model.addPhysicalGroup(3, [186], 10);
 gmsh.model.geo.synchronize()
-gmsh.fltk.run()
 
 gmsh.model.mesh.generate(3)
 gmsh.write("t5.msh")
 
+if !("-nopopup" in ARGS)
+    gmsh.fltk.run()
+end
+
 gmsh.finalize()
diff --git a/tutorial/python/t1.py b/tutorial/python/t1.py
index f0718a1ed3..6296b3f14a 100644
--- a/tutorial/python/t1.py
+++ b/tutorial/python/t1.py
@@ -9,6 +9,7 @@
 # The Python API is entirely defined in the `gmsh.py' module (which contains the
 # full documentation of all the functions in the API):
 import gmsh
+import sys
 
 # Before using any functions in the Python API, Gmsh must be initialized:
 gmsh.initialize()
@@ -141,9 +142,11 @@ gmsh.write("t1.msh")
 # format explicitly, and just choose a filename with the `.msh2' or `.msh4'
 # extension.
 
-# To visualize the model we could run the graphical user interface with:
-#
-# gmsh.fltk.run()
+# To visualize the model we can run the graphical user interface with
+# `gmsh.fltk.run()'. Here we run it only if the "-nopopup" is not provided in
+# the command line arguments:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
 
 # Note that starting with Gmsh 3.0, models can be built using other geometry
 # kernels than the default "built-in" kernel. To use the OpenCASCADE geometry
diff --git a/tutorial/python/t10.py b/tutorial/python/t10.py
index 635f9f68b0..107e3bdcce 100644
--- a/tutorial/python/t10.py
+++ b/tutorial/python/t10.py
@@ -138,6 +138,8 @@ gmsh.option.setNumber("Mesh.CharacteristicLengthFromCurvature", 0)
 gmsh.model.mesh.generate(2)
 gmsh.write("t10.msh")
 
-# gmsh.fltk.run()
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
 
 gmsh.finalize()
diff --git a/tutorial/python/t11.py b/tutorial/python/t11.py
index c61705b8c8..5c52c9f0ce 100644
--- a/tutorial/python/t11.py
+++ b/tutorial/python/t11.py
@@ -7,6 +7,7 @@
 # ------------------------------------------------------------------------------
 
 import gmsh
+import sys
 
 gmsh.initialize()
 gmsh.option.setNumber("General.Terminal", 1)
@@ -89,6 +90,8 @@ gmsh.model.mesh.generate(2)
 # gmsh.option.setNumber("Mesh.SubdivisionAlgorithm", 1)
 # gmsh.model.mesh.refine()
 
-# gmsh.fltk.run()
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
 
 gmsh.finalize()
diff --git a/tutorial/python/t12.py b/tutorial/python/t12.py
index 20ca52fc5b..22ed7710db 100644
--- a/tutorial/python/t12.py
+++ b/tutorial/python/t12.py
@@ -7,6 +7,7 @@
 # ------------------------------------------------------------------------------
 
 import gmsh
+import sys
 
 # "Compound" meshing constraints allow to generate meshes across surface
 # boundaries, which can be useful e.g. for imported CAD models (e.g. STEP) with
@@ -88,6 +89,8 @@ gmsh.model.mesh.setCompound(2, [1, 5, 10])
 gmsh.model.mesh.generate(2)
 gmsh.write('t12.msh')
 
-# gmsh.fltk.run()
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
 
 gmsh.finalize()
diff --git a/tutorial/python/t13.py b/tutorial/python/t13.py
index 209cb7b7c1..36fe3fb477 100644
--- a/tutorial/python/t13.py
+++ b/tutorial/python/t13.py
@@ -9,6 +9,7 @@
 import gmsh
 import math
 import os
+import sys
 
 gmsh.initialize()
 
@@ -64,6 +65,8 @@ gmsh.model.mesh.field.setAsBackgroundMesh(f)
 gmsh.model.mesh.generate(3)
 gmsh.write('t13.msh')
 
-# gmsh.fltk.run()
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
 
 gmsh.finalize()
diff --git a/tutorial/python/t14.py b/tutorial/python/t14.py
index b60df75fe7..d52a34f4a2 100644
--- a/tutorial/python/t14.py
+++ b/tutorial/python/t14.py
@@ -140,4 +140,9 @@ gmsh.model.mesh.generate(3)
 # modeling. SIAM Journal on Scientific Computing 35(5), pp. 1195-1214, 2013.
 
 gmsh.write("t14.msh")
+
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
+
 gmsh.finalize()
diff --git a/tutorial/python/t15.py b/tutorial/python/t15.py
index 0c89bb5bbd..357d38c912 100644
--- a/tutorial/python/t15.py
+++ b/tutorial/python/t15.py
@@ -15,6 +15,7 @@
 # dimensional entities.
 
 import gmsh
+import sys
 
 gmsh.initialize()
 gmsh.option.setNumber("General.Terminal", 1)
@@ -95,4 +96,8 @@ gmsh.model.mesh.generate(3)
 
 gmsh.write("t15.msh")
 
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
+
 gmsh.finalize()
diff --git a/tutorial/python/t16.py b/tutorial/python/t16.py
index 706214f640..b98b689071 100644
--- a/tutorial/python/t16.py
+++ b/tutorial/python/t16.py
@@ -12,6 +12,7 @@
 
 import gmsh
 import math
+import sys
 
 gmsh.initialize()
 gmsh.option.setNumber("General.Terminal", 1)
@@ -118,7 +119,8 @@ log = gmsh.logger.get()
 print("Logger has recorded " + str(len(log)) + " lines")
 gmsh.logger.stop()
 
-# Show the GUI:
-# gmsh.fltk.run()
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
 
 gmsh.finalize()
diff --git a/tutorial/python/t17.py b/tutorial/python/t17.py
index caf8f5074d..0abd78e100 100644
--- a/tutorial/python/t17.py
+++ b/tutorial/python/t17.py
@@ -17,6 +17,7 @@
 import gmsh
 import math
 import os
+import sys
 
 gmsh.initialize()
 gmsh.option.setNumber("General.Terminal", 1)
@@ -43,6 +44,8 @@ gmsh.option.setNumber("Mesh.Algorithm", 7)
 gmsh.model.mesh.generate(2)
 gmsh.write("t17.msh")
 
-# gmsh.fltk.run()
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
 
 gmsh.finalize()
diff --git a/tutorial/python/t18.py b/tutorial/python/t18.py
index 42c3e67a1f..c7dab984d9 100644
--- a/tutorial/python/t18.py
+++ b/tutorial/python/t18.py
@@ -11,6 +11,7 @@
 import gmsh
 import math
 import os
+import sys
 
 gmsh.initialize()
 gmsh.option.setNumber("General.Terminal", 1)
@@ -121,6 +122,8 @@ for i in sxmin:
 gmsh.model.mesh.generate(3)
 gmsh.write("t18.msh")
 
-# gmsh.fltk.run()
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
 
 gmsh.finalize()
diff --git a/tutorial/python/t19.py b/tutorial/python/t19.py
index 4dee47800d..35b114769c 100644
--- a/tutorial/python/t19.py
+++ b/tutorial/python/t19.py
@@ -12,6 +12,7 @@
 import gmsh
 import math
 import os
+import sys
 
 gmsh.initialize()
 gmsh.option.setNumber("General.Terminal", 1)
@@ -92,4 +93,8 @@ gmsh.option.setNumber("Mesh.CharacteristicLengthMax", 0.3)
 gmsh.model.mesh.generate(3)
 gmsh.write("t19.msh")
 
-# gmsh.fltk.run()
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
+
+gmsh.finalize()
diff --git a/tutorial/python/t2.py b/tutorial/python/t2.py
index 4e18179e64..b5aa68decd 100644
--- a/tutorial/python/t2.py
+++ b/tutorial/python/t2.py
@@ -157,4 +157,8 @@ gmsh.write("t2.msh")
 # a geometry constructed with the built-in kernel as an OpenCASCADE BRep file;
 # or export an OpenCASCADE model as an Unrolled GEO file.
 
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
+
 gmsh.finalize()
diff --git a/tutorial/python/t20.py b/tutorial/python/t20.py
index 417fe88ed1..6874f69422 100644
--- a/tutorial/python/t20.py
+++ b/tutorial/python/t20.py
@@ -13,6 +13,7 @@
 import gmsh
 import math
 import os
+import sys
 
 gmsh.initialize()
 gmsh.option.setNumber("General.Terminal", 1)
@@ -111,7 +112,8 @@ gmsh.option.setNumber("Mesh.CharacteristicLengthMax", 3)
 gmsh.model.mesh.generate(3)
 gmsh.write("t20.msh")
 
-# Show the result:
-# gmsh.fltk.run()
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
 
 gmsh.finalize()
diff --git a/tutorial/python/t21.py b/tutorial/python/t21.py
index 8b3744e2c5..04f68f587e 100644
--- a/tutorial/python/t21.py
+++ b/tutorial/python/t21.py
@@ -7,6 +7,7 @@
 # ------------------------------------------------------------------------------
 
 import gmsh
+import sys
 
 # Gmsh can partition meshes using different algorithms, e.g. the graph
 # partitioner Metis or the `SimplePartition' plugin. For all the partitioning
@@ -98,6 +99,8 @@ for e in entities:
         print(" - Parent: " + str(gmsh.model.getParent(e[0], e[1])))
         print(" - Boundary: " + str(gmsh.model.getBoundary([e])))
 
-# gmsh.fltk.run()
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
 
 gmsh.finalize()
diff --git a/tutorial/python/t3.py b/tutorial/python/t3.py
index a98e33851e..bc8210cde6 100644
--- a/tutorial/python/t3.py
+++ b/tutorial/python/t3.py
@@ -8,6 +8,7 @@
 
 import gmsh
 import math
+import sys
 
 gmsh.initialize()
 gmsh.option.setNumber("General.Terminal", 1)
@@ -89,8 +90,8 @@ r, g, b, a = gmsh.option.getColor("Geometry.Points")
 gmsh.option.setColor("Geometry.Surfaces", r, g, b, a)
 
 # Launch the GUI to see the effects of the color changes:
-
-# gmsh.fltk.run();
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
 
 # When the GUI is launched, you can use the `Help->Current Options and
 # Workspace' menu to see the current values of all options. To save the options
diff --git a/tutorial/python/t5.py b/tutorial/python/t5.py
index 21fd30d156..9ba991eb20 100644
--- a/tutorial/python/t5.py
+++ b/tutorial/python/t5.py
@@ -8,6 +8,7 @@
 
 import gmsh
 import math
+import sys
 
 gmsh.initialize()
 gmsh.option.setNumber("General.Terminal", 1)
@@ -218,6 +219,8 @@ gmsh.model.mesh.setAlgorithm(2, 33, 1)
 gmsh.model.mesh.generate(3)
 gmsh.write("t5.msh")
 
-# gmsh.fltk.run()
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
 
 gmsh.finalize()
diff --git a/tutorial/python/t6.py b/tutorial/python/t6.py
index 52f50e3258..898f9251c3 100644
--- a/tutorial/python/t6.py
+++ b/tutorial/python/t6.py
@@ -8,6 +8,7 @@
 
 import gmsh
 import math
+import sys
 
 gmsh.initialize()
 gmsh.option.setNumber("General.Terminal", 1)
@@ -99,4 +100,9 @@ gmsh.option.setNumber("Mesh.Smoothing", 100)
 
 gmsh.model.mesh.generate(2)
 gmsh.write("t6.msh")
+
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
+
 gmsh.finalize()
diff --git a/tutorial/python/t8.py b/tutorial/python/t8.py
index 0f9f206b32..da2286a2b0 100644
--- a/tutorial/python/t8.py
+++ b/tutorial/python/t8.py
@@ -67,7 +67,7 @@ gmsh.option.setNumber("General.Orthographic", 0)
 gmsh.option.setNumber("General.Axes", 0)
 gmsh.option.setNumber("General.SmallAxes", 0)
 
-# Show the GUI
+# Show the GUI:
 if '-nopopup' not in sys.argv:
     gmsh.fltk.initialize()
 
diff --git a/tutorial/python/t9.py b/tutorial/python/t9.py
index a934df5c7b..494def879a 100644
--- a/tutorial/python/t9.py
+++ b/tutorial/python/t9.py
@@ -67,7 +67,7 @@ gmsh.option.setNumber("View[0].SmoothNormals", 1)
 gmsh.option.setNumber("View[1].IntervalsType", 2)
 gmsh.option.setNumber("View[2].IntervalsType", 2)
 
-# show the GUI at the end
+# Launch the GUI to see the results:
 if '-nopopup' not in sys.argv:
     gmsh.fltk.run()
 
diff --git a/tutorial/python/x2.py b/tutorial/python/x2.py
index 2e9b1d079e..b6c79de9a4 100644
--- a/tutorial/python/x2.py
+++ b/tutorial/python/x2.py
@@ -164,6 +164,8 @@ else:
 gmsh.model.mesh.generate(3)
 gmsh.write('x2.msh')
 
-# gmsh.fltk.run()
+# Launch the GUI to see the results:
+if '-nopopup' not in sys.argv:
+    gmsh.fltk.run()
 
 gmsh.finalize()
-- 
GitLab