Determining Presence Of GUI Support

Tim Daneliuk tundra at tundraware.com
Sat Nov 9 12:40:11 EST 2002


Alex Martelli wrote:
> Tim Daneliuk wrote:
> 
> 
>>Is there a portable method of determining whether the current runtime
>>environment supports a GUI or text-based interface?  I would like to
>>write a single program which autosenses the presentation environment
>>and works accordingly.
> 
> 
> Well, you could do something like:
> 
> try:
>     import tkinter    # or whatever other GUI toolkit you want
> except:
>     # set things for no-GUI
> else:
>     # set things for yes-GUI
> 
> but that depends on what you mean by "support" -- it's conceivable
> that tkinter might load but then not be able to display anything
> because for example X11 isn't started (a rather platform-specific
> issue), or because it's started with parameters inappropriate to
> the display so the display is actually showing just a jumble of
> color streaks (more and more platform-specific), and so on.
> 
> 
> Alex
> 

Well, the inability of X to init properly is not really the issue I am
trying to handle. There is probably no reasonable way to consider every
possible permutation of what might fail.

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.  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.
Another option, I suppose, would be to provide a command line interface
option to force the mode of choice.

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.


Thanks to you and all the others who responded...


-- 
------------------------------------------------------------------------------
Tim Daneliuk
tundra at tundraware.com




More information about the Python-list mailing list