Add wx.App.DisplayAvailable() which can be used to determine if a GUI

can be created in the current environment.  (Still need an
implementation for wxMSW...)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40828 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2006-08-25 21:53:12 +00:00
parent 086ee959df
commit 4d9de11075
5 changed files with 104 additions and 18 deletions

View File

@@ -2753,6 +2753,62 @@ int wxPyImageHandler::GetImageCount( wxInputStream& stream ) {
}
//----------------------------------------------------------------------
// Function to test if the Display (or whatever is the platform equivallent)
// can be connected to. This is accessable from wxPython as a staticmethod of
// wx.App called DisplayAvailable().
bool wxPyTestDisplayAvailable()
{
#ifdef __WXGTK__
Display* display;
display = XOpenDisplay(NULL);
if (display == NULL)
return false;
XCloseDisplay(display);
return true;
#endif
#ifdef __WXMAC__
// This is adapted from Python's Mac/Modules/MacOS.c in the
// MacOS_WMAvailable function.
bool rv;
ProcessSerialNumber psn;
/*
** This is a fairly innocuous call to make if we don't have a window
** manager, or if we have no permission to talk to it. It will print
** a message on stderr, but at least it won't abort the process.
** It appears the function caches the result itself, and it's cheap, so
** no need for us to cache.
*/
#ifdef kCGNullDirectDisplay
/* On 10.1 CGMainDisplayID() isn't available, and
** kCGNullDirectDisplay isn't defined.
*/
if (CGMainDisplayID() == 0) {
rv = false;
} else
#endif
{
// Also foreground the application on the first call as a side-effect.
if (GetCurrentProcess(&psn) < 0 || SetFrontProcess(&psn) < 0) {
rv = false;
} else {
rv = true;
}
}
return rv;
#endif
#ifdef __WXMSW__
// TODO...
return true;
#endif
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------