Detect if X11 is available (python)
python, user-interface
Solution
You could simply launch the gui part, and catch the exception it raises when X (or any other platform dependent graphics system is not available.
Make sure you really have an interactive terminal before running the text based part. Your process might have been started without a visible terminal, as is common in graphical user environments like KDE, gnome or windows.
Problem
Firstly, what is the best/simplest way to detect if X11 is running and available for a python script. parent process? session leader? X environment variables? other? Secondly, I would like to have a utility (python script) to present a gui if available, otherwise use a command line backed tool. Off the top of my head I thought of this -main python script (detects if gui is available and launches appropriate script) -gui or command line python script starts -both use a generic module to do actual work I am very open to suggestions to simplify this.