[Tutor] Finding out if we can use a graphical environment or not
lonetwin
lonetwin@yahoo.com
Wed Jul 16 11:49:02 2003
Hi Jorge,
> > Personally, I'd use different scripts to start up the GUI and
> > console version of the application. Keep it simple.
>
> I've been doing that with other tools. I just wanted to know if I was
> doing the right thing or the wrong thing... Everything is in separate
> modules and the interface is a separate thing that can reuse the other
> code, so this won't make me write more core (actually, I wouldn't
> write the check for the X environment...).
Actually it's a common practise (at least for installation/configuration
utils) to have a "wrapper" script that checks the environment and then calls
the appropriate interface script ....
ie:
if os.environ.get('DISPLAY', 'console') == 'console':
call_console_app()
else:
call_X_app()
...or the wrapper script can decide the interface depending on how the script
was called :
ie:
if sys.argv[0] == 'proggy':
call_console_app()
elif sys.argv[0] == 'Xproggy':
call_X_app()
...and link 'proggy' and 'Xproggy'
The advantage of this is, if the user is in X, the DISPLAY variable may be
set, however if some necessary interface/X libs are not present, calling
Xproggy might fail. So, then he can always call (or you can fall back to
call) 'proggy' (of course you'd want to use isatty() and stuff like that)...
so on second thoughts, maybe keeping it simple is a good idea :). However,
look and feel *does* matter.
HTH
Regards
Steve
--
The devil finds work for idle glands.