| 1 | n/a | /****************************************************************** |
|---|
| 2 | n/a | Copyright 1998 by Just van Rossum, Den Haag, The Netherlands. |
|---|
| 3 | n/a | |
|---|
| 4 | n/a | All Rights Reserved |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | Permission to use, copy, modify, and distribute this software and its |
|---|
| 7 | n/a | documentation for any purpose and without fee is hereby granted, |
|---|
| 8 | n/a | provided that the above copyright notice appear in all copies and that |
|---|
| 9 | n/a | both that copyright notice and this permission notice appear in |
|---|
| 10 | n/a | supporting documentation, and that the name of Just van Rossum not be |
|---|
| 11 | n/a | used in advertising or publicity pertaining to distribution of the |
|---|
| 12 | n/a | software without specific, written prior permission. |
|---|
| 13 | n/a | |
|---|
| 14 | n/a | JUST VAN ROSSUM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
|---|
| 15 | n/a | INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
|---|
| 16 | n/a | EVENT SHALL JUST VAN ROSSUM BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
|---|
| 17 | n/a | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF |
|---|
| 18 | n/a | USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
|---|
| 19 | n/a | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|---|
| 20 | n/a | PERFORMANCE OF THIS SOFTWARE. |
|---|
| 21 | n/a | |
|---|
| 22 | n/a | ******************************************************************/ |
|---|
| 23 | n/a | |
|---|
| 24 | n/a | #include <Carbon/Carbon.h> |
|---|
| 25 | n/a | #include "Python.h" |
|---|
| 26 | n/a | #include "pymactoolbox.h" |
|---|
| 27 | n/a | |
|---|
| 28 | n/a | /* ----------------------------------------------------- */ |
|---|
| 29 | n/a | |
|---|
| 30 | n/a | |
|---|
| 31 | n/a | #ifndef __LP64__ |
|---|
| 32 | n/a | |
|---|
| 33 | n/a | static char cp_GetColor__doc__[] = |
|---|
| 34 | n/a | "GetColor(prompt, (r, g, b)) -> (r, g, b), ok" |
|---|
| 35 | n/a | ; |
|---|
| 36 | n/a | |
|---|
| 37 | n/a | static PyObject * |
|---|
| 38 | n/a | cp_GetColor(PyObject *self, PyObject *args) |
|---|
| 39 | n/a | { |
|---|
| 40 | n/a | RGBColor inColor, outColor; |
|---|
| 41 | n/a | Boolean ok; |
|---|
| 42 | n/a | Point where = {0, 0}; |
|---|
| 43 | n/a | Str255 prompt; |
|---|
| 44 | n/a | |
|---|
| 45 | n/a | if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetStr255, prompt, QdRGB_Convert, &inColor)) |
|---|
| 46 | n/a | return NULL; |
|---|
| 47 | n/a | |
|---|
| 48 | n/a | ok = GetColor(where, prompt, &inColor, &outColor); |
|---|
| 49 | n/a | |
|---|
| 50 | n/a | return Py_BuildValue("O&h", QdRGB_New, &outColor, ok); |
|---|
| 51 | n/a | } |
|---|
| 52 | n/a | #endif /* __LP64__ */ |
|---|
| 53 | n/a | |
|---|
| 54 | n/a | /* List of methods defined in the module */ |
|---|
| 55 | n/a | |
|---|
| 56 | n/a | static struct PyMethodDef cp_methods[] = { |
|---|
| 57 | n/a | #ifndef __LP64__ |
|---|
| 58 | n/a | {"GetColor", (PyCFunction)cp_GetColor, METH_VARARGS, cp_GetColor__doc__}, |
|---|
| 59 | n/a | #endif /* __LP64__ */ |
|---|
| 60 | n/a | {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ |
|---|
| 61 | n/a | }; |
|---|
| 62 | n/a | |
|---|
| 63 | n/a | |
|---|
| 64 | n/a | /* Initialization function for the module (*must* be called initColorPicker) */ |
|---|
| 65 | n/a | |
|---|
| 66 | n/a | static char cp_module_documentation[] = |
|---|
| 67 | n/a | "" |
|---|
| 68 | n/a | ; |
|---|
| 69 | n/a | |
|---|
| 70 | n/a | void initColorPicker(void) |
|---|
| 71 | n/a | { |
|---|
| 72 | n/a | PyObject *m; |
|---|
| 73 | n/a | |
|---|
| 74 | n/a | if (PyErr_WarnPy3k("In 3.x, the ColorPicker module is removed.", 1) < 0) |
|---|
| 75 | n/a | return; |
|---|
| 76 | n/a | |
|---|
| 77 | n/a | /* Create the module and add the functions */ |
|---|
| 78 | n/a | m = Py_InitModule4("ColorPicker", cp_methods, |
|---|
| 79 | n/a | cp_module_documentation, |
|---|
| 80 | n/a | (PyObject*)NULL,PYTHON_API_VERSION); |
|---|
| 81 | n/a | |
|---|
| 82 | n/a | /* Add symbolic constants to the module here */ |
|---|
| 83 | n/a | |
|---|
| 84 | n/a | /* XXXX Add constants here */ |
|---|
| 85 | n/a | |
|---|
| 86 | n/a | /* Check for errors */ |
|---|
| 87 | n/a | if (PyErr_Occurred()) |
|---|
| 88 | n/a | Py_FatalError("can't initialize module ColorPicker"); |
|---|
| 89 | n/a | } |
|---|
| 90 | n/a | |
|---|