|
| 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" |
| 26 | + |
| 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}; |
| 45 | + char * prompt; |
| 46 | + Str255 pprompt; |
| 47 | + |
| 48 | + if (!PyArg_ParseTuple(args, "sO&", &prompt, QdRGB_Convert, &inColor)) |
| 49 | + return NULL; |
| 50 | + |
| 51 | + BlockMove(prompt, pprompt + 1, strlen(prompt)); |
| 52 | + pprompt[0] = strlen(prompt); |
| 53 | + |
| 54 | + ok = GetColor(where, pprompt, &inColor, &outColor); |
| 55 | + |
| 56 | + return Py_BuildValue("O&h", QdRGB_New, &outColor, ok); |
| 57 | +} |
| 58 | + |
| 59 | +/* List of methods defined in the module */ |
| 60 | + |
| 61 | +static struct PyMethodDef cp_methods[] = { |
| 62 | + {"GetColor", (PyCFunction)cp_GetColor, METH_VARARGS, cp_GetColor__doc__}, |
| 63 | + {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ |
| 64 | +}; |
| 65 | + |
| 66 | + |
| 67 | +/* Initialization function for the module (*must* be called initColorPicker) */ |
| 68 | + |
| 69 | +static char cp_module_documentation[] = |
| 70 | +"" |
| 71 | +; |
| 72 | + |
| 73 | +void initColorPicker(); |
| 74 | + |
| 75 | +void initColorPicker() |
| 76 | +{ |
| 77 | + PyObject *m; |
| 78 | + |
| 79 | + /* Create the module and add the functions */ |
| 80 | + m = Py_InitModule4("ColorPicker", cp_methods, |
| 81 | + cp_module_documentation, |
| 82 | + (PyObject*)NULL,PYTHON_API_VERSION); |
| 83 | + |
| 84 | + /* Add symbolic constants to the module here */ |
| 85 | + |
| 86 | + /* XXXX Add constants here */ |
| 87 | + |
| 88 | + /* Check for errors */ |
| 89 | + if (PyErr_Occurred()) |
| 90 | + Py_FatalError("can't initialize module ColorPicker"); |
| 91 | +} |
| 92 | + |
0 commit comments