Determining Presence Of GUI Support

Grant Edwards grante at visi.com
Sat Nov 9 13:22:49 EST 2002


In article <vpgjqa.l7h2.ln at boundary.tundraware.com>, Tim Daneliuk wrote:

> I was thinking more of the problem of trying to determine whether I
> should use textual output or invoke some GUI presentation. I guess the
> best I could do would be to figure out whether I am in xterm, character
> term (vt100...), or Win32 environment (and whatever a Mac returns for
> $TERM) and use that as the determining factor.

That sounds like a pretty bad idea to me.  Under X11, my terminal type may
be ansi, vt102, rxvt, rxvt-color, or xterm depending on how I'm logged in.
X11 users expect applications to do the character/X11 decision based on the
DISPLAY environment variable.  

If you want to know whether X is _supposed_ to work, check for the env
variable DISPLAY.  If you want to know whether it does work, there are small
executables that I've seen used in scripts to check for the presence of an X
server -- you could take a look to see what they do. 

> This is also imperfect in that a number of textual terminal programs like
> puTTY set their type as 'xterm' even though they are not actually graphical
> interfaces.

The TERM variable has nothing to do with whether or not ther terminal
program is running under a "graphical inteface" or not.  It tells the
text-mode UI libraries with set of escape sequences the terminal program
knows how to interpret.

> Another option, I suppose, would be to provide a command line interface
> option to force the mode of choice.

You should definitely do that regardless of whatever other method you use to
choose an appropriate default.  Just because I've got X11 running it doesn't
mean I always want a GUI to pop up when I run a program.

> Years ago, in the transition from MS-DOS to Windows, there used to be
> a way to lay a DOS binary into the Windows executable file.  That way,
> a single file worked for either environment.  This, by analogy, is
> what I wanted to accomplish.

If you're worried about chossing between X11 and ncurses, use the DISPLAY
environment variable.  It's what everybody else does.

-- 
Grant Edwards                   grante             Yow!  Everywhere I look
                                  at               I see NEGATIVITY and
                               visi.com            ASPHALT...



More information about the Python-list mailing list