From 5b43f4645b47f3ff862b1b645cfa6d0fb8f1e8e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= Date: Tue, 19 Oct 2021 19:49:14 +0200 Subject: [PATCH] GRC: be tolerant against Gtk.init_check failure, which seems to be flimsy From 4de91e691fecb5abc3a842c9e25112de0db67e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= Date: Tue, 19 Oct 2021 19:37:38 +0200 Subject: [PATCH] GRC: don't rely on GUI to inform about failure to initialize GUI Index: grc/scripts/gnuradio-companion --- grc/scripts/gnuradio-companion.orig +++ grc/scripts/gnuradio-companion @@ -18,7 +18,6 @@ import os import sys -import warnings GR_IMPORT_ERROR_MESSAGE = """\ @@ -47,22 +46,33 @@ def die(error, message): ) d.set_title(type(error).__name__) d.run() - exit(1) + sys.exit(1) except ImportError: - exit(type(error).__name__ + '\n\n' + msg) + sys.exit(type(error).__name__ + '\n\n' + msg) + except Exception as _exception: + print( + "While trying to display an error message, another error occurred", + file=sys.stderr) + print(_exception, file=sys.stderr) + print("The original error message follows.", file=sys.stderr) + sys.exit(type(error).__name__ + '\n\n' + msg) - def check_gtk(): try: - warnings.filterwarnings("error") import gi gi.require_version('Gtk', '3.0') gi.require_version('PangoCairo', '1.0') gi.require_foreign('cairo', 'Context') from gi.repository import Gtk - Gtk.init_check() - warnings.filterwarnings("always") + success = Gtk.init_check()[0] + if not success: + # Don't display a warning dialogue. This seems to be a Gtk bug. If it + # still can display warning dialogues, it does probably work! + print( + "Gtk init_check failed. GRC might not be able to start a GUI.", + file=sys.stderr) + except Exception as err: die(err, "Failed to initialize GTK. If you are running over ssh, " "did you enable X forwarding and start ssh with -X?") @@ -92,7 +102,7 @@ def run_main(): print("Running from source tree") sys.path.insert(1, script_path[:-len(source_tree_subpath)]) from grc.main import main - exit(main()) + sys.exit(main()) if __name__ == '__main__':