[Python-checkins] python/dist/src/Mac/Modules macosmodule.c,1.63,1.64
jackjansen@users.sourceforge.net
jackjansen@users.sourceforge.net
Fri, 21 Feb 2003 08:31:15 -0800
Update of /cvsroot/python/python/dist/src/Mac/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv28507
Modified Files:
macosmodule.c
Log Message:
Added a method WMAvailable(). This will return True if and only if there
is a window manager and we can connect to it, i.e. if it is safe to try
and put up windows.
As a side effect the first call will make the current process frontmost.
Index: macosmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/macosmodule.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -C2 -d -r1.63 -r1.64
*** macosmodule.c 23 Dec 2002 23:16:20 -0000 1.63
--- macosmodule.c 21 Feb 2003 16:31:11 -0000 1.64
***************
*** 37,40 ****
--- 37,41 ----
#else
#include <Carbon/Carbon.h>
+ #include <ApplicationServices/ApplicationServices.h>
#endif
***************
*** 522,525 ****
--- 523,567 ----
}
+ static char WMAvailable_doc[] =
+ "True if this process can interact with the display."
+ "Will foreground the application on the first call as a side-effect."
+ ;
+
+ static PyObject *
+ MacOS_WMAvailable(PyObject *self, PyObject *args)
+ {
+ static PyObject *rv = NULL;
+
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+ if (!rv) {
+ #if TARGET_API_MAC_OSX
+ 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.
+ */
+ if (CGMainDisplayID() == 0) {
+ rv = Py_False;
+ } else {
+ if (GetCurrentProcess(&psn) < 0 ||
+ SetFrontProcess(&psn) < 0) {
+ rv = Py_False;
+ } else {
+ rv = Py_True;
+ }
+ }
+ #else
+ rv = Py_True;
+ #endif
+ }
+ Py_INCREF(rv);
+ return rv;
+ }
+
static char GetTicks_doc[] = "Return number of ticks since bootup";
***************
*** 673,676 ****
--- 715,719 ----
{"GetTicks", MacOS_GetTicks, 1, GetTicks_doc},
{"SysBeep", MacOS_SysBeep, 1, SysBeep_doc},
+ {"WMAvailable", MacOS_WMAvailable, 1, WMAvailable_doc},
#if !TARGET_API_MAC_OSX
{"FreeMem", MacOS_FreeMem, 1, FreeMem_doc},