473,387 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Checking for X availability

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
Jul 18 '05 #1
4 1319
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 <ni**@nordman.org>
Jul 18 '05 #2
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.
Jul 18 '05 #3
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.

Jul 18 '05 #4
In article <ma**************************************@python.o rg>,
Nils Nordman <ni**@nordman.org> 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).

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dave Robinson | last post by:
I was wondering if anyone could help me with a problem I'm having. I've been using Dreamweaver to create a hotel booking system for a friend of mine, using MySQL (version 4.0.21) and PHP 5. The...
5
by: Tongu? Yumruk | last post by:
I have a little proposal about type checking in python. I'll be glad if you read and comment on it. Sorry for my bad english (I'm not a native English speaker) A Little Stricter Typing in Python...
9
by: Dan Williams | last post by:
Can anyone tell me how to go about creating my own custom ASP page that can show several different peoples availability from their Outlook/Exchange 2000 calendars? I don't want to have to ask...
2
by: Robert | last post by:
Hi there! I have a problem I can't get rid of... I hope anyone can help me with it! For a room-booking application I need to select available rooms for a given period. First I do the...
7
by: Sundew Shin | last post by:
Hi, I'm wanting to check the availability of the 'document.body' element. In Mozilla and IE, the function below: window.onload = function(){ alert(document.body); }; alerts '' or '', so I...
4
by: John Coen | last post by:
Help, does anyone have a database I could use to record downtime on multiple systems, that will also show me availability percentages on a day to day basis worked against actual service hours. If...
0
by: lennart | last post by:
Hi, For a website i'm looking for a script which can check the availabililty of several users for an $event. There are several apps that does the job the other way: checking the availability...
1
by: =?Utf-8?B?QVZM?= | last post by:
hi, i need to check the availability of my web service.... how can i do that. i dont want to call any of the methods present in web service to test availability.. i just want to ping to the web...
1
by: lintolawrance | last post by:
hi friends, can any one out here help me by giving the guidelines for checking the username availability at run time with the help of Ajax.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.