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