Checking for X availability

Discussion in 'Python' started by Flavio codeco coelho, Jan 11, 2005.

  1. I have a program that uses pythondialog for its UI.

    Pythondialog is a wrapper of the shell dialog and xdialog libs.

    But I would like for it to switch between using Dialog ( when X is not
    available ) and xdialog (when X is available)

    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?

    thanks,

    Flávio
     
    Flavio codeco coelho, Jan 11, 2005
    #1
    1. Advertising

  2. Flavio codeco coelho

    Nils Nordman Guest

    On Tue, Jan 11, 2005 at 03:32:01AM -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?


    Well, one way to do it is to check whether the environment variable
    DISPLAY is set (which it is when running under X, and should not be
    otherwise).

    Cheers,

    --
    Nils Nordman <>
     
    Nils Nordman, Jan 11, 2005
    #2
    1. Advertising

  3. 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.
     
    Jeremy Bowers, Jan 11, 2005
    #3
  4. On Tue, 11 Jan 2005 03:32:01 -0800, Flavio codeco coelho wrote:

    > I have a program that uses pythondialog for its UI.
    >
    > Pythondialog is a wrapper of the shell dialog and xdialog libs.
    >
    > But I would like for it to switch between using Dialog ( when X is not
    > available ) and xdialog (when X is available)
    >
    > 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?
    >
    > thanks,
    >
    > Flávio


    If there's interest, I could make available my "pdialog" module, which is
    also a wrapper around *dialog, but uses X when available, and curses when
    it is not.
     
    Dan Stromberg, Jan 12, 2005
    #4
  5. In article <>,
    Nils Nordman <> wrote:
    >On Tue, Jan 11, 2005 at 03:32:01AM -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?

    >
    >Well, one way to do it is to check whether the environment variable
    >DISPLAY is set (which it is when running under X, and should not be
    >otherwise).

    .
    .
    .
    While there certainly are successful programs that use this
    approach, it's NOT true in general--at least in the generality
    I encounter. It can happen, for example, that a user withOUT
    $DISPLAY in the environment launches

    interesting_application -display SOME_DISPLAY ...

    Jeremy Bowers gives excellent advice elsewhere in this thread:
    try, and use exceptions to learn what's going on; as you learn
    more, relaunch the application with a refined command-line.
     
    Cameron Laird, Jan 16, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob
    Replies:
    2
    Views:
    3,121
    jcha129
    Aug 16, 2007
  2. =?Utf-8?B?QVZM?=

    web service availability checking

    =?Utf-8?B?QVZM?=, Jul 19, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    499
    nahid
    Jul 20, 2007
  3. NightCrawler
    Replies:
    0
    Views:
    333
    NightCrawler
    Feb 12, 2008
  4. NightCrawler
    Replies:
    2
    Views:
    346
    Mark Space
    Feb 14, 2008
  5. Sundew Shin

    checking 'document.body' availability (opera)

    Sundew Shin, Aug 24, 2005, in forum: Javascript
    Replies:
    7
    Views:
    141
    Martin Honnen
    Aug 24, 2005
Loading...

Share This Page