blob: 5101d25f639b7a3b94c436e9cdd2709d88125949 [file] [log] [blame]
Jack Jansen02facaf1998-04-21 15:23:02 +00001/******************************************************************
2Copyright 1998 by Just van Rossum, Den Haag, The Netherlands.
3
4 All Rights Reserved
5
6Permission to use, copy, modify, and distribute this software and its
7documentation for any purpose and without fee is hereby granted,
8provided that the above copyright notice appear in all copies and that
9both that copyright notice and this permission notice appear in
10supporting documentation, and that the name of Just van Rossum not be
11used in advertising or publicity pertaining to distribution of the
12software without specific, written prior permission.
13
14JUST VAN ROSSUM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16EVENT SHALL JUST VAN ROSSUM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
18USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20PERFORMANCE OF THIS SOFTWARE.
21
22******************************************************************/
23
24#include <ColorPicker.h>
25#include "Python.h"
26
27
28/* ----------------------------------------------------- */
29
30extern QdRGB_Convert(PyObject *v, RGBColorPtr p_itself);
31extern PyObject *QdRGB_New(RGBColorPtr itself);
32
33static char cp_GetColor__doc__[] =
34"GetColor(prompt, (r, g, b)) -> (r, g, b), ok"
35;
36
37static PyObject *
38cp_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
61static 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
69static char cp_module_documentation[] =
70""
71;
72
73void initColorPicker();
74
75void 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