summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1995-12-09 14:04:31 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1995-12-09 14:04:31 (GMT)
commit232f3cd190720f2db408c5654a19496ba572c3fa (patch)
treef99a71804a962d27a28ce03f48f42839b096b008
parent1e4ce733fcb00b9f694b9b41ce9e4cd5622607ca (diff)
downloadcpython-232f3cd190720f2db408c5654a19496ba572c3fa.zip
cpython-232f3cd190720f2db408c5654a19496ba572c3fa.tar.gz
cpython-232f3cd190720f2db408c5654a19496ba572c3fa.tar.bz2
Added support for RGB objects (tuples in python)
-rw-r--r--Mac/Modules/qd/Qdmodule.c261
-rw-r--r--Mac/Modules/qd/qdgen.py71
-rw-r--r--Mac/Modules/qd/qdscan.py2
-rw-r--r--Mac/Modules/qd/qdsupport.py27
4 files changed, 359 insertions, 2 deletions
diff --git a/Mac/Modules/qd/Qdmodule.c b/Mac/Modules/qd/Qdmodule.c
index b6ac737..8b03fc2 100644
--- a/Mac/Modules/qd/Qdmodule.c
+++ b/Mac/Modules/qd/Qdmodule.c
@@ -46,6 +46,31 @@ extern PyObject *WinObj_WhichWindow(WindowPtr);
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
+/*
+** Parse/generate RGB records
+*/
+PyObject *QdRGB_New(itself)
+ RGBColorPtr itself;
+{
+
+ return Py_BuildValue("lll", (long)itself->red, (long)itself->green, (long)itself->blue);
+}
+
+QdRGB_Convert(v, p_itself)
+ PyObject *v;
+ RGBColorPtr p_itself;
+{
+ long red, green, blue;
+
+ if( !PyArg_ParseTuple(v, "lll", &red, &green, &blue) )
+ return 0;
+ p_itself->red = (unsigned short)red;
+ p_itself->green = (unsigned short)green;
+ p_itself->blue = (unsigned short)blue;
+ return 1;
+}
+
+
static PyObject *Qd_Error;
/* ---------------------- Object type GrafPort ---------------------- */
@@ -2238,6 +2263,24 @@ static PyObject *Qd_GetPixPat(_self, _args)
return _res;
}
+static PyObject *Qd_MakeRGBPat(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ PixPatHandle pp;
+ RGBColor myColor;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, &pp,
+ QdRGB_Convert, &myColor))
+ return NULL;
+ MakeRGBPat(pp,
+ &myColor);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
static PyObject *Qd_FillCRect(_self, _args)
PyObject *_self;
PyObject *_args;
@@ -2358,6 +2401,57 @@ static PyObject *Qd_FillCPoly(_self, _args)
return _res;
}
+static PyObject *Qd_RGBForeColor(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ RGBColor color;
+ if (!PyArg_ParseTuple(_args, "O&",
+ QdRGB_Convert, &color))
+ return NULL;
+ RGBForeColor(&color);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_RGBBackColor(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ RGBColor color;
+ if (!PyArg_ParseTuple(_args, "O&",
+ QdRGB_Convert, &color))
+ return NULL;
+ RGBBackColor(&color);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetCPixel(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short h;
+ short v;
+ RGBColor cPix;
+ if (!PyArg_ParseTuple(_args, "hhO&",
+ &h,
+ &v,
+ QdRGB_Convert, &cPix))
+ return NULL;
+ SetCPixel(h,
+ v,
+ &cPix);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
static PyObject *Qd_SetPortPix(_self, _args)
PyObject *_self;
PyObject *_args;
@@ -2373,6 +2467,84 @@ static PyObject *Qd_SetPortPix(_self, _args)
return _res;
}
+static PyObject *Qd_GetCPixel(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short h;
+ short v;
+ RGBColor cPix;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &h,
+ &v))
+ return NULL;
+ GetCPixel(h,
+ v,
+ &cPix);
+ _res = Py_BuildValue("O&",
+ QdRGB_New, &cPix);
+ return _res;
+}
+
+static PyObject *Qd_GetForeColor(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ RGBColor color;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetForeColor(&color);
+ _res = Py_BuildValue("O&",
+ QdRGB_New, &color);
+ return _res;
+}
+
+static PyObject *Qd_GetBackColor(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ RGBColor color;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetBackColor(&color);
+ _res = Py_BuildValue("O&",
+ QdRGB_New, &color);
+ return _res;
+}
+
+static PyObject *Qd_OpColor(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ RGBColor color;
+ if (!PyArg_ParseTuple(_args, "O&",
+ QdRGB_Convert, &color))
+ return NULL;
+ OpColor(&color);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_HiliteColor(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ RGBColor color;
+ if (!PyArg_ParseTuple(_args, "O&",
+ QdRGB_Convert, &color))
+ return NULL;
+ HiliteColor(&color);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
static PyObject *Qd_AllocCursor(_self, _args)
PyObject *_self;
PyObject *_args;
@@ -2400,6 +2572,69 @@ static PyObject *Qd_GetCTSeed(_self, _args)
return _res;
}
+static PyObject *Qd_Color2Index(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ long _rv;
+ RGBColor myColor;
+ if (!PyArg_ParseTuple(_args, "O&",
+ QdRGB_Convert, &myColor))
+ return NULL;
+ _rv = Color2Index(&myColor);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_Index2Color(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ long index;
+ RGBColor aColor;
+ if (!PyArg_ParseTuple(_args, "l",
+ &index))
+ return NULL;
+ Index2Color(index,
+ &aColor);
+ _res = Py_BuildValue("O&",
+ QdRGB_New, &aColor);
+ return _res;
+}
+
+static PyObject *Qd_InvertColor(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ RGBColor myColor;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ InvertColor(&myColor);
+ _res = Py_BuildValue("O&",
+ QdRGB_New, &myColor);
+ return _res;
+}
+
+static PyObject *Qd_RealColor(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ RGBColor color;
+ if (!PyArg_ParseTuple(_args, "O&",
+ QdRGB_Convert, &color))
+ return NULL;
+ _rv = RealColor(&color);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
static PyObject *Qd_SetClientID(_self, _args)
PyObject *_self;
PyObject *_args;
@@ -3067,6 +3302,8 @@ static PyMethodDef Qd_methods[] = {
"(PixPatHandle pp) -> None"},
{"GetPixPat", (PyCFunction)Qd_GetPixPat, 1,
"(short patID) -> (PixPatHandle _rv)"},
+ {"MakeRGBPat", (PyCFunction)Qd_MakeRGBPat, 1,
+ "(PixPatHandle pp, RGBColor myColor) -> None"},
{"FillCRect", (PyCFunction)Qd_FillCRect, 1,
"(Rect r, PixPatHandle pp) -> None"},
{"FillCOval", (PyCFunction)Qd_FillCOval, 1,
@@ -3079,12 +3316,36 @@ static PyMethodDef Qd_methods[] = {
"(RgnHandle rgn, PixPatHandle pp) -> None"},
{"FillCPoly", (PyCFunction)Qd_FillCPoly, 1,
"(PolyHandle poly, PixPatHandle pp) -> None"},
+ {"RGBForeColor", (PyCFunction)Qd_RGBForeColor, 1,
+ "(RGBColor color) -> None"},
+ {"RGBBackColor", (PyCFunction)Qd_RGBBackColor, 1,
+ "(RGBColor color) -> None"},
+ {"SetCPixel", (PyCFunction)Qd_SetCPixel, 1,
+ "(short h, short v, RGBColor cPix) -> None"},
{"SetPortPix", (PyCFunction)Qd_SetPortPix, 1,
"(PixMapHandle pm) -> None"},
+ {"GetCPixel", (PyCFunction)Qd_GetCPixel, 1,
+ "(short h, short v) -> (RGBColor cPix)"},
+ {"GetForeColor", (PyCFunction)Qd_GetForeColor, 1,
+ "() -> (RGBColor color)"},
+ {"GetBackColor", (PyCFunction)Qd_GetBackColor, 1,
+ "() -> (RGBColor color)"},
+ {"OpColor", (PyCFunction)Qd_OpColor, 1,
+ "(RGBColor color) -> None"},
+ {"HiliteColor", (PyCFunction)Qd_HiliteColor, 1,
+ "(RGBColor color) -> None"},
{"AllocCursor", (PyCFunction)Qd_AllocCursor, 1,
"() -> None"},
{"GetCTSeed", (PyCFunction)Qd_GetCTSeed, 1,
"() -> (long _rv)"},
+ {"Color2Index", (PyCFunction)Qd_Color2Index, 1,
+ "(RGBColor myColor) -> (long _rv)"},
+ {"Index2Color", (PyCFunction)Qd_Index2Color, 1,
+ "(long index) -> (RGBColor aColor)"},
+ {"InvertColor", (PyCFunction)Qd_InvertColor, 1,
+ "() -> (RGBColor myColor)"},
+ {"RealColor", (PyCFunction)Qd_RealColor, 1,
+ "(RGBColor color) -> (Boolean _rv)"},
{"SetClientID", (PyCFunction)Qd_SetClientID, 1,
"(short id) -> None"},
{"ProtectEntry", (PyCFunction)Qd_ProtectEntry, 1,
diff --git a/Mac/Modules/qd/qdgen.py b/Mac/Modules/qd/qdgen.py
index 83479d1..f58cb03 100644
--- a/Mac/Modules/qd/qdgen.py
+++ b/Mac/Modules/qd/qdgen.py
@@ -664,6 +664,12 @@ f = Function(PixPatHandle, 'GetPixPat',
)
functions.append(f)
+f = Function(void, 'MakeRGBPat',
+ (PixPatHandle, 'pp', InMode),
+ (RGBColor_ptr, 'myColor', InMode),
+)
+functions.append(f)
+
f = Function(void, 'FillCRect',
(Rect_ptr, 'r', InMode),
(PixPatHandle, 'pp', InMode),
@@ -704,11 +710,55 @@ f = Function(void, 'FillCPoly',
)
functions.append(f)
+f = Function(void, 'RGBForeColor',
+ (RGBColor_ptr, 'color', InMode),
+)
+functions.append(f)
+
+f = Function(void, 'RGBBackColor',
+ (RGBColor_ptr, 'color', InMode),
+)
+functions.append(f)
+
+f = Function(void, 'SetCPixel',
+ (short, 'h', InMode),
+ (short, 'v', InMode),
+ (RGBColor_ptr, 'cPix', InMode),
+)
+functions.append(f)
+
f = Function(void, 'SetPortPix',
(PixMapHandle, 'pm', InMode),
)
functions.append(f)
+f = Function(void, 'GetCPixel',
+ (short, 'h', InMode),
+ (short, 'v', InMode),
+ (RGBColor, 'cPix', OutMode),
+)
+functions.append(f)
+
+f = Function(void, 'GetForeColor',
+ (RGBColor, 'color', OutMode),
+)
+functions.append(f)
+
+f = Function(void, 'GetBackColor',
+ (RGBColor, 'color', OutMode),
+)
+functions.append(f)
+
+f = Function(void, 'OpColor',
+ (RGBColor_ptr, 'color', InMode),
+)
+functions.append(f)
+
+f = Function(void, 'HiliteColor',
+ (RGBColor_ptr, 'color', InMode),
+)
+functions.append(f)
+
f = Function(void, 'AllocCursor',
)
functions.append(f)
@@ -717,6 +767,27 @@ f = Function(long, 'GetCTSeed',
)
functions.append(f)
+f = Function(long, 'Color2Index',
+ (RGBColor_ptr, 'myColor', InMode),
+)
+functions.append(f)
+
+f = Function(void, 'Index2Color',
+ (long, 'index', InMode),
+ (RGBColor, 'aColor', OutMode),
+)
+functions.append(f)
+
+f = Function(void, 'InvertColor',
+ (RGBColor, 'myColor', OutMode),
+)
+functions.append(f)
+
+f = Function(Boolean, 'RealColor',
+ (RGBColor_ptr, 'color', InMode),
+)
+functions.append(f)
+
f = Function(void, 'SetClientID',
(short, 'id', InMode),
)
diff --git a/Mac/Modules/qd/qdscan.py b/Mac/Modules/qd/qdscan.py
index 0708733..e86895a 100644
--- a/Mac/Modules/qd/qdscan.py
+++ b/Mac/Modules/qd/qdscan.py
@@ -98,8 +98,6 @@ class MyScanner(Scanner):
'PenState_ptr',
'Ptr',
'QDProcs',
- 'RGBColor',
- 'RGBColor_ptr',
'ReqListRec',
'void_ptr',
]
diff --git a/Mac/Modules/qd/qdsupport.py b/Mac/Modules/qd/qdsupport.py
index 5739c50..245b6fd 100644
--- a/Mac/Modules/qd/qdsupport.py
+++ b/Mac/Modules/qd/qdsupport.py
@@ -42,12 +42,39 @@ CursHandle = OpaqueByValueType("CursHandle", "ResObj")
CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj")
GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj")
BitMap_ptr = OpaqueByValueType("BitMapPtr", "BMObj")
+RGBColor = OpaqueType('RGBColor', 'QdRGB')
+RGBColor_ptr = RGBColor
includestuff = includestuff + """
#include <%s>""" % MACHEADERFILE + """
#include <Desk.h>
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
+
+/*
+** Parse/generate RGB records
+*/
+PyObject *QdRGB_New(itself)
+ RGBColorPtr itself;
+{
+
+ return Py_BuildValue("lll", (long)itself->red, (long)itself->green, (long)itself->blue);
+}
+
+QdRGB_Convert(v, p_itself)
+ PyObject *v;
+ RGBColorPtr p_itself;
+{
+ long red, green, blue;
+
+ if( !PyArg_ParseTuple(v, "lll", &red, &green, &blue) )
+ return 0;
+ p_itself->red = (unsigned short)red;
+ p_itself->green = (unsigned short)green;
+ p_itself->blue = (unsigned short)blue;
+ return 1;
+}
+
"""
## not yet...
##