From 7644927de952a7b8e7f9f21fed6bf01ff0f55018 Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Mon, 9 Oct 2023 17:03:23 +0200
Subject: [PATCH] pamhyr: Allow Pamhyr2 script run on tty mode.

---
 src/pamhyr.py | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/pamhyr.py b/src/pamhyr.py
index 4226efd6..93386f06 100755
--- a/src/pamhyr.py
+++ b/src/pamhyr.py
@@ -68,10 +68,6 @@ def gui(app:QApplication, conf:Config):
 
 def main():
     conf = Config.load()
-    app = QApplication(sys.argv)
-
-    tr = setup_lang(app, conf)
-    app.installTranslator(tr)
 
     legal_info()
 
@@ -81,17 +77,27 @@ def main():
 
         if script == "help":
             ret = usage(sys.argv)
-        elif script == "gui":
-            ret = gui(app, conf)
-        elif script == "debug":
-            conf.debug = True
+        elif script == "gui" or script == "debug":
+            if script == "debug":
+                conf.debug = True
+
+            app = QApplication(sys.argv)
+            tr = setup_lang(app, conf)
+            app.installTranslator(tr)
             ret = gui(app, conf)
         else:
             if script not in scripts:
-                logger.error(f"{logger_color_red()}Invalid script name '{sys.argv[1]}'{logger_color_reset()}")
+                logger.error(
+                    f"{logger_color_red()}Invalid script name " +
+                    f"'{sys.argv[1]}'{logger_color_reset()}"
+                )
                 usage(sys.argv)
                 sys.exit(-1)
 
+            # By default script as no QApplication (allow run script
+            # in tty mode)
+            app = None
+
             application = scripts[script](app, conf, sys.argv)
             ret = application.run()
             if ret != 0:
-- 
GitLab