Re: Checking for X availability

From: Jeremy Bowers (jerf_at_jerf.org)
Date: 01/11/05


Date: Tue, 11 Jan 2005 07:39:21 -0500

On Tue, 11 Jan 2005 03:32:01 -0800, Flavio codeco coelho wrote:
> So my question is: how can I check for the availability of X? i.e., How
> will my program know if its running in a text only console or in console
> window over X?

The first thing that leaps to mind is... try it. If it fails, switch to
the other. Remember modules are just variables and can be re-assigned, if
needed.

try:
        import xdialog as mydialog
except ImportError:
        # user must not have it
        import dialog as mydialog

try:
        # do something with mydialog here
except YouDontHaveXError:
        # tried to use xdialog, but it failed
        import dialog as mydialog

etc.

That won't be useful, and I don't know what exception will be thrown when
X isn't found, but you should get something. This should be invisible to
the user, and is also the most transparent way to get it right; using
environment vars and such may not be the best way to do it.

This, by the way, was assuming that xdialog and dialog have identical
APIs. If that is not the case, I'd suggest "process-level recursion"; try
starting up with X, and if it fails, os.execl your process again with a
command line parameter to use console dialog. That will be somewhat
simpler than trying to detect it inside the program itself.



Relevant Pages

  • Re: Disappearing files, created from /etc/X11/Xclients
    ... Please include freebsd-questions on any replies. ... Also there is no console because this is the /etcX11/Xclients script, e.g. it is executed by gdm after logging in to X window system through xdmpc. ... If that fails, then try opening the file in the home directory of the user who you are testing as. ...
    (freebsd-questions)
  • Re: javaldx failed.
    ... mozilla start from default fails, ... error message. ... console in the icewm window but I resolved this for the console window ... get script ...
    (Debian-User)
  • Re: Fax has died
    ... >No messages, just fails. ... >When you right click in the Fax Console> Outbox, ... >I have checked every configuration setting I possibly can, ...
    (microsoft.public.windowsxp.general)
  • Fax has died
    ... The MS Fax in XP SP2 has died. ... No messages, just fails. ... When you right click in the Fax Console> Outbox, ...
    (microsoft.public.windowsxp.general)