'release21-maint'.
--- /dev/null
+\section{History of the software}
+
+Python was created in the early 1990s by Guido van Rossum at Stichting
+Mathematisch Centrum (CWI) in the Netherlands as a successor of a
+language called ABC. Guido is Python's principal author, although it
+includes many contributions from others. The last version released
+from CWI was Python 1.2. In 1995, Guido continued his work on Python
+at the Corporation for National Research Initiatives (CNRI) in Reston,
+Virginia where he released several versions of the software. Python
+1.6 was the last of the versions released by CNRI. In 2000, Guido and
+the Python core development team moved to BeOpen.com to form the
+BeOpen PythonLabs team. Python 2.0 was the first and only release
+from BeOpen.com.
+
+Following the release of Python 1.6, and after Guido van Rossum left
+CNRI to work with commercial software developers, it became clear that
+the ability to use Python with software available under the GNU Public
+License (GPL) was very desirable. CNRI and the Free Software
+Foundation (FSF) interacted to develop enabling wording changes to the
+Python license. Python 1.6.1 is essentially the same as Python 1.6,
+with a few minor bug fixes, and with a different license that enables
+later versions to be GPL-compatible. Python 2.0.1 is a derivative work
+of Python 1.6.1, as well as of Python 2.0.
+
+After Python 2.0 was released by BeOpen.com, Guido van Rossum and the
+other PythonLabs developers joined Digital Creations. All
+intellectual property added from this point on, including Python
+2.0.1 and its alpha and beta releases, is owned by the Python Software
+Foundation (PSF), a non-profit modeled after the Apache Software
+Foundation. See \url{http://www.python.org/psf/} for more information
+about the PSF.
+
+Thanks to the many outside volunteers who have worked under Guido's
+direction to make these releases possible.
+
+
+\section{Terms and conditions for accessing or otherwise using Python}
+
+\centerline{\strong{PSF LICENSE AGREEMENT}}
+
+\begin{enumerate}
+\item
+This LICENSE AGREEMENT is between the Python Software Foundation
+(``PSF''), and the Individual or Organization (``Licensee'') accessing
+and otherwise using Python \version{} software in source or binary
+form and its associated documentation.
+
+\item
+Subject to the terms and conditions of this License Agreement, PSF
+hereby grants Licensee a nonexclusive, royalty-free, world-wide
+license to reproduce, analyze, test, perform and/or display publicly,
+prepare derivative works, distribute, and otherwise use Python
+\version{} alone or in any derivative version, provided, however, that
+PSF's License Agreement and PSF's notice of copyright, i.e.,
+``Copyright \copyright{} 2001 Python Software Foundation; All Rights
+Reserved'' are retained in Python \version{} alone or in any
+derivative version prepared by Licensee.
+
+\item
+In the event Licensee prepares a derivative work that is based on
+or incorporates Python \version{} or any part thereof, and wants to
+make the derivative work available to others as provided herein, then
+Licensee hereby agrees to include in any such work a brief summary of
+the changes made to Python \version.
+
+\item
+PSF is making Python \version{} available to Licensee on an ``AS IS''
+basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
+IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
+DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
+FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON \version{} WILL
+NOT INFRINGE ANY THIRD PARTY RIGHTS.
+
+\item
+PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
+\version{} FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
+LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON
+\version, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE
+POSSIBILITY THEREOF.
+
+\item
+This License Agreement will automatically terminate upon a material
+breach of its terms and conditions.
+
+\item
+Nothing in this License Agreement shall be deemed to create any
+relationship of agency, partnership, or joint venture between PSF and
+Licensee. This License Agreement does not grant permission to use PSF
+trademarks or trade name in a trademark sense to endorse or promote
+products or services of Licensee, or any third party.
+
+\item
+By copying, installing or otherwise using Python \version, Licensee
+agrees to be bound by the terms and conditions of this License
+Agreement.
+\end{enumerate}
+
+
+\centerline{\strong{BEOPEN.COM TERMS AND CONDITIONS FOR PYTHON 2.0}}
+
+\centerline{\strong{BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1}}
+
+\begin{enumerate}
+\item
+This LICENSE AGREEMENT is between BeOpen.com (``BeOpen''), having an
+office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the
+Individual or Organization (``Licensee'') accessing and otherwise
+using this software in source or binary form and its associated
+documentation (``the Software'').
+
+\item
+Subject to the terms and conditions of this BeOpen Python License
+Agreement, BeOpen hereby grants Licensee a non-exclusive,
+royalty-free, world-wide license to reproduce, analyze, test, perform
+and/or display publicly, prepare derivative works, distribute, and
+otherwise use the Software alone or in any derivative version,
+provided, however, that the BeOpen Python License is retained in the
+Software, alone or in any derivative version prepared by Licensee.
+
+\item
+BeOpen is making the Software available to Licensee on an ``AS IS''
+basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
+IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND
+DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
+FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT
+INFRINGE ANY THIRD PARTY RIGHTS.
+
+\item
+BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE
+SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS
+AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY
+DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
+
+\item
+This License Agreement will automatically terminate upon a material
+breach of its terms and conditions.
+
+\item
+This License Agreement shall be governed by and interpreted in all
+respects by the law of the State of California, excluding conflict of
+law provisions. Nothing in this License Agreement shall be deemed to
+create any relationship of agency, partnership, or joint venture
+between BeOpen and Licensee. This License Agreement does not grant
+permission to use BeOpen trademarks or trade names in a trademark
+sense to endorse or promote products or services of Licensee, or any
+third party. As an exception, the ``BeOpen Python'' logos available
+at http://www.pythonlabs.com/logos.html may be used according to the
+permissions granted on that web page.
+
+\item
+By copying, installing or otherwise using the software, Licensee
+agrees to be bound by the terms and conditions of this License
+Agreement.
+\end{enumerate}
+
+
+\centerline{\strong{CNRI OPEN SOURCE GPL-COMPATIBLE LICENSE AGREEMENT}}
+
+\begin{enumerate}
+\item
+This LICENSE AGREEMENT is between the Corporation for National
+Research Initiatives, having an office at 1895 Preston White Drive,
+Reston, VA 20191 (``CNRI''), and the Individual or Organization
+(``Licensee'') accessing and otherwise using Python 1.6.1 software in
+source or binary form and its associated documentation.
+
+\item
+Subject to the terms and conditions of this License Agreement, CNRI
+hereby grants Licensee a nonexclusive, royalty-free, world-wide
+license to reproduce, analyze, test, perform and/or display publicly,
+prepare derivative works, distribute, and otherwise use Python 1.6.1
+alone or in any derivative version, provided, however, that CNRI's
+License Agreement and CNRI's notice of copyright, i.e., ``Copyright
+\copyright{} 1995-2001 Corporation for National Research Initiatives;
+All Rights Reserved'' are retained in Python 1.6.1 alone or in any
+derivative version prepared by Licensee. Alternately, in lieu of
+CNRI's License Agreement, Licensee may substitute the following text
+(omitting the quotes): ``Python 1.6.1 is made available subject to the
+terms and conditions in CNRI's License Agreement. This Agreement
+together with Python 1.6.1 may be located on the Internet using the
+following unique, persistent identifier (known as a handle):
+1895.22/1013. This Agreement may also be obtained from a proxy server
+on the Internet using the following URL:
+\url{http://hdl.handle.net/1895.22/1013}.''
+
+\item
+In the event Licensee prepares a derivative work that is based on
+or incorporates Python 1.6.1 or any part thereof, and wants to make
+the derivative work available to others as provided herein, then
+Licensee hereby agrees to include in any such work a brief summary of
+the changes made to Python 1.6.1.
+
+\item
+CNRI is making Python 1.6.1 available to Licensee on an ``AS IS''
+basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
+IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND
+DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
+FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT
+INFRINGE ANY THIRD PARTY RIGHTS.
+
+\item
+CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
+1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
+A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1,
+OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
+
+\item
+This License Agreement will automatically terminate upon a material
+breach of its terms and conditions.
+
+\item
+This License Agreement shall be governed by the federal
+intellectual property law of the United States, including without
+limitation the federal copyright law, and, to the extent such
+U.S. federal law does not apply, by the law of the Commonwealth of
+Virginia, excluding Virginia's conflict of law provisions.
+Notwithstanding the foregoing, with regard to derivative works based
+on Python 1.6.1 that incorporate non-separable material that was
+previously distributed under the GNU General Public License (GPL), the
+law of the Commonwealth of Virginia shall govern this License
+Agreement only as to issues arising under or with respect to
+Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this
+License Agreement shall be deemed to create any relationship of
+agency, partnership, or joint venture between CNRI and Licensee. This
+License Agreement does not grant permission to use CNRI trademarks or
+trade name in a trademark sense to endorse or promote products or
+services of Licensee, or any third party.
+
+\item
+By clicking on the ``ACCEPT'' button where indicated, or by copying,
+installing or otherwise using Python 1.6.1, Licensee agrees to be
+bound by the terms and conditions of this License Agreement.
+\end{enumerate}
+
+\centerline{ACCEPT}
+
+
+
+\centerline{\strong{CWI PERMISSIONS STATEMENT AND DISCLAIMER}}
+
+Copyright \copyright{} 1991 - 1995, Stichting Mathematisch Centrum
+Amsterdam, The Netherlands. All rights reserved.
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Stichting Mathematisch
+Centrum or CWI not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
+THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
+FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
--- /dev/null
+import W
+
+# define some callbacks
+def callback():
+ window.close()
+
+def checkcallback(value):
+ print "hit the checkbox", value
+
+def radiocallback(value):
+ print "hit radiobutton #3", value
+
+def scrollcallback(value):
+ widget = window.hbar
+ if value == "+":
+ widget.set(widget.get() - 1)
+ elif value == "-":
+ widget.set(widget.get() + 1)
+ elif value == "++":
+ widget.set(widget.get() - 10)
+ elif value == "--":
+ widget.set(widget.get() + 10)
+ else: # in thumb
+ widget.set(value)
+ print "scroll...", widget.get()
+
+def textcallback():
+ window.et3.set(window.et1.get())
+
+def cancel():
+ import EasyDialogs
+ EasyDialogs.Message("Cancel!")
+
+# make a non-sizable window
+#window = W.Window((200, 300), "Fixed Size")
+
+# make a sizable window
+window = W.Window((200, 300), "Variable Size!", minsize = (200, 300))
+
+# make some edit text widgets
+window.et1 = W.EditText((10, 10, 110, 110), "Hallo!", textcallback)
+window.et2 = W.EditText((130, 40, 60, 30), "one!")
+window.et3 = W.EditText((130, 80, -10, 40), "two?")
+
+# a button
+window.button = W.Button((-70, 10, 60, 16), "Close", callback)
+
+# a checkbox
+window.ch = W.CheckBox((10, 130, 160, 16), "Check (command \xa4)", checkcallback)
+
+# set of radio buttons (should become easier/nicer)
+thebuttons = []
+window.r1 = W.RadioButton((10, 150, 180, 16), "Radio 1 (cmd 1)", thebuttons)
+window.r2 = W.RadioButton((10, 170, 180, 16), "Radio 2 (cmd 2)", thebuttons)
+window.r3 = W.RadioButton((10, 190, 180, 16), "Radio 3 (cmd 3)", thebuttons, radiocallback)
+window.r1.set(1)
+
+# a normal button
+window.cancelbutton = W.Button((10, 220, 60, 16), "Cancel", cancel)
+
+# a scrollbar
+window.hbar = W.Scrollbar((-1, -15, -14, 16), scrollcallback, max = 100)
+
+# some static text
+window.static = W.TextBox((10, 260, 110, 16), "Schtatic")
+
+# bind some keystrokes to functions
+window.bind('cmd\xa4', window.ch.push)
+window.bind('cmd1', window.r1.push)
+window.bind('cmd2', window.r2.push)
+window.bind('cmd3', window.r3.push)
+window.bind('cmdw', window.button.push)
+window.bind('cmd.', window.cancelbutton.push)
+
+window.setdefaultbutton(window.button)
+# open the window
+window.open()
+
+if 0:
+ import time
+ for i in range(20):
+ window.et2.set(`i`)
+ #window.et2.SetPort()
+ #window.et2.draw()
+ time.sleep(0.1)
--- /dev/null
+
+/* =========================== Module AE ============================ */
+
+#include "Python.h"
+
+
+
+#include "macglue.h"
+#include "pymactoolbox.h"
+
+#ifdef WITHOUT_FRAMEWORKS
+#include <AppleEvents.h>
+#include <AEObjects.h>
+#else
+#include <Carbon/Carbon.h>
+#endif
+
+#ifdef USE_TOOLBOX_OBJECT_GLUE
+extern PyObject *_AEDesc_New(AEDesc *);
+extern int _AEDesc_Convert(PyObject *, AEDesc *);
+
+#define AEDesc_New _AEDesc_New
+#define AEDesc_Convert _AEDesc_Convert
+#endif
+
+static pascal OSErr GenericEventHandler(); /* Forward */
+
+AEEventHandlerUPP upp_GenericEventHandler;
+
+static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn)
+{
+ if ( PyOS_InterruptOccurred() )
+ return 1;
+ if ( PyMac_HandleEvent(theEvent) < 0 ) {
+ PySys_WriteStderr("Exception in user event handler during AE processing\n");
+ PyErr_Clear();
+ }
+ return 0;
+}
+
+AEIdleUPP upp_AEIdleProc;
+
+static PyObject *AE_Error;
+
+/* ----------------------- Object type AEDesc ----------------------- */
+
+PyTypeObject AEDesc_Type;
+
+#define AEDesc_Check(x) ((x)->ob_type == &AEDesc_Type)
+
+typedef struct AEDescObject {
+ PyObject_HEAD
+ AEDesc ob_itself;
+} AEDescObject;
+
+PyObject *AEDesc_New(AEDesc *itself)
+{
+ AEDescObject *it;
+ it = PyObject_NEW(AEDescObject, &AEDesc_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = *itself;
+ return (PyObject *)it;
+}
+AEDesc_Convert(PyObject *v, AEDesc *p_itself)
+{
+ if (!AEDesc_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "AEDesc required");
+ return 0;
+ }
+ *p_itself = ((AEDescObject *)v)->ob_itself;
+ return 1;
+}
+
+static void AEDesc_dealloc(AEDescObject *self)
+{
+ AEDisposeDesc(&self->ob_itself);
+ PyMem_DEL(self);
+}
+
+static PyObject *AEDesc_AECoerceDesc(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ DescType toType;
+ AEDesc result;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetOSType, &toType))
+ return NULL;
+ _err = AECoerceDesc(&_self->ob_itself,
+ toType,
+ &result);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ AEDesc_New, &result);
+ return _res;
+}
+
+static PyObject *AEDesc_AEDuplicateDesc(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEDesc result;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = AEDuplicateDesc(&_self->ob_itself,
+ &result);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ AEDesc_New, &result);
+ return _res;
+}
+
+static PyObject *AEDesc_AECountItems(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long theCount;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = AECountItems(&_self->ob_itself,
+ &theCount);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ theCount);
+ return _res;
+}
+
+static PyObject *AEDesc_AEPutPtr(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long index;
+ DescType typeCode;
+ char *dataPtr__in__;
+ long dataPtr__len__;
+ int dataPtr__in_len__;
+ if (!PyArg_ParseTuple(_args, "lO&s#",
+ &index,
+ PyMac_GetOSType, &typeCode,
+ &dataPtr__in__, &dataPtr__in_len__))
+ return NULL;
+ dataPtr__len__ = dataPtr__in_len__;
+ _err = AEPutPtr(&_self->ob_itself,
+ index,
+ typeCode,
+ dataPtr__in__, dataPtr__len__);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ dataPtr__error__: ;
+ return _res;
+}
+
+static PyObject *AEDesc_AEPutDesc(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long index;
+ AEDesc theAEDesc;
+ if (!PyArg_ParseTuple(_args, "lO&",
+ &index,
+ AEDesc_Convert, &theAEDesc))
+ return NULL;
+ _err = AEPutDesc(&_self->ob_itself,
+ index,
+ &theAEDesc);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AEDesc_AEGetNthPtr(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long index;
+ DescType desiredType;
+ AEKeyword theAEKeyword;
+ DescType typeCode;
+ char *dataPtr__out__;
+ long dataPtr__len__;
+ int dataPtr__in_len__;
+ if (!PyArg_ParseTuple(_args, "lO&i",
+ &index,
+ PyMac_GetOSType, &desiredType,
+ &dataPtr__in_len__))
+ return NULL;
+ if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
+ {
+ PyErr_NoMemory();
+ goto dataPtr__error__;
+ }
+ dataPtr__len__ = dataPtr__in_len__;
+ _err = AEGetNthPtr(&_self->ob_itself,
+ index,
+ desiredType,
+ &theAEKeyword,
+ &typeCode,
+ dataPtr__out__, dataPtr__len__, &dataPtr__len__);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&O&s#",
+ PyMac_BuildOSType, theAEKeyword,
+ PyMac_BuildOSType, typeCode,
+ dataPtr__out__, (int)dataPtr__len__);
+ free(dataPtr__out__);
+ dataPtr__error__: ;
+ return _res;
+}
+
+static PyObject *AEDesc_AEGetNthDesc(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long index;
+ DescType desiredType;
+ AEKeyword theAEKeyword;
+ AEDesc result;
+ if (!PyArg_ParseTuple(_args, "lO&",
+ &index,
+ PyMac_GetOSType, &desiredType))
+ return NULL;
+ _err = AEGetNthDesc(&_self->ob_itself,
+ index,
+ desiredType,
+ &theAEKeyword,
+ &result);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&O&",
+ PyMac_BuildOSType, theAEKeyword,
+ AEDesc_New, &result);
+ return _res;
+}
+
+static PyObject *AEDesc_AESizeOfNthItem(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long index;
+ DescType typeCode;
+ Size dataSize;
+ if (!PyArg_ParseTuple(_args, "l",
+ &index))
+ return NULL;
+ _err = AESizeOfNthItem(&_self->ob_itself,
+ index,
+ &typeCode,
+ &dataSize);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&l",
+ PyMac_BuildOSType, typeCode,
+ dataSize);
+ return _res;
+}
+
+static PyObject *AEDesc_AEDeleteItem(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long index;
+ if (!PyArg_ParseTuple(_args, "l",
+ &index))
+ return NULL;
+ _err = AEDeleteItem(&_self->ob_itself,
+ index);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AEDesc_AEPutParamPtr(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEKeyword theAEKeyword;
+ DescType typeCode;
+ char *dataPtr__in__;
+ long dataPtr__len__;
+ int dataPtr__in_len__;
+ if (!PyArg_ParseTuple(_args, "O&O&s#",
+ PyMac_GetOSType, &theAEKeyword,
+ PyMac_GetOSType, &typeCode,
+ &dataPtr__in__, &dataPtr__in_len__))
+ return NULL;
+ dataPtr__len__ = dataPtr__in_len__;
+ _err = AEPutParamPtr(&_self->ob_itself,
+ theAEKeyword,
+ typeCode,
+ dataPtr__in__, dataPtr__len__);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ dataPtr__error__: ;
+ return _res;
+}
+
+static PyObject *AEDesc_AEPutParamDesc(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEKeyword theAEKeyword;
+ AEDesc theAEDesc;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetOSType, &theAEKeyword,
+ AEDesc_Convert, &theAEDesc))
+ return NULL;
+ _err = AEPutParamDesc(&_self->ob_itself,
+ theAEKeyword,
+ &theAEDesc);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AEDesc_AEGetParamPtr(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEKeyword theAEKeyword;
+ DescType desiredType;
+ DescType typeCode;
+ char *dataPtr__out__;
+ long dataPtr__len__;
+ int dataPtr__in_len__;
+ if (!PyArg_ParseTuple(_args, "O&O&i",
+ PyMac_GetOSType, &theAEKeyword,
+ PyMac_GetOSType, &desiredType,
+ &dataPtr__in_len__))
+ return NULL;
+ if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
+ {
+ PyErr_NoMemory();
+ goto dataPtr__error__;
+ }
+ dataPtr__len__ = dataPtr__in_len__;
+ _err = AEGetParamPtr(&_self->ob_itself,
+ theAEKeyword,
+ desiredType,
+ &typeCode,
+ dataPtr__out__, dataPtr__len__, &dataPtr__len__);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&s#",
+ PyMac_BuildOSType, typeCode,
+ dataPtr__out__, (int)dataPtr__len__);
+ free(dataPtr__out__);
+ dataPtr__error__: ;
+ return _res;
+}
+
+static PyObject *AEDesc_AEGetParamDesc(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEKeyword theAEKeyword;
+ DescType desiredType;
+ AEDesc result;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetOSType, &theAEKeyword,
+ PyMac_GetOSType, &desiredType))
+ return NULL;
+ _err = AEGetParamDesc(&_self->ob_itself,
+ theAEKeyword,
+ desiredType,
+ &result);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ AEDesc_New, &result);
+ return _res;
+}
+
+static PyObject *AEDesc_AESizeOfParam(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEKeyword theAEKeyword;
+ DescType typeCode;
+ Size dataSize;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetOSType, &theAEKeyword))
+ return NULL;
+ _err = AESizeOfParam(&_self->ob_itself,
+ theAEKeyword,
+ &typeCode,
+ &dataSize);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&l",
+ PyMac_BuildOSType, typeCode,
+ dataSize);
+ return _res;
+}
+
+static PyObject *AEDesc_AEDeleteParam(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEKeyword theAEKeyword;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetOSType, &theAEKeyword))
+ return NULL;
+ _err = AEDeleteParam(&_self->ob_itself,
+ theAEKeyword);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AEDesc_AEGetAttributePtr(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEKeyword theAEKeyword;
+ DescType desiredType;
+ DescType typeCode;
+ char *dataPtr__out__;
+ long dataPtr__len__;
+ int dataPtr__in_len__;
+ if (!PyArg_ParseTuple(_args, "O&O&i",
+ PyMac_GetOSType, &theAEKeyword,
+ PyMac_GetOSType, &desiredType,
+ &dataPtr__in_len__))
+ return NULL;
+ if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
+ {
+ PyErr_NoMemory();
+ goto dataPtr__error__;
+ }
+ dataPtr__len__ = dataPtr__in_len__;
+ _err = AEGetAttributePtr(&_self->ob_itself,
+ theAEKeyword,
+ desiredType,
+ &typeCode,
+ dataPtr__out__, dataPtr__len__, &dataPtr__len__);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&s#",
+ PyMac_BuildOSType, typeCode,
+ dataPtr__out__, (int)dataPtr__len__);
+ free(dataPtr__out__);
+ dataPtr__error__: ;
+ return _res;
+}
+
+static PyObject *AEDesc_AEGetAttributeDesc(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEKeyword theAEKeyword;
+ DescType desiredType;
+ AEDesc result;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetOSType, &theAEKeyword,
+ PyMac_GetOSType, &desiredType))
+ return NULL;
+ _err = AEGetAttributeDesc(&_self->ob_itself,
+ theAEKeyword,
+ desiredType,
+ &result);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ AEDesc_New, &result);
+ return _res;
+}
+
+static PyObject *AEDesc_AESizeOfAttribute(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEKeyword theAEKeyword;
+ DescType typeCode;
+ Size dataSize;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetOSType, &theAEKeyword))
+ return NULL;
+ _err = AESizeOfAttribute(&_self->ob_itself,
+ theAEKeyword,
+ &typeCode,
+ &dataSize);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&l",
+ PyMac_BuildOSType, typeCode,
+ dataSize);
+ return _res;
+}
+
+static PyObject *AEDesc_AEPutAttributePtr(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEKeyword theAEKeyword;
+ DescType typeCode;
+ char *dataPtr__in__;
+ long dataPtr__len__;
+ int dataPtr__in_len__;
+ if (!PyArg_ParseTuple(_args, "O&O&s#",
+ PyMac_GetOSType, &theAEKeyword,
+ PyMac_GetOSType, &typeCode,
+ &dataPtr__in__, &dataPtr__in_len__))
+ return NULL;
+ dataPtr__len__ = dataPtr__in_len__;
+ _err = AEPutAttributePtr(&_self->ob_itself,
+ theAEKeyword,
+ typeCode,
+ dataPtr__in__, dataPtr__len__);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ dataPtr__error__: ;
+ return _res;
+}
+
+static PyObject *AEDesc_AEPutAttributeDesc(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEKeyword theAEKeyword;
+ AEDesc theAEDesc;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetOSType, &theAEKeyword,
+ AEDesc_Convert, &theAEDesc))
+ return NULL;
+ _err = AEPutAttributeDesc(&_self->ob_itself,
+ theAEKeyword,
+ &theAEDesc);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *AEDesc_AEGetDescDataSize(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Size _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = AEGetDescDataSize(&_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+#endif
+
+static PyObject *AEDesc_AESend(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AppleEvent reply;
+ AESendMode sendMode;
+ AESendPriority sendPriority;
+ long timeOutInTicks;
+ if (!PyArg_ParseTuple(_args, "lhl",
+ &sendMode,
+ &sendPriority,
+ &timeOutInTicks))
+ return NULL;
+ _err = AESend(&_self->ob_itself,
+ &reply,
+ sendMode,
+ sendPriority,
+ timeOutInTicks,
+ upp_AEIdleProc,
+ (AEFilterUPP)0);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ AEDesc_New, &reply);
+ return _res;
+}
+
+static PyObject *AEDesc_AEResetTimer(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = AEResetTimer(&_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AEDesc_AESuspendTheCurrentEvent(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = AESuspendTheCurrentEvent(&_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AEDesc_AEResumeTheCurrentEvent(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AppleEvent reply;
+ AEEventHandlerUPP dispatcher__proc__ = upp_GenericEventHandler;
+ PyObject *dispatcher;
+ if (!PyArg_ParseTuple(_args, "O&O",
+ AEDesc_Convert, &reply,
+ &dispatcher))
+ return NULL;
+ _err = AEResumeTheCurrentEvent(&_self->ob_itself,
+ &reply,
+ dispatcher__proc__, (long)dispatcher);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ Py_INCREF(dispatcher); /* XXX leak, but needed */
+ return _res;
+}
+
+static PyObject *AEDesc_AEGetTheCurrentEvent(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = AEGetTheCurrentEvent(&_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AEDesc_AESetTheCurrentEvent(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = AESetTheCurrentEvent(&_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AEDesc_AEResolve(AEDescObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ short callbackFlags;
+ AEDesc theToken;
+ if (!PyArg_ParseTuple(_args, "h",
+ &callbackFlags))
+ return NULL;
+ _err = AEResolve(&_self->ob_itself,
+ callbackFlags,
+ &theToken);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ AEDesc_New, &theToken);
+ return _res;
+}
+
+static PyMethodDef AEDesc_methods[] = {
+ {"AECoerceDesc", (PyCFunction)AEDesc_AECoerceDesc, 1,
+ "(DescType toType) -> (AEDesc result)"},
+ {"AEDuplicateDesc", (PyCFunction)AEDesc_AEDuplicateDesc, 1,
+ "() -> (AEDesc result)"},
+ {"AECountItems", (PyCFunction)AEDesc_AECountItems, 1,
+ "() -> (long theCount)"},
+ {"AEPutPtr", (PyCFunction)AEDesc_AEPutPtr, 1,
+ "(long index, DescType typeCode, Buffer dataPtr) -> None"},
+ {"AEPutDesc", (PyCFunction)AEDesc_AEPutDesc, 1,
+ "(long index, AEDesc theAEDesc) -> None"},
+ {"AEGetNthPtr", (PyCFunction)AEDesc_AEGetNthPtr, 1,
+ "(long index, DescType desiredType, Buffer dataPtr) -> (AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr)"},
+ {"AEGetNthDesc", (PyCFunction)AEDesc_AEGetNthDesc, 1,
+ "(long index, DescType desiredType) -> (AEKeyword theAEKeyword, AEDesc result)"},
+ {"AESizeOfNthItem", (PyCFunction)AEDesc_AESizeOfNthItem, 1,
+ "(long index) -> (DescType typeCode, Size dataSize)"},
+ {"AEDeleteItem", (PyCFunction)AEDesc_AEDeleteItem, 1,
+ "(long index) -> None"},
+ {"AEPutParamPtr", (PyCFunction)AEDesc_AEPutParamPtr, 1,
+ "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"},
+ {"AEPutParamDesc", (PyCFunction)AEDesc_AEPutParamDesc, 1,
+ "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"},
+ {"AEGetParamPtr", (PyCFunction)AEDesc_AEGetParamPtr, 1,
+ "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"},
+ {"AEGetParamDesc", (PyCFunction)AEDesc_AEGetParamDesc, 1,
+ "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"},
+ {"AESizeOfParam", (PyCFunction)AEDesc_AESizeOfParam, 1,
+ "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"},
+ {"AEDeleteParam", (PyCFunction)AEDesc_AEDeleteParam, 1,
+ "(AEKeyword theAEKeyword) -> None"},
+ {"AEGetAttributePtr", (PyCFunction)AEDesc_AEGetAttributePtr, 1,
+ "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"},
+ {"AEGetAttributeDesc", (PyCFunction)AEDesc_AEGetAttributeDesc, 1,
+ "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"},
+ {"AESizeOfAttribute", (PyCFunction)AEDesc_AESizeOfAttribute, 1,
+ "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"},
+ {"AEPutAttributePtr", (PyCFunction)AEDesc_AEPutAttributePtr, 1,
+ "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"},
+ {"AEPutAttributeDesc", (PyCFunction)AEDesc_AEPutAttributeDesc, 1,
+ "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"},
+
+#if TARGET_API_MAC_CARBON
+ {"AEGetDescDataSize", (PyCFunction)AEDesc_AEGetDescDataSize, 1,
+ "() -> (Size _rv)"},
+#endif
+ {"AESend", (PyCFunction)AEDesc_AESend, 1,
+ "(AESendMode sendMode, AESendPriority sendPriority, long timeOutInTicks) -> (AppleEvent reply)"},
+ {"AEResetTimer", (PyCFunction)AEDesc_AEResetTimer, 1,
+ "() -> None"},
+ {"AESuspendTheCurrentEvent", (PyCFunction)AEDesc_AESuspendTheCurrentEvent, 1,
+ "() -> None"},
+ {"AEResumeTheCurrentEvent", (PyCFunction)AEDesc_AEResumeTheCurrentEvent, 1,
+ "(AppleEvent reply, EventHandler dispatcher) -> None"},
+ {"AEGetTheCurrentEvent", (PyCFunction)AEDesc_AEGetTheCurrentEvent, 1,
+ "() -> None"},
+ {"AESetTheCurrentEvent", (PyCFunction)AEDesc_AESetTheCurrentEvent, 1,
+ "() -> None"},
+ {"AEResolve", (PyCFunction)AEDesc_AEResolve, 1,
+ "(short callbackFlags) -> (AEDesc theToken)"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain AEDesc_chain = { AEDesc_methods, NULL };
+
+static PyObject *AEDesc_getattr(AEDescObject *self, char *name)
+{
+
+ if (strcmp(name, "type") == 0)
+ return PyMac_BuildOSType(self->ob_itself.descriptorType);
+ if (strcmp(name, "data") == 0) {
+ PyObject *res;
+#if !TARGET_API_MAC_CARBON
+ char state;
+ state = HGetState(self->ob_itself.dataHandle);
+ HLock(self->ob_itself.dataHandle);
+ res = PyString_FromStringAndSize(
+ *self->ob_itself.dataHandle,
+ GetHandleSize(self->ob_itself.dataHandle));
+ HUnlock(self->ob_itself.dataHandle);
+ HSetState(self->ob_itself.dataHandle, state);
+#else
+ Size size;
+ char *ptr;
+ OSErr err;
+
+ size = AEGetDescDataSize(&self->ob_itself);
+ if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL )
+ return NULL;
+ if ( (ptr = PyString_AsString(res)) == NULL )
+ return NULL;
+ if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
+ return PyMac_Error(err);
+#endif
+ return res;
+ }
+ if (strcmp(name, "__members__") == 0)
+ return Py_BuildValue("[ss]", "data", "type");
+
+ return Py_FindMethodInChain(&AEDesc_chain, (PyObject *)self, name);
+}
+
+#define AEDesc_setattr NULL
+
+#define AEDesc_compare NULL
+
+#define AEDesc_repr NULL
+
+#define AEDesc_hash NULL
+
+PyTypeObject AEDesc_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "AEDesc", /*tp_name*/
+ sizeof(AEDescObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) AEDesc_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) AEDesc_getattr, /*tp_getattr*/
+ (setattrfunc) AEDesc_setattr, /*tp_setattr*/
+ (cmpfunc) AEDesc_compare, /*tp_compare*/
+ (reprfunc) AEDesc_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) AEDesc_hash, /*tp_hash*/
+};
+
+/* --------------------- End object type AEDesc --------------------- */
+
+
+static PyObject *AE_AECoercePtr(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ DescType typeCode;
+ char *dataPtr__in__;
+ long dataPtr__len__;
+ int dataPtr__in_len__;
+ DescType toType;
+ AEDesc result;
+ if (!PyArg_ParseTuple(_args, "O&s#O&",
+ PyMac_GetOSType, &typeCode,
+ &dataPtr__in__, &dataPtr__in_len__,
+ PyMac_GetOSType, &toType))
+ return NULL;
+ dataPtr__len__ = dataPtr__in_len__;
+ _err = AECoercePtr(typeCode,
+ dataPtr__in__, dataPtr__len__,
+ toType,
+ &result);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ AEDesc_New, &result);
+ dataPtr__error__: ;
+ return _res;
+}
+
+static PyObject *AE_AECreateDesc(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ DescType typeCode;
+ char *dataPtr__in__;
+ long dataPtr__len__;
+ int dataPtr__in_len__;
+ AEDesc result;
+ if (!PyArg_ParseTuple(_args, "O&s#",
+ PyMac_GetOSType, &typeCode,
+ &dataPtr__in__, &dataPtr__in_len__))
+ return NULL;
+ dataPtr__len__ = dataPtr__in_len__;
+ _err = AECreateDesc(typeCode,
+ dataPtr__in__, dataPtr__len__,
+ &result);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ AEDesc_New, &result);
+ dataPtr__error__: ;
+ return _res;
+}
+
+static PyObject *AE_AECreateList(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ char *factoringPtr__in__;
+ long factoringPtr__len__;
+ int factoringPtr__in_len__;
+ Boolean isRecord;
+ AEDescList resultList;
+ if (!PyArg_ParseTuple(_args, "s#b",
+ &factoringPtr__in__, &factoringPtr__in_len__,
+ &isRecord))
+ return NULL;
+ factoringPtr__len__ = factoringPtr__in_len__;
+ _err = AECreateList(factoringPtr__in__, factoringPtr__len__,
+ isRecord,
+ &resultList);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ AEDesc_New, &resultList);
+ factoringPtr__error__: ;
+ return _res;
+}
+
+static PyObject *AE_AECreateAppleEvent(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEEventClass theAEEventClass;
+ AEEventID theAEEventID;
+ AEAddressDesc target;
+ AEReturnID returnID;
+ AETransactionID transactionID;
+ AppleEvent result;
+ if (!PyArg_ParseTuple(_args, "O&O&O&hl",
+ PyMac_GetOSType, &theAEEventClass,
+ PyMac_GetOSType, &theAEEventID,
+ AEDesc_Convert, &target,
+ &returnID,
+ &transactionID))
+ return NULL;
+ _err = AECreateAppleEvent(theAEEventClass,
+ theAEEventID,
+ &target,
+ returnID,
+ transactionID,
+ &result);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ AEDesc_New, &result);
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *AE_AEReplaceDescData(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ DescType typeCode;
+ char *dataPtr__in__;
+ long dataPtr__len__;
+ int dataPtr__in_len__;
+ AEDesc theAEDesc;
+ if (!PyArg_ParseTuple(_args, "O&s#",
+ PyMac_GetOSType, &typeCode,
+ &dataPtr__in__, &dataPtr__in_len__))
+ return NULL;
+ dataPtr__len__ = dataPtr__in_len__;
+ _err = AEReplaceDescData(typeCode,
+ dataPtr__in__, dataPtr__len__,
+ &theAEDesc);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ AEDesc_New, &theAEDesc);
+ dataPtr__error__: ;
+ return _res;
+}
+#endif
+
+static PyObject *AE_AEProcessAppleEvent(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ EventRecord theEventRecord;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetEventRecord, &theEventRecord))
+ return NULL;
+ _err = AEProcessAppleEvent(&theEventRecord);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AE_AEGetInteractionAllowed(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEInteractAllowed level;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = AEGetInteractionAllowed(&level);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("b",
+ level);
+ return _res;
+}
+
+static PyObject *AE_AESetInteractionAllowed(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEInteractAllowed level;
+ if (!PyArg_ParseTuple(_args, "b",
+ &level))
+ return NULL;
+ _err = AESetInteractionAllowed(level);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AE_AEInteractWithUser(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long timeOutInTicks;
+ if (!PyArg_ParseTuple(_args, "l",
+ &timeOutInTicks))
+ return NULL;
+ _err = AEInteractWithUser(timeOutInTicks,
+ (NMRecPtr)0,
+ upp_AEIdleProc);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AE_AEInstallEventHandler(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEEventClass theAEEventClass;
+ AEEventID theAEEventID;
+ AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler;
+ PyObject *handler;
+ if (!PyArg_ParseTuple(_args, "O&O&O",
+ PyMac_GetOSType, &theAEEventClass,
+ PyMac_GetOSType, &theAEEventID,
+ &handler))
+ return NULL;
+ _err = AEInstallEventHandler(theAEEventClass,
+ theAEEventID,
+ handler__proc__, (long)handler,
+ 0);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ Py_INCREF(handler); /* XXX leak, but needed */
+ return _res;
+}
+
+static PyObject *AE_AERemoveEventHandler(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEEventClass theAEEventClass;
+ AEEventID theAEEventID;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetOSType, &theAEEventClass,
+ PyMac_GetOSType, &theAEEventID))
+ return NULL;
+ _err = AERemoveEventHandler(theAEEventClass,
+ theAEEventID,
+ upp_GenericEventHandler,
+ 0);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AE_AEGetEventHandler(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEEventClass theAEEventClass;
+ AEEventID theAEEventID;
+ AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler;
+ PyObject *handler;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetOSType, &theAEEventClass,
+ PyMac_GetOSType, &theAEEventID))
+ return NULL;
+ _err = AEGetEventHandler(theAEEventClass,
+ theAEEventID,
+ &handler__proc__, (long *)&handler,
+ 0);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O",
+ handler);
+ Py_INCREF(handler); /* XXX leak, but needed */
+ return _res;
+}
+
+static PyObject *AE_AEInstallSpecialHandler(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEKeyword functionClass;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetOSType, &functionClass))
+ return NULL;
+ _err = AEInstallSpecialHandler(functionClass,
+ upp_GenericEventHandler,
+ 0);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AE_AERemoveSpecialHandler(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEKeyword functionClass;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetOSType, &functionClass))
+ return NULL;
+ _err = AERemoveSpecialHandler(functionClass,
+ upp_GenericEventHandler,
+ 0);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AE_AEManagerInfo(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEKeyword keyWord;
+ long result;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetOSType, &keyWord))
+ return NULL;
+ _err = AEManagerInfo(keyWord,
+ &result);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ result);
+ return _res;
+}
+
+static PyObject *AE_AEObjectInit(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = AEObjectInit();
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *AE_AEDisposeToken(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AEDesc theToken;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = AEDisposeToken(&theToken);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ AEDesc_New, &theToken);
+ return _res;
+}
+
+static PyObject *AE_AECallObjectAccessor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ DescType desiredClass;
+ AEDesc containerToken;
+ DescType containerClass;
+ DescType keyForm;
+ AEDesc keyData;
+ AEDesc token;
+ if (!PyArg_ParseTuple(_args, "O&O&O&O&O&",
+ PyMac_GetOSType, &desiredClass,
+ AEDesc_Convert, &containerToken,
+ PyMac_GetOSType, &containerClass,
+ PyMac_GetOSType, &keyForm,
+ AEDesc_Convert, &keyData))
+ return NULL;
+ _err = AECallObjectAccessor(desiredClass,
+ &containerToken,
+ containerClass,
+ keyForm,
+ &keyData,
+ &token);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ AEDesc_New, &token);
+ return _res;
+}
+
+static PyMethodDef AE_methods[] = {
+ {"AECoercePtr", (PyCFunction)AE_AECoercePtr, 1,
+ "(DescType typeCode, Buffer dataPtr, DescType toType) -> (AEDesc result)"},
+ {"AECreateDesc", (PyCFunction)AE_AECreateDesc, 1,
+ "(DescType typeCode, Buffer dataPtr) -> (AEDesc result)"},
+ {"AECreateList", (PyCFunction)AE_AECreateList, 1,
+ "(Buffer factoringPtr, Boolean isRecord) -> (AEDescList resultList)"},
+ {"AECreateAppleEvent", (PyCFunction)AE_AECreateAppleEvent, 1,
+ "(AEEventClass theAEEventClass, AEEventID theAEEventID, AEAddressDesc target, AEReturnID returnID, AETransactionID transactionID) -> (AppleEvent result)"},
+
+#if TARGET_API_MAC_CARBON
+ {"AEReplaceDescData", (PyCFunction)AE_AEReplaceDescData, 1,
+ "(DescType typeCode, Buffer dataPtr) -> (AEDesc theAEDesc)"},
+#endif
+ {"AEProcessAppleEvent", (PyCFunction)AE_AEProcessAppleEvent, 1,
+ "(EventRecord theEventRecord) -> None"},
+ {"AEGetInteractionAllowed", (PyCFunction)AE_AEGetInteractionAllowed, 1,
+ "() -> (AEInteractAllowed level)"},
+ {"AESetInteractionAllowed", (PyCFunction)AE_AESetInteractionAllowed, 1,
+ "(AEInteractAllowed level) -> None"},
+ {"AEInteractWithUser", (PyCFunction)AE_AEInteractWithUser, 1,
+ "(long timeOutInTicks) -> None"},
+ {"AEInstallEventHandler", (PyCFunction)AE_AEInstallEventHandler, 1,
+ "(AEEventClass theAEEventClass, AEEventID theAEEventID, EventHandler handler) -> None"},
+ {"AERemoveEventHandler", (PyCFunction)AE_AERemoveEventHandler, 1,
+ "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> None"},
+ {"AEGetEventHandler", (PyCFunction)AE_AEGetEventHandler, 1,
+ "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> (EventHandler handler)"},
+ {"AEInstallSpecialHandler", (PyCFunction)AE_AEInstallSpecialHandler, 1,
+ "(AEKeyword functionClass) -> None"},
+ {"AERemoveSpecialHandler", (PyCFunction)AE_AERemoveSpecialHandler, 1,
+ "(AEKeyword functionClass) -> None"},
+ {"AEManagerInfo", (PyCFunction)AE_AEManagerInfo, 1,
+ "(AEKeyword keyWord) -> (long result)"},
+ {"AEObjectInit", (PyCFunction)AE_AEObjectInit, 1,
+ "() -> None"},
+ {"AEDisposeToken", (PyCFunction)AE_AEDisposeToken, 1,
+ "() -> (AEDesc theToken)"},
+ {"AECallObjectAccessor", (PyCFunction)AE_AECallObjectAccessor, 1,
+ "(DescType desiredClass, AEDesc containerToken, DescType containerClass, DescType keyForm, AEDesc keyData) -> (AEDesc token)"},
+ {NULL, NULL, 0}
+};
+
+
+#if UNIVERSAL_INTERFACES_VERSION >= 0x0340
+typedef long refcontype;
+#else
+typedef unsigned long refcontype;
+#endif
+
+static pascal OSErr
+GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon)
+{
+ PyObject *handler = (PyObject *)refcon;
+ AEDescObject *requestObject, *replyObject;
+ PyObject *args, *res;
+ if ((requestObject = (AEDescObject *)AEDesc_New((AppleEvent *)request)) == NULL) {
+ return -1;
+ }
+ if ((replyObject = (AEDescObject *)AEDesc_New(reply)) == NULL) {
+ Py_DECREF(requestObject);
+ return -1;
+ }
+ if ((args = Py_BuildValue("OO", requestObject, replyObject)) == NULL) {
+ Py_DECREF(requestObject);
+ Py_DECREF(replyObject);
+ return -1;
+ }
+ res = PyEval_CallObject(handler, args);
+ requestObject->ob_itself.descriptorType = 'null';
+ requestObject->ob_itself.dataHandle = NULL;
+ replyObject->ob_itself.descriptorType = 'null';
+ replyObject->ob_itself.dataHandle = NULL;
+ Py_DECREF(args);
+ if (res == NULL)
+ return -1;
+ Py_DECREF(res);
+ return noErr;
+}
+
+
+void initAE(void)
+{
+ PyObject *m;
+ PyObject *d;
+
+
+
+ upp_AEIdleProc = NewAEIdleUPP(AEIdleProc);
+ upp_GenericEventHandler = NewAEEventHandlerUPP(&GenericEventHandler);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc, AEDesc_Convert);
+
+
+ m = Py_InitModule("AE", AE_methods);
+ d = PyModule_GetDict(m);
+ AE_Error = PyMac_GetOSErrException();
+ if (AE_Error == NULL ||
+ PyDict_SetItemString(d, "Error", AE_Error) != 0)
+ return;
+ AEDesc_Type.ob_type = &PyType_Type;
+ Py_INCREF(&AEDesc_Type);
+ if (PyDict_SetItemString(d, "AEDescType", (PyObject *)&AEDesc_Type) != 0)
+ Py_FatalError("can't initialize AEDescType");
+}
+
+/* ========================= End module AE ========================== */
+
--- /dev/null
+# This script will generate the AppleEvents interface for Python.
+# It uses the "bgen" package to generate C code.
+# It execs the file aegen.py which contain the function definitions
+# (aegen.py was generated by aescan.py, scanning the <AppleEvents.h> header file).
+
+
+from macsupport import *
+
+
+AEArrayType = Type("AEArrayType", "c")
+AESendMode = Type("AESendMode", "l")
+AESendPriority = Type("AESendPriority", "h")
+AEInteractAllowed = Type("AEInteractAllowed", "b")
+AEReturnID = Type("AEReturnID", "h")
+AETransactionID = Type("AETransactionID", "l")
+
+
+
+AEEventClass = OSTypeType('AEEventClass')
+AEEventID = OSTypeType('AEEventID')
+AEKeyword = OSTypeType('AEKeyword')
+DescType = OSTypeType('DescType')
+
+
+AEDesc = OpaqueType('AEDesc')
+AEDesc_ptr = OpaqueType('AEDesc')
+
+AEAddressDesc = OpaqueType('AEAddressDesc', 'AEDesc')
+AEAddressDesc_ptr = OpaqueType('AEAddressDesc', 'AEDesc')
+
+AEDescList = OpaqueType('AEDescList', 'AEDesc')
+AEDescList_ptr = OpaqueType('AEDescList', 'AEDesc')
+
+AERecord = OpaqueType('AERecord', 'AEDesc')
+AERecord_ptr = OpaqueType('AERecord', 'AEDesc')
+
+AppleEvent = OpaqueType('AppleEvent', 'AEDesc')
+AppleEvent_ptr = OpaqueType('AppleEvent', 'AEDesc')
+
+
+class EHType(Type):
+ def __init__(self, name = 'EventHandler', format = ''):
+ Type.__init__(self, name, format)
+ def declare(self, name):
+ Output("AEEventHandlerUPP %s__proc__ = upp_GenericEventHandler;", name)
+ Output("PyObject *%s;", name)
+ def getargsFormat(self):
+ return "O"
+ def getargsArgs(self, name):
+ return "&%s" % name
+ def passInput(self, name):
+ return "%s__proc__, (long)%s" % (name, name)
+ def passOutput(self, name):
+ return "&%s__proc__, (long *)&%s" % (name, name)
+ def mkvalueFormat(self):
+ return "O"
+ def mkvalueArgs(self, name):
+ return name
+ def cleanup(self, name):
+ Output("Py_INCREF(%s); /* XXX leak, but needed */", name)
+
+class EHNoRefConType(EHType):
+ def passInput(self, name):
+ return "upp_GenericEventHandler"
+
+EventHandler = EHType()
+EventHandlerNoRefCon = EHNoRefConType()
+
+
+IdleProcPtr = FakeType("upp_AEIdleProc")
+AEIdleUPP = IdleProcPtr
+EventFilterProcPtr = FakeType("(AEFilterUPP)0")
+AEFilterUPP = EventFilterProcPtr
+NMRecPtr = FakeType("(NMRecPtr)0")
+EventHandlerProcPtr = FakeType("upp_GenericEventHandler")
+AEEventHandlerUPP = EventHandlerProcPtr
+AlwaysFalse = FakeType("0")
+
+
+AEFunction = OSErrFunctionGenerator
+AEMethod = OSErrMethodGenerator
+
+
+includestuff = includestuff + """
+#ifdef WITHOUT_FRAMEWORKS
+#include <AppleEvents.h>
+#include <AEObjects.h>
+#else
+#include <Carbon/Carbon.h>
+#endif
+
+#ifdef USE_TOOLBOX_OBJECT_GLUE
+extern PyObject *_AEDesc_New(AEDesc *);
+extern int _AEDesc_Convert(PyObject *, AEDesc *);
+
+#define AEDesc_New _AEDesc_New
+#define AEDesc_Convert _AEDesc_Convert
+#endif
+
+static pascal OSErr GenericEventHandler(); /* Forward */
+
+AEEventHandlerUPP upp_GenericEventHandler;
+
+static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn)
+{
+ if ( PyOS_InterruptOccurred() )
+ return 1;
+ if ( PyMac_HandleEvent(theEvent) < 0 ) {
+ PySys_WriteStderr("Exception in user event handler during AE processing\\n");
+ PyErr_Clear();
+ }
+ return 0;
+}
+
+AEIdleUPP upp_AEIdleProc;
+"""
+
+finalstuff = finalstuff + """
+#if UNIVERSAL_INTERFACES_VERSION >= 0x0340
+typedef long refcontype;
+#else
+typedef unsigned long refcontype;
+#endif
+
+static pascal OSErr
+GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon)
+{
+ PyObject *handler = (PyObject *)refcon;
+ AEDescObject *requestObject, *replyObject;
+ PyObject *args, *res;
+ if ((requestObject = (AEDescObject *)AEDesc_New((AppleEvent *)request)) == NULL) {
+ return -1;
+ }
+ if ((replyObject = (AEDescObject *)AEDesc_New(reply)) == NULL) {
+ Py_DECREF(requestObject);
+ return -1;
+ }
+ if ((args = Py_BuildValue("OO", requestObject, replyObject)) == NULL) {
+ Py_DECREF(requestObject);
+ Py_DECREF(replyObject);
+ return -1;
+ }
+ res = PyEval_CallObject(handler, args);
+ requestObject->ob_itself.descriptorType = 'null';
+ requestObject->ob_itself.dataHandle = NULL;
+ replyObject->ob_itself.descriptorType = 'null';
+ replyObject->ob_itself.dataHandle = NULL;
+ Py_DECREF(args);
+ if (res == NULL)
+ return -1;
+ Py_DECREF(res);
+ return noErr;
+}
+"""
+
+initstuff = initstuff + """
+ upp_AEIdleProc = NewAEIdleUPP(AEIdleProc);
+#if UNIVERSAL_INTERFACES_VERSION >= 0x03400
+ upp_GenericEventHandler = NewAEEventHandlerUPP(&GenericEventHandler);
+#else
+ upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler);
+#endif
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc, AEDesc_Convert);
+"""
+
+module = MacModule('AE', 'AE', includestuff, finalstuff, initstuff)
+
+class AEDescDefinition(GlobalObjectDefinition):
+
+ def __init__(self, name, prefix = None, itselftype = None):
+ GlobalObjectDefinition.__init__(self, name, prefix or name, itselftype or name)
+ self.argref = "*"
+
+ def outputFreeIt(self, name):
+ Output("AEDisposeDesc(&%s);", name)
+
+ def outputGetattrHook(self):
+ Output("""
+if (strcmp(name, "type") == 0)
+ return PyMac_BuildOSType(self->ob_itself.descriptorType);
+if (strcmp(name, "data") == 0) {
+ PyObject *res;
+#if !TARGET_API_MAC_CARBON
+ char state;
+ state = HGetState(self->ob_itself.dataHandle);
+ HLock(self->ob_itself.dataHandle);
+ res = PyString_FromStringAndSize(
+ *self->ob_itself.dataHandle,
+ GetHandleSize(self->ob_itself.dataHandle));
+ HUnlock(self->ob_itself.dataHandle);
+ HSetState(self->ob_itself.dataHandle, state);
+#else
+ Size size;
+ char *ptr;
+ OSErr err;
+
+ size = AEGetDescDataSize(&self->ob_itself);
+ if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL )
+ return NULL;
+ if ( (ptr = PyString_AsString(res)) == NULL )
+ return NULL;
+ if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
+ return PyMac_Error(err);
+#endif
+ return res;
+}
+if (strcmp(name, "__members__") == 0)
+ return Py_BuildValue("[ss]", "data", "type");
+""")
+
+
+aedescobject = AEDescDefinition('AEDesc')
+module.addobject(aedescobject)
+
+functions = []
+aedescmethods = []
+
+execfile('aegen.py')
+##execfile('aedatamodelgen.py')
+
+for f in functions: module.add(f)
+for f in aedescmethods: aedescobject.add(f)
+
+SetOutputFileName('AEmodule.c')
+module.generate()
--- /dev/null
+
+/* =========================== Module Ctl =========================== */
+
+#include "Python.h"
+
+
+
+#include "macglue.h"
+#include "pymactoolbox.h"
+
+#ifdef WITHOUT_FRAMEWORKS
+#include <Controls.h>
+#include <ControlDefinitions.h>
+#else
+#include <Carbon/Carbon.h>
+#endif
+
+#ifdef USE_TOOLBOX_OBJECT_GLUE
+extern PyObject *_CtlObj_New(ControlHandle);
+extern int _CtlObj_Convert(PyObject *, ControlHandle *);
+
+#define CtlObj_New _CtlObj_New
+#define CtlObj_Convert _CtlObj_Convert
+#endif
+
+staticforward PyObject *CtlObj_WhichControl(ControlHandle);
+
+#define as_Control(h) ((ControlHandle)h)
+#define as_Resource(ctl) ((Handle)ctl)
+#if TARGET_API_MAC_CARBON
+#define GetControlRect(ctl, rectp) GetControlBounds(ctl, rectp)
+#else
+#define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
+#endif
+
+/*
+** Parse/generate ControlFontStyleRec records
+*/
+#if 0 /* Not needed */
+static PyObject *
+ControlFontStyle_New(ControlFontStyleRec *itself)
+{
+
+ return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
+ itself->size, itself->style, itself->mode, itself->just,
+ QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
+}
+#endif
+
+static int
+ControlFontStyle_Convert(PyObject *v, ControlFontStyleRec *itself)
+{
+ return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
+ &itself->font, &itself->size, &itself->style, &itself->mode,
+ &itself->just, QdRGB_Convert, &itself->foreColor,
+ QdRGB_Convert, &itself->backColor);
+}
+
+/*
+** Parse/generate ControlID records
+*/
+static PyObject *
+PyControlID_New(ControlID *itself)
+{
+
+ return Py_BuildValue("O&l", PyMac_BuildOSType, itself->signature, itself->id);
+}
+
+static int
+PyControlID_Convert(PyObject *v, ControlID *itself)
+{
+ return PyArg_ParseTuple(v, "O&l", PyMac_GetOSType, &itself->signature, &itself->id);
+}
+
+
+/* TrackControl and HandleControlClick callback support */
+static PyObject *tracker;
+static ControlActionUPP mytracker_upp;
+static ControlUserPaneDrawUPP mydrawproc_upp;
+static ControlUserPaneIdleUPP myidleproc_upp;
+static ControlUserPaneHitTestUPP myhittestproc_upp;
+static ControlUserPaneTrackingUPP mytrackingproc_upp;
+
+staticforward int settrackfunc(PyObject *); /* forward */
+staticforward void clrtrackfunc(void); /* forward */
+staticforward int setcallback(PyObject *, OSType, PyObject *, UniversalProcPtr *);
+
+static PyObject *Ctl_Error;
+
+/* ---------------------- Object type Control ----------------------- */
+
+PyTypeObject Control_Type;
+
+#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
+
+typedef struct ControlObject {
+ PyObject_HEAD
+ ControlHandle ob_itself;
+ PyObject *ob_callbackdict;
+} ControlObject;
+
+PyObject *CtlObj_New(ControlHandle itself)
+{
+ ControlObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(ControlObject, &Control_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ SetControlReference(itself, (long)it);
+ it->ob_callbackdict = NULL;
+ return (PyObject *)it;
+}
+CtlObj_Convert(PyObject *v, ControlHandle *p_itself)
+{
+ if (!CtlObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "Control required");
+ return 0;
+ }
+ *p_itself = ((ControlObject *)v)->ob_itself;
+ return 1;
+}
+
+static void CtlObj_dealloc(ControlObject *self)
+{
+ Py_XDECREF(self->ob_callbackdict);
+ if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
+ PyMem_DEL(self);
+}
+
+static PyObject *CtlObj_HiliteControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ ControlPartCode hiliteState;
+ if (!PyArg_ParseTuple(_args, "h",
+ &hiliteState))
+ return NULL;
+ HiliteControl(_self->ob_itself,
+ hiliteState);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_ShowControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ ShowControl(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_HideControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ HideControl(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_IsControlActive(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = IsControlActive(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_IsControlVisible(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = IsControlVisible(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_ActivateControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = ActivateControl(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_DeactivateControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = DeactivateControl(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_SetControlVisibility(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ Boolean inIsVisible;
+ Boolean inDoDraw;
+ if (!PyArg_ParseTuple(_args, "bb",
+ &inIsVisible,
+ &inDoDraw))
+ return NULL;
+ _err = SetControlVisibility(_self->ob_itself,
+ inIsVisible,
+ inDoDraw);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_Draw1Control(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ Draw1Control(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetBestControlRect(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ Rect outRect;
+ SInt16 outBaseLineOffset;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetBestControlRect(_self->ob_itself,
+ &outRect,
+ &outBaseLineOffset);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&h",
+ PyMac_BuildRect, &outRect,
+ outBaseLineOffset);
+ return _res;
+}
+
+static PyObject *CtlObj_SetControlFontStyle(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ ControlFontStyleRec inStyle;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ControlFontStyle_Convert, &inStyle))
+ return NULL;
+ _err = SetControlFontStyle(_self->ob_itself,
+ &inStyle);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_DrawControlInCurrentPort(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ DrawControlInCurrentPort(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_SetUpControlBackground(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SInt16 inDepth;
+ Boolean inIsColorDevice;
+ if (!PyArg_ParseTuple(_args, "hb",
+ &inDepth,
+ &inIsColorDevice))
+ return NULL;
+ _err = SetUpControlBackground(_self->ob_itself,
+ inDepth,
+ inIsColorDevice);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_SetUpControlTextColor(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SInt16 inDepth;
+ Boolean inIsColorDevice;
+ if (!PyArg_ParseTuple(_args, "hb",
+ &inDepth,
+ &inIsColorDevice))
+ return NULL;
+ _err = SetUpControlTextColor(_self->ob_itself,
+ inDepth,
+ inIsColorDevice);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_DragControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Point startPoint;
+ Rect limitRect;
+ Rect slopRect;
+ DragConstraint axis;
+ if (!PyArg_ParseTuple(_args, "O&O&O&H",
+ PyMac_GetPoint, &startPoint,
+ PyMac_GetRect, &limitRect,
+ PyMac_GetRect, &slopRect,
+ &axis))
+ return NULL;
+ DragControl(_self->ob_itself,
+ startPoint,
+ &limitRect,
+ &slopRect,
+ axis);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_TestControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ ControlPartCode _rv;
+ Point testPoint;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetPoint, &testPoint))
+ return NULL;
+ _rv = TestControl(_self->ob_itself,
+ testPoint);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_HandleControlContextualMenuClick(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Point inWhere;
+ Boolean menuDisplayed;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetPoint, &inWhere))
+ return NULL;
+ _err = HandleControlContextualMenuClick(_self->ob_itself,
+ inWhere,
+ &menuDisplayed);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("b",
+ menuDisplayed);
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_GetControlClickActivation(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Point inWhere;
+ EventModifiers inModifiers;
+ ClickActivationResult outResult;
+ if (!PyArg_ParseTuple(_args, "O&H",
+ PyMac_GetPoint, &inWhere,
+ &inModifiers))
+ return NULL;
+ _err = GetControlClickActivation(_self->ob_itself,
+ inWhere,
+ inModifiers,
+ &outResult);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ outResult);
+ return _res;
+}
+#endif
+
+static PyObject *CtlObj_HandleControlKey(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 _rv;
+ SInt16 inKeyCode;
+ SInt16 inCharCode;
+ EventModifiers inModifiers;
+ if (!PyArg_ParseTuple(_args, "hhH",
+ &inKeyCode,
+ &inCharCode,
+ &inModifiers))
+ return NULL;
+ _rv = HandleControlKey(_self->ob_itself,
+ inKeyCode,
+ inCharCode,
+ inModifiers);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_HandleControlSetCursor(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Point localPoint;
+ EventModifiers modifiers;
+ Boolean cursorWasSet;
+ if (!PyArg_ParseTuple(_args, "O&H",
+ PyMac_GetPoint, &localPoint,
+ &modifiers))
+ return NULL;
+ _err = HandleControlSetCursor(_self->ob_itself,
+ localPoint,
+ modifiers,
+ &cursorWasSet);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("b",
+ cursorWasSet);
+ return _res;
+}
+#endif
+
+static PyObject *CtlObj_MoveControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 h;
+ SInt16 v;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &h,
+ &v))
+ return NULL;
+ MoveControl(_self->ob_itself,
+ h,
+ v);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_SizeControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 w;
+ SInt16 h;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &w,
+ &h))
+ return NULL;
+ SizeControl(_self->ob_itself,
+ w,
+ h);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_SetControlTitle(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Str255 title;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetStr255, title))
+ return NULL;
+ SetControlTitle(_self->ob_itself,
+ title);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetControlTitle(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Str255 title;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetControlTitle(_self->ob_itself,
+ title);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildStr255, title);
+ return _res;
+}
+
+static PyObject *CtlObj_GetControlValue(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetControlValue(_self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_SetControlValue(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 newValue;
+ if (!PyArg_ParseTuple(_args, "h",
+ &newValue))
+ return NULL;
+ SetControlValue(_self->ob_itself,
+ newValue);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetControlMinimum(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetControlMinimum(_self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_SetControlMinimum(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 newMinimum;
+ if (!PyArg_ParseTuple(_args, "h",
+ &newMinimum))
+ return NULL;
+ SetControlMinimum(_self->ob_itself,
+ newMinimum);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetControlMaximum(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetControlMaximum(_self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_SetControlMaximum(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 newMaximum;
+ if (!PyArg_ParseTuple(_args, "h",
+ &newMaximum))
+ return NULL;
+ SetControlMaximum(_self->ob_itself,
+ newMaximum);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetControlViewSize(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetControlViewSize(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_SetControlViewSize(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 newViewSize;
+ if (!PyArg_ParseTuple(_args, "l",
+ &newViewSize))
+ return NULL;
+ SetControlViewSize(_self->ob_itself,
+ newViewSize);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetControl32BitValue(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetControl32BitValue(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_SetControl32BitValue(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 newValue;
+ if (!PyArg_ParseTuple(_args, "l",
+ &newValue))
+ return NULL;
+ SetControl32BitValue(_self->ob_itself,
+ newValue);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetControl32BitMaximum(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetControl32BitMaximum(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_SetControl32BitMaximum(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 newMaximum;
+ if (!PyArg_ParseTuple(_args, "l",
+ &newMaximum))
+ return NULL;
+ SetControl32BitMaximum(_self->ob_itself,
+ newMaximum);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetControl32BitMinimum(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetControl32BitMinimum(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_SetControl32BitMinimum(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 newMinimum;
+ if (!PyArg_ParseTuple(_args, "l",
+ &newMinimum))
+ return NULL;
+ SetControl32BitMinimum(_self->ob_itself,
+ newMinimum);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_IsValidControlHandle(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = IsValidControlHandle(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_SetControlID(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ ControlID inID;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyControlID_Convert, &inID))
+ return NULL;
+ _err = SetControlID(_self->ob_itself,
+ &inID);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_GetControlID(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ ControlID outID;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetControlID(_self->ob_itself,
+ &outID);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ PyControlID_New, &outID);
+ return _res;
+}
+#endif
+
+static PyObject *CtlObj_RemoveControlProperty(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ OSType propertyCreator;
+ OSType propertyTag;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetOSType, &propertyCreator,
+ PyMac_GetOSType, &propertyTag))
+ return NULL;
+ _err = RemoveControlProperty(_self->ob_itself,
+ propertyCreator,
+ propertyTag);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_GetControlPropertyAttributes(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ OSType propertyCreator;
+ OSType propertyTag;
+ UInt32 attributes;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetOSType, &propertyCreator,
+ PyMac_GetOSType, &propertyTag))
+ return NULL;
+ _err = GetControlPropertyAttributes(_self->ob_itself,
+ propertyCreator,
+ propertyTag,
+ &attributes);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ attributes);
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_ChangeControlPropertyAttributes(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ OSType propertyCreator;
+ OSType propertyTag;
+ UInt32 attributesToSet;
+ UInt32 attributesToClear;
+ if (!PyArg_ParseTuple(_args, "O&O&ll",
+ PyMac_GetOSType, &propertyCreator,
+ PyMac_GetOSType, &propertyTag,
+ &attributesToSet,
+ &attributesToClear))
+ return NULL;
+ _err = ChangeControlPropertyAttributes(_self->ob_itself,
+ propertyCreator,
+ propertyTag,
+ attributesToSet,
+ attributesToClear);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *CtlObj_GetControlRegion(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ ControlPartCode inPart;
+ RgnHandle outRegion;
+ if (!PyArg_ParseTuple(_args, "hO&",
+ &inPart,
+ ResObj_Convert, &outRegion))
+ return NULL;
+ _err = GetControlRegion(_self->ob_itself,
+ inPart,
+ outRegion);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetControlVariant(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ ControlVariant _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetControlVariant(_self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_SetControlReference(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 data;
+ if (!PyArg_ParseTuple(_args, "l",
+ &data))
+ return NULL;
+ SetControlReference(_self->ob_itself,
+ data);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetControlReference(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetControlReference(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_GetAuxiliaryControlRecord(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ AuxCtlHandle acHndl;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetAuxiliaryControlRecord(_self->ob_itself,
+ &acHndl);
+ _res = Py_BuildValue("bO&",
+ _rv,
+ ResObj_New, acHndl);
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_SetControlColor(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CCTabHandle newColorTable;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &newColorTable))
+ return NULL;
+ SetControlColor(_self->ob_itself,
+ newColorTable);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *CtlObj_EmbedControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ ControlHandle inContainer;
+ if (!PyArg_ParseTuple(_args, "O&",
+ CtlObj_Convert, &inContainer))
+ return NULL;
+ _err = EmbedControl(_self->ob_itself,
+ inContainer);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_AutoEmbedControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WindowPtr inWindow;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &inWindow))
+ return NULL;
+ _err = AutoEmbedControl(_self->ob_itself,
+ inWindow);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetSuperControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ ControlHandle outParent;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetSuperControl(_self->ob_itself,
+ &outParent);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ CtlObj_WhichControl, outParent);
+ return _res;
+}
+
+static PyObject *CtlObj_CountSubControls(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ UInt16 outNumChildren;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = CountSubControls(_self->ob_itself,
+ &outNumChildren);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("H",
+ outNumChildren);
+ return _res;
+}
+
+static PyObject *CtlObj_GetIndexedSubControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ UInt16 inIndex;
+ ControlHandle outSubControl;
+ if (!PyArg_ParseTuple(_args, "H",
+ &inIndex))
+ return NULL;
+ _err = GetIndexedSubControl(_self->ob_itself,
+ inIndex,
+ &outSubControl);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ CtlObj_WhichControl, outSubControl);
+ return _res;
+}
+
+static PyObject *CtlObj_SetControlSupervisor(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ ControlHandle inBoss;
+ if (!PyArg_ParseTuple(_args, "O&",
+ CtlObj_Convert, &inBoss))
+ return NULL;
+ _err = SetControlSupervisor(_self->ob_itself,
+ inBoss);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetControlFeatures(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ UInt32 outFeatures;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetControlFeatures(_self->ob_itself,
+ &outFeatures);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ outFeatures);
+ return _res;
+}
+
+static PyObject *CtlObj_GetControlDataSize(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ ControlPartCode inPart;
+ ResType inTagName;
+ Size outMaxSize;
+ if (!PyArg_ParseTuple(_args, "hO&",
+ &inPart,
+ PyMac_GetOSType, &inTagName))
+ return NULL;
+ _err = GetControlDataSize(_self->ob_itself,
+ inPart,
+ inTagName,
+ &outMaxSize);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ outMaxSize);
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_HandleControlDragTracking(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ DragTrackingMessage inMessage;
+ DragReference inDrag;
+ Boolean outLikesDrag;
+ if (!PyArg_ParseTuple(_args, "hO&",
+ &inMessage,
+ DragObj_Convert, &inDrag))
+ return NULL;
+ _err = HandleControlDragTracking(_self->ob_itself,
+ inMessage,
+ inDrag,
+ &outLikesDrag);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("b",
+ outLikesDrag);
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_HandleControlDragReceive(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ DragReference inDrag;
+ if (!PyArg_ParseTuple(_args, "O&",
+ DragObj_Convert, &inDrag))
+ return NULL;
+ _err = HandleControlDragReceive(_self->ob_itself,
+ inDrag);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_SetControlDragTrackingEnabled(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Boolean tracks;
+ if (!PyArg_ParseTuple(_args, "b",
+ &tracks))
+ return NULL;
+ _err = SetControlDragTrackingEnabled(_self->ob_itself,
+ tracks);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_IsControlDragTrackingEnabled(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Boolean tracks;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = IsControlDragTrackingEnabled(_self->ob_itself,
+ &tracks);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("b",
+ tracks);
+ return _res;
+}
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+
+static PyObject *CtlObj_GetControlBounds(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect bounds;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetControlBounds(_self->ob_itself,
+ &bounds);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &bounds);
+ return _res;
+}
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+
+static PyObject *CtlObj_IsControlHilited(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = IsControlHilited(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+
+static PyObject *CtlObj_GetControlHilite(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ UInt16 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetControlHilite(_self->ob_itself);
+ _res = Py_BuildValue("H",
+ _rv);
+ return _res;
+}
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+
+static PyObject *CtlObj_GetControlOwner(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetControlOwner(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ WinObj_New, _rv);
+ return _res;
+}
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+
+static PyObject *CtlObj_GetControlDataHandle(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Handle _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetControlDataHandle(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+
+static PyObject *CtlObj_GetControlPopupMenuHandle(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ MenuHandle _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetControlPopupMenuHandle(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ MenuObj_New, _rv);
+ return _res;
+}
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+
+static PyObject *CtlObj_GetControlPopupMenuID(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetControlPopupMenuID(_self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+
+static PyObject *CtlObj_SetControlDataHandle(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Handle dataHandle;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &dataHandle))
+ return NULL;
+ SetControlDataHandle(_self->ob_itself,
+ dataHandle);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+
+static PyObject *CtlObj_SetControlBounds(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect bounds;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &bounds))
+ return NULL;
+ SetControlBounds(_self->ob_itself,
+ &bounds);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+
+static PyObject *CtlObj_SetControlPopupMenuHandle(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ MenuHandle popupMenu;
+ if (!PyArg_ParseTuple(_args, "O&",
+ MenuObj_Convert, &popupMenu))
+ return NULL;
+ SetControlPopupMenuHandle(_self->ob_itself,
+ popupMenu);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+
+static PyObject *CtlObj_SetControlPopupMenuID(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short menuID;
+ if (!PyArg_ParseTuple(_args, "h",
+ &menuID))
+ return NULL;
+ SetControlPopupMenuID(_self->ob_itself,
+ menuID);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *CtlObj_GetBevelButtonMenuValue(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SInt16 outValue;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetBevelButtonMenuValue(_self->ob_itself,
+ &outValue);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("h",
+ outValue);
+ return _res;
+}
+
+static PyObject *CtlObj_SetBevelButtonMenuValue(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SInt16 inValue;
+ if (!PyArg_ParseTuple(_args, "h",
+ &inValue))
+ return NULL;
+ _err = SetBevelButtonMenuValue(_self->ob_itself,
+ inValue);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetBevelButtonMenuHandle(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ MenuHandle outHandle;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetBevelButtonMenuHandle(_self->ob_itself,
+ &outHandle);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ MenuObj_New, outHandle);
+ return _res;
+}
+
+static PyObject *CtlObj_SetBevelButtonTransform(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ IconTransformType transform;
+ if (!PyArg_ParseTuple(_args, "h",
+ &transform))
+ return NULL;
+ _err = SetBevelButtonTransform(_self->ob_itself,
+ transform);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_SetDisclosureTriangleLastValue(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SInt16 inValue;
+ if (!PyArg_ParseTuple(_args, "h",
+ &inValue))
+ return NULL;
+ _err = SetDisclosureTriangleLastValue(_self->ob_itself,
+ inValue);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetTabContentRect(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ Rect outContentRect;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetTabContentRect(_self->ob_itself,
+ &outContentRect);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &outContentRect);
+ return _res;
+}
+
+static PyObject *CtlObj_SetTabEnabled(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SInt16 inTabToHilite;
+ Boolean inEnabled;
+ if (!PyArg_ParseTuple(_args, "hb",
+ &inTabToHilite,
+ &inEnabled))
+ return NULL;
+ _err = SetTabEnabled(_self->ob_itself,
+ inTabToHilite,
+ inEnabled);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_SetImageWellTransform(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ IconTransformType inTransform;
+ if (!PyArg_ParseTuple(_args, "h",
+ &inTransform))
+ return NULL;
+ _err = SetImageWellTransform(_self->ob_itself,
+ inTransform);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_as_Resource(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Handle _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = as_Resource(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_GetControlRect(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect rect;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetControlRect(_self->ob_itself,
+ &rect);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &rect);
+ return _res;
+}
+
+static PyObject *CtlObj_DisposeControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ if ( _self->ob_itself ) {
+ SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
+ DisposeControl(_self->ob_itself);
+ _self->ob_itself = NULL;
+ }
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+
+}
+
+static PyObject *CtlObj_TrackControl(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ ControlPartCode _rv;
+ Point startPoint;
+ ControlActionUPP upp = 0;
+ PyObject *callback = 0;
+
+ if (!PyArg_ParseTuple(_args, "O&|O",
+ PyMac_GetPoint, &startPoint, &callback))
+ return NULL;
+ if (callback && callback != Py_None) {
+ if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
+ upp = (ControlActionUPP)-1;
+ else {
+ settrackfunc(callback);
+ upp = mytracker_upp;
+ }
+ }
+ _rv = TrackControl(_self->ob_itself,
+ startPoint,
+ upp);
+ clrtrackfunc();
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+
+}
+
+static PyObject *CtlObj_HandleControlClick(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ ControlPartCode _rv;
+ Point startPoint;
+ SInt16 modifiers;
+ ControlActionUPP upp = 0;
+ PyObject *callback = 0;
+
+ if (!PyArg_ParseTuple(_args, "O&h|O",
+ PyMac_GetPoint, &startPoint,
+ &modifiers,
+ &callback))
+ return NULL;
+ if (callback && callback != Py_None) {
+ if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
+ upp = (ControlActionUPP)-1;
+ else {
+ settrackfunc(callback);
+ upp = mytracker_upp;
+ }
+ }
+ _rv = HandleControlClick(_self->ob_itself,
+ startPoint,
+ modifiers,
+ upp);
+ clrtrackfunc();
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+
+}
+
+static PyObject *CtlObj_SetControlData(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ OSErr _err;
+ ControlPartCode inPart;
+ ResType inTagName;
+ Size bufferSize;
+ Ptr buffer;
+
+ if (!PyArg_ParseTuple(_args, "hO&s#",
+ &inPart,
+ PyMac_GetOSType, &inTagName,
+ &buffer, &bufferSize))
+ return NULL;
+
+ _err = SetControlData(_self->ob_itself,
+ inPart,
+ inTagName,
+ bufferSize,
+ buffer);
+
+ if (_err != noErr)
+ return PyMac_Error(_err);
+ _res = Py_None;
+ return _res;
+
+}
+
+static PyObject *CtlObj_GetControlData(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ OSErr _err;
+ ControlPartCode inPart;
+ ResType inTagName;
+ Size bufferSize;
+ Ptr buffer;
+ Size outSize;
+
+ if (!PyArg_ParseTuple(_args, "hO&",
+ &inPart,
+ PyMac_GetOSType, &inTagName))
+ return NULL;
+
+ /* allocate a buffer for the data */
+ _err = GetControlDataSize(_self->ob_itself,
+ inPart,
+ inTagName,
+ &bufferSize);
+ if (_err != noErr)
+ return PyMac_Error(_err);
+ buffer = PyMem_NEW(char, bufferSize);
+ if (buffer == NULL)
+ return PyErr_NoMemory();
+
+ _err = GetControlData(_self->ob_itself,
+ inPart,
+ inTagName,
+ bufferSize,
+ buffer,
+ &outSize);
+
+ if (_err != noErr) {
+ PyMem_DEL(buffer);
+ return PyMac_Error(_err);
+ }
+ _res = Py_BuildValue("s#", buffer, outSize);
+ PyMem_DEL(buffer);
+ return _res;
+
+}
+
+static PyObject *CtlObj_SetControlData_Handle(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ OSErr _err;
+ ControlPartCode inPart;
+ ResType inTagName;
+ Handle buffer;
+
+ if (!PyArg_ParseTuple(_args, "hO&O&",
+ &inPart,
+ PyMac_GetOSType, &inTagName,
+ OptResObj_Convert, &buffer))
+ return NULL;
+
+ _err = SetControlData(_self->ob_itself,
+ inPart,
+ inTagName,
+ sizeof(buffer),
+ (Ptr)&buffer);
+
+ if (_err != noErr)
+ return PyMac_Error(_err);
+ _res = Py_None;
+ return _res;
+
+}
+
+static PyObject *CtlObj_GetControlData_Handle(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ OSErr _err;
+ ControlPartCode inPart;
+ ResType inTagName;
+ Size bufferSize;
+ Handle hdl;
+
+ if (!PyArg_ParseTuple(_args, "hO&",
+ &inPart,
+ PyMac_GetOSType, &inTagName))
+ return NULL;
+
+ /* Check it is handle-sized */
+ _err = GetControlDataSize(_self->ob_itself,
+ inPart,
+ inTagName,
+ &bufferSize);
+ if (_err != noErr)
+ return PyMac_Error(_err);
+ if (bufferSize != sizeof(Handle)) {
+ PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
+ return NULL;
+ }
+
+ _err = GetControlData(_self->ob_itself,
+ inPart,
+ inTagName,
+ sizeof(Handle),
+ (Ptr)&hdl,
+ &bufferSize);
+
+ if (_err != noErr) {
+ return PyMac_Error(_err);
+ }
+ return Py_BuildValue("O&", OptResObj_New, hdl);
+
+}
+
+static PyObject *CtlObj_SetControlData_Callback(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ OSErr _err;
+ ControlPartCode inPart;
+ ResType inTagName;
+ PyObject *callback;
+ UniversalProcPtr c_callback;
+
+ if (!PyArg_ParseTuple(_args, "hO&O",
+ &inPart,
+ PyMac_GetOSType, &inTagName,
+ &callback))
+ return NULL;
+
+ if ( setcallback((PyObject *)_self, inTagName, callback, &c_callback) < 0 )
+ return NULL;
+ _err = SetControlData(_self->ob_itself,
+ inPart,
+ inTagName,
+ sizeof(c_callback),
+ (Ptr)&c_callback);
+
+ if (_err != noErr)
+ return PyMac_Error(_err);
+ _res = Py_None;
+ return _res;
+
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_GetPopupData(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ PopupPrivateDataHandle hdl;
+
+ if ( (*_self->ob_itself)->contrlData == NULL ) {
+ PyErr_SetString(Ctl_Error, "No contrlData handle in control");
+ return 0;
+ }
+ hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
+ HLock((Handle)hdl);
+ _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
+ HUnlock((Handle)hdl);
+ return _res;
+
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *CtlObj_SetPopupData(ControlObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ PopupPrivateDataHandle hdl;
+ MenuHandle mHandle;
+ short mID;
+
+ if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
+ return 0;
+ if ( (*_self->ob_itself)->contrlData == NULL ) {
+ PyErr_SetString(Ctl_Error, "No contrlData handle in control");
+ return 0;
+ }
+ hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
+ (*hdl)->mHandle = mHandle;
+ (*hdl)->mID = mID;
+ Py_INCREF(Py_None);
+ return Py_None;
+
+}
+#endif
+
+static PyMethodDef CtlObj_methods[] = {
+ {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
+ "(ControlPartCode hiliteState) -> None"},
+ {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
+ "() -> None"},
+ {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
+ "() -> None"},
+ {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
+ "() -> (Boolean _rv)"},
+ {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
+ "() -> (Boolean _rv)"},
+ {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
+ "() -> None"},
+ {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
+ "() -> None"},
+ {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
+ "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
+ {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
+ "() -> None"},
+ {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
+ "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
+ {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
+ "(ControlFontStyleRec inStyle) -> None"},
+ {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
+ "() -> None"},
+ {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
+ "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
+ {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
+ "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
+ {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
+ "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
+ {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
+ "(Point testPoint) -> (ControlPartCode _rv)"},
+
+#if TARGET_API_MAC_CARBON
+ {"HandleControlContextualMenuClick", (PyCFunction)CtlObj_HandleControlContextualMenuClick, 1,
+ "(Point inWhere) -> (Boolean menuDisplayed)"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"GetControlClickActivation", (PyCFunction)CtlObj_GetControlClickActivation, 1,
+ "(Point inWhere, EventModifiers inModifiers) -> (ClickActivationResult outResult)"},
+#endif
+ {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
+ "(SInt16 inKeyCode, SInt16 inCharCode, EventModifiers inModifiers) -> (SInt16 _rv)"},
+
+#if TARGET_API_MAC_CARBON
+ {"HandleControlSetCursor", (PyCFunction)CtlObj_HandleControlSetCursor, 1,
+ "(Point localPoint, EventModifiers modifiers) -> (Boolean cursorWasSet)"},
+#endif
+ {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
+ "(SInt16 h, SInt16 v) -> None"},
+ {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
+ "(SInt16 w, SInt16 h) -> None"},
+ {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
+ "(Str255 title) -> None"},
+ {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
+ "() -> (Str255 title)"},
+ {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
+ "() -> (SInt16 _rv)"},
+ {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
+ "(SInt16 newValue) -> None"},
+ {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
+ "() -> (SInt16 _rv)"},
+ {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
+ "(SInt16 newMinimum) -> None"},
+ {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
+ "() -> (SInt16 _rv)"},
+ {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
+ "(SInt16 newMaximum) -> None"},
+ {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
+ "() -> (SInt32 _rv)"},
+ {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
+ "(SInt32 newViewSize) -> None"},
+ {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
+ "() -> (SInt32 _rv)"},
+ {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
+ "(SInt32 newValue) -> None"},
+ {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
+ "() -> (SInt32 _rv)"},
+ {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
+ "(SInt32 newMaximum) -> None"},
+ {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
+ "() -> (SInt32 _rv)"},
+ {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
+ "(SInt32 newMinimum) -> None"},
+ {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
+ "() -> (Boolean _rv)"},
+
+#if TARGET_API_MAC_CARBON
+ {"SetControlID", (PyCFunction)CtlObj_SetControlID, 1,
+ "(ControlID inID) -> None"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"GetControlID", (PyCFunction)CtlObj_GetControlID, 1,
+ "() -> (ControlID outID)"},
+#endif
+ {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
+ "(OSType propertyCreator, OSType propertyTag) -> None"},
+
+#if TARGET_API_MAC_CARBON
+ {"GetControlPropertyAttributes", (PyCFunction)CtlObj_GetControlPropertyAttributes, 1,
+ "(OSType propertyCreator, OSType propertyTag) -> (UInt32 attributes)"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"ChangeControlPropertyAttributes", (PyCFunction)CtlObj_ChangeControlPropertyAttributes, 1,
+ "(OSType propertyCreator, OSType propertyTag, UInt32 attributesToSet, UInt32 attributesToClear) -> None"},
+#endif
+ {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
+ "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
+ {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
+ "() -> (ControlVariant _rv)"},
+ {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
+ "(SInt32 data) -> None"},
+ {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
+ "() -> (SInt32 _rv)"},
+
+#if !TARGET_API_MAC_CARBON
+ {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
+ "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
+ "(CCTabHandle newColorTable) -> None"},
+#endif
+ {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
+ "(ControlHandle inContainer) -> None"},
+ {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
+ "(WindowPtr inWindow) -> None"},
+ {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
+ "() -> (ControlHandle outParent)"},
+ {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
+ "() -> (UInt16 outNumChildren)"},
+ {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
+ "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
+ {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
+ "(ControlHandle inBoss) -> None"},
+ {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
+ "() -> (UInt32 outFeatures)"},
+ {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
+ "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
+
+#if TARGET_API_MAC_CARBON
+ {"HandleControlDragTracking", (PyCFunction)CtlObj_HandleControlDragTracking, 1,
+ "(DragTrackingMessage inMessage, DragReference inDrag) -> (Boolean outLikesDrag)"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"HandleControlDragReceive", (PyCFunction)CtlObj_HandleControlDragReceive, 1,
+ "(DragReference inDrag) -> None"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"SetControlDragTrackingEnabled", (PyCFunction)CtlObj_SetControlDragTrackingEnabled, 1,
+ "(Boolean tracks) -> None"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"IsControlDragTrackingEnabled", (PyCFunction)CtlObj_IsControlDragTrackingEnabled, 1,
+ "() -> (Boolean tracks)"},
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+ {"GetControlBounds", (PyCFunction)CtlObj_GetControlBounds, 1,
+ "() -> (Rect bounds)"},
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+ {"IsControlHilited", (PyCFunction)CtlObj_IsControlHilited, 1,
+ "() -> (Boolean _rv)"},
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+ {"GetControlHilite", (PyCFunction)CtlObj_GetControlHilite, 1,
+ "() -> (UInt16 _rv)"},
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+ {"GetControlOwner", (PyCFunction)CtlObj_GetControlOwner, 1,
+ "() -> (WindowPtr _rv)"},
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+ {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
+ "() -> (Handle _rv)"},
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+ {"GetControlPopupMenuHandle", (PyCFunction)CtlObj_GetControlPopupMenuHandle, 1,
+ "() -> (MenuHandle _rv)"},
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+ {"GetControlPopupMenuID", (PyCFunction)CtlObj_GetControlPopupMenuID, 1,
+ "() -> (short _rv)"},
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+ {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
+ "(Handle dataHandle) -> None"},
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+ {"SetControlBounds", (PyCFunction)CtlObj_SetControlBounds, 1,
+ "(Rect bounds) -> None"},
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+ {"SetControlPopupMenuHandle", (PyCFunction)CtlObj_SetControlPopupMenuHandle, 1,
+ "(MenuHandle popupMenu) -> None"},
+#endif
+
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+ {"SetControlPopupMenuID", (PyCFunction)CtlObj_SetControlPopupMenuID, 1,
+ "(short menuID) -> None"},
+#endif
+ {"GetBevelButtonMenuValue", (PyCFunction)CtlObj_GetBevelButtonMenuValue, 1,
+ "() -> (SInt16 outValue)"},
+ {"SetBevelButtonMenuValue", (PyCFunction)CtlObj_SetBevelButtonMenuValue, 1,
+ "(SInt16 inValue) -> None"},
+ {"GetBevelButtonMenuHandle", (PyCFunction)CtlObj_GetBevelButtonMenuHandle, 1,
+ "() -> (MenuHandle outHandle)"},
+ {"SetBevelButtonTransform", (PyCFunction)CtlObj_SetBevelButtonTransform, 1,
+ "(IconTransformType transform) -> None"},
+ {"SetDisclosureTriangleLastValue", (PyCFunction)CtlObj_SetDisclosureTriangleLastValue, 1,
+ "(SInt16 inValue) -> None"},
+ {"GetTabContentRect", (PyCFunction)CtlObj_GetTabContentRect, 1,
+ "() -> (Rect outContentRect)"},
+ {"SetTabEnabled", (PyCFunction)CtlObj_SetTabEnabled, 1,
+ "(SInt16 inTabToHilite, Boolean inEnabled) -> None"},
+ {"SetImageWellTransform", (PyCFunction)CtlObj_SetImageWellTransform, 1,
+ "(IconTransformType inTransform) -> None"},
+ {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
+ "() -> (Handle _rv)"},
+ {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
+ "() -> (Rect rect)"},
+ {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
+ "() -> None"},
+ {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
+ "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
+ {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
+ "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
+ {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
+ "(stuff) -> None"},
+ {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
+ "(part, type) -> String"},
+ {"SetControlData_Handle", (PyCFunction)CtlObj_SetControlData_Handle, 1,
+ "(ResObj) -> None"},
+ {"GetControlData_Handle", (PyCFunction)CtlObj_GetControlData_Handle, 1,
+ "(part, type) -> ResObj"},
+ {"SetControlData_Callback", (PyCFunction)CtlObj_SetControlData_Callback, 1,
+ "(callbackfunc) -> None"},
+
+#if !TARGET_API_MAC_CARBON
+ {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
+ NULL},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
+ NULL},
+#endif
+ {NULL, NULL, 0}
+};
+
+PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
+
+static PyObject *CtlObj_getattr(ControlObject *self, char *name)
+{
+ return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
+}
+
+#define CtlObj_setattr NULL
+
+static int CtlObj_compare(ControlObject *self, ControlObject *other)
+{
+ unsigned long v, w;
+
+ if (!CtlObj_Check((PyObject *)other))
+ {
+ v=(unsigned long)self;
+ w=(unsigned long)other;
+ }
+ else
+ {
+ v=(unsigned long)self->ob_itself;
+ w=(unsigned long)other->ob_itself;
+ }
+ if( v < w ) return -1;
+ if( v > w ) return 1;
+ return 0;
+}
+
+#define CtlObj_repr NULL
+
+static long CtlObj_hash(ControlObject *self)
+{
+ return (long)self->ob_itself;
+}
+
+PyTypeObject Control_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "Control", /*tp_name*/
+ sizeof(ControlObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) CtlObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) CtlObj_getattr, /*tp_getattr*/
+ (setattrfunc) CtlObj_setattr, /*tp_setattr*/
+ (cmpfunc) CtlObj_compare, /*tp_compare*/
+ (reprfunc) CtlObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) CtlObj_hash, /*tp_hash*/
+};
+
+/* -------------------- End object type Control --------------------- */
+
+
+static PyObject *Ctl_NewControl(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ ControlHandle _rv;
+ WindowPtr owningWindow;
+ Rect boundsRect;
+ Str255 controlTitle;
+ Boolean initiallyVisible;
+ SInt16 initialValue;
+ SInt16 minimumValue;
+ SInt16 maximumValue;
+ SInt16 procID;
+ SInt32 controlReference;
+ if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
+ WinObj_Convert, &owningWindow,
+ PyMac_GetRect, &boundsRect,
+ PyMac_GetStr255, controlTitle,
+ &initiallyVisible,
+ &initialValue,
+ &minimumValue,
+ &maximumValue,
+ &procID,
+ &controlReference))
+ return NULL;
+ _rv = NewControl(owningWindow,
+ &boundsRect,
+ controlTitle,
+ initiallyVisible,
+ initialValue,
+ minimumValue,
+ maximumValue,
+ procID,
+ controlReference);
+ _res = Py_BuildValue("O&",
+ CtlObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Ctl_GetNewControl(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ ControlHandle _rv;
+ SInt16 resourceID;
+ WindowPtr owningWindow;
+ if (!PyArg_ParseTuple(_args, "hO&",
+ &resourceID,
+ WinObj_Convert, &owningWindow))
+ return NULL;
+ _rv = GetNewControl(resourceID,
+ owningWindow);
+ _res = Py_BuildValue("O&",
+ CtlObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Ctl_DrawControls(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr theWindow;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &theWindow))
+ return NULL;
+ DrawControls(theWindow);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Ctl_UpdateControls(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr theWindow;
+ RgnHandle updateRegion;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ WinObj_Convert, &theWindow,
+ ResObj_Convert, &updateRegion))
+ return NULL;
+ UpdateControls(theWindow,
+ updateRegion);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Ctl_FindControl(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ ControlPartCode _rv;
+ Point testPoint;
+ WindowPtr theWindow;
+ ControlHandle theControl;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &testPoint,
+ WinObj_Convert, &theWindow))
+ return NULL;
+ _rv = FindControl(testPoint,
+ theWindow,
+ &theControl);
+ _res = Py_BuildValue("hO&",
+ _rv,
+ CtlObj_WhichControl, theControl);
+ return _res;
+}
+
+static PyObject *Ctl_FindControlUnderMouse(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ ControlHandle _rv;
+ Point inWhere;
+ WindowPtr inWindow;
+ SInt16 outPart;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &inWhere,
+ WinObj_Convert, &inWindow))
+ return NULL;
+ _rv = FindControlUnderMouse(inWhere,
+ inWindow,
+ &outPart);
+ _res = Py_BuildValue("O&h",
+ CtlObj_New, _rv,
+ outPart);
+ return _res;
+}
+
+static PyObject *Ctl_IdleControls(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr inWindow;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &inWindow))
+ return NULL;
+ IdleControls(inWindow);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *Ctl_GetControlByID(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ WindowPtr inWindow;
+ ControlID inID;
+ ControlHandle outControl;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ WinObj_Convert, &inWindow,
+ PyControlID_Convert, &inID))
+ return NULL;
+ _err = GetControlByID(inWindow,
+ &inID,
+ &outControl);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ CtlObj_WhichControl, outControl);
+ return _res;
+}
+#endif
+
+static PyObject *Ctl_DumpControlHierarchy(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WindowPtr inWindow;
+ FSSpec inDumpFile;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ WinObj_Convert, &inWindow,
+ PyMac_GetFSSpec, &inDumpFile))
+ return NULL;
+ _err = DumpControlHierarchy(inWindow,
+ &inDumpFile);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Ctl_CreateRootControl(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WindowPtr inWindow;
+ ControlHandle outControl;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &inWindow))
+ return NULL;
+ _err = CreateRootControl(inWindow,
+ &outControl);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ CtlObj_WhichControl, outControl);
+ return _res;
+}
+
+static PyObject *Ctl_GetRootControl(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WindowPtr inWindow;
+ ControlHandle outControl;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &inWindow))
+ return NULL;
+ _err = GetRootControl(inWindow,
+ &outControl);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ CtlObj_WhichControl, outControl);
+ return _res;
+}
+
+static PyObject *Ctl_GetKeyboardFocus(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WindowPtr inWindow;
+ ControlHandle outControl;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &inWindow))
+ return NULL;
+ _err = GetKeyboardFocus(inWindow,
+ &outControl);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ CtlObj_WhichControl, outControl);
+ return _res;
+}
+
+static PyObject *Ctl_SetKeyboardFocus(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WindowPtr inWindow;
+ ControlHandle inControl;
+ ControlFocusPart inPart;
+ if (!PyArg_ParseTuple(_args, "O&O&h",
+ WinObj_Convert, &inWindow,
+ CtlObj_Convert, &inControl,
+ &inPart))
+ return NULL;
+ _err = SetKeyboardFocus(inWindow,
+ inControl,
+ inPart);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Ctl_AdvanceKeyboardFocus(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WindowPtr inWindow;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &inWindow))
+ return NULL;
+ _err = AdvanceKeyboardFocus(inWindow);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Ctl_ReverseKeyboardFocus(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WindowPtr inWindow;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &inWindow))
+ return NULL;
+ _err = ReverseKeyboardFocus(inWindow);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Ctl_ClearKeyboardFocus(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WindowPtr inWindow;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &inWindow))
+ return NULL;
+ _err = ClearKeyboardFocus(inWindow);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *Ctl_SetAutomaticControlDragTrackingEnabledForWindow(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ WindowPtr theWindow;
+ Boolean tracks;
+ if (!PyArg_ParseTuple(_args, "O&b",
+ WinObj_Convert, &theWindow,
+ &tracks))
+ return NULL;
+ _err = SetAutomaticControlDragTrackingEnabledForWindow(theWindow,
+ tracks);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *Ctl_IsAutomaticControlDragTrackingEnabledForWindow(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ WindowPtr theWindow;
+ Boolean tracks;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &theWindow))
+ return NULL;
+ _err = IsAutomaticControlDragTrackingEnabledForWindow(theWindow,
+ &tracks);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("b",
+ tracks);
+ return _res;
+}
+#endif
+
+static PyObject *Ctl_as_Control(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ ControlHandle _rv;
+ Handle h;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &h))
+ return NULL;
+ _rv = as_Control(h);
+ _res = Py_BuildValue("O&",
+ CtlObj_New, _rv);
+ return _res;
+}
+
+static PyMethodDef Ctl_methods[] = {
+ {"NewControl", (PyCFunction)Ctl_NewControl, 1,
+ "(WindowPtr owningWindow, Rect boundsRect, Str255 controlTitle, Boolean initiallyVisible, SInt16 initialValue, SInt16 minimumValue, SInt16 maximumValue, SInt16 procID, SInt32 controlReference) -> (ControlHandle _rv)"},
+ {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
+ "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
+ {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
+ "(WindowPtr theWindow) -> None"},
+ {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
+ "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
+ {"FindControl", (PyCFunction)Ctl_FindControl, 1,
+ "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
+ {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
+ "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
+ {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
+ "(WindowPtr inWindow) -> None"},
+
+#if TARGET_API_MAC_CARBON
+ {"GetControlByID", (PyCFunction)Ctl_GetControlByID, 1,
+ "(WindowPtr inWindow, ControlID inID) -> (ControlHandle outControl)"},
+#endif
+ {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
+ "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
+ {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
+ "(WindowPtr inWindow) -> (ControlHandle outControl)"},
+ {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
+ "(WindowPtr inWindow) -> (ControlHandle outControl)"},
+ {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
+ "(WindowPtr inWindow) -> (ControlHandle outControl)"},
+ {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
+ "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
+ {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
+ "(WindowPtr inWindow) -> None"},
+ {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
+ "(WindowPtr inWindow) -> None"},
+ {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
+ "(WindowPtr inWindow) -> None"},
+
+#if TARGET_API_MAC_CARBON
+ {"SetAutomaticControlDragTrackingEnabledForWindow", (PyCFunction)Ctl_SetAutomaticControlDragTrackingEnabledForWindow, 1,
+ "(WindowPtr theWindow, Boolean tracks) -> None"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"IsAutomaticControlDragTrackingEnabledForWindow", (PyCFunction)Ctl_IsAutomaticControlDragTrackingEnabledForWindow, 1,
+ "(WindowPtr theWindow) -> (Boolean tracks)"},
+#endif
+ {"as_Control", (PyCFunction)Ctl_as_Control, 1,
+ "(Handle h) -> (ControlHandle _rv)"},
+ {NULL, NULL, 0}
+};
+
+
+
+static PyObject *
+CtlObj_NewUnmanaged(ControlHandle itself)
+{
+ ControlObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(ControlObject, &Control_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_callbackdict = NULL;
+ return (PyObject *)it;
+}
+
+static PyObject *
+CtlObj_WhichControl(ControlHandle c)
+{
+ PyObject *it;
+
+ if (c == NULL)
+ it = Py_None;
+ else {
+ it = (PyObject *) GetControlReference(c);
+ /*
+ ** If the refcon is zero or doesn't point back to the Python object
+ ** the control is not ours. Return a temporary object.
+ */
+ if (it == NULL || ((ControlObject *)it)->ob_itself != c)
+ return CtlObj_NewUnmanaged(c);
+ }
+ Py_INCREF(it);
+ return it;
+}
+
+static int
+settrackfunc(PyObject *obj)
+{
+ if (tracker) {
+ PyErr_SetString(Ctl_Error, "Tracker function in use");
+ return 0;
+ }
+ tracker = obj;
+ Py_INCREF(tracker);
+}
+
+static void
+clrtrackfunc(void)
+{
+ Py_XDECREF(tracker);
+ tracker = 0;
+}
+
+static pascal void
+mytracker(ControlHandle ctl, short part)
+{
+ PyObject *args, *rv=0;
+
+ args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
+ if (args && tracker) {
+ rv = PyEval_CallObject(tracker, args);
+ Py_DECREF(args);
+ }
+ if (rv)
+ Py_DECREF(rv);
+ else
+ PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
+}
+
+static int
+setcallback(PyObject *myself, OSType which, PyObject *callback, UniversalProcPtr *uppp)
+{
+ ControlObject *self = (ControlObject *)myself;
+ char keybuf[9];
+
+ if ( which == kControlUserPaneDrawProcTag )
+ *uppp = (UniversalProcPtr)mydrawproc_upp;
+ else if ( which == kControlUserPaneIdleProcTag )
+ *uppp = (UniversalProcPtr)myidleproc_upp;
+ else if ( which == kControlUserPaneHitTestProcTag )
+ *uppp = (UniversalProcPtr)myhittestproc_upp;
+ else if ( which == kControlUserPaneTrackingProcTag )
+ *uppp = (UniversalProcPtr)mytrackingproc_upp;
+ else
+ return -1;
+ /* Only now do we test for clearing of the callback: */
+ if ( callback == Py_None )
+ *uppp = NULL;
+ /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
+ if ( self->ob_callbackdict == NULL )
+ if ( (self->ob_callbackdict = PyDict_New()) == NULL )
+ return -1;
+ /* And store the Python callback */
+ sprintf(keybuf, "%x", which);
+ if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
+ return -1;
+ return 0;
+}
+
+static PyObject *
+callcallback(ControlObject *self, OSType which, PyObject *arglist)
+{
+ char keybuf[9];
+ PyObject *func, *rv;
+
+ sprintf(keybuf, "%x", which);
+ if ( self->ob_callbackdict == NULL ||
+ (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
+ PySys_WriteStderr("Control callback %x without callback object\n", which);
+ return NULL;
+ }
+ rv = PyEval_CallObject(func, arglist);
+ if ( rv == NULL )
+ PySys_WriteStderr("Exception in control callback %x handler\n", which);
+ return rv;
+}
+
+static pascal void
+mydrawproc(ControlHandle control, SInt16 part)
+{
+ ControlObject *ctl_obj;
+ PyObject *arglist, *rv;
+
+ ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
+ arglist = Py_BuildValue("Oh", ctl_obj, part);
+ rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
+ Py_XDECREF(arglist);
+ Py_XDECREF(rv);
+}
+
+static pascal void
+myidleproc(ControlHandle control)
+{
+ ControlObject *ctl_obj;
+ PyObject *arglist, *rv;
+
+ ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
+ arglist = Py_BuildValue("O", ctl_obj);
+ rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
+ Py_XDECREF(arglist);
+ Py_XDECREF(rv);
+}
+
+static pascal ControlPartCode
+myhittestproc(ControlHandle control, Point where)
+{
+ ControlObject *ctl_obj;
+ PyObject *arglist, *rv;
+ short c_rv = -1;
+
+ ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
+ arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where);
+ rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist);
+ Py_XDECREF(arglist);
+ /* Ignore errors, nothing we can do about them */
+ if ( rv )
+ PyArg_Parse(rv, "h", &c_rv);
+ Py_XDECREF(rv);
+ return (ControlPartCode)c_rv;
+}
+
+static pascal ControlPartCode
+mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc)
+{
+ ControlObject *ctl_obj;
+ PyObject *arglist, *rv;
+ short c_rv = -1;
+
+ ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
+ /* We cannot pass the actionProc without lots of work */
+ arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt);
+ rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist);
+ Py_XDECREF(arglist);
+ if ( rv )
+ PyArg_Parse(rv, "h", &c_rv);
+ Py_XDECREF(rv);
+ return (ControlPartCode)c_rv;
+}
+
+
+void initCtl(void)
+{
+ PyObject *m;
+ PyObject *d;
+
+
+
+ mytracker_upp = NewControlActionUPP(mytracker);
+ mydrawproc_upp = NewControlUserPaneDrawUPP(mydrawproc);
+ myidleproc_upp = NewControlUserPaneIdleUPP(myidleproc);
+ myhittestproc_upp = NewControlUserPaneHitTestUPP(myhittestproc);
+ mytrackingproc_upp = NewControlUserPaneTrackingUPP(mytrackingproc);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(ControlHandle, CtlObj_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ControlHandle, CtlObj_Convert);
+
+
+ m = Py_InitModule("Ctl", Ctl_methods);
+ d = PyModule_GetDict(m);
+ Ctl_Error = PyMac_GetOSErrException();
+ if (Ctl_Error == NULL ||
+ PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
+ return;
+ Control_Type.ob_type = &PyType_Type;
+ Py_INCREF(&Control_Type);
+ if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
+ Py_FatalError("can't initialize ControlType");
+}
+
+/* ========================= End module Ctl ========================= */
+
--- /dev/null
+# Scan <Controls.h>, generating ctlgen.py.
+import sys
+import os
+BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
+sys.path.append(BGENDIR)
+
+from scantools import Scanner
+from bgenlocations import TOOLBOXDIR
+
+def main():
+# input = "Controls.h" # Universal Headers < 3.3
+ input = ["Controls.h", "ControlDefinitions.h"] # Universal Headers >= 3.3
+ output = "ctlgen.py"
+ defsoutput = TOOLBOXDIR + "Controls.py"
+ scanner = MyScanner(input, output, defsoutput)
+ scanner.scan()
+ scanner.close()
+ print "=== Done scanning and generating, now doing 'import ctlsupport' ==="
+ import ctlsupport
+ print "=== Done. It's up to you to compile Ctlmodule.c ==="
+
+class MyScanner(Scanner):
+
+ def destination(self, type, name, arglist):
+ classname = "Function"
+ listname = "functions"
+ if arglist:
+ t, n, m = arglist[0]
+ if t in ("ControlHandle", "ControlRef") and m == "InMode":
+ classname = "Method"
+ listname = "methods"
+ return classname, listname
+
+ def writeinitialdefs(self):
+ self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
+ self.defsfile.write("from TextEdit import *\n")
+ self.defsfile.write("from QuickDraw import *\n")
+ self.defsfile.write("from Dragconst import *\n")
+ self.defsfile.write("\n")
+
+ def makeblacklistnames(self):
+ return [
+ 'DisposeControl', # Generated manually
+ 'KillControls', # Implied by close of dialog
+ 'SetCtlAction',
+ 'TrackControl', # Generated manually
+ 'HandleControlClick', # Generated manually
+ 'SetControlData', # Generated manually
+ 'GetControlData', # Generated manually
+ 'kControlBevelButtonCenterPopupGlyphTag', # Constant with funny definition
+ 'kControlProgressBarIndeterminateTag', # ditto
+ # The following are unavailable for static 68k (appearance manager)
+## 'GetBevelButtonMenuValue',
+## 'SetBevelButtonMenuValue',
+## 'GetBevelButtonMenuHandle',
+## 'SetBevelButtonTransform',
+ 'SetBevelButtonGraphicAlignment',
+ 'SetBevelButtonTextAlignment',
+ 'SetBevelButtonTextPlacement',
+## 'SetImageWellTransform',
+## 'GetTabContentRect',
+## 'SetTabEnabled',
+## 'SetDisclosureTriangleLastValue',
+## # Unavailable in CW Pro 3 libraries
+## 'SetUpControlTextColor',
+## # Unavailable in Jack's CW Pro 5.1 libraries
+## 'GetControlRegion',
+## 'RemoveControlProperty',
+## 'IsValidControlHandle',
+## 'SetControl32BitMinimum',
+## 'GetControl32BitMinimum',
+## 'SetControl32BitMaximum',
+## 'GetControl32BitMaximum',
+## 'SetControl32BitValue',
+## 'GetControl32BitValue',
+## 'SetControlViewSize',
+## 'GetControlViewSize',
+ # Generally Bad News
+ 'GetControlProperty',
+ 'SetControlProperty',
+ 'GetControlPropertySize',
+ 'SendControlMessage', # Parameter changed from long to void* from UH3.3 to UH3.4
+ ]
+
+ def makegreylist(self):
+ return [
+ ('#if !TARGET_API_MAC_CARBON', [
+ 'GetAuxiliaryControlRecord',
+ 'SetControlColor',
+ # These have suddenly disappeared in UH 3.3.2...
+## 'GetBevelButtonMenuValue',
+## 'SetBevelButtonMenuValue',
+## 'GetBevelButtonMenuHandle',
+## 'SetBevelButtonTransform',
+## 'SetImageWellTransform',
+## 'GetTabContentRect',
+## 'SetTabEnabled',
+## 'SetDisclosureTriangleLastValue',
+ ]),
+ ('#if TARGET_API_MAC_CARBON', [
+ 'IsAutomaticControlDragTrackingEnabledForWindow',
+ 'SetAutomaticControlDragTrackingEnabledForWindow',
+ 'HandleControlDragReceive',
+ 'HandleControlDragTracking',
+ 'GetControlByID',
+ 'IsControlDragTrackingEnabled',
+ 'SetControlDragTrackingEnabled',
+ 'GetControlPropertyAttributes',
+ 'ChangeControlPropertyAttributes',
+ 'GetControlID',
+ 'SetControlID',
+ 'HandleControlSetCursor',
+ 'GetControlClickActivation',
+ 'HandleControlContextualMenuClick',
+ ]),
+ ('#if ACCESSOR_CALLS_ARE_FUNCTIONS', [
+ # XXX These are silly, they should be #defined to access the fields
+ # directly. Later...
+ 'GetControlBounds',
+ 'IsControlHilited',
+ 'GetControlHilite',
+ 'GetControlOwner',
+ 'GetControlDataHandle',
+ 'GetControlPopupMenuHandle',
+ 'GetControlPopupMenuID',
+ 'SetControlDataHandle',
+ 'SetControlBounds',
+ 'SetControlPopupMenuHandle',
+ 'SetControlPopupMenuID',
+ ])]
+
+ def makeblacklisttypes(self):
+ return [
+ 'ProcPtr',
+ 'ControlActionUPP',
+ 'ControlButtonContentInfoPtr',
+ 'Ptr',
+ 'ControlDefSpec', # Don't know how to do this yet
+ 'ControlDefSpec_ptr', # ditto
+ 'Collection', # Ditto
+ ]
+
+ def makerepairinstructions(self):
+ return [
+ ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
+ [("InBuffer", "*", "*")]),
+
+ ([("void", "*", "OutMode"), ("long", "*", "InMode"),
+ ("long", "*", "OutMode")],
+ [("VarVarOutBuffer", "*", "InOutMode")]),
+
+## # For TrackControl
+## ([("ProcPtr", "actionProc", "InMode")],
+## [("FakeType('(ControlActionUPP)0')", "*", "*")]),
+## ([("ControlActionUPP", "actionProc", "InMode")],
+## [("FakeType('(ControlActionUPP)0')", "*", "*")]),
+
+ # For GetControlTitle
+ ([('Str255', 'title', 'InMode')],
+ [('Str255', 'title', 'OutMode')]),
+
+ ([("ControlHandle", "*", "OutMode")],
+ [("ExistingControlHandle", "*", "*")]),
+ ([("ControlRef", "*", "OutMode")], # Ditto, for Universal Headers
+ [("ExistingControlHandle", "*", "*")]),
+
+ ([("Rect_ptr", "*", "ReturnMode")], # GetControlBounds
+ [("void", "*", "ReturnMode")]),
+ ]
+
+if __name__ == "__main__":
+ main()
--- /dev/null
+# This script generates a Python interface for an Apple Macintosh Manager.
+# It uses the "bgen" package to generate C code.
+# The function specifications are generated by scanning the mamager's header file,
+# using the "scantools" package (customized for this particular manager).
+
+import string
+
+# Declarations that change for each manager
+MACHEADERFILE = 'Controls.h' # The Apple header file
+MODNAME = 'Ctl' # The name of the module
+OBJECTNAME = 'Control' # The basic name of the objects used here
+
+# The following is *usually* unchanged but may still require tuning
+MODPREFIX = MODNAME # The prefix for module-wide routines
+OBJECTTYPE = OBJECTNAME + 'Handle' # The C type used to represent them
+OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
+INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
+OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
+
+from macsupport import *
+
+# Create the type objects
+
+ControlHandle = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX)
+ControlRef = ControlHandle
+ExistingControlHandle = OpaqueByValueType(OBJECTTYPE, "CtlObj_WhichControl", "BUG")
+
+RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
+CCTabHandle = OpaqueByValueType("CCTabHandle", "ResObj")
+AuxCtlHandle = OpaqueByValueType("AuxCtlHandle", "ResObj")
+ControlPartCode = Type("ControlPartCode", "h")
+DragConstraint = Type("DragConstraint", "H")
+ControlVariant = Type("ControlVariant", "h")
+IconTransformType = Type("IconTransformType", "h")
+EventModifiers = Type("EventModifiers", "H")
+ClickActivationResult = Type("ClickActivationResult", "l")
+ControlButtonGraphicAlignment = Type("ControlButtonGraphicAlignment", "h")
+ControlButtonTextAlignment = Type("ControlButtonTextAlignment", "h")
+ControlButtonTextPlacement = Type("ControlButtonTextPlacement", "h")
+ControlContentType = Type("ControlContentType", "h")
+ControlFocusPart = Type("ControlFocusPart", "h")
+
+ControlFontStyleRec = OpaqueType('ControlFontStyleRec', 'ControlFontStyle')
+ControlFontStyleRec_ptr = ControlFontStyleRec
+ControlID = OpaqueType('ControlID', 'PyControlID')
+ControlID_ptr = ControlID
+
+DragTrackingMessage = Type("DragTrackingMessage", "h")
+DragReference = OpaqueByValueType("DragReference", "DragObj")
+
+includestuff = includestuff + """
+#ifdef WITHOUT_FRAMEWORKS
+#include <Controls.h>
+#include <ControlDefinitions.h>
+#else
+#include <Carbon/Carbon.h>
+#endif
+
+#ifdef USE_TOOLBOX_OBJECT_GLUE
+extern PyObject *_CtlObj_New(ControlHandle);
+extern int _CtlObj_Convert(PyObject *, ControlHandle *);
+
+#define CtlObj_New _CtlObj_New
+#define CtlObj_Convert _CtlObj_Convert
+#endif
+
+staticforward PyObject *CtlObj_WhichControl(ControlHandle);
+
+#define as_Control(h) ((ControlHandle)h)
+#define as_Resource(ctl) ((Handle)ctl)
+#if TARGET_API_MAC_CARBON
+#define GetControlRect(ctl, rectp) GetControlBounds(ctl, rectp)
+#else
+#define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
+#endif
+
+/*
+** Parse/generate ControlFontStyleRec records
+*/
+#if 0 /* Not needed */
+static PyObject *
+ControlFontStyle_New(ControlFontStyleRec *itself)
+{
+
+ return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
+ itself->size, itself->style, itself->mode, itself->just,
+ QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
+}
+#endif
+
+static int
+ControlFontStyle_Convert(PyObject *v, ControlFontStyleRec *itself)
+{
+ return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
+ &itself->font, &itself->size, &itself->style, &itself->mode,
+ &itself->just, QdRGB_Convert, &itself->foreColor,
+ QdRGB_Convert, &itself->backColor);
+}
+
+/*
+** Parse/generate ControlID records
+*/
+static PyObject *
+PyControlID_New(ControlID *itself)
+{
+
+ return Py_BuildValue("O&l", PyMac_BuildOSType, itself->signature, itself->id);
+}
+
+static int
+PyControlID_Convert(PyObject *v, ControlID *itself)
+{
+ return PyArg_ParseTuple(v, "O&l", PyMac_GetOSType, &itself->signature, &itself->id);
+}
+
+
+/* TrackControl and HandleControlClick callback support */
+static PyObject *tracker;
+static ControlActionUPP mytracker_upp;
+static ControlUserPaneDrawUPP mydrawproc_upp;
+static ControlUserPaneIdleUPP myidleproc_upp;
+static ControlUserPaneHitTestUPP myhittestproc_upp;
+static ControlUserPaneTrackingUPP mytrackingproc_upp;
+
+staticforward int settrackfunc(PyObject *); /* forward */
+staticforward void clrtrackfunc(void); /* forward */
+staticforward int setcallback(PyObject *, OSType, PyObject *, UniversalProcPtr *);
+"""
+
+finalstuff = finalstuff + """
+static PyObject *
+CtlObj_NewUnmanaged(ControlHandle itself)
+{
+ ControlObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(ControlObject, &Control_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_callbackdict = NULL;
+ return (PyObject *)it;
+}
+
+static PyObject *
+CtlObj_WhichControl(ControlHandle c)
+{
+ PyObject *it;
+
+ if (c == NULL)
+ it = Py_None;
+ else {
+ it = (PyObject *) GetControlReference(c);
+ /*
+ ** If the refcon is zero or doesn't point back to the Python object
+ ** the control is not ours. Return a temporary object.
+ */
+ if (it == NULL || ((ControlObject *)it)->ob_itself != c)
+ return CtlObj_NewUnmanaged(c);
+ }
+ Py_INCREF(it);
+ return it;
+}
+
+static int
+settrackfunc(PyObject *obj)
+{
+ if (tracker) {
+ PyErr_SetString(Ctl_Error, "Tracker function in use");
+ return 0;
+ }
+ tracker = obj;
+ Py_INCREF(tracker);
+}
+
+static void
+clrtrackfunc(void)
+{
+ Py_XDECREF(tracker);
+ tracker = 0;
+}
+
+static pascal void
+mytracker(ControlHandle ctl, short part)
+{
+ PyObject *args, *rv=0;
+
+ args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
+ if (args && tracker) {
+ rv = PyEval_CallObject(tracker, args);
+ Py_DECREF(args);
+ }
+ if (rv)
+ Py_DECREF(rv);
+ else
+ PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\\n");
+}
+
+static int
+setcallback(PyObject *myself, OSType which, PyObject *callback, UniversalProcPtr *uppp)
+{
+ ControlObject *self = (ControlObject *)myself;
+ char keybuf[9];
+
+ if ( which == kControlUserPaneDrawProcTag )
+ *uppp = (UniversalProcPtr)mydrawproc_upp;
+ else if ( which == kControlUserPaneIdleProcTag )
+ *uppp = (UniversalProcPtr)myidleproc_upp;
+ else if ( which == kControlUserPaneHitTestProcTag )
+ *uppp = (UniversalProcPtr)myhittestproc_upp;
+ else if ( which == kControlUserPaneTrackingProcTag )
+ *uppp = (UniversalProcPtr)mytrackingproc_upp;
+ else
+ return -1;
+ /* Only now do we test for clearing of the callback: */
+ if ( callback == Py_None )
+ *uppp = NULL;
+ /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
+ if ( self->ob_callbackdict == NULL )
+ if ( (self->ob_callbackdict = PyDict_New()) == NULL )
+ return -1;
+ /* And store the Python callback */
+ sprintf(keybuf, "%x", which);
+ if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
+ return -1;
+ return 0;
+}
+
+static PyObject *
+callcallback(ControlObject *self, OSType which, PyObject *arglist)
+{
+ char keybuf[9];
+ PyObject *func, *rv;
+
+ sprintf(keybuf, "%x", which);
+ if ( self->ob_callbackdict == NULL ||
+ (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
+ PySys_WriteStderr("Control callback %x without callback object\\n", which);
+ return NULL;
+ }
+ rv = PyEval_CallObject(func, arglist);
+ if ( rv == NULL )
+ PySys_WriteStderr("Exception in control callback %x handler\\n", which);
+ return rv;
+}
+
+static pascal void
+mydrawproc(ControlHandle control, SInt16 part)
+{
+ ControlObject *ctl_obj;
+ PyObject *arglist, *rv;
+
+ ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
+ arglist = Py_BuildValue("Oh", ctl_obj, part);
+ rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
+ Py_XDECREF(arglist);
+ Py_XDECREF(rv);
+}
+
+static pascal void
+myidleproc(ControlHandle control)
+{
+ ControlObject *ctl_obj;
+ PyObject *arglist, *rv;
+
+ ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
+ arglist = Py_BuildValue("O", ctl_obj);
+ rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
+ Py_XDECREF(arglist);
+ Py_XDECREF(rv);
+}
+
+static pascal ControlPartCode
+myhittestproc(ControlHandle control, Point where)
+{
+ ControlObject *ctl_obj;
+ PyObject *arglist, *rv;
+ short c_rv = -1;
+
+ ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
+ arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where);
+ rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist);
+ Py_XDECREF(arglist);
+ /* Ignore errors, nothing we can do about them */
+ if ( rv )
+ PyArg_Parse(rv, "h", &c_rv);
+ Py_XDECREF(rv);
+ return (ControlPartCode)c_rv;
+}
+
+static pascal ControlPartCode
+mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc)
+{
+ ControlObject *ctl_obj;
+ PyObject *arglist, *rv;
+ short c_rv = -1;
+
+ ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
+ /* We cannot pass the actionProc without lots of work */
+ arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt);
+ rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist);
+ Py_XDECREF(arglist);
+ if ( rv )
+ PyArg_Parse(rv, "h", &c_rv);
+ Py_XDECREF(rv);
+ return (ControlPartCode)c_rv;
+}
+"""
+
+initstuff = initstuff + """
+mytracker_upp = NewControlActionUPP(mytracker);
+mydrawproc_upp = NewControlUserPaneDrawUPP(mydrawproc);
+myidleproc_upp = NewControlUserPaneIdleUPP(myidleproc);
+myhittestproc_upp = NewControlUserPaneHitTestUPP(myhittestproc);
+mytrackingproc_upp = NewControlUserPaneTrackingUPP(mytrackingproc);
+PyMac_INIT_TOOLBOX_OBJECT_NEW(ControlHandle, CtlObj_New);
+PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ControlHandle, CtlObj_Convert);
+"""
+
+class MyObjectDefinition(ObjectIdentityMixin, GlobalObjectDefinition):
+ def outputStructMembers(self):
+ GlobalObjectDefinition.outputStructMembers(self)
+ Output("PyObject *ob_callbackdict;")
+ def outputCheckNewArg(self):
+ Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+ def outputInitStructMembers(self):
+ GlobalObjectDefinition.outputInitStructMembers(self)
+ Output("SetControlReference(itself, (long)it);")
+ Output("it->ob_callbackdict = NULL;")
+ def outputCleanupStructMembers(self):
+ Output("Py_XDECREF(self->ob_callbackdict);")
+ Output("if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */")
+
+# Create the generator groups and link them
+module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
+object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
+module.addobject(object)
+
+# Create the generator classes used to populate the lists
+Function = OSErrFunctionGenerator
+Method = OSErrMethodGenerator
+
+# Create and populate the lists
+functions = []
+methods = []
+execfile(INPUTFILE)
+execfile('ctledit.py')
+
+# add the populated lists to the generator groups
+for f in functions: module.add(f)
+for f in methods: object.add(f)
+
+# Manual generator for TrackControl, due to callback ideosyncracies
+trackcontrol_body = """
+ControlPartCode _rv;
+Point startPoint;
+ControlActionUPP upp = 0;
+PyObject *callback = 0;
+
+if (!PyArg_ParseTuple(_args, "O&|O",
+ PyMac_GetPoint, &startPoint, &callback))
+ return NULL;
+if (callback && callback != Py_None) {
+ if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
+ upp = (ControlActionUPP)-1;
+ else {
+ settrackfunc(callback);
+ upp = mytracker_upp;
+ }
+}
+_rv = TrackControl(_self->ob_itself,
+ startPoint,
+ upp);
+clrtrackfunc();
+_res = Py_BuildValue("h",
+ _rv);
+return _res;
+"""
+
+f = ManualGenerator("TrackControl", trackcontrol_body);
+f.docstring = lambda: "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"
+object.add(f)
+
+# CJW - added 5/12/99
+# Manual generator for HandleControlClick, as for TrackControl
+handlecontrolclick_body = """
+ControlPartCode _rv;
+Point startPoint;
+SInt16 modifiers;
+ControlActionUPP upp = 0;
+PyObject *callback = 0;
+
+if (!PyArg_ParseTuple(_args, "O&h|O",
+ PyMac_GetPoint, &startPoint,
+ &modifiers,
+ &callback))
+ return NULL;
+if (callback && callback != Py_None) {
+ if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
+ upp = (ControlActionUPP)-1;
+ else {
+ settrackfunc(callback);
+ upp = mytracker_upp;
+ }
+}
+_rv = HandleControlClick(_self->ob_itself,
+ startPoint,
+ modifiers,
+ upp);
+clrtrackfunc();
+_res = Py_BuildValue("h",
+ _rv);
+return _res;
+"""
+
+f = ManualGenerator("HandleControlClick", handlecontrolclick_body);
+f.docstring = lambda: "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"
+object.add(f)
+
+# Manual Generator for SetControlData
+setcontroldata_body = """
+OSErr _err;
+ControlPartCode inPart;
+ResType inTagName;
+Size bufferSize;
+Ptr buffer;
+
+if (!PyArg_ParseTuple(_args, "hO&s#",
+ &inPart,
+ PyMac_GetOSType, &inTagName,
+ &buffer, &bufferSize))
+ return NULL;
+
+_err = SetControlData(_self->ob_itself,
+ inPart,
+ inTagName,
+ bufferSize,
+ buffer);
+
+if (_err != noErr)
+ return PyMac_Error(_err);
+_res = Py_None;
+return _res;
+"""
+
+f = ManualGenerator("SetControlData", setcontroldata_body);
+f.docstring = lambda: "(stuff) -> None"
+object.add(f)
+
+# Manual Generator for GetControlData
+getcontroldata_body = """
+OSErr _err;
+ControlPartCode inPart;
+ResType inTagName;
+Size bufferSize;
+Ptr buffer;
+Size outSize;
+
+if (!PyArg_ParseTuple(_args, "hO&",
+ &inPart,
+ PyMac_GetOSType, &inTagName))
+ return NULL;
+
+/* allocate a buffer for the data */
+_err = GetControlDataSize(_self->ob_itself,
+ inPart,
+ inTagName,
+ &bufferSize);
+if (_err != noErr)
+ return PyMac_Error(_err);
+buffer = PyMem_NEW(char, bufferSize);
+if (buffer == NULL)
+ return PyErr_NoMemory();
+
+_err = GetControlData(_self->ob_itself,
+ inPart,
+ inTagName,
+ bufferSize,
+ buffer,
+ &outSize);
+
+if (_err != noErr) {
+ PyMem_DEL(buffer);
+ return PyMac_Error(_err);
+}
+_res = Py_BuildValue("s#", buffer, outSize);
+PyMem_DEL(buffer);
+return _res;
+"""
+
+f = ManualGenerator("GetControlData", getcontroldata_body);
+f.docstring = lambda: "(part, type) -> String"
+object.add(f)
+
+# Manual Generator for SetControlData_Handle
+setcontroldata_handle_body = """
+OSErr _err;
+ControlPartCode inPart;
+ResType inTagName;
+Handle buffer;
+
+if (!PyArg_ParseTuple(_args, "hO&O&",
+ &inPart,
+ PyMac_GetOSType, &inTagName,
+ OptResObj_Convert, &buffer))
+ return NULL;
+
+_err = SetControlData(_self->ob_itself,
+ inPart,
+ inTagName,
+ sizeof(buffer),
+ (Ptr)&buffer);
+
+if (_err != noErr)
+ return PyMac_Error(_err);
+_res = Py_None;
+return _res;
+"""
+
+f = ManualGenerator("SetControlData_Handle", setcontroldata_handle_body);
+f.docstring = lambda: "(ResObj) -> None"
+object.add(f)
+
+# Manual Generator for GetControlData_Handle
+getcontroldata_handle_body = """
+OSErr _err;
+ControlPartCode inPart;
+ResType inTagName;
+Size bufferSize;
+Handle hdl;
+
+if (!PyArg_ParseTuple(_args, "hO&",
+ &inPart,
+ PyMac_GetOSType, &inTagName))
+ return NULL;
+
+/* Check it is handle-sized */
+_err = GetControlDataSize(_self->ob_itself,
+ inPart,
+ inTagName,
+ &bufferSize);
+if (_err != noErr)
+ return PyMac_Error(_err);
+if (bufferSize != sizeof(Handle)) {
+ PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
+ return NULL;
+}
+
+_err = GetControlData(_self->ob_itself,
+ inPart,
+ inTagName,
+ sizeof(Handle),
+ (Ptr)&hdl,
+ &bufferSize);
+
+if (_err != noErr) {
+ return PyMac_Error(_err);
+}
+return Py_BuildValue("O&", OptResObj_New, hdl);
+"""
+
+f = ManualGenerator("GetControlData_Handle", getcontroldata_handle_body);
+f.docstring = lambda: "(part, type) -> ResObj"
+object.add(f)
+
+# Manual Generator for SetControlData_Callback
+setcontroldata_callback_body = """
+OSErr _err;
+ControlPartCode inPart;
+ResType inTagName;
+PyObject *callback;
+UniversalProcPtr c_callback;
+
+if (!PyArg_ParseTuple(_args, "hO&O",
+ &inPart,
+ PyMac_GetOSType, &inTagName,
+ &callback))
+ return NULL;
+
+if ( setcallback((PyObject *)_self, inTagName, callback, &c_callback) < 0 )
+ return NULL;
+_err = SetControlData(_self->ob_itself,
+ inPart,
+ inTagName,
+ sizeof(c_callback),
+ (Ptr)&c_callback);
+
+if (_err != noErr)
+ return PyMac_Error(_err);
+_res = Py_None;
+return _res;
+"""
+
+f = ManualGenerator("SetControlData_Callback", setcontroldata_callback_body);
+f.docstring = lambda: "(callbackfunc) -> None"
+object.add(f)
+
+# And manual generators to get/set popup menu information
+getpopupdata_body = """
+PopupPrivateDataHandle hdl;
+
+if ( (*_self->ob_itself)->contrlData == NULL ) {
+ PyErr_SetString(Ctl_Error, "No contrlData handle in control");
+ return 0;
+}
+hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
+HLock((Handle)hdl);
+_res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
+HUnlock((Handle)hdl);
+return _res;
+"""
+f = ManualGenerator("GetPopupData", getpopupdata_body, condition="#if !TARGET_API_MAC_CARBON")
+object.add(f)
+
+setpopupdata_body = """
+PopupPrivateDataHandle hdl;
+MenuHandle mHandle;
+short mID;
+
+if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
+ return 0;
+if ( (*_self->ob_itself)->contrlData == NULL ) {
+ PyErr_SetString(Ctl_Error, "No contrlData handle in control");
+ return 0;
+}
+hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
+(*hdl)->mHandle = mHandle;
+(*hdl)->mID = mID;
+Py_INCREF(Py_None);
+return Py_None;
+"""
+f = ManualGenerator("SetPopupData", setpopupdata_body, condition="#if !TARGET_API_MAC_CARBON")
+object.add(f)
+
+
+# generate output (open the output file as late as possible)
+SetOutputFileName(OUTPUTFILE)
+module.generate()
--- /dev/null
+
+/* =========================== Module Fm ============================ */
+
+#include "Python.h"
+
+
+
+#include "macglue.h"
+#include "pymactoolbox.h"
+
+#ifdef WITHOUT_FRAMEWORKS
+#include <Fonts.h>
+#else
+#include <Carbon/Carbon.h>
+#endif
+
+
+/*
+** Parse/generate ComponentDescriptor records
+*/
+static PyObject *
+FMRec_New(FMetricRec *itself)
+{
+
+ return Py_BuildValue("O&O&O&O&O&",
+ PyMac_BuildFixed, itself->ascent,
+ PyMac_BuildFixed, itself->descent,
+ PyMac_BuildFixed, itself->leading,
+ PyMac_BuildFixed, itself->widMax,
+ ResObj_New, itself->wTabHandle);
+}
+
+#if 0
+/* Not needed... */
+static int
+FMRec_Convert(PyObject *v, FMetricRec *p_itself)
+{
+ return PyArg_ParseTuple(v, "O&O&O&O&O&",
+ PyMac_GetFixed, &itself->ascent,
+ PyMac_GetFixed, &itself->descent,
+ PyMac_GetFixed, &itself->leading,
+ PyMac_GetFixed, &itself->widMax,
+ ResObj_Convert, &itself->wTabHandle);
+}
+#endif
+
+
+static PyObject *Fm_Error;
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Fm_InitFonts(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ InitFonts();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *Fm_GetFontName(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short familyID;
+ Str255 name;
+ if (!PyArg_ParseTuple(_args, "h",
+ &familyID))
+ return NULL;
+ GetFontName(familyID,
+ name);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildStr255, name);
+ return _res;
+}
+
+static PyObject *Fm_GetFNum(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Str255 name;
+ short familyID;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetStr255, name))
+ return NULL;
+ GetFNum(name,
+ &familyID);
+ _res = Py_BuildValue("h",
+ familyID);
+ return _res;
+}
+
+static PyObject *Fm_RealFont(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ short fontNum;
+ short size;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &fontNum,
+ &size))
+ return NULL;
+ _rv = RealFont(fontNum,
+ size);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Fm_SetFontLock(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean lockFlag;
+ if (!PyArg_ParseTuple(_args, "b",
+ &lockFlag))
+ return NULL;
+ SetFontLock(lockFlag);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *Fm_SetFScaleDisable(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean fscaleDisable;
+ if (!PyArg_ParseTuple(_args, "b",
+ &fscaleDisable))
+ return NULL;
+ SetFScaleDisable(fscaleDisable);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Fm_FontMetrics(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ FMetricRec theMetrics;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ FontMetrics(&theMetrics);
+ _res = Py_BuildValue("O&",
+ FMRec_New, &theMetrics);
+ return _res;
+}
+
+static PyObject *Fm_SetFractEnable(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean fractEnable;
+ if (!PyArg_ParseTuple(_args, "b",
+ &fractEnable))
+ return NULL;
+ SetFractEnable(fractEnable);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Fm_GetDefFontSize(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetDefFontSize();
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *Fm_IsOutline(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Point numer;
+ Point denom;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &numer,
+ PyMac_GetPoint, &denom))
+ return NULL;
+ _rv = IsOutline(numer,
+ denom);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Fm_SetOutlinePreferred(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean outlinePreferred;
+ if (!PyArg_ParseTuple(_args, "b",
+ &outlinePreferred))
+ return NULL;
+ SetOutlinePreferred(outlinePreferred);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Fm_GetOutlinePreferred(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetOutlinePreferred();
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Fm_SetPreserveGlyph(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean preserveGlyph;
+ if (!PyArg_ParseTuple(_args, "b",
+ &preserveGlyph))
+ return NULL;
+ SetPreserveGlyph(preserveGlyph);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Fm_GetPreserveGlyph(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetPreserveGlyph();
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Fm_FlushFonts(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = FlushFonts();
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *Fm_GetSysFont(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetSysFont();
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *Fm_GetAppFont(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetAppFont();
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyMethodDef Fm_methods[] = {
+
+#if !TARGET_API_MAC_CARBON
+ {"InitFonts", (PyCFunction)Fm_InitFonts, 1,
+ "() -> None"},
+#endif
+ {"GetFontName", (PyCFunction)Fm_GetFontName, 1,
+ "(short familyID) -> (Str255 name)"},
+ {"GetFNum", (PyCFunction)Fm_GetFNum, 1,
+ "(Str255 name) -> (short familyID)"},
+ {"RealFont", (PyCFunction)Fm_RealFont, 1,
+ "(short fontNum, short size) -> (Boolean _rv)"},
+
+#if !TARGET_API_MAC_CARBON
+ {"SetFontLock", (PyCFunction)Fm_SetFontLock, 1,
+ "(Boolean lockFlag) -> None"},
+#endif
+ {"SetFScaleDisable", (PyCFunction)Fm_SetFScaleDisable, 1,
+ "(Boolean fscaleDisable) -> None"},
+ {"FontMetrics", (PyCFunction)Fm_FontMetrics, 1,
+ "() -> (FMetricRec theMetrics)"},
+ {"SetFractEnable", (PyCFunction)Fm_SetFractEnable, 1,
+ "(Boolean fractEnable) -> None"},
+ {"GetDefFontSize", (PyCFunction)Fm_GetDefFontSize, 1,
+ "() -> (short _rv)"},
+ {"IsOutline", (PyCFunction)Fm_IsOutline, 1,
+ "(Point numer, Point denom) -> (Boolean _rv)"},
+ {"SetOutlinePreferred", (PyCFunction)Fm_SetOutlinePreferred, 1,
+ "(Boolean outlinePreferred) -> None"},
+ {"GetOutlinePreferred", (PyCFunction)Fm_GetOutlinePreferred, 1,
+ "() -> (Boolean _rv)"},
+ {"SetPreserveGlyph", (PyCFunction)Fm_SetPreserveGlyph, 1,
+ "(Boolean preserveGlyph) -> None"},
+ {"GetPreserveGlyph", (PyCFunction)Fm_GetPreserveGlyph, 1,
+ "() -> (Boolean _rv)"},
+
+#if !TARGET_API_MAC_CARBON
+ {"FlushFonts", (PyCFunction)Fm_FlushFonts, 1,
+ "() -> None"},
+#endif
+ {"GetSysFont", (PyCFunction)Fm_GetSysFont, 1,
+ "() -> (short _rv)"},
+ {"GetAppFont", (PyCFunction)Fm_GetAppFont, 1,
+ "() -> (short _rv)"},
+ {NULL, NULL, 0}
+};
+
+
+
+
+void initFm(void)
+{
+ PyObject *m;
+ PyObject *d;
+
+
+
+
+ m = Py_InitModule("Fm", Fm_methods);
+ d = PyModule_GetDict(m);
+ Fm_Error = PyMac_GetOSErrException();
+ if (Fm_Error == NULL ||
+ PyDict_SetItemString(d, "Error", Fm_Error) != 0)
+ return;
+}
+
+/* ========================= End module Fm ========================== */
+
--- /dev/null
+# Scan an Apple header file, generating a Python file of generator calls.
+
+import sys
+import os
+BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
+sys.path.append(BGENDIR)
+from scantools import Scanner
+from bgenlocations import TOOLBOXDIR
+
+LONG = "Fonts"
+SHORT = "fm"
+
+def main():
+ input = "Fonts.h"
+ output = SHORT + "gen.py"
+ defsoutput = TOOLBOXDIR + LONG + ".py"
+ scanner = MyScanner(input, output, defsoutput)
+ scanner.scan()
+ scanner.close()
+ print "=== Done scanning and generating, now importing the generated code... ==="
+ exec "import " + SHORT + "support"
+ print "=== Done. It's up to you to compile it now! ==="
+
+class MyScanner(Scanner):
+
+ def destination(self, type, name, arglist):
+ classname = "Function"
+ listname = "functions"
+ return classname, listname
+
+ def makeblacklistnames(self):
+ return [
+ "OutlineMetrics", # Too complicated
+ "AntiTextIsAntiAliased", # XXXX Missing from library...
+ "AntiTextGetEnabled",
+ "AntiTextSetEnabled",
+ "AntiTextGetApplicationAware",
+ "AntiTextSetApplicationAware",
+ # These are tricky: they're not Carbon dependent or anything, but they
+ # exist only on 8.6 or later (both in Carbon and Classic).
+ # Disabling them is the easiest path.
+ 'SetAntiAliasedTextEnabled',
+ 'IsAntiAliasedTextEnabled',
+ ]
+
+ def makegreylist(self):
+ return [
+ ('#if !TARGET_API_MAC_CARBON', [
+ 'InitFonts',
+ 'SetFontLock',
+ 'FlushFonts',
+ ])]
+ def makeblacklisttypes(self):
+ return [
+ "FMInput_ptr", # Not needed for now
+ "FMOutPtr", # Ditto
+ "void_ptr", # Don't know how to do this right now
+ "FontInfo", # Ditto
+ ]
+
+ def makerepairinstructions(self):
+ return [
+ ([('Str255', '*', 'InMode')], [('Str255', '*', 'OutMode')]),
+ ([('FMetricRecPtr', 'theMetrics', 'InMode')], [('FMetricRecPtr', 'theMetrics', 'OutMode')]),
+ ]
+
+ def writeinitialdefs(self):
+ self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
+ self.defsfile.write("kNilOptions = 0\n")
+
+if __name__ == "__main__":
+ main()
--- /dev/null
+/***********************************************************
+Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
+The Netherlands.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the names of Stichting Mathematisch
+Centrum or CWI not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+
+STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
+THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
+FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+******************************************************************/
+
+/* Macintosh Python configuration file */
+
+#include "Python.h"
+/* Table of built-in modules.
+ These are initialized when first imported.
+ Note: selection of optional extensions is now generally done by the
+ makesetup script. */
+
+extern void initarray();
+extern void initmath();
+#ifndef WITHOUT_COMPLEX
+extern void initcmath();
+#endif
+extern void initparser();
+extern void initmac();
+extern void initMacOS();
+extern void initregex();
+extern void initstrop();
+extern void initstruct();
+extern void inittime();
+extern void initdbm();
+extern void initfcntl();
+extern void initnis();
+extern void initpwd();
+extern void initgrp();
+extern void initcrypt();
+extern void initselect();
+extern void init_socket();
+extern void initaudioop();
+extern void initimageop();
+extern void initrgbimg();
+extern void initmd5();
+extern void initmpz();
+extern void initrotor();
+extern void inital();
+extern void initcd();
+extern void initcl();
+extern void initfm();
+extern void initgl();
+extern void initimgfile();
+extern void initimgformat();
+extern void initsgi();
+extern void initsv();
+extern void initfl();
+extern void initthread();
+extern void inittiming();
+extern void initsignal();
+extern void initnew();
+extern void initdl();
+extern void initsyslog();
+extern void initgestalt();
+extern void initmacfs();
+extern void initbinascii();
+extern void initoperator();
+extern void initerrno();
+extern void initpcre();
+extern void initunicodedata();
+extern void init_codecs();
+#ifdef USE_MACCTB
+extern void initctb();
+#endif
+#ifdef USE_MACSPEECH
+extern void initmacspeech();
+#endif
+#ifdef USE_MACTCP
+extern void initmacdnr();
+extern void initmactcp();
+#endif
+#ifdef USE_IC
+extern void initicglue();
+#endif
+#ifdef USE_TOOLBOX
+#ifndef USE_CORE_TOOLBOX
+#define USE_CORE_TOOLBOX
+#endif
+extern void initApp();
+extern void initFm();
+extern void initHelp();
+extern void initIcn();
+extern void initList();
+extern void initQdoffs();
+extern void initSnd();
+extern void initSndihooks();
+extern void initScrap();
+extern void initTE();
+extern void initColorPicker();
+extern void initPrinting();
+#endif
+#ifdef USE_CORE_TOOLBOX
+extern void initAE();
+extern void initCtl();
+extern void initDlg();
+extern void initDrag();
+extern void initEvt();
+extern void initMenu();
+extern void initQd();
+extern void initRes();
+extern void initWin();
+extern void initNav();
+#endif
+#ifdef USE_QT
+extern void initCm();
+extern void initQt();
+#endif
+
+#ifdef USE_IMG
+extern void initimgcolormap();
+extern void initimgformat();
+extern void initimggif();
+extern void initimgjpeg();
+extern void initimgpbm();
+extern void initimgppm();
+extern void initimgpgm();
+extern void initimgtiff();
+extern void initimgsgi();
+extern void initimgpng();
+extern void initimgop();
+#endif
+#ifdef USE_TK
+extern void init_tkinter();
+#endif
+#ifdef USE_GUSI
+extern void init_socket();
+extern void initselect();
+#endif
+#ifdef USE_WASTE
+extern void initwaste();
+#endif
+#ifdef USE_GDBM
+extern void initgdbm();
+#endif
+#ifdef USE_ZLIB
+extern void initzlib();
+#endif
+#ifdef WITH_THREAD
+extern void initthread();
+#endif
+#ifdef USE_PYEXPAT
+extern void initpyexpat();
+#endif
+#ifdef WITH_CYCLE_GC
+extern void initgc();
+#endif
+
+extern void initcPickle();
+extern void initcStringIO();
+extern void init_codecs();
+extern void initsha();
+extern void init_locale();
+extern void init_sre();
+extern void initxreadlines();
+/* -- ADDMODULE MARKER 1 -- */
+
+extern void PyMarshal_Init();
+extern void initimp();
+
+struct _inittab _PyImport_Inittab[] = {
+
+ {"array", initarray},
+ {"math", initmath},
+#ifndef WITHOUT_COMPLEX
+ {"cmath", initcmath},
+#endif
+ {"parser", initparser},
+ {"mac", initmac},
+ {"MacOS", initMacOS},
+ {"regex", initregex},
+ {"strop", initstrop},
+ {"struct", initstruct},
+ {"time", inittime},
+ {"audioop", initaudioop},
+ {"imageop", initimageop},
+ {"rgbimg", initrgbimg},
+ {"md5", initmd5},
+ {"rotor", initrotor},
+ {"new", initnew},
+ {"gestalt", initgestalt},
+ {"macfs", initmacfs},
+ {"binascii", initbinascii},
+ {"operator", initoperator},
+ {"errno", initerrno},
+ {"pcre", initpcre},
+ {"unicodedata", initunicodedata},
+ {"_codecs", init_codecs},
+ {"sha", initsha},
+#ifdef USE_MACCTB
+ {"ctb", initctb},
+#endif
+/* This could probably be made to work on other compilers... */
+#ifdef USE_MACSPEECH
+ {"macspeech", initmacspeech},
+#endif
+#ifdef USE_MACTCP
+ {"macdnr", initmacdnr},
+ {"mactcp", initmactcp},
+#endif
+#ifdef USE_IC
+ {"icglue", initicglue},
+#endif
+#ifdef USE_CORE_TOOLBOX
+ {"AE", initAE},
+ {"Ctl", initCtl},
+ {"Dlg", initDlg},
+ {"Drag", initDrag},
+ {"Evt", initEvt},
+ {"Menu", initMenu},
+ {"Nav", initNav},
+ {"Qd", initQd},
+ {"Win", initWin},
+ {"Res", initRes},
+#endif
+#ifdef USE_TOOLBOX
+ {"App", initApp},
+ {"Fm", initFm},
+ {"Icn", initIcn},
+ {"List", initList},
+ {"Qdoffs", initQdoffs},
+ {"Snd", initSnd},
+ {"Sndihooks", initSndihooks},
+ /* Carbon scrap manager is completely different */
+ {"Scrap", initScrap},
+ {"TE", initTE},
+ {"ColorPicker", initColorPicker},
+#if !TARGET_API_MAC_CARBON
+ {"Help", initHelp},
+ {"Printing", initPrinting},
+#endif
+#endif
+#ifdef USE_QT
+ {"Cm", initCm},
+ {"Qt", initQt},
+#endif
+#ifdef USE_IMG
+ {"imgcolormap", initimgcolormap},
+ {"imgformat", initimgformat},
+ {"imggif", initimggif},
+ {"imgjpeg", initimgjpeg},
+ {"imgpbm", initimgpbm},
+ {"imgppm", initimgppm},
+ {"imgpgm", initimgpgm},
+ {"imgtiff", initimgtiff},
+ {"imgsgi", initimgsgi},
+ {"imgpng", initimgpng},
+ {"imgop", initimgop},
+#endif
+#ifdef USE_TK
+ {"_tkinter", init_tkinter},
+#endif
+#ifdef USE_GUSI
+ {"_socket", init_socket},
+ {"select", initselect},
+#endif
+#ifdef USE_WASTE
+ {"waste", initwaste},
+#endif
+#ifdef USE_GDBM
+ {"gdbm", initgdbm},
+#endif /* USE_GDBM */
+#ifdef USE_ZLIB
+ {"zlib", initzlib},
+#endif
+#ifdef WITH_THREAD
+ {"thread", initthread},
+#endif
+#ifdef USE_PYEXPAT
+ {"pyexpat", initpyexpat},
+#endif
+#ifdef WITH_CYCLE_GC
+ {"gc", initgc},
+#endif
+ {"cPickle", initcPickle},
+ {"cStringIO", initcStringIO},
+ {"_locale", init_locale},
+ {"_sre", init_sre},
+ {"xreadlines", initxreadlines},
+/* -- ADDMODULE MARKER 2 -- */
+
+ /* This module "lives in" with marshal.c */
+ {"marshal", PyMarshal_Init},
+
+ /* This module "lives in" with import.c */
+ {"imp", initimp},
+
+ /* These entries are here for sys.builtin_module_names */
+ {"__main__", NULL},
+ {"__builtin__", NULL},
+ {"sys", NULL},
+
+ /* Sentinel */
+ {0, 0}
+};
--- /dev/null
+
+/* =========================== Module Qd ============================ */
+
+#include "Python.h"
+
+
+
+#include "macglue.h"
+#include "pymactoolbox.h"
+
+#ifdef WITHOUT_FRAMEWORKS
+#include <QuickDraw.h>
+#else
+#include <Carbon/Carbon.h>
+#endif
+
+#ifdef USE_TOOLBOX_OBJECT_GLUE
+extern PyObject *_GrafObj_New(GrafPtr);
+extern int _GrafObj_Convert(PyObject *, GrafPtr *);
+extern PyObject *_BMObj_New(BitMapPtr);
+extern int _BMObj_Convert(PyObject *, BitMapPtr *);
+extern PyObject *_QdRGB_New(RGBColorPtr);
+extern int _QdRGB_Convert(PyObject *, RGBColorPtr);
+
+#define GrafObj_New _GrafObj_New
+#define GrafObj_Convert _GrafObj_Convert
+#define BMObj_New _BMObj_New
+#define BMObj_Convert _BMObj_Convert
+#define QdRGB_New _QdRGB_New
+#define QdRGB_Convert _QdRGB_Convert
+#endif
+
+#if !ACCESSOR_CALLS_ARE_FUNCTIONS
+#define GetPortBitMapForCopyBits(port) ((const struct BitMap *)&((GrafPort *)(port))->portBits)
+#define GetPortPixMap(port) (((CGrafPtr)(port))->portPixMap)
+#define GetPortBounds(port, bounds) (*(bounds) = (port)->portRect, (bounds))
+#define GetPortForeColor(port, color) (*(color) = (port)->rgbFgColor, (color))
+#define GetPortBackColor(port, color) (*(color) = (port)->rgbBkColor, (color))
+#define GetPortOpColor(port, color) (*(color) = (*(GVarHandle)((port)->grafVars))->rgbOpColor, (color))
+#define GetPortHiliteColor(port, color) (*(color) = (*(GVarHandle)((port)->grafVars))->rgbHiliteColor, (color))
+#define GetPortTextFont(port) ((port)->txFont)
+#define GetPortTextFace(port) ((port)->txFace)
+#define GetPortTextMode(port) ((port)->txMode)
+#define GetPortTextSize(port) ((port)->txSize)
+#define GetPortChExtra(port) ((port)->chExtra)
+#define GetPortFracHPenLocation(port) ((port)->pnLocHFrac)
+#define GetPortSpExtra(port) ((port)->spExtra)
+#define GetPortPenVisibility(port) ((port)->pnVis)
+#define GetPortVisibleRegion(port, rgn) ((rgn) = (port)->visRgn, (rgn))
+#define GetPortClipRegion(port, rgn) ((rgn) = (port)->clipRgn, (rgn))
+#define GetPortBackPixPat(port, pat) ((pat) = (port)->bkPixPat, (pat))
+#define GetPortPenPixPat(port, pat) ((pat) = (port)->pnPixPat, (pat))
+#define GetPortFillPixPat(port, pat) ((pat) = (port)->fillPixPat, (pat))
+#define GetPortPenSize(port, pensize) (*(pensize) = (port)->pnSize, (pensize))
+#define GetPortPenMode(port) ((port)->pnMode)
+#define GetPortPenLocation(port, location) ((*location) = (port)->pnLoc, (location))
+#define IsPortRegionBeingDefined(port) (!!((port)->rgnSave))
+#define IsPortPictureBeingDefined(port) (!!((port)->picSave))
+/* #define IsPortOffscreen(port) */
+/* #define IsPortColor(port) */
+
+#define SetPortBounds(port, bounds) ((port)->portRect = *(bounds))
+#define SetPortOpColor(port, color) ((*(GVarHandle)((port)->grafVars))->rgbOpColor = *(color))
+#define SetPortVisibleRegion(port, rgn) ((port)->visRgn = (rgn))
+#define SetPortClipRegion(port, rgn) ((port)->clipRgn = (rgn))
+#define SetPortBackPixPat(port, pat) ((port)->bkPixPat = (pat))
+#define SetPortPenPixPat(port, pat) ((port)->pnPixPat = (pat))
+#define SetPortFillPixPat(port, pat) ((port)->fillPixPat = (pat))
+#define SetPortPenSize(port, pensize) ((port)->pnSize = (pensize))
+#define SetPortPenMode(port, mode) ((port)->pnMode = (mode))
+#define SetPortFracHPenLocation(port, frac) ((port)->pnLocHFrac = (frac))
+
+/* On pixmaps */
+#define GetPixBounds(pixmap, rect) (*(rect) = (*(pixmap))->bounds, (rect))
+#define GetPixDepth(pixmap) ((*(pixmap))->pixelSize)
+
+/* On regions */
+#define GetRegionBounds(rgn, rect) (*(rect) = (*(rgn))->rgnBBox, (rect))
+
+/* On QD Globals */
+#define GetQDGlobalsRandomSeed() (qd.randSeed)
+#define GetQDGlobalsScreenBits(bits) (*(bits) = qd.screenBits, (bits))
+#define GetQDGlobalsArrow(crsr) (*(crsr) = qd.arrow, (crsr))
+#define GetQDGlobalsDarkGray(pat) (*(pat) = qd.dkGray, (pat))
+#define GetQDGlobalsLightGray(pat) (*(pat) = qd.ltGray, (pat))
+#define GetQDGlobalsGray(pat) (*(pat) = qd.gray, (pat))
+#define GetQDGlobalsBlack(pat) (*(pat) = qd.black, (pat))
+#define GetQDGlobalsWhite(pat) (*(pat) = qd.white, (pat))
+#define GetQDGlobalsThePort() ((CGrafPtr)qd.thePort)
+
+#define SetQDGlobalsRandomSeed(seed) (qd.randSeed = (seed))
+#define SetQDGlobalsArrow(crsr) (qd.arrow = *(crsr))
+
+#endif /* ACCESSOR_CALLS_ARE_FUNCTIONS */
+
+#if !TARGET_API_MAC_CARBON
+#define QDFlushPortBuffer(port, rgn) /* pass */
+#define QDIsPortBufferDirty(port) 0
+#define QDIsPortBuffered(port) 0
+#endif /* !TARGET_API_MAC_CARBON */
+
+staticforward PyObject *BMObj_NewCopied(BitMapPtr);
+
+/*
+** Parse/generate RGB records
+*/
+PyObject *QdRGB_New(RGBColorPtr itself)
+{
+
+ return Py_BuildValue("lll", (long)itself->red, (long)itself->green, (long)itself->blue);
+}
+
+QdRGB_Convert(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;
+}
+
+/*
+** Generate FontInfo records
+*/
+static
+PyObject *QdFI_New(FontInfo *itself)
+{
+
+ return Py_BuildValue("hhhh", itself->ascent, itself->descent,
+ itself->widMax, itself->leading);
+}
+
+static PyObject *Qd_Error;
+
+/* ---------------------- Object type GrafPort ---------------------- */
+
+PyTypeObject GrafPort_Type;
+
+#define GrafObj_Check(x) ((x)->ob_type == &GrafPort_Type)
+
+typedef struct GrafPortObject {
+ PyObject_HEAD
+ GrafPtr ob_itself;
+} GrafPortObject;
+
+PyObject *GrafObj_New(GrafPtr itself)
+{
+ GrafPortObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(GrafPortObject, &GrafPort_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ return (PyObject *)it;
+}
+GrafObj_Convert(PyObject *v, GrafPtr *p_itself)
+{
+#if 1
+ {
+ WindowRef win;
+ if (WinObj_Convert(v, &win) && v) {
+ *p_itself = (GrafPtr)GetWindowPort(win);
+ return 1;
+ }
+ PyErr_Clear();
+ }
+#else
+ if (DlgObj_Check(v)) {
+ DialogRef dlg = (DialogRef)((GrafPortObject *)v)->ob_itself;
+ *p_itself = (GrafPtr)GetWindowPort(GetDialogWindow(dlg));
+ return 1;
+ }
+ if (WinObj_Check(v)) {
+ WindowRef win = (WindowRef)((GrafPortObject *)v)->ob_itself;
+ *p_itself = (GrafPtr)GetWindowPort(win);
+ return 1;
+ }
+#endif
+ if (!GrafObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "GrafPort required");
+ return 0;
+ }
+ *p_itself = ((GrafPortObject *)v)->ob_itself;
+ return 1;
+}
+
+static void GrafObj_dealloc(GrafPortObject *self)
+{
+ /* Cleanup of self->ob_itself goes here */
+ PyMem_DEL(self);
+}
+
+static PyMethodDef GrafObj_methods[] = {
+ {NULL, NULL, 0}
+};
+
+PyMethodChain GrafObj_chain = { GrafObj_methods, NULL };
+
+static PyObject *GrafObj_getattr(GrafPortObject *self, char *name)
+{
+#if !ACCESSOR_CALLS_ARE_FUNCTIONS
+
+ { CGrafPtr itself_color = (CGrafPtr)self->ob_itself;
+
+ if ( strcmp(name, "data") == 0 )
+ return PyString_FromStringAndSize((char *)self->ob_itself, sizeof(GrafPort));
+
+ if ( (itself_color->portVersion&0xc000) == 0xc000 ) {
+ /* Color-only attributes */
+
+ if ( strcmp(name, "portBits") == 0 )
+ /* XXXX Do we need HLock() stuff here?? */
+ return BMObj_New((BitMapPtr)*itself_color->portPixMap);
+ if ( strcmp(name, "grafVars") == 0 )
+ return Py_BuildValue("O&", ResObj_New, (Handle)itself_color->visRgn);
+ if ( strcmp(name, "chExtra") == 0 )
+ return Py_BuildValue("h", itself_color->chExtra);
+ if ( strcmp(name, "pnLocHFrac") == 0 )
+ return Py_BuildValue("h", itself_color->pnLocHFrac);
+ if ( strcmp(name, "bkPixPat") == 0 )
+ return Py_BuildValue("O&", ResObj_New, (Handle)itself_color->bkPixPat);
+ if ( strcmp(name, "rgbFgColor") == 0 )
+ return Py_BuildValue("O&", QdRGB_New, &itself_color->rgbFgColor);
+ if ( strcmp(name, "rgbBkColor") == 0 )
+ return Py_BuildValue("O&", QdRGB_New, &itself_color->rgbBkColor);
+ if ( strcmp(name, "pnPixPat") == 0 )
+ return Py_BuildValue("O&", ResObj_New, (Handle)itself_color->pnPixPat);
+ if ( strcmp(name, "fillPixPat") == 0 )
+ return Py_BuildValue("O&", ResObj_New, (Handle)itself_color->fillPixPat);
+ } else {
+ /* Mono-only attributes */
+ if ( strcmp(name, "portBits") == 0 )
+ return BMObj_New(&self->ob_itself->portBits);
+ if ( strcmp(name, "bkPat") == 0 )
+ return Py_BuildValue("s#", (char *)&self->ob_itself->bkPat, sizeof(Pattern));
+ if ( strcmp(name, "fillPat") == 0 )
+ return Py_BuildValue("s#", (char *)&self->ob_itself->fillPat, sizeof(Pattern));
+ if ( strcmp(name, "pnPat") == 0 )
+ return Py_BuildValue("s#", (char *)&self->ob_itself->pnPat, sizeof(Pattern));
+ }
+ /*
+ ** Accessible for both color/mono windows.
+ ** portVersion is really color-only, but we put it here
+ ** for convenience
+ */
+ if ( strcmp(name, "portVersion") == 0 )
+ return Py_BuildValue("h", itself_color->portVersion);
+ if ( strcmp(name, "device") == 0 )
+ return PyInt_FromLong((long)self->ob_itself->device);
+ if ( strcmp(name, "portRect") == 0 )
+ return Py_BuildValue("O&", PyMac_BuildRect, &self->ob_itself->portRect);
+ if ( strcmp(name, "visRgn") == 0 )
+ return Py_BuildValue("O&", ResObj_New, (Handle)self->ob_itself->visRgn);
+ if ( strcmp(name, "clipRgn") == 0 )
+ return Py_BuildValue("O&", ResObj_New, (Handle)self->ob_itself->clipRgn);
+ if ( strcmp(name, "pnLoc") == 0 )
+ return Py_BuildValue("O&", PyMac_BuildPoint, self->ob_itself->pnLoc);
+ if ( strcmp(name, "pnSize") == 0 )
+ return Py_BuildValue("O&", PyMac_BuildPoint, self->ob_itself->pnSize);
+ if ( strcmp(name, "pnMode") == 0 )
+ return Py_BuildValue("h", self->ob_itself->pnMode);
+ if ( strcmp(name, "pnVis") == 0 )
+ return Py_BuildValue("h", self->ob_itself->pnVis);
+ if ( strcmp(name, "txFont") == 0 )
+ return Py_BuildValue("h", self->ob_itself->txFont);
+ if ( strcmp(name, "txFace") == 0 )
+ return Py_BuildValue("h", (short)self->ob_itself->txFace);
+ if ( strcmp(name, "txMode") == 0 )
+ return Py_BuildValue("h", self->ob_itself->txMode);
+ if ( strcmp(name, "txSize") == 0 )
+ return Py_BuildValue("h", self->ob_itself->txSize);
+ if ( strcmp(name, "spExtra") == 0 )
+ return Py_BuildValue("O&", PyMac_BuildFixed, self->ob_itself->spExtra);
+ /* XXXX Add more, as needed */
+ /* This one is so we can compare grafports: */
+ if ( strcmp(name, "_id") == 0 )
+ return Py_BuildValue("l", (long)self->ob_itself);
+ }
+#else
+
+ { CGrafPtr itself_color = (CGrafPtr)self->ob_itself;
+ if ( strcmp(name, "portBits") == 0 )
+ return BMObj_New((BitMapPtr)GetPortBitMapForCopyBits(itself_color));
+ if ( strcmp(name, "chExtra") == 0 )
+ return Py_BuildValue("h", GetPortChExtra(itself_color));
+ if ( strcmp(name, "pnLocHFrac") == 0 )
+ return Py_BuildValue("h", GetPortFracHPenLocation(itself_color));
+ if ( strcmp(name, "bkPixPat") == 0 ) {
+ PixPatHandle h=0;
+ return Py_BuildValue("O&", ResObj_New, (Handle)GetPortBackPixPat(itself_color, h));
+ }
+ if ( strcmp(name, "rgbFgColor") == 0 ) {
+ RGBColor c;
+ return Py_BuildValue("O&", QdRGB_New, GetPortForeColor(itself_color, &c));
+ }
+ if ( strcmp(name, "rgbBkColor") == 0 ) {
+ RGBColor c;
+ return Py_BuildValue("O&", QdRGB_New, GetPortBackColor(itself_color, &c));
+ }
+ if ( strcmp(name, "pnPixPat") == 0 ) {
+ PixPatHandle h=NewPixPat(); /* XXXX wrong dispose routine */
+
+ return Py_BuildValue("O&", ResObj_New, (Handle)GetPortPenPixPat(itself_color, h));
+ }
+ if ( strcmp(name, "fillPixPat") == 0 ) {
+ PixPatHandle h=NewPixPat(); /* XXXX wrong dispose routine */
+ return Py_BuildValue("O&", ResObj_New, (Handle)GetPortFillPixPat(itself_color, h));
+ }
+ if ( strcmp(name, "portRect") == 0 ) {
+ Rect r;
+ return Py_BuildValue("O&", PyMac_BuildRect, GetPortBounds(itself_color, &r));
+ }
+ if ( strcmp(name, "visRgn") == 0 ) {
+ RgnHandle h=NewRgn(); /* XXXX wrong dispose routine */
+ return Py_BuildValue("O&", ResObj_New, (Handle)GetPortVisibleRegion(itself_color, h));
+ }
+ if ( strcmp(name, "clipRgn") == 0 ) {
+ RgnHandle h=NewRgn(); /* XXXX wrong dispose routine */
+ return Py_BuildValue("O&", ResObj_New, (Handle)GetPortClipRegion(itself_color, h));
+ }
+ if ( strcmp(name, "pnLoc") == 0 ) {
+ Point p;
+ return Py_BuildValue("O&", PyMac_BuildPoint, *GetPortPenLocation(itself_color, &p));
+ }
+ if ( strcmp(name, "pnSize") == 0 ) {
+ Point p;
+ return Py_BuildValue("O&", PyMac_BuildPoint, *GetPortPenSize(itself_color, &p));
+ }
+ if ( strcmp(name, "pnMode") == 0 )
+ return Py_BuildValue("h", GetPortPenMode(itself_color));
+ if ( strcmp(name, "pnVis") == 0 )
+ return Py_BuildValue("h", GetPortPenVisibility(itself_color));
+ if ( strcmp(name, "txFont") == 0 )
+ return Py_BuildValue("h", GetPortTextFont(itself_color));
+ if ( strcmp(name, "txFace") == 0 )
+ return Py_BuildValue("h", (short)GetPortTextFace(itself_color));
+ if ( strcmp(name, "txMode") == 0 )
+ return Py_BuildValue("h", GetPortTextMode(itself_color));
+ if ( strcmp(name, "txSize") == 0 )
+ return Py_BuildValue("h", GetPortTextSize(itself_color));
+ if ( strcmp(name, "spExtra") == 0 )
+ return Py_BuildValue("O&", PyMac_BuildFixed, GetPortSpExtra(itself_color));
+ /* XXXX Add more, as needed */
+ /* This one is so we can compare grafports: */
+ if ( strcmp(name, "_id") == 0 )
+ return Py_BuildValue("l", (long)self->ob_itself);
+ }
+#endif
+ return Py_FindMethodInChain(&GrafObj_chain, (PyObject *)self, name);
+}
+
+#define GrafObj_setattr NULL
+
+#define GrafObj_compare NULL
+
+#define GrafObj_repr NULL
+
+#define GrafObj_hash NULL
+
+PyTypeObject GrafPort_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "GrafPort", /*tp_name*/
+ sizeof(GrafPortObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) GrafObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) GrafObj_getattr, /*tp_getattr*/
+ (setattrfunc) GrafObj_setattr, /*tp_setattr*/
+ (cmpfunc) GrafObj_compare, /*tp_compare*/
+ (reprfunc) GrafObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) GrafObj_hash, /*tp_hash*/
+};
+
+/* -------------------- End object type GrafPort -------------------- */
+
+
+/* ----------------------- Object type BitMap ----------------------- */
+
+PyTypeObject BitMap_Type;
+
+#define BMObj_Check(x) ((x)->ob_type == &BitMap_Type)
+
+typedef struct BitMapObject {
+ PyObject_HEAD
+ BitMapPtr ob_itself;
+ PyObject *referred_object;
+ BitMap *referred_bitmap;
+} BitMapObject;
+
+PyObject *BMObj_New(BitMapPtr itself)
+{
+ BitMapObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(BitMapObject, &BitMap_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->referred_object = NULL;
+ it->referred_bitmap = NULL;
+ return (PyObject *)it;
+}
+BMObj_Convert(PyObject *v, BitMapPtr *p_itself)
+{
+ if (!BMObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "BitMap required");
+ return 0;
+ }
+ *p_itself = ((BitMapObject *)v)->ob_itself;
+ return 1;
+}
+
+static void BMObj_dealloc(BitMapObject *self)
+{
+ Py_XDECREF(self->referred_object);
+ if (self->referred_bitmap) free(self->referred_bitmap);
+ PyMem_DEL(self);
+}
+
+static PyObject *BMObj_getdata(BitMapObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ int from, length;
+ char *cp;
+
+ if ( !PyArg_ParseTuple(_args, "ii", &from, &length) )
+ return NULL;
+ cp = _self->ob_itself->baseAddr+from;
+ return PyString_FromStringAndSize(cp, length);
+
+}
+
+static PyObject *BMObj_putdata(BitMapObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ int from, length;
+ char *cp, *icp;
+
+ if ( !PyArg_ParseTuple(_args, "is#", &from, &icp, &length) )
+ return NULL;
+ cp = _self->ob_itself->baseAddr+from;
+ memcpy(cp, icp, length);
+ Py_INCREF(Py_None);
+ return Py_None;
+
+}
+
+static PyMethodDef BMObj_methods[] = {
+ {"getdata", (PyCFunction)BMObj_getdata, 1,
+ "(int start, int size) -> string. Return bytes from the bitmap"},
+ {"putdata", (PyCFunction)BMObj_putdata, 1,
+ "(int start, string data). Store bytes into the bitmap"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain BMObj_chain = { BMObj_methods, NULL };
+
+static PyObject *BMObj_getattr(BitMapObject *self, char *name)
+{
+ if ( strcmp(name, "baseAddr") == 0 )
+ return PyInt_FromLong((long)self->ob_itself->baseAddr);
+ if ( strcmp(name, "rowBytes") == 0 )
+ return PyInt_FromLong((long)self->ob_itself->rowBytes);
+ if ( strcmp(name, "bounds") == 0 )
+ return Py_BuildValue("O&", PyMac_BuildRect, &self->ob_itself->bounds);
+ /* XXXX Add more, as needed */
+ if ( strcmp(name, "bitmap_data") == 0 )
+ return PyString_FromStringAndSize((char *)self->ob_itself, sizeof(BitMap));
+ if ( strcmp(name, "pixmap_data") == 0 )
+ return PyString_FromStringAndSize((char *)self->ob_itself, sizeof(PixMap));
+
+ return Py_FindMethodInChain(&BMObj_chain, (PyObject *)self, name);
+}
+
+#define BMObj_setattr NULL
+
+#define BMObj_compare NULL
+
+#define BMObj_repr NULL
+
+#define BMObj_hash NULL
+
+PyTypeObject BitMap_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "BitMap", /*tp_name*/
+ sizeof(BitMapObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) BMObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) BMObj_getattr, /*tp_getattr*/
+ (setattrfunc) BMObj_setattr, /*tp_setattr*/
+ (cmpfunc) BMObj_compare, /*tp_compare*/
+ (reprfunc) BMObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) BMObj_hash, /*tp_hash*/
+};
+
+/* --------------------- End object type BitMap --------------------- */
+
+
+/* ------------------ Object type QDGlobalsAccess ------------------- */
+
+staticforward PyTypeObject QDGlobalsAccess_Type;
+
+#define QDGA_Check(x) ((x)->ob_type == &QDGlobalsAccess_Type)
+
+typedef struct QDGlobalsAccessObject {
+ PyObject_HEAD
+} QDGlobalsAccessObject;
+
+static PyObject *QDGA_New(void)
+{
+ QDGlobalsAccessObject *it;
+ it = PyObject_NEW(QDGlobalsAccessObject, &QDGlobalsAccess_Type);
+ if (it == NULL) return NULL;
+ return (PyObject *)it;
+}
+
+static void QDGA_dealloc(QDGlobalsAccessObject *self)
+{
+ PyMem_DEL(self);
+}
+
+static PyMethodDef QDGA_methods[] = {
+ {NULL, NULL, 0}
+};
+
+static PyMethodChain QDGA_chain = { QDGA_methods, NULL };
+
+static PyObject *QDGA_getattr(QDGlobalsAccessObject *self, char *name)
+{
+#if !ACCESSOR_CALLS_ARE_FUNCTIONS
+
+ if ( strcmp(name, "arrow") == 0 )
+ return PyString_FromStringAndSize((char *)&qd.arrow, sizeof(qd.arrow));
+ if ( strcmp(name, "black") == 0 )
+ return PyString_FromStringAndSize((char *)&qd.black, sizeof(qd.black));
+ if ( strcmp(name, "white") == 0 )
+ return PyString_FromStringAndSize((char *)&qd.white, sizeof(qd.white));
+ if ( strcmp(name, "gray") == 0 )
+ return PyString_FromStringAndSize((char *)&qd.gray, sizeof(qd.gray));
+ if ( strcmp(name, "ltGray") == 0 )
+ return PyString_FromStringAndSize((char *)&qd.ltGray, sizeof(qd.ltGray));
+ if ( strcmp(name, "dkGray") == 0 )
+ return PyString_FromStringAndSize((char *)&qd.dkGray, sizeof(qd.dkGray));
+ if ( strcmp(name, "screenBits") == 0 )
+ return BMObj_New(&qd.screenBits);
+ if ( strcmp(name, "thePort") == 0 )
+ return GrafObj_New(qd.thePort);
+ if ( strcmp(name, "randSeed") == 0 )
+ return Py_BuildValue("l", &qd.randSeed);
+
+#else
+
+ if ( strcmp(name, "arrow") == 0 ) {
+ Cursor rv;
+ GetQDGlobalsArrow(&rv);
+ return PyString_FromStringAndSize((char *)&rv, sizeof(rv));
+ }
+ if ( strcmp(name, "black") == 0 ) {
+ Pattern rv;
+ GetQDGlobalsBlack(&rv);
+ return PyString_FromStringAndSize((char *)&rv, sizeof(rv));
+ }
+ if ( strcmp(name, "white") == 0 ) {
+ Pattern rv;
+ GetQDGlobalsWhite(&rv);
+ return PyString_FromStringAndSize((char *)&rv, sizeof(rv));
+ }
+ if ( strcmp(name, "gray") == 0 ) {
+ Pattern rv;
+ GetQDGlobalsGray(&rv);
+ return PyString_FromStringAndSize((char *)&rv, sizeof(rv));
+ }
+ if ( strcmp(name, "ltGray") == 0 ) {
+ Pattern rv;
+ GetQDGlobalsLightGray(&rv);
+ return PyString_FromStringAndSize((char *)&rv, sizeof(rv));
+ }
+ if ( strcmp(name, "dkGray") == 0 ) {
+ Pattern rv;
+ GetQDGlobalsDarkGray(&rv);
+ return PyString_FromStringAndSize((char *)&rv, sizeof(rv));
+ }
+ if ( strcmp(name, "screenBits") == 0 ) {
+ BitMap rv;
+ GetQDGlobalsScreenBits(&rv);
+ return BMObj_NewCopied(&rv);
+ }
+ if ( strcmp(name, "thePort") == 0 )
+ return GrafObj_New(GetQDGlobalsThePort());
+ if ( strcmp(name, "randSeed") == 0 )
+ return Py_BuildValue("l", GetQDGlobalsRandomSeed());
+
+#endif
+ return Py_FindMethodInChain(&QDGA_chain, (PyObject *)self, name);
+}
+
+#define QDGA_setattr NULL
+
+#define QDGA_compare NULL
+
+#define QDGA_repr NULL
+
+#define QDGA_hash NULL
+
+staticforward PyTypeObject QDGlobalsAccess_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "QDGlobalsAccess", /*tp_name*/
+ sizeof(QDGlobalsAccessObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) QDGA_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) QDGA_getattr, /*tp_getattr*/
+ (setattrfunc) QDGA_setattr, /*tp_setattr*/
+ (cmpfunc) QDGA_compare, /*tp_compare*/
+ (reprfunc) QDGA_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) QDGA_hash, /*tp_hash*/
+};
+
+/* ---------------- End object type QDGlobalsAccess ----------------- */
+
+
+static PyObject *Qd_MacSetPort(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ GrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ MacSetPort(port);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_GetPort(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ GrafPtr port;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetPort(&port);
+ _res = Py_BuildValue("O&",
+ GrafObj_New, port);
+ return _res;
+}
+
+static PyObject *Qd_GrafDevice(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short device;
+ if (!PyArg_ParseTuple(_args, "h",
+ &device))
+ return NULL;
+ GrafDevice(device);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetPortBits(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ BitMapPtr bm;
+ if (!PyArg_ParseTuple(_args, "O&",
+ BMObj_Convert, &bm))
+ return NULL;
+ SetPortBits(bm);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_PortSize(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short width;
+ short height;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &width,
+ &height))
+ return NULL;
+ PortSize(width,
+ height);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MovePortTo(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short leftGlobal;
+ short topGlobal;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &leftGlobal,
+ &topGlobal))
+ return NULL;
+ MovePortTo(leftGlobal,
+ topGlobal);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetOrigin(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short h;
+ short v;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &h,
+ &v))
+ return NULL;
+ SetOrigin(h,
+ v);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetClip(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &rgn))
+ return NULL;
+ SetClip(rgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_GetClip(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &rgn))
+ return NULL;
+ GetClip(rgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_ClipRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &r))
+ return NULL;
+ ClipRect(&r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_BackPat(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Pattern *pat__in__;
+ int pat__in_len__;
+ if (!PyArg_ParseTuple(_args, "s#",
+ (char **)&pat__in__, &pat__in_len__))
+ return NULL;
+ if (pat__in_len__ != sizeof(Pattern))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(Pattern)");
+ goto pat__error__;
+ }
+ BackPat(pat__in__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ pat__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_InitCursor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ InitCursor();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacSetCursor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Cursor *crsr__in__;
+ int crsr__in_len__;
+ if (!PyArg_ParseTuple(_args, "s#",
+ (char **)&crsr__in__, &crsr__in_len__))
+ return NULL;
+ if (crsr__in_len__ != sizeof(Cursor))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(Cursor)");
+ goto crsr__error__;
+ }
+ MacSetCursor(crsr__in__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ crsr__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_HideCursor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ HideCursor();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacShowCursor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ MacShowCursor();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_ObscureCursor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ ObscureCursor();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_HidePen(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ HidePen();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_ShowPen(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ ShowPen();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_GetPen(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Point pt;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetPen(&pt);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildPoint, pt);
+ return _res;
+}
+
+static PyObject *Qd_GetPenState(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PenState pnState__out__;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetPenState(&pnState__out__);
+ _res = Py_BuildValue("s#",
+ (char *)&pnState__out__, (int)sizeof(PenState));
+ pnState__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_SetPenState(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PenState *pnState__in__;
+ int pnState__in_len__;
+ if (!PyArg_ParseTuple(_args, "s#",
+ (char **)&pnState__in__, &pnState__in_len__))
+ return NULL;
+ if (pnState__in_len__ != sizeof(PenState))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(PenState)");
+ goto pnState__error__;
+ }
+ SetPenState(pnState__in__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ pnState__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_PenSize(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short width;
+ short height;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &width,
+ &height))
+ return NULL;
+ PenSize(width,
+ height);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_PenMode(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short mode;
+ if (!PyArg_ParseTuple(_args, "h",
+ &mode))
+ return NULL;
+ PenMode(mode);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_PenPat(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Pattern *pat__in__;
+ int pat__in_len__;
+ if (!PyArg_ParseTuple(_args, "s#",
+ (char **)&pat__in__, &pat__in_len__))
+ return NULL;
+ if (pat__in_len__ != sizeof(Pattern))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(Pattern)");
+ goto pat__error__;
+ }
+ PenPat(pat__in__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ pat__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_PenNormal(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ PenNormal();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MoveTo(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short h;
+ short v;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &h,
+ &v))
+ return NULL;
+ MoveTo(h,
+ v);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_Move(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short dh;
+ short dv;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &dh,
+ &dv))
+ return NULL;
+ Move(dh,
+ dv);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacLineTo(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short h;
+ short v;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &h,
+ &v))
+ return NULL;
+ MacLineTo(h,
+ v);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_Line(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short dh;
+ short dv;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &dh,
+ &dv))
+ return NULL;
+ Line(dh,
+ dv);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_ForeColor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ long color;
+ if (!PyArg_ParseTuple(_args, "l",
+ &color))
+ return NULL;
+ ForeColor(color);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_BackColor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ long color;
+ if (!PyArg_ParseTuple(_args, "l",
+ &color))
+ return NULL;
+ BackColor(color);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_ColorBit(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short whichBit;
+ if (!PyArg_ParseTuple(_args, "h",
+ &whichBit))
+ return NULL;
+ ColorBit(whichBit);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacSetRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short left;
+ short top;
+ short right;
+ short bottom;
+ if (!PyArg_ParseTuple(_args, "hhhh",
+ &left,
+ &top,
+ &right,
+ &bottom))
+ return NULL;
+ MacSetRect(&r,
+ left,
+ top,
+ right,
+ bottom);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &r);
+ return _res;
+}
+
+static PyObject *Qd_MacOffsetRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short dh;
+ short dv;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ PyMac_GetRect, &r,
+ &dh,
+ &dv))
+ return NULL;
+ MacOffsetRect(&r,
+ dh,
+ dv);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &r);
+ return _res;
+}
+
+static PyObject *Qd_MacInsetRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short dh;
+ short dv;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ PyMac_GetRect, &r,
+ &dh,
+ &dv))
+ return NULL;
+ MacInsetRect(&r,
+ dh,
+ dv);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &r);
+ return _res;
+}
+
+static PyObject *Qd_SectRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Rect src1;
+ Rect src2;
+ Rect dstRect;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetRect, &src1,
+ PyMac_GetRect, &src2))
+ return NULL;
+ _rv = SectRect(&src1,
+ &src2,
+ &dstRect);
+ _res = Py_BuildValue("bO&",
+ _rv,
+ PyMac_BuildRect, &dstRect);
+ return _res;
+}
+
+static PyObject *Qd_MacUnionRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect src1;
+ Rect src2;
+ Rect dstRect;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetRect, &src1,
+ PyMac_GetRect, &src2))
+ return NULL;
+ MacUnionRect(&src1,
+ &src2,
+ &dstRect);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &dstRect);
+ return _res;
+}
+
+static PyObject *Qd_MacEqualRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Rect rect1;
+ Rect rect2;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetRect, &rect1,
+ PyMac_GetRect, &rect2))
+ return NULL;
+ _rv = MacEqualRect(&rect1,
+ &rect2);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_EmptyRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &r))
+ return NULL;
+ _rv = EmptyRect(&r);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_MacFrameRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &r))
+ return NULL;
+ MacFrameRect(&r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_PaintRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &r))
+ return NULL;
+ PaintRect(&r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_EraseRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &r))
+ return NULL;
+ EraseRect(&r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacInvertRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &r))
+ return NULL;
+ MacInvertRect(&r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacFillRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ Pattern *pat__in__;
+ int pat__in_len__;
+ if (!PyArg_ParseTuple(_args, "O&s#",
+ PyMac_GetRect, &r,
+ (char **)&pat__in__, &pat__in_len__))
+ return NULL;
+ if (pat__in_len__ != sizeof(Pattern))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(Pattern)");
+ goto pat__error__;
+ }
+ MacFillRect(&r,
+ pat__in__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ pat__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_FrameOval(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &r))
+ return NULL;
+ FrameOval(&r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_PaintOval(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &r))
+ return NULL;
+ PaintOval(&r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_EraseOval(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &r))
+ return NULL;
+ EraseOval(&r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_InvertOval(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &r))
+ return NULL;
+ InvertOval(&r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_FillOval(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ Pattern *pat__in__;
+ int pat__in_len__;
+ if (!PyArg_ParseTuple(_args, "O&s#",
+ PyMac_GetRect, &r,
+ (char **)&pat__in__, &pat__in_len__))
+ return NULL;
+ if (pat__in_len__ != sizeof(Pattern))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(Pattern)");
+ goto pat__error__;
+ }
+ FillOval(&r,
+ pat__in__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ pat__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_FrameRoundRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short ovalWidth;
+ short ovalHeight;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ PyMac_GetRect, &r,
+ &ovalWidth,
+ &ovalHeight))
+ return NULL;
+ FrameRoundRect(&r,
+ ovalWidth,
+ ovalHeight);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_PaintRoundRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short ovalWidth;
+ short ovalHeight;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ PyMac_GetRect, &r,
+ &ovalWidth,
+ &ovalHeight))
+ return NULL;
+ PaintRoundRect(&r,
+ ovalWidth,
+ ovalHeight);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_EraseRoundRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short ovalWidth;
+ short ovalHeight;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ PyMac_GetRect, &r,
+ &ovalWidth,
+ &ovalHeight))
+ return NULL;
+ EraseRoundRect(&r,
+ ovalWidth,
+ ovalHeight);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_InvertRoundRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short ovalWidth;
+ short ovalHeight;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ PyMac_GetRect, &r,
+ &ovalWidth,
+ &ovalHeight))
+ return NULL;
+ InvertRoundRect(&r,
+ ovalWidth,
+ ovalHeight);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_FillRoundRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short ovalWidth;
+ short ovalHeight;
+ Pattern *pat__in__;
+ int pat__in_len__;
+ if (!PyArg_ParseTuple(_args, "O&hhs#",
+ PyMac_GetRect, &r,
+ &ovalWidth,
+ &ovalHeight,
+ (char **)&pat__in__, &pat__in_len__))
+ return NULL;
+ if (pat__in_len__ != sizeof(Pattern))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(Pattern)");
+ goto pat__error__;
+ }
+ FillRoundRect(&r,
+ ovalWidth,
+ ovalHeight,
+ pat__in__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ pat__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_FrameArc(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short startAngle;
+ short arcAngle;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ PyMac_GetRect, &r,
+ &startAngle,
+ &arcAngle))
+ return NULL;
+ FrameArc(&r,
+ startAngle,
+ arcAngle);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_PaintArc(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short startAngle;
+ short arcAngle;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ PyMac_GetRect, &r,
+ &startAngle,
+ &arcAngle))
+ return NULL;
+ PaintArc(&r,
+ startAngle,
+ arcAngle);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_EraseArc(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short startAngle;
+ short arcAngle;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ PyMac_GetRect, &r,
+ &startAngle,
+ &arcAngle))
+ return NULL;
+ EraseArc(&r,
+ startAngle,
+ arcAngle);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_InvertArc(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short startAngle;
+ short arcAngle;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ PyMac_GetRect, &r,
+ &startAngle,
+ &arcAngle))
+ return NULL;
+ InvertArc(&r,
+ startAngle,
+ arcAngle);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_FillArc(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short startAngle;
+ short arcAngle;
+ Pattern *pat__in__;
+ int pat__in_len__;
+ if (!PyArg_ParseTuple(_args, "O&hhs#",
+ PyMac_GetRect, &r,
+ &startAngle,
+ &arcAngle,
+ (char **)&pat__in__, &pat__in_len__))
+ return NULL;
+ if (pat__in_len__ != sizeof(Pattern))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(Pattern)");
+ goto pat__error__;
+ }
+ FillArc(&r,
+ startAngle,
+ arcAngle,
+ pat__in__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ pat__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_NewRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = NewRgn();
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_OpenRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ OpenRgn();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_CloseRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle dstRgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &dstRgn))
+ return NULL;
+ CloseRgn(dstRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_BitMapToRegion(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ RgnHandle region;
+ BitMapPtr bMap;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, ®ion,
+ BMObj_Convert, &bMap))
+ return NULL;
+ _err = BitMapToRegion(region,
+ bMap);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_DisposeRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &rgn))
+ return NULL;
+ DisposeRgn(rgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacCopyRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle srcRgn;
+ RgnHandle dstRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, &srcRgn,
+ ResObj_Convert, &dstRgn))
+ return NULL;
+ MacCopyRgn(srcRgn,
+ dstRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetEmptyRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &rgn))
+ return NULL;
+ SetEmptyRgn(rgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacSetRectRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ short left;
+ short top;
+ short right;
+ short bottom;
+ if (!PyArg_ParseTuple(_args, "O&hhhh",
+ ResObj_Convert, &rgn,
+ &left,
+ &top,
+ &right,
+ &bottom))
+ return NULL;
+ MacSetRectRgn(rgn,
+ left,
+ top,
+ right,
+ bottom);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_RectRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, &rgn,
+ PyMac_GetRect, &r))
+ return NULL;
+ RectRgn(rgn,
+ &r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacOffsetRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ short dh;
+ short dv;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ ResObj_Convert, &rgn,
+ &dh,
+ &dv))
+ return NULL;
+ MacOffsetRgn(rgn,
+ dh,
+ dv);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_InsetRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ short dh;
+ short dv;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ ResObj_Convert, &rgn,
+ &dh,
+ &dv))
+ return NULL;
+ InsetRgn(rgn,
+ dh,
+ dv);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SectRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle srcRgnA;
+ RgnHandle srcRgnB;
+ RgnHandle dstRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&O&",
+ ResObj_Convert, &srcRgnA,
+ ResObj_Convert, &srcRgnB,
+ ResObj_Convert, &dstRgn))
+ return NULL;
+ SectRgn(srcRgnA,
+ srcRgnB,
+ dstRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacUnionRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle srcRgnA;
+ RgnHandle srcRgnB;
+ RgnHandle dstRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&O&",
+ ResObj_Convert, &srcRgnA,
+ ResObj_Convert, &srcRgnB,
+ ResObj_Convert, &dstRgn))
+ return NULL;
+ MacUnionRgn(srcRgnA,
+ srcRgnB,
+ dstRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_DiffRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle srcRgnA;
+ RgnHandle srcRgnB;
+ RgnHandle dstRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&O&",
+ ResObj_Convert, &srcRgnA,
+ ResObj_Convert, &srcRgnB,
+ ResObj_Convert, &dstRgn))
+ return NULL;
+ DiffRgn(srcRgnA,
+ srcRgnB,
+ dstRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacXorRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle srcRgnA;
+ RgnHandle srcRgnB;
+ RgnHandle dstRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&O&",
+ ResObj_Convert, &srcRgnA,
+ ResObj_Convert, &srcRgnB,
+ ResObj_Convert, &dstRgn))
+ return NULL;
+ MacXorRgn(srcRgnA,
+ srcRgnB,
+ dstRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_RectInRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Rect r;
+ RgnHandle rgn;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetRect, &r,
+ ResObj_Convert, &rgn))
+ return NULL;
+ _rv = RectInRgn(&r,
+ rgn);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_MacEqualRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ RgnHandle rgnA;
+ RgnHandle rgnB;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, &rgnA,
+ ResObj_Convert, &rgnB))
+ return NULL;
+ _rv = MacEqualRgn(rgnA,
+ rgnB);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_EmptyRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ RgnHandle rgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &rgn))
+ return NULL;
+ _rv = EmptyRgn(rgn);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_MacFrameRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &rgn))
+ return NULL;
+ MacFrameRgn(rgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacPaintRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &rgn))
+ return NULL;
+ MacPaintRgn(rgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_EraseRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &rgn))
+ return NULL;
+ EraseRgn(rgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacInvertRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &rgn))
+ return NULL;
+ MacInvertRgn(rgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacFillRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ Pattern *pat__in__;
+ int pat__in_len__;
+ if (!PyArg_ParseTuple(_args, "O&s#",
+ ResObj_Convert, &rgn,
+ (char **)&pat__in__, &pat__in_len__))
+ return NULL;
+ if (pat__in_len__ != sizeof(Pattern))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(Pattern)");
+ goto pat__error__;
+ }
+ MacFillRgn(rgn,
+ pat__in__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ pat__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_ScrollRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short dh;
+ short dv;
+ RgnHandle updateRgn;
+ if (!PyArg_ParseTuple(_args, "O&hhO&",
+ PyMac_GetRect, &r,
+ &dh,
+ &dv,
+ ResObj_Convert, &updateRgn))
+ return NULL;
+ ScrollRect(&r,
+ dh,
+ dv,
+ updateRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_CopyBits(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ BitMapPtr srcBits;
+ BitMapPtr dstBits;
+ Rect srcRect;
+ Rect dstRect;
+ short mode;
+ RgnHandle maskRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&O&O&hO&",
+ BMObj_Convert, &srcBits,
+ BMObj_Convert, &dstBits,
+ PyMac_GetRect, &srcRect,
+ PyMac_GetRect, &dstRect,
+ &mode,
+ OptResObj_Convert, &maskRgn))
+ return NULL;
+ CopyBits(srcBits,
+ dstBits,
+ &srcRect,
+ &dstRect,
+ mode,
+ maskRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_CopyMask(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ BitMapPtr srcBits;
+ BitMapPtr maskBits;
+ BitMapPtr dstBits;
+ Rect srcRect;
+ Rect maskRect;
+ Rect dstRect;
+ if (!PyArg_ParseTuple(_args, "O&O&O&O&O&O&",
+ BMObj_Convert, &srcBits,
+ BMObj_Convert, &maskBits,
+ BMObj_Convert, &dstBits,
+ PyMac_GetRect, &srcRect,
+ PyMac_GetRect, &maskRect,
+ PyMac_GetRect, &dstRect))
+ return NULL;
+ CopyMask(srcBits,
+ maskBits,
+ dstBits,
+ &srcRect,
+ &maskRect,
+ &dstRect);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_OpenPicture(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PicHandle _rv;
+ Rect picFrame;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &picFrame))
+ return NULL;
+ _rv = OpenPicture(&picFrame);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_PicComment(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short kind;
+ short dataSize;
+ Handle dataHandle;
+ if (!PyArg_ParseTuple(_args, "hhO&",
+ &kind,
+ &dataSize,
+ ResObj_Convert, &dataHandle))
+ return NULL;
+ PicComment(kind,
+ dataSize,
+ dataHandle);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_ClosePicture(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ ClosePicture();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_DrawPicture(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PicHandle myPicture;
+ Rect dstRect;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, &myPicture,
+ PyMac_GetRect, &dstRect))
+ return NULL;
+ DrawPicture(myPicture,
+ &dstRect);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_KillPicture(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PicHandle myPicture;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &myPicture))
+ return NULL;
+ KillPicture(myPicture);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_OpenPoly(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PolyHandle _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = OpenPoly();
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_ClosePoly(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ ClosePoly();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_KillPoly(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PolyHandle poly;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &poly))
+ return NULL;
+ KillPoly(poly);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_OffsetPoly(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PolyHandle poly;
+ short dh;
+ short dv;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ ResObj_Convert, &poly,
+ &dh,
+ &dv))
+ return NULL;
+ OffsetPoly(poly,
+ dh,
+ dv);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_FramePoly(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PolyHandle poly;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &poly))
+ return NULL;
+ FramePoly(poly);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_PaintPoly(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PolyHandle poly;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &poly))
+ return NULL;
+ PaintPoly(poly);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_ErasePoly(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PolyHandle poly;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &poly))
+ return NULL;
+ ErasePoly(poly);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_InvertPoly(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PolyHandle poly;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &poly))
+ return NULL;
+ InvertPoly(poly);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_FillPoly(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PolyHandle poly;
+ Pattern *pat__in__;
+ int pat__in_len__;
+ if (!PyArg_ParseTuple(_args, "O&s#",
+ ResObj_Convert, &poly,
+ (char **)&pat__in__, &pat__in_len__))
+ return NULL;
+ if (pat__in_len__ != sizeof(Pattern))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(Pattern)");
+ goto pat__error__;
+ }
+ FillPoly(poly,
+ pat__in__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ pat__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_SetPt(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Point pt;
+ short h;
+ short v;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &h,
+ &v))
+ return NULL;
+ SetPt(&pt,
+ h,
+ v);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildPoint, pt);
+ return _res;
+}
+
+static PyObject *Qd_LocalToGlobal(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Point pt;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetPoint, &pt))
+ return NULL;
+ LocalToGlobal(&pt);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildPoint, pt);
+ return _res;
+}
+
+static PyObject *Qd_GlobalToLocal(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Point pt;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetPoint, &pt))
+ return NULL;
+ GlobalToLocal(&pt);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildPoint, pt);
+ return _res;
+}
+
+static PyObject *Qd_Random(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = Random();
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_MacGetPixel(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ short h;
+ short v;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &h,
+ &v))
+ return NULL;
+ _rv = MacGetPixel(h,
+ v);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_ScalePt(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Point pt;
+ Rect srcRect;
+ Rect dstRect;
+ if (!PyArg_ParseTuple(_args, "O&O&O&",
+ PyMac_GetPoint, &pt,
+ PyMac_GetRect, &srcRect,
+ PyMac_GetRect, &dstRect))
+ return NULL;
+ ScalePt(&pt,
+ &srcRect,
+ &dstRect);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildPoint, pt);
+ return _res;
+}
+
+static PyObject *Qd_MapPt(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Point pt;
+ Rect srcRect;
+ Rect dstRect;
+ if (!PyArg_ParseTuple(_args, "O&O&O&",
+ PyMac_GetPoint, &pt,
+ PyMac_GetRect, &srcRect,
+ PyMac_GetRect, &dstRect))
+ return NULL;
+ MapPt(&pt,
+ &srcRect,
+ &dstRect);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildPoint, pt);
+ return _res;
+}
+
+static PyObject *Qd_MapRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ Rect srcRect;
+ Rect dstRect;
+ if (!PyArg_ParseTuple(_args, "O&O&O&",
+ PyMac_GetRect, &r,
+ PyMac_GetRect, &srcRect,
+ PyMac_GetRect, &dstRect))
+ return NULL;
+ MapRect(&r,
+ &srcRect,
+ &dstRect);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &r);
+ return _res;
+}
+
+static PyObject *Qd_MapRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ Rect srcRect;
+ Rect dstRect;
+ if (!PyArg_ParseTuple(_args, "O&O&O&",
+ ResObj_Convert, &rgn,
+ PyMac_GetRect, &srcRect,
+ PyMac_GetRect, &dstRect))
+ return NULL;
+ MapRgn(rgn,
+ &srcRect,
+ &dstRect);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MapPoly(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PolyHandle poly;
+ Rect srcRect;
+ Rect dstRect;
+ if (!PyArg_ParseTuple(_args, "O&O&O&",
+ ResObj_Convert, &poly,
+ PyMac_GetRect, &srcRect,
+ PyMac_GetRect, &dstRect))
+ return NULL;
+ MapPoly(poly,
+ &srcRect,
+ &dstRect);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_StdBits(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ BitMapPtr srcBits;
+ Rect srcRect;
+ Rect dstRect;
+ short mode;
+ RgnHandle maskRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&O&hO&",
+ BMObj_Convert, &srcBits,
+ PyMac_GetRect, &srcRect,
+ PyMac_GetRect, &dstRect,
+ &mode,
+ OptResObj_Convert, &maskRgn))
+ return NULL;
+ StdBits(srcBits,
+ &srcRect,
+ &dstRect,
+ mode,
+ maskRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_AddPt(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Point src;
+ Point dst;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &src,
+ PyMac_GetPoint, &dst))
+ return NULL;
+ AddPt(src,
+ &dst);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildPoint, dst);
+ return _res;
+}
+
+static PyObject *Qd_EqualPt(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Point pt1;
+ Point pt2;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &pt1,
+ PyMac_GetPoint, &pt2))
+ return NULL;
+ _rv = EqualPt(pt1,
+ pt2);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_MacPtInRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Point pt;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &pt,
+ PyMac_GetRect, &r))
+ return NULL;
+ _rv = MacPtInRect(pt,
+ &r);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_Pt2Rect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Point pt1;
+ Point pt2;
+ Rect dstRect;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &pt1,
+ PyMac_GetPoint, &pt2))
+ return NULL;
+ Pt2Rect(pt1,
+ pt2,
+ &dstRect);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &dstRect);
+ return _res;
+}
+
+static PyObject *Qd_PtToAngle(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ Point pt;
+ short angle;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetRect, &r,
+ PyMac_GetPoint, &pt))
+ return NULL;
+ PtToAngle(&r,
+ pt,
+ &angle);
+ _res = Py_BuildValue("h",
+ angle);
+ return _res;
+}
+
+static PyObject *Qd_SubPt(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Point src;
+ Point dst;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &src,
+ PyMac_GetPoint, &dst))
+ return NULL;
+ SubPt(src,
+ &dst);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildPoint, dst);
+ return _res;
+}
+
+static PyObject *Qd_PtInRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Point pt;
+ RgnHandle rgn;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &pt,
+ ResObj_Convert, &rgn))
+ return NULL;
+ _rv = PtInRgn(pt,
+ rgn);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_NewPixMap(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixMapHandle _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = NewPixMap();
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_DisposePixMap(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixMapHandle pm;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &pm))
+ return NULL;
+ DisposePixMap(pm);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_CopyPixMap(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixMapHandle srcPM;
+ PixMapHandle dstPM;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, &srcPM,
+ ResObj_Convert, &dstPM))
+ return NULL;
+ CopyPixMap(srcPM,
+ dstPM);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_NewPixPat(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixPatHandle _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = NewPixPat();
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_DisposePixPat(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixPatHandle pp;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &pp))
+ return NULL;
+ DisposePixPat(pp);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_CopyPixPat(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixPatHandle srcPP;
+ PixPatHandle dstPP;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, &srcPP,
+ ResObj_Convert, &dstPP))
+ return NULL;
+ CopyPixPat(srcPP,
+ dstPP);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_PenPixPat(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixPatHandle pp;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &pp))
+ return NULL;
+ PenPixPat(pp);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_BackPixPat(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixPatHandle pp;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &pp))
+ return NULL;
+ BackPixPat(pp);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_GetPixPat(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixPatHandle _rv;
+ short patID;
+ if (!PyArg_ParseTuple(_args, "h",
+ &patID))
+ return NULL;
+ _rv = GetPixPat(patID);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_MakeRGBPat(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(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ PixPatHandle pp;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetRect, &r,
+ ResObj_Convert, &pp))
+ return NULL;
+ FillCRect(&r,
+ pp);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_FillCOval(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ PixPatHandle pp;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetRect, &r,
+ ResObj_Convert, &pp))
+ return NULL;
+ FillCOval(&r,
+ pp);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_FillCRoundRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short ovalWidth;
+ short ovalHeight;
+ PixPatHandle pp;
+ if (!PyArg_ParseTuple(_args, "O&hhO&",
+ PyMac_GetRect, &r,
+ &ovalWidth,
+ &ovalHeight,
+ ResObj_Convert, &pp))
+ return NULL;
+ FillCRoundRect(&r,
+ ovalWidth,
+ ovalHeight,
+ pp);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_FillCArc(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short startAngle;
+ short arcAngle;
+ PixPatHandle pp;
+ if (!PyArg_ParseTuple(_args, "O&hhO&",
+ PyMac_GetRect, &r,
+ &startAngle,
+ &arcAngle,
+ ResObj_Convert, &pp))
+ return NULL;
+ FillCArc(&r,
+ startAngle,
+ arcAngle,
+ pp);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_FillCRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ PixPatHandle pp;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, &rgn,
+ ResObj_Convert, &pp))
+ return NULL;
+ FillCRgn(rgn,
+ pp);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_FillCPoly(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PolyHandle poly;
+ PixPatHandle pp;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, &poly,
+ ResObj_Convert, &pp))
+ return NULL;
+ FillCPoly(poly,
+ pp);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_RGBForeColor(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(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(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(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixMapHandle pm;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &pm))
+ return NULL;
+ SetPortPix(pm);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_GetCPixel(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(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(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(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(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_DisposeCTable(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CTabHandle cTable;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &cTable))
+ return NULL;
+ DisposeCTable(cTable);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_GetCTable(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CTabHandle _rv;
+ short ctID;
+ if (!PyArg_ParseTuple(_args, "h",
+ &ctID))
+ return NULL;
+ _rv = GetCTable(ctID);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetCCursor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CCrsrHandle _rv;
+ short crsrID;
+ if (!PyArg_ParseTuple(_args, "h",
+ &crsrID))
+ return NULL;
+ _rv = GetCCursor(crsrID);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_SetCCursor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CCrsrHandle cCrsr;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &cCrsr))
+ return NULL;
+ SetCCursor(cCrsr);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_AllocCursor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ AllocCursor();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_DisposeCCursor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CCrsrHandle cCrsr;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &cCrsr))
+ return NULL;
+ DisposeCCursor(cCrsr);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_GetMaxDevice(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ GDHandle _rv;
+ Rect globalRect;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &globalRect))
+ return NULL;
+ _rv = GetMaxDevice(&globalRect);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetCTSeed(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ long _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetCTSeed();
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetDeviceList(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ GDHandle _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetDeviceList();
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetMainDevice(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ GDHandle _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetMainDevice();
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetNextDevice(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ GDHandle _rv;
+ GDHandle curDevice;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &curDevice))
+ return NULL;
+ _rv = GetNextDevice(curDevice);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_TestDeviceAttribute(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ GDHandle gdh;
+ short attribute;
+ if (!PyArg_ParseTuple(_args, "O&h",
+ ResObj_Convert, &gdh,
+ &attribute))
+ return NULL;
+ _rv = TestDeviceAttribute(gdh,
+ attribute);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_SetDeviceAttribute(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ GDHandle gdh;
+ short attribute;
+ Boolean value;
+ if (!PyArg_ParseTuple(_args, "O&hb",
+ ResObj_Convert, &gdh,
+ &attribute,
+ &value))
+ return NULL;
+ SetDeviceAttribute(gdh,
+ attribute,
+ value);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_InitGDevice(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short qdRefNum;
+ long mode;
+ GDHandle gdh;
+ if (!PyArg_ParseTuple(_args, "hlO&",
+ &qdRefNum,
+ &mode,
+ ResObj_Convert, &gdh))
+ return NULL;
+ InitGDevice(qdRefNum,
+ mode,
+ gdh);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_NewGDevice(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ GDHandle _rv;
+ short refNum;
+ long mode;
+ if (!PyArg_ParseTuple(_args, "hl",
+ &refNum,
+ &mode))
+ return NULL;
+ _rv = NewGDevice(refNum,
+ mode);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_DisposeGDevice(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ GDHandle gdh;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &gdh))
+ return NULL;
+ DisposeGDevice(gdh);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetGDevice(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ GDHandle gd;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &gd))
+ return NULL;
+ SetGDevice(gd);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_GetGDevice(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ GDHandle _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetGDevice();
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_Color2Index(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(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(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(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_GetSubTable(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CTabHandle myColors;
+ short iTabRes;
+ CTabHandle targetTbl;
+ if (!PyArg_ParseTuple(_args, "O&hO&",
+ ResObj_Convert, &myColors,
+ &iTabRes,
+ ResObj_Convert, &targetTbl))
+ return NULL;
+ GetSubTable(myColors,
+ iTabRes,
+ targetTbl);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MakeITable(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CTabHandle cTabH;
+ ITabHandle iTabH;
+ short res;
+ if (!PyArg_ParseTuple(_args, "O&O&h",
+ ResObj_Convert, &cTabH,
+ ResObj_Convert, &iTabH,
+ &res))
+ return NULL;
+ MakeITable(cTabH,
+ iTabH,
+ res);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetClientID(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short id;
+ if (!PyArg_ParseTuple(_args, "h",
+ &id))
+ return NULL;
+ SetClientID(id);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_ProtectEntry(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short index;
+ Boolean protect;
+ if (!PyArg_ParseTuple(_args, "hb",
+ &index,
+ &protect))
+ return NULL;
+ ProtectEntry(index,
+ protect);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_ReserveEntry(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short index;
+ Boolean reserve;
+ if (!PyArg_ParseTuple(_args, "hb",
+ &index,
+ &reserve))
+ return NULL;
+ ReserveEntry(index,
+ reserve);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_QDError(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = QDError();
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_CopyDeepMask(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ BitMapPtr srcBits;
+ BitMapPtr maskBits;
+ BitMapPtr dstBits;
+ Rect srcRect;
+ Rect maskRect;
+ Rect dstRect;
+ short mode;
+ RgnHandle maskRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&O&O&O&O&hO&",
+ BMObj_Convert, &srcBits,
+ BMObj_Convert, &maskBits,
+ BMObj_Convert, &dstBits,
+ PyMac_GetRect, &srcRect,
+ PyMac_GetRect, &maskRect,
+ PyMac_GetRect, &dstRect,
+ &mode,
+ OptResObj_Convert, &maskRgn))
+ return NULL;
+ CopyDeepMask(srcBits,
+ maskBits,
+ dstBits,
+ &srcRect,
+ &maskRect,
+ &dstRect,
+ mode,
+ maskRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_GetPattern(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PatHandle _rv;
+ short patternID;
+ if (!PyArg_ParseTuple(_args, "h",
+ &patternID))
+ return NULL;
+ _rv = GetPattern(patternID);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_MacGetCursor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CursHandle _rv;
+ short cursorID;
+ if (!PyArg_ParseTuple(_args, "h",
+ &cursorID))
+ return NULL;
+ _rv = MacGetCursor(cursorID);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPicture(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PicHandle _rv;
+ short pictureID;
+ if (!PyArg_ParseTuple(_args, "h",
+ &pictureID))
+ return NULL;
+ _rv = GetPicture(pictureID);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_DeltaPoint(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ long _rv;
+ Point ptA;
+ Point ptB;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &ptA,
+ PyMac_GetPoint, &ptB))
+ return NULL;
+ _rv = DeltaPoint(ptA,
+ ptB);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_ShieldCursor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect shieldRect;
+ Point offsetPt;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetRect, &shieldRect,
+ PyMac_GetPoint, &offsetPt))
+ return NULL;
+ ShieldCursor(&shieldRect,
+ offsetPt);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_ScreenRes(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short scrnHRes;
+ short scrnVRes;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ ScreenRes(&scrnHRes,
+ &scrnVRes);
+ _res = Py_BuildValue("hh",
+ scrnHRes,
+ scrnVRes);
+ return _res;
+}
+
+static PyObject *Qd_GetIndPattern(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Pattern thePat__out__;
+ short patternListID;
+ short index;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &patternListID,
+ &index))
+ return NULL;
+ GetIndPattern(&thePat__out__,
+ patternListID,
+ index);
+ _res = Py_BuildValue("s#",
+ (char *)&thePat__out__, (int)sizeof(Pattern));
+ thePat__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_SlopeFromAngle(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Fixed _rv;
+ short angle;
+ if (!PyArg_ParseTuple(_args, "h",
+ &angle))
+ return NULL;
+ _rv = SlopeFromAngle(angle);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildFixed, _rv);
+ return _res;
+}
+
+static PyObject *Qd_AngleFromSlope(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ Fixed slope;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetFixed, &slope))
+ return NULL;
+ _rv = AngleFromSlope(slope);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortPixMap(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixMapHandle _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = GetPortPixMap(port);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortBitMapForCopyBits(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ const BitMap * _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = GetPortBitMapForCopyBits(port);
+ _res = Py_BuildValue("O&",
+ BMObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortBounds(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ Rect rect;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ GetPortBounds(port,
+ &rect);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &rect);
+ return _res;
+}
+
+static PyObject *Qd_GetPortForeColor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ RGBColor foreColor;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ GetPortForeColor(port,
+ &foreColor);
+ _res = Py_BuildValue("O&",
+ QdRGB_New, &foreColor);
+ return _res;
+}
+
+static PyObject *Qd_GetPortBackColor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ RGBColor backColor;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ GetPortBackColor(port,
+ &backColor);
+ _res = Py_BuildValue("O&",
+ QdRGB_New, &backColor);
+ return _res;
+}
+
+static PyObject *Qd_GetPortOpColor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ RGBColor opColor;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ GetPortOpColor(port,
+ &opColor);
+ _res = Py_BuildValue("O&",
+ QdRGB_New, &opColor);
+ return _res;
+}
+
+static PyObject *Qd_GetPortHiliteColor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ RGBColor hiliteColor;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ GetPortHiliteColor(port,
+ &hiliteColor);
+ _res = Py_BuildValue("O&",
+ QdRGB_New, &hiliteColor);
+ return _res;
+}
+
+static PyObject *Qd_GetPortTextFont(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = GetPortTextFont(port);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortTextFace(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Style _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = GetPortTextFace(port);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortTextMode(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = GetPortTextMode(port);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortTextSize(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = GetPortTextSize(port);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortChExtra(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = GetPortChExtra(port);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortFracHPenLocation(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = GetPortFracHPenLocation(port);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortSpExtra(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Fixed _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = GetPortSpExtra(port);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildFixed, _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortPenVisibility(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = GetPortPenVisibility(port);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortVisibleRegion(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle _rv;
+ CGrafPtr port;
+ RgnHandle visRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ ResObj_Convert, &visRgn))
+ return NULL;
+ _rv = GetPortVisibleRegion(port,
+ visRgn);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortClipRegion(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle _rv;
+ CGrafPtr port;
+ RgnHandle clipRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ ResObj_Convert, &clipRgn))
+ return NULL;
+ _rv = GetPortClipRegion(port,
+ clipRgn);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortBackPixPat(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixPatHandle _rv;
+ CGrafPtr port;
+ PixPatHandle backPattern;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ ResObj_Convert, &backPattern))
+ return NULL;
+ _rv = GetPortBackPixPat(port,
+ backPattern);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortPenPixPat(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixPatHandle _rv;
+ CGrafPtr port;
+ PixPatHandle penPattern;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ ResObj_Convert, &penPattern))
+ return NULL;
+ _rv = GetPortPenPixPat(port,
+ penPattern);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortFillPixPat(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixPatHandle _rv;
+ CGrafPtr port;
+ PixPatHandle fillPattern;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ ResObj_Convert, &fillPattern))
+ return NULL;
+ _rv = GetPortFillPixPat(port,
+ fillPattern);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortPenSize(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ Point penSize;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ PyMac_GetPoint, &penSize))
+ return NULL;
+ GetPortPenSize(port,
+ &penSize);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildPoint, penSize);
+ return _res;
+}
+
+static PyObject *Qd_GetPortPenMode(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = GetPortPenMode(port);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetPortPenLocation(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ Point penLocation;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ PyMac_GetPoint, &penLocation))
+ return NULL;
+ GetPortPenLocation(port,
+ &penLocation);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildPoint, penLocation);
+ return _res;
+}
+
+static PyObject *Qd_IsPortRegionBeingDefined(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = IsPortRegionBeingDefined(port);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_IsPortPictureBeingDefined(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = IsPortPictureBeingDefined(port);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *Qd_IsPortOffscreen(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = IsPortOffscreen(port);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *Qd_IsPortColor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = IsPortColor(port);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+#endif
+
+static PyObject *Qd_SetPortBounds(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ Rect rect;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ PyMac_GetRect, &rect))
+ return NULL;
+ SetPortBounds(port,
+ &rect);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetPortOpColor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ RGBColor opColor;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ QdRGB_Convert, &opColor))
+ return NULL;
+ SetPortOpColor(port,
+ &opColor);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetPortVisibleRegion(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ RgnHandle visRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ ResObj_Convert, &visRgn))
+ return NULL;
+ SetPortVisibleRegion(port,
+ visRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetPortClipRegion(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ RgnHandle clipRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ ResObj_Convert, &clipRgn))
+ return NULL;
+ SetPortClipRegion(port,
+ clipRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetPortPenPixPat(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ PixPatHandle penPattern;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ ResObj_Convert, &penPattern))
+ return NULL;
+ SetPortPenPixPat(port,
+ penPattern);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetPortBackPixPat(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ PixPatHandle backPattern;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ ResObj_Convert, &backPattern))
+ return NULL;
+ SetPortBackPixPat(port,
+ backPattern);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetPortPenSize(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ Point penSize;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ PyMac_GetPoint, &penSize))
+ return NULL;
+ SetPortPenSize(port,
+ penSize);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetPortPenMode(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ SInt32 penMode;
+ if (!PyArg_ParseTuple(_args, "O&l",
+ GrafObj_Convert, &port,
+ &penMode))
+ return NULL;
+ SetPortPenMode(port,
+ penMode);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetPortFracHPenLocation(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ short pnLocHFrac;
+ if (!PyArg_ParseTuple(_args, "O&h",
+ GrafObj_Convert, &port,
+ &pnLocHFrac))
+ return NULL;
+ SetPortFracHPenLocation(port,
+ pnLocHFrac);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_GetPixBounds(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixMapHandle pixMap;
+ Rect bounds;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &pixMap))
+ return NULL;
+ GetPixBounds(pixMap,
+ &bounds);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &bounds);
+ return _res;
+}
+
+static PyObject *Qd_GetPixDepth(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ PixMapHandle pixMap;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &pixMap))
+ return NULL;
+ _rv = GetPixDepth(pixMap);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetQDGlobalsRandomSeed(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ long _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetQDGlobalsRandomSeed();
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_GetQDGlobalsScreenBits(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ BitMap screenBits;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetQDGlobalsScreenBits(&screenBits);
+ _res = Py_BuildValue("O&",
+ BMObj_NewCopied, &screenBits);
+ return _res;
+}
+
+static PyObject *Qd_GetQDGlobalsArrow(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Cursor arrow__out__;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetQDGlobalsArrow(&arrow__out__);
+ _res = Py_BuildValue("s#",
+ (char *)&arrow__out__, (int)sizeof(Cursor));
+ arrow__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_GetQDGlobalsDarkGray(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Pattern dkGray__out__;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetQDGlobalsDarkGray(&dkGray__out__);
+ _res = Py_BuildValue("s#",
+ (char *)&dkGray__out__, (int)sizeof(Pattern));
+ dkGray__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_GetQDGlobalsLightGray(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Pattern ltGray__out__;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetQDGlobalsLightGray(<Gray__out__);
+ _res = Py_BuildValue("s#",
+ (char *)<Gray__out__, (int)sizeof(Pattern));
+ ltGray__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_GetQDGlobalsGray(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Pattern gray__out__;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetQDGlobalsGray(&gray__out__);
+ _res = Py_BuildValue("s#",
+ (char *)&gray__out__, (int)sizeof(Pattern));
+ gray__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_GetQDGlobalsBlack(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Pattern black__out__;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetQDGlobalsBlack(&black__out__);
+ _res = Py_BuildValue("s#",
+ (char *)&black__out__, (int)sizeof(Pattern));
+ black__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_GetQDGlobalsWhite(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Pattern white__out__;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetQDGlobalsWhite(&white__out__);
+ _res = Py_BuildValue("s#",
+ (char *)&white__out__, (int)sizeof(Pattern));
+ white__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_GetQDGlobalsThePort(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetQDGlobalsThePort();
+ _res = Py_BuildValue("O&",
+ GrafObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_SetQDGlobalsRandomSeed(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ long randomSeed;
+ if (!PyArg_ParseTuple(_args, "l",
+ &randomSeed))
+ return NULL;
+ SetQDGlobalsRandomSeed(randomSeed);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetQDGlobalsArrow(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Cursor *arrow__in__;
+ int arrow__in_len__;
+ if (!PyArg_ParseTuple(_args, "s#",
+ (char **)&arrow__in__, &arrow__in_len__))
+ return NULL;
+ if (arrow__in_len__ != sizeof(Cursor))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(Cursor)");
+ goto arrow__error__;
+ }
+ SetQDGlobalsArrow(arrow__in__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ arrow__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_GetRegionBounds(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle region;
+ Rect bounds;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, ®ion))
+ return NULL;
+ GetRegionBounds(region,
+ &bounds);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &bounds);
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *Qd_IsRegionRectangular(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ RgnHandle region;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, ®ion))
+ return NULL;
+ _rv = IsRegionRectangular(region);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *Qd_CreateNewPort(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CreateNewPort();
+ _res = Py_BuildValue("O&",
+ GrafObj_New, _rv);
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *Qd_DisposePort(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ DisposePort(port);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *Qd_SetQDError(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr err;
+ if (!PyArg_ParseTuple(_args, "h",
+ &err))
+ return NULL;
+ SetQDError(err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *Qd_QDIsPortBuffered(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = QDIsPortBuffered(port);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_QDIsPortBufferDirty(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = QDIsPortBufferDirty(port);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_QDFlushPortBuffer(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr port;
+ RgnHandle region;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ GrafObj_Convert, &port,
+ OptResObj_Convert, ®ion))
+ return NULL;
+ QDFlushPortBuffer(port,
+ region);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_TextFont(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short font;
+ if (!PyArg_ParseTuple(_args, "h",
+ &font))
+ return NULL;
+ TextFont(font);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_TextFace(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ StyleParameter face;
+ if (!PyArg_ParseTuple(_args, "h",
+ &face))
+ return NULL;
+ TextFace(face);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_TextMode(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short mode;
+ if (!PyArg_ParseTuple(_args, "h",
+ &mode))
+ return NULL;
+ TextMode(mode);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_TextSize(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short size;
+ if (!PyArg_ParseTuple(_args, "h",
+ &size))
+ return NULL;
+ TextSize(size);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SpaceExtra(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Fixed extra;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetFixed, &extra))
+ return NULL;
+ SpaceExtra(extra);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_DrawChar(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CharParameter ch;
+ if (!PyArg_ParseTuple(_args, "h",
+ &ch))
+ return NULL;
+ DrawChar(ch);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_DrawString(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Str255 s;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetStr255, s))
+ return NULL;
+ DrawString(s);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_MacDrawText(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ char *textBuf__in__;
+ int textBuf__len__;
+ int textBuf__in_len__;
+ short firstByte;
+ short byteCount;
+ if (!PyArg_ParseTuple(_args, "s#hh",
+ &textBuf__in__, &textBuf__in_len__,
+ &firstByte,
+ &byteCount))
+ return NULL;
+ MacDrawText(textBuf__in__,
+ firstByte,
+ byteCount);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ textBuf__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_CharWidth(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ CharParameter ch;
+ if (!PyArg_ParseTuple(_args, "h",
+ &ch))
+ return NULL;
+ _rv = CharWidth(ch);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_StringWidth(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ Str255 s;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetStr255, s))
+ return NULL;
+ _rv = StringWidth(s);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_TextWidth(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ char *textBuf__in__;
+ int textBuf__len__;
+ int textBuf__in_len__;
+ short firstByte;
+ short byteCount;
+ if (!PyArg_ParseTuple(_args, "s#hh",
+ &textBuf__in__, &textBuf__in_len__,
+ &firstByte,
+ &byteCount))
+ return NULL;
+ _rv = TextWidth(textBuf__in__,
+ firstByte,
+ byteCount);
+ _res = Py_BuildValue("h",
+ _rv);
+ textBuf__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_GetFontInfo(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ FontInfo info;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetFontInfo(&info);
+ _res = Py_BuildValue("O&",
+ QdFI_New, &info);
+ return _res;
+}
+
+static PyObject *Qd_CharExtra(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Fixed extra;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetFixed, &extra))
+ return NULL;
+ CharExtra(extra);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetPort(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ GrafPtr thePort;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &thePort))
+ return NULL;
+ SetPort(thePort);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_GetCursor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CursHandle _rv;
+ short cursorID;
+ if (!PyArg_ParseTuple(_args, "h",
+ &cursorID))
+ return NULL;
+ _rv = GetCursor(cursorID);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Qd_SetCursor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Cursor *crsr__in__;
+ int crsr__in_len__;
+ if (!PyArg_ParseTuple(_args, "s#",
+ (char **)&crsr__in__, &crsr__in_len__))
+ return NULL;
+ if (crsr__in_len__ != sizeof(Cursor))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(Cursor)");
+ goto crsr__error__;
+ }
+ SetCursor(crsr__in__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ crsr__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_ShowCursor(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ ShowCursor();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_LineTo(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short h;
+ short v;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &h,
+ &v))
+ return NULL;
+ LineTo(h,
+ v);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short left;
+ short top;
+ short right;
+ short bottom;
+ if (!PyArg_ParseTuple(_args, "hhhh",
+ &left,
+ &top,
+ &right,
+ &bottom))
+ return NULL;
+ SetRect(&r,
+ left,
+ top,
+ right,
+ bottom);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &r);
+ return _res;
+}
+
+static PyObject *Qd_OffsetRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short dh;
+ short dv;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ PyMac_GetRect, &r,
+ &dh,
+ &dv))
+ return NULL;
+ OffsetRect(&r,
+ dh,
+ dv);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &r);
+ return _res;
+}
+
+static PyObject *Qd_InsetRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ short dh;
+ short dv;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ PyMac_GetRect, &r,
+ &dh,
+ &dv))
+ return NULL;
+ InsetRect(&r,
+ dh,
+ dv);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &r);
+ return _res;
+}
+
+static PyObject *Qd_UnionRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect src1;
+ Rect src2;
+ Rect dstRect;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetRect, &src1,
+ PyMac_GetRect, &src2))
+ return NULL;
+ UnionRect(&src1,
+ &src2,
+ &dstRect);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &dstRect);
+ return _res;
+}
+
+static PyObject *Qd_EqualRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Rect rect1;
+ Rect rect2;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetRect, &rect1,
+ PyMac_GetRect, &rect2))
+ return NULL;
+ _rv = EqualRect(&rect1,
+ &rect2);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_FrameRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &r))
+ return NULL;
+ FrameRect(&r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_InvertRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &r))
+ return NULL;
+ InvertRect(&r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_FillRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ Pattern *pat__in__;
+ int pat__in_len__;
+ if (!PyArg_ParseTuple(_args, "O&s#",
+ PyMac_GetRect, &r,
+ (char **)&pat__in__, &pat__in_len__))
+ return NULL;
+ if (pat__in_len__ != sizeof(Pattern))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(Pattern)");
+ goto pat__error__;
+ }
+ FillRect(&r,
+ pat__in__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ pat__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_CopyRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle srcRgn;
+ RgnHandle dstRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, &srcRgn,
+ ResObj_Convert, &dstRgn))
+ return NULL;
+ CopyRgn(srcRgn,
+ dstRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_SetRectRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ short left;
+ short top;
+ short right;
+ short bottom;
+ if (!PyArg_ParseTuple(_args, "O&hhhh",
+ ResObj_Convert, &rgn,
+ &left,
+ &top,
+ &right,
+ &bottom))
+ return NULL;
+ SetRectRgn(rgn,
+ left,
+ top,
+ right,
+ bottom);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_OffsetRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ short dh;
+ short dv;
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ ResObj_Convert, &rgn,
+ &dh,
+ &dv))
+ return NULL;
+ OffsetRgn(rgn,
+ dh,
+ dv);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_UnionRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle srcRgnA;
+ RgnHandle srcRgnB;
+ RgnHandle dstRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&O&",
+ ResObj_Convert, &srcRgnA,
+ ResObj_Convert, &srcRgnB,
+ ResObj_Convert, &dstRgn))
+ return NULL;
+ UnionRgn(srcRgnA,
+ srcRgnB,
+ dstRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_XorRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle srcRgnA;
+ RgnHandle srcRgnB;
+ RgnHandle dstRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&O&",
+ ResObj_Convert, &srcRgnA,
+ ResObj_Convert, &srcRgnB,
+ ResObj_Convert, &dstRgn))
+ return NULL;
+ XorRgn(srcRgnA,
+ srcRgnB,
+ dstRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_EqualRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ RgnHandle rgnA;
+ RgnHandle rgnB;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, &rgnA,
+ ResObj_Convert, &rgnB))
+ return NULL;
+ _rv = EqualRgn(rgnA,
+ rgnB);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_FrameRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &rgn))
+ return NULL;
+ FrameRgn(rgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_PaintRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &rgn))
+ return NULL;
+ PaintRgn(rgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_InvertRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &rgn))
+ return NULL;
+ InvertRgn(rgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Qd_FillRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle rgn;
+ Pattern *pat__in__;
+ int pat__in_len__;
+ if (!PyArg_ParseTuple(_args, "O&s#",
+ ResObj_Convert, &rgn,
+ (char **)&pat__in__, &pat__in_len__))
+ return NULL;
+ if (pat__in_len__ != sizeof(Pattern))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(Pattern)");
+ goto pat__error__;
+ }
+ FillRgn(rgn,
+ pat__in__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ pat__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_GetPixel(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ short h;
+ short v;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &h,
+ &v))
+ return NULL;
+ _rv = GetPixel(h,
+ v);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_PtInRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Point pt;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &pt,
+ PyMac_GetRect, &r))
+ return NULL;
+ _rv = PtInRect(pt,
+ &r);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Qd_DrawText(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ char *textBuf__in__;
+ int textBuf__len__;
+ int textBuf__in_len__;
+ short firstByte;
+ short byteCount;
+ if (!PyArg_ParseTuple(_args, "s#hh",
+ &textBuf__in__, &textBuf__in_len__,
+ &firstByte,
+ &byteCount))
+ return NULL;
+ DrawText(textBuf__in__,
+ firstByte,
+ byteCount);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ textBuf__error__: ;
+ return _res;
+}
+
+static PyObject *Qd_BitMap(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ BitMap *ptr;
+ PyObject *source;
+ Rect bounds;
+ int rowbytes;
+ char *data;
+
+ if ( !PyArg_ParseTuple(_args, "O!iO&", &PyString_Type, &source, &rowbytes, PyMac_GetRect,
+ &bounds) )
+ return NULL;
+ data = PyString_AsString(source);
+ if ((ptr=(BitMap *)malloc(sizeof(BitMap))) == NULL )
+ return PyErr_NoMemory();
+ ptr->baseAddr = (Ptr)data;
+ ptr->rowBytes = rowbytes;
+ ptr->bounds = bounds;
+ if ( (_res = BMObj_New(ptr)) == NULL ) {
+ free(ptr);
+ return NULL;
+ }
+ ((BitMapObject *)_res)->referred_object = source;
+ Py_INCREF(source);
+ ((BitMapObject *)_res)->referred_bitmap = ptr;
+ return _res;
+
+}
+
+static PyObject *Qd_RawBitMap(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ BitMap *ptr;
+ PyObject *source;
+
+ if ( !PyArg_ParseTuple(_args, "O!", &PyString_Type, &source) )
+ return NULL;
+ if ( PyString_Size(source) != sizeof(BitMap) && PyString_Size(source) != sizeof(PixMap) ) {
+ PyErr_BadArgument();
+ return NULL;
+ }
+ ptr = (BitMapPtr)PyString_AsString(source);
+ if ( (_res = BMObj_New(ptr)) == NULL ) {
+ return NULL;
+ }
+ ((BitMapObject *)_res)->referred_object = source;
+ Py_INCREF(source);
+ return _res;
+
+}
+
+static PyMethodDef Qd_methods[] = {
+ {"MacSetPort", (PyCFunction)Qd_MacSetPort, 1,
+ "(GrafPtr port) -> None"},
+ {"GetPort", (PyCFunction)Qd_GetPort, 1,
+ "() -> (GrafPtr port)"},
+ {"GrafDevice", (PyCFunction)Qd_GrafDevice, 1,
+ "(short device) -> None"},
+ {"SetPortBits", (PyCFunction)Qd_SetPortBits, 1,
+ "(BitMapPtr bm) -> None"},
+ {"PortSize", (PyCFunction)Qd_PortSize, 1,
+ "(short width, short height) -> None"},
+ {"MovePortTo", (PyCFunction)Qd_MovePortTo, 1,
+ "(short leftGlobal, short topGlobal) -> None"},
+ {"SetOrigin", (PyCFunction)Qd_SetOrigin, 1,
+ "(short h, short v) -> None"},
+ {"SetClip", (PyCFunction)Qd_SetClip, 1,
+ "(RgnHandle rgn) -> None"},
+ {"GetClip", (PyCFunction)Qd_GetClip, 1,
+ "(RgnHandle rgn) -> None"},
+ {"ClipRect", (PyCFunction)Qd_ClipRect, 1,
+ "(Rect r) -> None"},
+ {"BackPat", (PyCFunction)Qd_BackPat, 1,
+ "(Pattern pat) -> None"},
+ {"InitCursor", (PyCFunction)Qd_InitCursor, 1,
+ "() -> None"},
+ {"MacSetCursor", (PyCFunction)Qd_MacSetCursor, 1,
+ "(Cursor crsr) -> None"},
+ {"HideCursor", (PyCFunction)Qd_HideCursor, 1,
+ "() -> None"},
+ {"MacShowCursor", (PyCFunction)Qd_MacShowCursor, 1,
+ "() -> None"},
+ {"ObscureCursor", (PyCFunction)Qd_ObscureCursor, 1,
+ "() -> None"},
+ {"HidePen", (PyCFunction)Qd_HidePen, 1,
+ "() -> None"},
+ {"ShowPen", (PyCFunction)Qd_ShowPen, 1,
+ "() -> None"},
+ {"GetPen", (PyCFunction)Qd_GetPen, 1,
+ "() -> (Point pt)"},
+ {"GetPenState", (PyCFunction)Qd_GetPenState, 1,
+ "() -> (PenState pnState)"},
+ {"SetPenState", (PyCFunction)Qd_SetPenState, 1,
+ "(PenState pnState) -> None"},
+ {"PenSize", (PyCFunction)Qd_PenSize, 1,
+ "(short width, short height) -> None"},
+ {"PenMode", (PyCFunction)Qd_PenMode, 1,
+ "(short mode) -> None"},
+ {"PenPat", (PyCFunction)Qd_PenPat, 1,
+ "(Pattern pat) -> None"},
+ {"PenNormal", (PyCFunction)Qd_PenNormal, 1,
+ "() -> None"},
+ {"MoveTo", (PyCFunction)Qd_MoveTo, 1,
+ "(short h, short v) -> None"},
+ {"Move", (PyCFunction)Qd_Move, 1,
+ "(short dh, short dv) -> None"},
+ {"MacLineTo", (PyCFunction)Qd_MacLineTo, 1,
+ "(short h, short v) -> None"},
+ {"Line", (PyCFunction)Qd_Line, 1,
+ "(short dh, short dv) -> None"},
+ {"ForeColor", (PyCFunction)Qd_ForeColor, 1,
+ "(long color) -> None"},
+ {"BackColor", (PyCFunction)Qd_BackColor, 1,
+ "(long color) -> None"},
+ {"ColorBit", (PyCFunction)Qd_ColorBit, 1,
+ "(short whichBit) -> None"},
+ {"MacSetRect", (PyCFunction)Qd_MacSetRect, 1,
+ "(short left, short top, short right, short bottom) -> (Rect r)"},
+ {"MacOffsetRect", (PyCFunction)Qd_MacOffsetRect, 1,
+ "(Rect r, short dh, short dv) -> (Rect r)"},
+ {"MacInsetRect", (PyCFunction)Qd_MacInsetRect, 1,
+ "(Rect r, short dh, short dv) -> (Rect r)"},
+ {"SectRect", (PyCFunction)Qd_SectRect, 1,
+ "(Rect src1, Rect src2) -> (Boolean _rv, Rect dstRect)"},
+ {"MacUnionRect", (PyCFunction)Qd_MacUnionRect, 1,
+ "(Rect src1, Rect src2) -> (Rect dstRect)"},
+ {"MacEqualRect", (PyCFunction)Qd_MacEqualRect, 1,
+ "(Rect rect1, Rect rect2) -> (Boolean _rv)"},
+ {"EmptyRect", (PyCFunction)Qd_EmptyRect, 1,
+ "(Rect r) -> (Boolean _rv)"},
+ {"MacFrameRect", (PyCFunction)Qd_MacFrameRect, 1,
+ "(Rect r) -> None"},
+ {"PaintRect", (PyCFunction)Qd_PaintRect, 1,
+ "(Rect r) -> None"},
+ {"EraseRect", (PyCFunction)Qd_EraseRect, 1,
+ "(Rect r) -> None"},
+ {"MacInvertRect", (PyCFunction)Qd_MacInvertRect, 1,
+ "(Rect r) -> None"},
+ {"MacFillRect", (PyCFunction)Qd_MacFillRect, 1,
+ "(Rect r, Pattern pat) -> None"},
+ {"FrameOval", (PyCFunction)Qd_FrameOval, 1,
+ "(Rect r) -> None"},
+ {"PaintOval", (PyCFunction)Qd_PaintOval, 1,
+ "(Rect r) -> None"},
+ {"EraseOval", (PyCFunction)Qd_EraseOval, 1,
+ "(Rect r) -> None"},
+ {"InvertOval", (PyCFunction)Qd_InvertOval, 1,
+ "(Rect r) -> None"},
+ {"FillOval", (PyCFunction)Qd_FillOval, 1,
+ "(Rect r, Pattern pat) -> None"},
+ {"FrameRoundRect", (PyCFunction)Qd_FrameRoundRect, 1,
+ "(Rect r, short ovalWidth, short ovalHeight) -> None"},
+ {"PaintRoundRect", (PyCFunction)Qd_PaintRoundRect, 1,
+ "(Rect r, short ovalWidth, short ovalHeight) -> None"},
+ {"EraseRoundRect", (PyCFunction)Qd_EraseRoundRect, 1,
+ "(Rect r, short ovalWidth, short ovalHeight) -> None"},
+ {"InvertRoundRect", (PyCFunction)Qd_InvertRoundRect, 1,
+ "(Rect r, short ovalWidth, short ovalHeight) -> None"},
+ {"FillRoundRect", (PyCFunction)Qd_FillRoundRect, 1,
+ "(Rect r, short ovalWidth, short ovalHeight, Pattern pat) -> None"},
+ {"FrameArc", (PyCFunction)Qd_FrameArc, 1,
+ "(Rect r, short startAngle, short arcAngle) -> None"},
+ {"PaintArc", (PyCFunction)Qd_PaintArc, 1,
+ "(Rect r, short startAngle, short arcAngle) -> None"},
+ {"EraseArc", (PyCFunction)Qd_EraseArc, 1,
+ "(Rect r, short startAngle, short arcAngle) -> None"},
+ {"InvertArc", (PyCFunction)Qd_InvertArc, 1,
+ "(Rect r, short startAngle, short arcAngle) -> None"},
+ {"FillArc", (PyCFunction)Qd_FillArc, 1,
+ "(Rect r, short startAngle, short arcAngle, Pattern pat) -> None"},
+ {"NewRgn", (PyCFunction)Qd_NewRgn, 1,
+ "() -> (RgnHandle _rv)"},
+ {"OpenRgn", (PyCFunction)Qd_OpenRgn, 1,
+ "() -> None"},
+ {"CloseRgn", (PyCFunction)Qd_CloseRgn, 1,
+ "(RgnHandle dstRgn) -> None"},
+ {"BitMapToRegion", (PyCFunction)Qd_BitMapToRegion, 1,
+ "(RgnHandle region, BitMapPtr bMap) -> None"},
+ {"DisposeRgn", (PyCFunction)Qd_DisposeRgn, 1,
+ "(RgnHandle rgn) -> None"},
+ {"MacCopyRgn", (PyCFunction)Qd_MacCopyRgn, 1,
+ "(RgnHandle srcRgn, RgnHandle dstRgn) -> None"},
+ {"SetEmptyRgn", (PyCFunction)Qd_SetEmptyRgn, 1,
+ "(RgnHandle rgn) -> None"},
+ {"MacSetRectRgn", (PyCFunction)Qd_MacSetRectRgn, 1,
+ "(RgnHandle rgn, short left, short top, short right, short bottom) -> None"},
+ {"RectRgn", (PyCFunction)Qd_RectRgn, 1,
+ "(RgnHandle rgn, Rect r) -> None"},
+ {"MacOffsetRgn", (PyCFunction)Qd_MacOffsetRgn, 1,
+ "(RgnHandle rgn, short dh, short dv) -> None"},
+ {"InsetRgn", (PyCFunction)Qd_InsetRgn, 1,
+ "(RgnHandle rgn, short dh, short dv) -> None"},
+ {"SectRgn", (PyCFunction)Qd_SectRgn, 1,
+ "(RgnHandle srcRgnA, RgnHandle srcRgnB, RgnHandle dstRgn) -> None"},
+ {"MacUnionRgn", (PyCFunction)Qd_MacUnionRgn, 1,
+ "(RgnHandle srcRgnA, RgnHandle srcRgnB, RgnHandle dstRgn) -> None"},
+ {"DiffRgn", (PyCFunction)Qd_DiffRgn, 1,
+ "(RgnHandle srcRgnA, RgnHandle srcRgnB, RgnHandle dstRgn) -> None"},
+ {"MacXorRgn", (PyCFunction)Qd_MacXorRgn, 1,
+ "(RgnHandle srcRgnA, RgnHandle srcRgnB, RgnHandle dstRgn) -> None"},
+ {"RectInRgn", (PyCFunction)Qd_RectInRgn, 1,
+ "(Rect r, RgnHandle rgn) -> (Boolean _rv)"},
+ {"MacEqualRgn", (PyCFunction)Qd_MacEqualRgn, 1,
+ "(RgnHandle rgnA, RgnHandle rgnB) -> (Boolean _rv)"},
+ {"EmptyRgn", (PyCFunction)Qd_EmptyRgn, 1,
+ "(RgnHandle rgn) -> (Boolean _rv)"},
+ {"MacFrameRgn", (PyCFunction)Qd_MacFrameRgn, 1,
+ "(RgnHandle rgn) -> None"},
+ {"MacPaintRgn", (PyCFunction)Qd_MacPaintRgn, 1,
+ "(RgnHandle rgn) -> None"},
+ {"EraseRgn", (PyCFunction)Qd_EraseRgn, 1,
+ "(RgnHandle rgn) -> None"},
+ {"MacInvertRgn", (PyCFunction)Qd_MacInvertRgn, 1,
+ "(RgnHandle rgn) -> None"},
+ {"MacFillRgn", (PyCFunction)Qd_MacFillRgn, 1,
+ "(RgnHandle rgn, Pattern pat) -> None"},
+ {"ScrollRect", (PyCFunction)Qd_ScrollRect, 1,
+ "(Rect r, short dh, short dv, RgnHandle updateRgn) -> None"},
+ {"CopyBits", (PyCFunction)Qd_CopyBits, 1,
+ "(BitMapPtr srcBits, BitMapPtr dstBits, Rect srcRect, Rect dstRect, short mode, RgnHandle maskRgn) -> None"},
+ {"CopyMask", (PyCFunction)Qd_CopyMask, 1,
+ "(BitMapPtr srcBits, BitMapPtr maskBits, BitMapPtr dstBits, Rect srcRect, Rect maskRect, Rect dstRect) -> None"},
+ {"OpenPicture", (PyCFunction)Qd_OpenPicture, 1,
+ "(Rect picFrame) -> (PicHandle _rv)"},
+ {"PicComment", (PyCFunction)Qd_PicComment, 1,
+ "(short kind, short dataSize, Handle dataHandle) -> None"},
+ {"ClosePicture", (PyCFunction)Qd_ClosePicture, 1,
+ "() -> None"},
+ {"DrawPicture", (PyCFunction)Qd_DrawPicture, 1,
+ "(PicHandle myPicture, Rect dstRect) -> None"},
+ {"KillPicture", (PyCFunction)Qd_KillPicture, 1,
+ "(PicHandle myPicture) -> None"},
+ {"OpenPoly", (PyCFunction)Qd_OpenPoly, 1,
+ "() -> (PolyHandle _rv)"},
+ {"ClosePoly", (PyCFunction)Qd_ClosePoly, 1,
+ "() -> None"},
+ {"KillPoly", (PyCFunction)Qd_KillPoly, 1,
+ "(PolyHandle poly) -> None"},
+ {"OffsetPoly", (PyCFunction)Qd_OffsetPoly, 1,
+ "(PolyHandle poly, short dh, short dv) -> None"},
+ {"FramePoly", (PyCFunction)Qd_FramePoly, 1,
+ "(PolyHandle poly) -> None"},
+ {"PaintPoly", (PyCFunction)Qd_PaintPoly, 1,
+ "(PolyHandle poly) -> None"},
+ {"ErasePoly", (PyCFunction)Qd_ErasePoly, 1,
+ "(PolyHandle poly) -> None"},
+ {"InvertPoly", (PyCFunction)Qd_InvertPoly, 1,
+ "(PolyHandle poly) -> None"},
+ {"FillPoly", (PyCFunction)Qd_FillPoly, 1,
+ "(PolyHandle poly, Pattern pat) -> None"},
+ {"SetPt", (PyCFunction)Qd_SetPt, 1,
+ "(short h, short v) -> (Point pt)"},
+ {"LocalToGlobal", (PyCFunction)Qd_LocalToGlobal, 1,
+ "(Point pt) -> (Point pt)"},
+ {"GlobalToLocal", (PyCFunction)Qd_GlobalToLocal, 1,
+ "(Point pt) -> (Point pt)"},
+ {"Random", (PyCFunction)Qd_Random, 1,
+ "() -> (short _rv)"},
+ {"MacGetPixel", (PyCFunction)Qd_MacGetPixel, 1,
+ "(short h, short v) -> (Boolean _rv)"},
+ {"ScalePt", (PyCFunction)Qd_ScalePt, 1,
+ "(Point pt, Rect srcRect, Rect dstRect) -> (Point pt)"},
+ {"MapPt", (PyCFunction)Qd_MapPt, 1,
+ "(Point pt, Rect srcRect, Rect dstRect) -> (Point pt)"},
+ {"MapRect", (PyCFunction)Qd_MapRect, 1,
+ "(Rect r, Rect srcRect, Rect dstRect) -> (Rect r)"},
+ {"MapRgn", (PyCFunction)Qd_MapRgn, 1,
+ "(RgnHandle rgn, Rect srcRect, Rect dstRect) -> None"},
+ {"MapPoly", (PyCFunction)Qd_MapPoly, 1,
+ "(PolyHandle poly, Rect srcRect, Rect dstRect) -> None"},
+ {"StdBits", (PyCFunction)Qd_StdBits, 1,
+ "(BitMapPtr srcBits, Rect srcRect, Rect dstRect, short mode, RgnHandle maskRgn) -> None"},
+ {"AddPt", (PyCFunction)Qd_AddPt, 1,
+ "(Point src, Point dst) -> (Point dst)"},
+ {"EqualPt", (PyCFunction)Qd_EqualPt, 1,
+ "(Point pt1, Point pt2) -> (Boolean _rv)"},
+ {"MacPtInRect", (PyCFunction)Qd_MacPtInRect, 1,
+ "(Point pt, Rect r) -> (Boolean _rv)"},
+ {"Pt2Rect", (PyCFunction)Qd_Pt2Rect, 1,
+ "(Point pt1, Point pt2) -> (Rect dstRect)"},
+ {"PtToAngle", (PyCFunction)Qd_PtToAngle, 1,
+ "(Rect r, Point pt) -> (short angle)"},
+ {"SubPt", (PyCFunction)Qd_SubPt, 1,
+ "(Point src, Point dst) -> (Point dst)"},
+ {"PtInRgn", (PyCFunction)Qd_PtInRgn, 1,
+ "(Point pt, RgnHandle rgn) -> (Boolean _rv)"},
+ {"NewPixMap", (PyCFunction)Qd_NewPixMap, 1,
+ "() -> (PixMapHandle _rv)"},
+ {"DisposePixMap", (PyCFunction)Qd_DisposePixMap, 1,
+ "(PixMapHandle pm) -> None"},
+ {"CopyPixMap", (PyCFunction)Qd_CopyPixMap, 1,
+ "(PixMapHandle srcPM, PixMapHandle dstPM) -> None"},
+ {"NewPixPat", (PyCFunction)Qd_NewPixPat, 1,
+ "() -> (PixPatHandle _rv)"},
+ {"DisposePixPat", (PyCFunction)Qd_DisposePixPat, 1,
+ "(PixPatHandle pp) -> None"},
+ {"CopyPixPat", (PyCFunction)Qd_CopyPixPat, 1,
+ "(PixPatHandle srcPP, PixPatHandle dstPP) -> None"},
+ {"PenPixPat", (PyCFunction)Qd_PenPixPat, 1,
+ "(PixPatHandle pp) -> None"},
+ {"BackPixPat", (PyCFunction)Qd_BackPixPat, 1,
+ "(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,
+ "(Rect r, PixPatHandle pp) -> None"},
+ {"FillCRoundRect", (PyCFunction)Qd_FillCRoundRect, 1,
+ "(Rect r, short ovalWidth, short ovalHeight, PixPatHandle pp) -> None"},
+ {"FillCArc", (PyCFunction)Qd_FillCArc, 1,
+ "(Rect r, short startAngle, short arcAngle, PixPatHandle pp) -> None"},
+ {"FillCRgn", (PyCFunction)Qd_FillCRgn, 1,
+ "(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"},
+ {"DisposeCTable", (PyCFunction)Qd_DisposeCTable, 1,
+ "(CTabHandle cTable) -> None"},
+ {"GetCTable", (PyCFunction)Qd_GetCTable, 1,
+ "(short ctID) -> (CTabHandle _rv)"},
+ {"GetCCursor", (PyCFunction)Qd_GetCCursor, 1,
+ "(short crsrID) -> (CCrsrHandle _rv)"},
+ {"SetCCursor", (PyCFunction)Qd_SetCCursor, 1,
+ "(CCrsrHandle cCrsr) -> None"},
+ {"AllocCursor", (PyCFunction)Qd_AllocCursor, 1,
+ "() -> None"},
+ {"DisposeCCursor", (PyCFunction)Qd_DisposeCCursor, 1,
+ "(CCrsrHandle cCrsr) -> None"},
+ {"GetMaxDevice", (PyCFunction)Qd_GetMaxDevice, 1,
+ "(Rect globalRect) -> (GDHandle _rv)"},
+ {"GetCTSeed", (PyCFunction)Qd_GetCTSeed, 1,
+ "() -> (long _rv)"},
+ {"GetDeviceList", (PyCFunction)Qd_GetDeviceList, 1,
+ "() -> (GDHandle _rv)"},
+ {"GetMainDevice", (PyCFunction)Qd_GetMainDevice, 1,
+ "() -> (GDHandle _rv)"},
+ {"GetNextDevice", (PyCFunction)Qd_GetNextDevice, 1,
+ "(GDHandle curDevice) -> (GDHandle _rv)"},
+ {"TestDeviceAttribute", (PyCFunction)Qd_TestDeviceAttribute, 1,
+ "(GDHandle gdh, short attribute) -> (Boolean _rv)"},
+ {"SetDeviceAttribute", (PyCFunction)Qd_SetDeviceAttribute, 1,
+ "(GDHandle gdh, short attribute, Boolean value) -> None"},
+ {"InitGDevice", (PyCFunction)Qd_InitGDevice, 1,
+ "(short qdRefNum, long mode, GDHandle gdh) -> None"},
+ {"NewGDevice", (PyCFunction)Qd_NewGDevice, 1,
+ "(short refNum, long mode) -> (GDHandle _rv)"},
+ {"DisposeGDevice", (PyCFunction)Qd_DisposeGDevice, 1,
+ "(GDHandle gdh) -> None"},
+ {"SetGDevice", (PyCFunction)Qd_SetGDevice, 1,
+ "(GDHandle gd) -> None"},
+ {"GetGDevice", (PyCFunction)Qd_GetGDevice, 1,
+ "() -> (GDHandle _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)"},
+ {"GetSubTable", (PyCFunction)Qd_GetSubTable, 1,
+ "(CTabHandle myColors, short iTabRes, CTabHandle targetTbl) -> None"},
+ {"MakeITable", (PyCFunction)Qd_MakeITable, 1,
+ "(CTabHandle cTabH, ITabHandle iTabH, short res) -> None"},
+ {"SetClientID", (PyCFunction)Qd_SetClientID, 1,
+ "(short id) -> None"},
+ {"ProtectEntry", (PyCFunction)Qd_ProtectEntry, 1,
+ "(short index, Boolean protect) -> None"},
+ {"ReserveEntry", (PyCFunction)Qd_ReserveEntry, 1,
+ "(short index, Boolean reserve) -> None"},
+ {"QDError", (PyCFunction)Qd_QDError, 1,
+ "() -> (short _rv)"},
+ {"CopyDeepMask", (PyCFunction)Qd_CopyDeepMask, 1,
+ "(BitMapPtr srcBits, BitMapPtr maskBits, BitMapPtr dstBits, Rect srcRect, Rect maskRect, Rect dstRect, short mode, RgnHandle maskRgn) -> None"},
+ {"GetPattern", (PyCFunction)Qd_GetPattern, 1,
+ "(short patternID) -> (PatHandle _rv)"},
+ {"MacGetCursor", (PyCFunction)Qd_MacGetCursor, 1,
+ "(short cursorID) -> (CursHandle _rv)"},
+ {"GetPicture", (PyCFunction)Qd_GetPicture, 1,
+ "(short pictureID) -> (PicHandle _rv)"},
+ {"DeltaPoint", (PyCFunction)Qd_DeltaPoint, 1,
+ "(Point ptA, Point ptB) -> (long _rv)"},
+ {"ShieldCursor", (PyCFunction)Qd_ShieldCursor, 1,
+ "(Rect shieldRect, Point offsetPt) -> None"},
+ {"ScreenRes", (PyCFunction)Qd_ScreenRes, 1,
+ "() -> (short scrnHRes, short scrnVRes)"},
+ {"GetIndPattern", (PyCFunction)Qd_GetIndPattern, 1,
+ "(short patternListID, short index) -> (Pattern thePat)"},
+ {"SlopeFromAngle", (PyCFunction)Qd_SlopeFromAngle, 1,
+ "(short angle) -> (Fixed _rv)"},
+ {"AngleFromSlope", (PyCFunction)Qd_AngleFromSlope, 1,
+ "(Fixed slope) -> (short _rv)"},
+ {"GetPortPixMap", (PyCFunction)Qd_GetPortPixMap, 1,
+ "(CGrafPtr port) -> (PixMapHandle _rv)"},
+ {"GetPortBitMapForCopyBits", (PyCFunction)Qd_GetPortBitMapForCopyBits, 1,
+ "(CGrafPtr port) -> (const BitMap * _rv)"},
+ {"GetPortBounds", (PyCFunction)Qd_GetPortBounds, 1,
+ "(CGrafPtr port) -> (Rect rect)"},
+ {"GetPortForeColor", (PyCFunction)Qd_GetPortForeColor, 1,
+ "(CGrafPtr port) -> (RGBColor foreColor)"},
+ {"GetPortBackColor", (PyCFunction)Qd_GetPortBackColor, 1,
+ "(CGrafPtr port) -> (RGBColor backColor)"},
+ {"GetPortOpColor", (PyCFunction)Qd_GetPortOpColor, 1,
+ "(CGrafPtr port) -> (RGBColor opColor)"},
+ {"GetPortHiliteColor", (PyCFunction)Qd_GetPortHiliteColor, 1,
+ "(CGrafPtr port) -> (RGBColor hiliteColor)"},
+ {"GetPortTextFont", (PyCFunction)Qd_GetPortTextFont, 1,
+ "(CGrafPtr port) -> (short _rv)"},
+ {"GetPortTextFace", (PyCFunction)Qd_GetPortTextFace, 1,
+ "(CGrafPtr port) -> (Style _rv)"},
+ {"GetPortTextMode", (PyCFunction)Qd_GetPortTextMode, 1,
+ "(CGrafPtr port) -> (short _rv)"},
+ {"GetPortTextSize", (PyCFunction)Qd_GetPortTextSize, 1,
+ "(CGrafPtr port) -> (short _rv)"},
+ {"GetPortChExtra", (PyCFunction)Qd_GetPortChExtra, 1,
+ "(CGrafPtr port) -> (short _rv)"},
+ {"GetPortFracHPenLocation", (PyCFunction)Qd_GetPortFracHPenLocation, 1,
+ "(CGrafPtr port) -> (short _rv)"},
+ {"GetPortSpExtra", (PyCFunction)Qd_GetPortSpExtra, 1,
+ "(CGrafPtr port) -> (Fixed _rv)"},
+ {"GetPortPenVisibility", (PyCFunction)Qd_GetPortPenVisibility, 1,
+ "(CGrafPtr port) -> (short _rv)"},
+ {"GetPortVisibleRegion", (PyCFunction)Qd_GetPortVisibleRegion, 1,
+ "(CGrafPtr port, RgnHandle visRgn) -> (RgnHandle _rv)"},
+ {"GetPortClipRegion", (PyCFunction)Qd_GetPortClipRegion, 1,
+ "(CGrafPtr port, RgnHandle clipRgn) -> (RgnHandle _rv)"},
+ {"GetPortBackPixPat", (PyCFunction)Qd_GetPortBackPixPat, 1,
+ "(CGrafPtr port, PixPatHandle backPattern) -> (PixPatHandle _rv)"},
+ {"GetPortPenPixPat", (PyCFunction)Qd_GetPortPenPixPat, 1,
+ "(CGrafPtr port, PixPatHandle penPattern) -> (PixPatHandle _rv)"},
+ {"GetPortFillPixPat", (PyCFunction)Qd_GetPortFillPixPat, 1,
+ "(CGrafPtr port, PixPatHandle fillPattern) -> (PixPatHandle _rv)"},
+ {"GetPortPenSize", (PyCFunction)Qd_GetPortPenSize, 1,
+ "(CGrafPtr port, Point penSize) -> (Point penSize)"},
+ {"GetPortPenMode", (PyCFunction)Qd_GetPortPenMode, 1,
+ "(CGrafPtr port) -> (SInt32 _rv)"},
+ {"GetPortPenLocation", (PyCFunction)Qd_GetPortPenLocation, 1,
+ "(CGrafPtr port, Point penLocation) -> (Point penLocation)"},
+ {"IsPortRegionBeingDefined", (PyCFunction)Qd_IsPortRegionBeingDefined, 1,
+ "(CGrafPtr port) -> (Boolean _rv)"},
+ {"IsPortPictureBeingDefined", (PyCFunction)Qd_IsPortPictureBeingDefined, 1,
+ "(CGrafPtr port) -> (Boolean _rv)"},
+
+#if TARGET_API_MAC_CARBON
+ {"IsPortOffscreen", (PyCFunction)Qd_IsPortOffscreen, 1,
+ "(CGrafPtr port) -> (Boolean _rv)"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"IsPortColor", (PyCFunction)Qd_IsPortColor, 1,
+ "(CGrafPtr port) -> (Boolean _rv)"},
+#endif
+ {"SetPortBounds", (PyCFunction)Qd_SetPortBounds, 1,
+ "(CGrafPtr port, Rect rect) -> None"},
+ {"SetPortOpColor", (PyCFunction)Qd_SetPortOpColor, 1,
+ "(CGrafPtr port, RGBColor opColor) -> None"},
+ {"SetPortVisibleRegion", (PyCFunction)Qd_SetPortVisibleRegion, 1,
+ "(CGrafPtr port, RgnHandle visRgn) -> None"},
+ {"SetPortClipRegion", (PyCFunction)Qd_SetPortClipRegion, 1,
+ "(CGrafPtr port, RgnHandle clipRgn) -> None"},
+ {"SetPortPenPixPat", (PyCFunction)Qd_SetPortPenPixPat, 1,
+ "(CGrafPtr port, PixPatHandle penPattern) -> None"},
+ {"SetPortBackPixPat", (PyCFunction)Qd_SetPortBackPixPat, 1,
+ "(CGrafPtr port, PixPatHandle backPattern) -> None"},
+ {"SetPortPenSize", (PyCFunction)Qd_SetPortPenSize, 1,
+ "(CGrafPtr port, Point penSize) -> None"},
+ {"SetPortPenMode", (PyCFunction)Qd_SetPortPenMode, 1,
+ "(CGrafPtr port, SInt32 penMode) -> None"},
+ {"SetPortFracHPenLocation", (PyCFunction)Qd_SetPortFracHPenLocation, 1,
+ "(CGrafPtr port, short pnLocHFrac) -> None"},
+ {"GetPixBounds", (PyCFunction)Qd_GetPixBounds, 1,
+ "(PixMapHandle pixMap) -> (Rect bounds)"},
+ {"GetPixDepth", (PyCFunction)Qd_GetPixDepth, 1,
+ "(PixMapHandle pixMap) -> (short _rv)"},
+ {"GetQDGlobalsRandomSeed", (PyCFunction)Qd_GetQDGlobalsRandomSeed, 1,
+ "() -> (long _rv)"},
+ {"GetQDGlobalsScreenBits", (PyCFunction)Qd_GetQDGlobalsScreenBits, 1,
+ "() -> (BitMap screenBits)"},
+ {"GetQDGlobalsArrow", (PyCFunction)Qd_GetQDGlobalsArrow, 1,
+ "() -> (Cursor arrow)"},
+ {"GetQDGlobalsDarkGray", (PyCFunction)Qd_GetQDGlobalsDarkGray, 1,
+ "() -> (Pattern dkGray)"},
+ {"GetQDGlobalsLightGray", (PyCFunction)Qd_GetQDGlobalsLightGray, 1,
+ "() -> (Pattern ltGray)"},
+ {"GetQDGlobalsGray", (PyCFunction)Qd_GetQDGlobalsGray, 1,
+ "() -> (Pattern gray)"},
+ {"GetQDGlobalsBlack", (PyCFunction)Qd_GetQDGlobalsBlack, 1,
+ "() -> (Pattern black)"},
+ {"GetQDGlobalsWhite", (PyCFunction)Qd_GetQDGlobalsWhite, 1,
+ "() -> (Pattern white)"},
+ {"GetQDGlobalsThePort", (PyCFunction)Qd_GetQDGlobalsThePort, 1,
+ "() -> (CGrafPtr _rv)"},
+ {"SetQDGlobalsRandomSeed", (PyCFunction)Qd_SetQDGlobalsRandomSeed, 1,
+ "(long randomSeed) -> None"},
+ {"SetQDGlobalsArrow", (PyCFunction)Qd_SetQDGlobalsArrow, 1,
+ "(Cursor arrow) -> None"},
+ {"GetRegionBounds", (PyCFunction)Qd_GetRegionBounds, 1,
+ "(RgnHandle region) -> (Rect bounds)"},
+
+#if TARGET_API_MAC_CARBON
+ {"IsRegionRectangular", (PyCFunction)Qd_IsRegionRectangular, 1,
+ "(RgnHandle region) -> (Boolean _rv)"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"CreateNewPort", (PyCFunction)Qd_CreateNewPort, 1,
+ "() -> (CGrafPtr _rv)"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"DisposePort", (PyCFunction)Qd_DisposePort, 1,
+ "(CGrafPtr port) -> None"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"SetQDError", (PyCFunction)Qd_SetQDError, 1,
+ "(OSErr err) -> None"},
+#endif
+ {"QDIsPortBuffered", (PyCFunction)Qd_QDIsPortBuffered, 1,
+ "(CGrafPtr port) -> (Boolean _rv)"},
+ {"QDIsPortBufferDirty", (PyCFunction)Qd_QDIsPortBufferDirty, 1,
+ "(CGrafPtr port) -> (Boolean _rv)"},
+ {"QDFlushPortBuffer", (PyCFunction)Qd_QDFlushPortBuffer, 1,
+ "(CGrafPtr port, RgnHandle region) -> None"},
+ {"TextFont", (PyCFunction)Qd_TextFont, 1,
+ "(short font) -> None"},
+ {"TextFace", (PyCFunction)Qd_TextFace, 1,
+ "(StyleParameter face) -> None"},
+ {"TextMode", (PyCFunction)Qd_TextMode, 1,
+ "(short mode) -> None"},
+ {"TextSize", (PyCFunction)Qd_TextSize, 1,
+ "(short size) -> None"},
+ {"SpaceExtra", (PyCFunction)Qd_SpaceExtra, 1,
+ "(Fixed extra) -> None"},
+ {"DrawChar", (PyCFunction)Qd_DrawChar, 1,
+ "(CharParameter ch) -> None"},
+ {"DrawString", (PyCFunction)Qd_DrawString, 1,
+ "(Str255 s) -> None"},
+ {"MacDrawText", (PyCFunction)Qd_MacDrawText, 1,
+ "(Buffer textBuf, short firstByte, short byteCount) -> None"},
+ {"CharWidth", (PyCFunction)Qd_CharWidth, 1,
+ "(CharParameter ch) -> (short _rv)"},
+ {"StringWidth", (PyCFunction)Qd_StringWidth, 1,
+ "(Str255 s) -> (short _rv)"},
+ {"TextWidth", (PyCFunction)Qd_TextWidth, 1,
+ "(Buffer textBuf, short firstByte, short byteCount) -> (short _rv)"},
+ {"GetFontInfo", (PyCFunction)Qd_GetFontInfo, 1,
+ "() -> (FontInfo info)"},
+ {"CharExtra", (PyCFunction)Qd_CharExtra, 1,
+ "(Fixed extra) -> None"},
+ {"SetPort", (PyCFunction)Qd_SetPort, 1,
+ "(GrafPtr thePort) -> None"},
+ {"GetCursor", (PyCFunction)Qd_GetCursor, 1,
+ "(short cursorID) -> (CursHandle _rv)"},
+ {"SetCursor", (PyCFunction)Qd_SetCursor, 1,
+ "(Cursor crsr) -> None"},
+ {"ShowCursor", (PyCFunction)Qd_ShowCursor, 1,
+ "() -> None"},
+ {"LineTo", (PyCFunction)Qd_LineTo, 1,
+ "(short h, short v) -> None"},
+ {"SetRect", (PyCFunction)Qd_SetRect, 1,
+ "(short left, short top, short right, short bottom) -> (Rect r)"},
+ {"OffsetRect", (PyCFunction)Qd_OffsetRect, 1,
+ "(Rect r, short dh, short dv) -> (Rect r)"},
+ {"InsetRect", (PyCFunction)Qd_InsetRect, 1,
+ "(Rect r, short dh, short dv) -> (Rect r)"},
+ {"UnionRect", (PyCFunction)Qd_UnionRect, 1,
+ "(Rect src1, Rect src2) -> (Rect dstRect)"},
+ {"EqualRect", (PyCFunction)Qd_EqualRect, 1,
+ "(Rect rect1, Rect rect2) -> (Boolean _rv)"},
+ {"FrameRect", (PyCFunction)Qd_FrameRect, 1,
+ "(Rect r) -> None"},
+ {"InvertRect", (PyCFunction)Qd_InvertRect, 1,
+ "(Rect r) -> None"},
+ {"FillRect", (PyCFunction)Qd_FillRect, 1,
+ "(Rect r, Pattern pat) -> None"},
+ {"CopyRgn", (PyCFunction)Qd_CopyRgn, 1,
+ "(RgnHandle srcRgn, RgnHandle dstRgn) -> None"},
+ {"SetRectRgn", (PyCFunction)Qd_SetRectRgn, 1,
+ "(RgnHandle rgn, short left, short top, short right, short bottom) -> None"},
+ {"OffsetRgn", (PyCFunction)Qd_OffsetRgn, 1,
+ "(RgnHandle rgn, short dh, short dv) -> None"},
+ {"UnionRgn", (PyCFunction)Qd_UnionRgn, 1,
+ "(RgnHandle srcRgnA, RgnHandle srcRgnB, RgnHandle dstRgn) -> None"},
+ {"XorRgn", (PyCFunction)Qd_XorRgn, 1,
+ "(RgnHandle srcRgnA, RgnHandle srcRgnB, RgnHandle dstRgn) -> None"},
+ {"EqualRgn", (PyCFunction)Qd_EqualRgn, 1,
+ "(RgnHandle rgnA, RgnHandle rgnB) -> (Boolean _rv)"},
+ {"FrameRgn", (PyCFunction)Qd_FrameRgn, 1,
+ "(RgnHandle rgn) -> None"},
+ {"PaintRgn", (PyCFunction)Qd_PaintRgn, 1,
+ "(RgnHandle rgn) -> None"},
+ {"InvertRgn", (PyCFunction)Qd_InvertRgn, 1,
+ "(RgnHandle rgn) -> None"},
+ {"FillRgn", (PyCFunction)Qd_FillRgn, 1,
+ "(RgnHandle rgn, Pattern pat) -> None"},
+ {"GetPixel", (PyCFunction)Qd_GetPixel, 1,
+ "(short h, short v) -> (Boolean _rv)"},
+ {"PtInRect", (PyCFunction)Qd_PtInRect, 1,
+ "(Point pt, Rect r) -> (Boolean _rv)"},
+ {"DrawText", (PyCFunction)Qd_DrawText, 1,
+ "(Buffer textBuf, short firstByte, short byteCount) -> None"},
+ {"BitMap", (PyCFunction)Qd_BitMap, 1,
+ "Take (string, int, Rect) argument and create BitMap"},
+ {"RawBitMap", (PyCFunction)Qd_RawBitMap, 1,
+ "Take string BitMap and turn into BitMap object"},
+ {NULL, NULL, 0}
+};
+
+
+
+/* Like BMObj_New, but the original bitmap data structure is copied (and
+** released when the object is released)
+*/
+PyObject *BMObj_NewCopied(BitMapPtr itself)
+{
+ BitMapObject *it;
+ BitMapPtr itself_copy;
+
+ if ((itself_copy=(BitMapPtr)malloc(sizeof(BitMap))) == NULL)
+ return PyErr_NoMemory();
+ *itself_copy = *itself;
+ it = (BitMapObject *)BMObj_New(itself_copy);
+ it->referred_bitmap = itself_copy;
+ return (PyObject *)it;
+}
+
+
+
+void initQd(void)
+{
+ PyObject *m;
+ PyObject *d;
+
+
+
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(BitMapPtr, BMObj_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(BitMapPtr, BMObj_Convert);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(GrafPtr, GrafObj_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(GrafPtr, GrafObj_Convert);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(RGBColorPtr, QdRGB_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(RGBColor, QdRGB_Convert);
+
+
+ m = Py_InitModule("Qd", Qd_methods);
+ d = PyModule_GetDict(m);
+ Qd_Error = PyMac_GetOSErrException();
+ if (Qd_Error == NULL ||
+ PyDict_SetItemString(d, "Error", Qd_Error) != 0)
+ return;
+ GrafPort_Type.ob_type = &PyType_Type;
+ Py_INCREF(&GrafPort_Type);
+ if (PyDict_SetItemString(d, "GrafPortType", (PyObject *)&GrafPort_Type) != 0)
+ Py_FatalError("can't initialize GrafPortType");
+ BitMap_Type.ob_type = &PyType_Type;
+ Py_INCREF(&BitMap_Type);
+ if (PyDict_SetItemString(d, "BitMapType", (PyObject *)&BitMap_Type) != 0)
+ Py_FatalError("can't initialize BitMapType");
+ QDGlobalsAccess_Type.ob_type = &PyType_Type;
+ Py_INCREF(&QDGlobalsAccess_Type);
+ if (PyDict_SetItemString(d, "QDGlobalsAccessType", (PyObject *)&QDGlobalsAccess_Type) != 0)
+ Py_FatalError("can't initialize QDGlobalsAccessType");
+
+ {
+ PyObject *o;
+
+ o = QDGA_New();
+ if (o == NULL || PyDict_SetItemString(d, "qd", o) != 0)
+ return;
+ }
+
+
+}
+
+/* ========================= End module Qd ========================== */
+
--- /dev/null
+# This script generates a Python interface for an Apple Macintosh Manager.
+# It uses the "bgen" package to generate C code.
+# The function specifications are generated by scanning the mamager's header file,
+# using the "scantools" package (customized for this particular manager).
+
+import string
+
+# Declarations that change for each manager
+MACHEADERFILE = 'QuickDraw.h' # The Apple header file
+MODNAME = 'Qd' # The name of the module
+OBJECTNAME = 'Graf' # The basic name of the objects used here
+
+# The following is *usually* unchanged but may still require tuning
+MODPREFIX = MODNAME # The prefix for module-wide routines
+OBJECTTYPE = OBJECTNAME + 'Ptr' # The C type used to represent them
+OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
+INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
+EXTRAFILE = string.lower(MODPREFIX) + 'edit.py' # A similar file but hand-made
+OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
+
+from macsupport import *
+
+# Create the type objects
+
+class TextThingieClass(FixedInputBufferType):
+ def getargsCheck(self, name):
+ pass
+
+TextThingie = TextThingieClass(None)
+
+# These are temporary!
+RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
+OptRgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
+PicHandle = OpaqueByValueType("PicHandle", "ResObj")
+PolyHandle = OpaqueByValueType("PolyHandle", "ResObj")
+PixMapHandle = OpaqueByValueType("PixMapHandle", "ResObj")
+PixPatHandle = OpaqueByValueType("PixPatHandle", "ResObj")
+PatHandle = OpaqueByValueType("PatHandle", "ResObj")
+CursHandle = OpaqueByValueType("CursHandle", "ResObj")
+CCrsrHandle = OpaqueByValueType("CCrsrHandle", "ResObj")
+CIconHandle = OpaqueByValueType("CIconHandle", "ResObj")
+CTabHandle = OpaqueByValueType("CTabHandle", "ResObj")
+ITabHandle = OpaqueByValueType("ITabHandle", "ResObj")
+GDHandle = OpaqueByValueType("GDHandle", "ResObj")
+CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj")
+GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj")
+BitMap_ptr = OpaqueByValueType("BitMapPtr", "BMObj")
+const_BitMap_ptr = OpaqueByValueType("const BitMap *", "BMObj")
+BitMap = OpaqueType("BitMap", "BMObj_NewCopied", "BUG")
+RGBColor = OpaqueType('RGBColor', 'QdRGB')
+RGBColor_ptr = RGBColor
+FontInfo = OpaqueType('FontInfo', 'QdFI')
+Component = OpaqueByValueType('Component', 'CmpObj')
+ComponentInstance = OpaqueByValueType('ComponentInstance', 'CmpInstObj')
+
+Cursor = StructOutputBufferType('Cursor')
+Cursor_ptr = StructInputBufferType('Cursor')
+Pattern = StructOutputBufferType('Pattern')
+Pattern_ptr = StructInputBufferType('Pattern')
+PenState = StructOutputBufferType('PenState')
+PenState_ptr = StructInputBufferType('PenState')
+
+includestuff = includestuff + """
+#ifdef WITHOUT_FRAMEWORKS
+#include <QuickDraw.h>
+#else
+#include <Carbon/Carbon.h>
+#endif
+
+#ifdef USE_TOOLBOX_OBJECT_GLUE
+extern PyObject *_GrafObj_New(GrafPtr);
+extern int _GrafObj_Convert(PyObject *, GrafPtr *);
+extern PyObject *_BMObj_New(BitMapPtr);
+extern int _BMObj_Convert(PyObject *, BitMapPtr *);
+extern PyObject *_QdRGB_New(RGBColorPtr);
+extern int _QdRGB_Convert(PyObject *, RGBColorPtr);
+
+#define GrafObj_New _GrafObj_New
+#define GrafObj_Convert _GrafObj_Convert
+#define BMObj_New _BMObj_New
+#define BMObj_Convert _BMObj_Convert
+#define QdRGB_New _QdRGB_New
+#define QdRGB_Convert _QdRGB_Convert
+#endif
+
+#if !ACCESSOR_CALLS_ARE_FUNCTIONS
+#define GetPortBitMapForCopyBits(port) ((const struct BitMap *)&((GrafPort *)(port))->portBits)
+#define GetPortPixMap(port) (((CGrafPtr)(port))->portPixMap)
+#define GetPortBounds(port, bounds) (*(bounds) = (port)->portRect, (bounds))
+#define GetPortForeColor(port, color) (*(color) = (port)->rgbFgColor, (color))
+#define GetPortBackColor(port, color) (*(color) = (port)->rgbBkColor, (color))
+#define GetPortOpColor(port, color) (*(color) = (*(GVarHandle)((port)->grafVars))->rgbOpColor, (color))
+#define GetPortHiliteColor(port, color) (*(color) = (*(GVarHandle)((port)->grafVars))->rgbHiliteColor, (color))
+#define GetPortTextFont(port) ((port)->txFont)
+#define GetPortTextFace(port) ((port)->txFace)
+#define GetPortTextMode(port) ((port)->txMode)
+#define GetPortTextSize(port) ((port)->txSize)
+#define GetPortChExtra(port) ((port)->chExtra)
+#define GetPortFracHPenLocation(port) ((port)->pnLocHFrac)
+#define GetPortSpExtra(port) ((port)->spExtra)
+#define GetPortPenVisibility(port) ((port)->pnVis)
+#define GetPortVisibleRegion(port, rgn) ((rgn) = (port)->visRgn, (rgn))
+#define GetPortClipRegion(port, rgn) ((rgn) = (port)->clipRgn, (rgn))
+#define GetPortBackPixPat(port, pat) ((pat) = (port)->bkPixPat, (pat))
+#define GetPortPenPixPat(port, pat) ((pat) = (port)->pnPixPat, (pat))
+#define GetPortFillPixPat(port, pat) ((pat) = (port)->fillPixPat, (pat))
+#define GetPortPenSize(port, pensize) (*(pensize) = (port)->pnSize, (pensize))
+#define GetPortPenMode(port) ((port)->pnMode)
+#define GetPortPenLocation(port, location) ((*location) = (port)->pnLoc, (location))
+#define IsPortRegionBeingDefined(port) (!!((port)->rgnSave))
+#define IsPortPictureBeingDefined(port) (!!((port)->picSave))
+/* #define IsPortOffscreen(port) */
+/* #define IsPortColor(port) */
+
+#define SetPortBounds(port, bounds) ((port)->portRect = *(bounds))
+#define SetPortOpColor(port, color) ((*(GVarHandle)((port)->grafVars))->rgbOpColor = *(color))
+#define SetPortVisibleRegion(port, rgn) ((port)->visRgn = (rgn))
+#define SetPortClipRegion(port, rgn) ((port)->clipRgn = (rgn))
+#define SetPortBackPixPat(port, pat) ((port)->bkPixPat = (pat))
+#define SetPortPenPixPat(port, pat) ((port)->pnPixPat = (pat))
+#define SetPortFillPixPat(port, pat) ((port)->fillPixPat = (pat))
+#define SetPortPenSize(port, pensize) ((port)->pnSize = (pensize))
+#define SetPortPenMode(port, mode) ((port)->pnMode = (mode))
+#define SetPortFracHPenLocation(port, frac) ((port)->pnLocHFrac = (frac))
+
+/* On pixmaps */
+#define GetPixBounds(pixmap, rect) (*(rect) = (*(pixmap))->bounds, (rect))
+#define GetPixDepth(pixmap) ((*(pixmap))->pixelSize)
+
+/* On regions */
+#define GetRegionBounds(rgn, rect) (*(rect) = (*(rgn))->rgnBBox, (rect))
+
+/* On QD Globals */
+#define GetQDGlobalsRandomSeed() (qd.randSeed)
+#define GetQDGlobalsScreenBits(bits) (*(bits) = qd.screenBits, (bits))
+#define GetQDGlobalsArrow(crsr) (*(crsr) = qd.arrow, (crsr))
+#define GetQDGlobalsDarkGray(pat) (*(pat) = qd.dkGray, (pat))
+#define GetQDGlobalsLightGray(pat) (*(pat) = qd.ltGray, (pat))
+#define GetQDGlobalsGray(pat) (*(pat) = qd.gray, (pat))
+#define GetQDGlobalsBlack(pat) (*(pat) = qd.black, (pat))
+#define GetQDGlobalsWhite(pat) (*(pat) = qd.white, (pat))
+#define GetQDGlobalsThePort() ((CGrafPtr)qd.thePort)
+
+#define SetQDGlobalsRandomSeed(seed) (qd.randSeed = (seed))
+#define SetQDGlobalsArrow(crsr) (qd.arrow = *(crsr))
+
+#endif /* ACCESSOR_CALLS_ARE_FUNCTIONS */
+
+#if !TARGET_API_MAC_CARBON
+#define QDFlushPortBuffer(port, rgn) /* pass */
+#define QDIsPortBufferDirty(port) 0
+#define QDIsPortBuffered(port) 0
+#endif /* !TARGET_API_MAC_CARBON */
+
+staticforward PyObject *BMObj_NewCopied(BitMapPtr);
+
+/*
+** Parse/generate RGB records
+*/
+PyObject *QdRGB_New(RGBColorPtr itself)
+{
+
+ return Py_BuildValue("lll", (long)itself->red, (long)itself->green, (long)itself->blue);
+}
+
+QdRGB_Convert(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;
+}
+
+/*
+** Generate FontInfo records
+*/
+static
+PyObject *QdFI_New(FontInfo *itself)
+{
+
+ return Py_BuildValue("hhhh", itself->ascent, itself->descent,
+ itself->widMax, itself->leading);
+}
+"""
+
+finalstuff = finalstuff + """
+/* Like BMObj_New, but the original bitmap data structure is copied (and
+** released when the object is released)
+*/
+PyObject *BMObj_NewCopied(BitMapPtr itself)
+{
+ BitMapObject *it;
+ BitMapPtr itself_copy;
+
+ if ((itself_copy=(BitMapPtr)malloc(sizeof(BitMap))) == NULL)
+ return PyErr_NoMemory();
+ *itself_copy = *itself;
+ it = (BitMapObject *)BMObj_New(itself_copy);
+ it->referred_bitmap = itself_copy;
+ return (PyObject *)it;
+}
+
+"""
+
+variablestuff = """
+{
+ PyObject *o;
+
+ o = QDGA_New();
+ if (o == NULL || PyDict_SetItemString(d, "qd", o) != 0)
+ return;
+}
+"""
+
+initstuff = initstuff + """
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(BitMapPtr, BMObj_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(BitMapPtr, BMObj_Convert);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(GrafPtr, GrafObj_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(GrafPtr, GrafObj_Convert);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(RGBColorPtr, QdRGB_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(RGBColor, QdRGB_Convert);
+"""
+
+## not yet...
+##
+##class Region_ObjectDefinition(GlobalObjectDefinition):
+## def outputCheckNewArg(self):
+## Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+## def outputFreeIt(self, itselfname):
+## Output("DisposeRegion(%s);", itselfname)
+##
+##class Polygon_ObjectDefinition(GlobalObjectDefinition):
+## def outputCheckNewArg(self):
+## Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+## def outputFreeIt(self, itselfname):
+## Output("KillPoly(%s);", itselfname)
+
+class MyGRObjectDefinition(GlobalObjectDefinition):
+ def outputCheckNewArg(self):
+ Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+ def outputCheckConvertArg(self):
+ Output("#if 1")
+ OutLbrace()
+ Output("WindowRef win;")
+ OutLbrace("if (WinObj_Convert(v, &win) && v)")
+ Output("*p_itself = (GrafPtr)GetWindowPort(win);")
+ Output("return 1;")
+ OutRbrace()
+ Output("PyErr_Clear();")
+ OutRbrace()
+ Output("#else")
+ OutLbrace("if (DlgObj_Check(v))")
+ Output("DialogRef dlg = (DialogRef)((GrafPortObject *)v)->ob_itself;")
+ Output("*p_itself = (GrafPtr)GetWindowPort(GetDialogWindow(dlg));")
+ Output("return 1;")
+ OutRbrace()
+ OutLbrace("if (WinObj_Check(v))")
+ Output("WindowRef win = (WindowRef)((GrafPortObject *)v)->ob_itself;")
+ Output("*p_itself = (GrafPtr)GetWindowPort(win);")
+ Output("return 1;")
+ OutRbrace()
+ Output("#endif")
+ def outputGetattrHook(self):
+ Output("#if !ACCESSOR_CALLS_ARE_FUNCTIONS")
+ Output("""
+ { CGrafPtr itself_color = (CGrafPtr)self->ob_itself;
+
+ if ( strcmp(name, "data") == 0 )
+ return PyString_FromStringAndSize((char *)self->ob_itself, sizeof(GrafPort));
+
+ if ( (itself_color->portVersion&0xc000) == 0xc000 ) {
+ /* Color-only attributes */
+
+ if ( strcmp(name, "portBits") == 0 )
+ /* XXXX Do we need HLock() stuff here?? */
+ return BMObj_New((BitMapPtr)*itself_color->portPixMap);
+ if ( strcmp(name, "grafVars") == 0 )
+ return Py_BuildValue("O&", ResObj_New, (Handle)itself_color->visRgn);
+ if ( strcmp(name, "chExtra") == 0 )
+ return Py_BuildValue("h", itself_color->chExtra);
+ if ( strcmp(name, "pnLocHFrac") == 0 )
+ return Py_BuildValue("h", itself_color->pnLocHFrac);
+ if ( strcmp(name, "bkPixPat") == 0 )
+ return Py_BuildValue("O&", ResObj_New, (Handle)itself_color->bkPixPat);
+ if ( strcmp(name, "rgbFgColor") == 0 )
+ return Py_BuildValue("O&", QdRGB_New, &itself_color->rgbFgColor);
+ if ( strcmp(name, "rgbBkColor") == 0 )
+ return Py_BuildValue("O&", QdRGB_New, &itself_color->rgbBkColor);
+ if ( strcmp(name, "pnPixPat") == 0 )
+ return Py_BuildValue("O&", ResObj_New, (Handle)itself_color->pnPixPat);
+ if ( strcmp(name, "fillPixPat") == 0 )
+ return Py_BuildValue("O&", ResObj_New, (Handle)itself_color->fillPixPat);
+ } else {
+ /* Mono-only attributes */
+ if ( strcmp(name, "portBits") == 0 )
+ return BMObj_New(&self->ob_itself->portBits);
+ if ( strcmp(name, "bkPat") == 0 )
+ return Py_BuildValue("s#", (char *)&self->ob_itself->bkPat, sizeof(Pattern));
+ if ( strcmp(name, "fillPat") == 0 )
+ return Py_BuildValue("s#", (char *)&self->ob_itself->fillPat, sizeof(Pattern));
+ if ( strcmp(name, "pnPat") == 0 )
+ return Py_BuildValue("s#", (char *)&self->ob_itself->pnPat, sizeof(Pattern));
+ }
+ /*
+ ** Accessible for both color/mono windows.
+ ** portVersion is really color-only, but we put it here
+ ** for convenience
+ */
+ if ( strcmp(name, "portVersion") == 0 )
+ return Py_BuildValue("h", itself_color->portVersion);
+ if ( strcmp(name, "device") == 0 )
+ return PyInt_FromLong((long)self->ob_itself->device);
+ if ( strcmp(name, "portRect") == 0 )
+ return Py_BuildValue("O&", PyMac_BuildRect, &self->ob_itself->portRect);
+ if ( strcmp(name, "visRgn") == 0 )
+ return Py_BuildValue("O&", ResObj_New, (Handle)self->ob_itself->visRgn);
+ if ( strcmp(name, "clipRgn") == 0 )
+ return Py_BuildValue("O&", ResObj_New, (Handle)self->ob_itself->clipRgn);
+ if ( strcmp(name, "pnLoc") == 0 )
+ return Py_BuildValue("O&", PyMac_BuildPoint, self->ob_itself->pnLoc);
+ if ( strcmp(name, "pnSize") == 0 )
+ return Py_BuildValue("O&", PyMac_BuildPoint, self->ob_itself->pnSize);
+ if ( strcmp(name, "pnMode") == 0 )
+ return Py_BuildValue("h", self->ob_itself->pnMode);
+ if ( strcmp(name, "pnVis") == 0 )
+ return Py_BuildValue("h", self->ob_itself->pnVis);
+ if ( strcmp(name, "txFont") == 0 )
+ return Py_BuildValue("h", self->ob_itself->txFont);
+ if ( strcmp(name, "txFace") == 0 )
+ return Py_BuildValue("h", (short)self->ob_itself->txFace);
+ if ( strcmp(name, "txMode") == 0 )
+ return Py_BuildValue("h", self->ob_itself->txMode);
+ if ( strcmp(name, "txSize") == 0 )
+ return Py_BuildValue("h", self->ob_itself->txSize);
+ if ( strcmp(name, "spExtra") == 0 )
+ return Py_BuildValue("O&", PyMac_BuildFixed, self->ob_itself->spExtra);
+ /* XXXX Add more, as needed */
+ /* This one is so we can compare grafports: */
+ if ( strcmp(name, "_id") == 0 )
+ return Py_BuildValue("l", (long)self->ob_itself);
+ }""")
+ Output("#else")
+ Output("""
+ { CGrafPtr itself_color = (CGrafPtr)self->ob_itself;
+ if ( strcmp(name, "portBits") == 0 )
+ return BMObj_New((BitMapPtr)GetPortBitMapForCopyBits(itself_color));
+ if ( strcmp(name, "chExtra") == 0 )
+ return Py_BuildValue("h", GetPortChExtra(itself_color));
+ if ( strcmp(name, "pnLocHFrac") == 0 )
+ return Py_BuildValue("h", GetPortFracHPenLocation(itself_color));
+ if ( strcmp(name, "bkPixPat") == 0 ) {
+ PixPatHandle h=0;
+ return Py_BuildValue("O&", ResObj_New, (Handle)GetPortBackPixPat(itself_color, h));
+ }
+ if ( strcmp(name, "rgbFgColor") == 0 ) {
+ RGBColor c;
+ return Py_BuildValue("O&", QdRGB_New, GetPortForeColor(itself_color, &c));
+ }
+ if ( strcmp(name, "rgbBkColor") == 0 ) {
+ RGBColor c;
+ return Py_BuildValue("O&", QdRGB_New, GetPortBackColor(itself_color, &c));
+ }
+ if ( strcmp(name, "pnPixPat") == 0 ) {
+ PixPatHandle h=NewPixPat(); /* XXXX wrong dispose routine */
+
+ return Py_BuildValue("O&", ResObj_New, (Handle)GetPortPenPixPat(itself_color, h));
+ }
+ if ( strcmp(name, "fillPixPat") == 0 ) {
+ PixPatHandle h=NewPixPat(); /* XXXX wrong dispose routine */
+ return Py_BuildValue("O&", ResObj_New, (Handle)GetPortFillPixPat(itself_color, h));
+ }
+ if ( strcmp(name, "portRect") == 0 ) {
+ Rect r;
+ return Py_BuildValue("O&", PyMac_BuildRect, GetPortBounds(itself_color, &r));
+ }
+ if ( strcmp(name, "visRgn") == 0 ) {
+ RgnHandle h=NewRgn(); /* XXXX wrong dispose routine */
+ return Py_BuildValue("O&", ResObj_New, (Handle)GetPortVisibleRegion(itself_color, h));
+ }
+ if ( strcmp(name, "clipRgn") == 0 ) {
+ RgnHandle h=NewRgn(); /* XXXX wrong dispose routine */
+ return Py_BuildValue("O&", ResObj_New, (Handle)GetPortClipRegion(itself_color, h));
+ }
+ if ( strcmp(name, "pnLoc") == 0 ) {
+ Point p;
+ return Py_BuildValue("O&", PyMac_BuildPoint, *GetPortPenLocation(itself_color, &p));
+ }
+ if ( strcmp(name, "pnSize") == 0 ) {
+ Point p;
+ return Py_BuildValue("O&", PyMac_BuildPoint, *GetPortPenSize(itself_color, &p));
+ }
+ if ( strcmp(name, "pnMode") == 0 )
+ return Py_BuildValue("h", GetPortPenMode(itself_color));
+ if ( strcmp(name, "pnVis") == 0 )
+ return Py_BuildValue("h", GetPortPenVisibility(itself_color));
+ if ( strcmp(name, "txFont") == 0 )
+ return Py_BuildValue("h", GetPortTextFont(itself_color));
+ if ( strcmp(name, "txFace") == 0 )
+ return Py_BuildValue("h", (short)GetPortTextFace(itself_color));
+ if ( strcmp(name, "txMode") == 0 )
+ return Py_BuildValue("h", GetPortTextMode(itself_color));
+ if ( strcmp(name, "txSize") == 0 )
+ return Py_BuildValue("h", GetPortTextSize(itself_color));
+ if ( strcmp(name, "spExtra") == 0 )
+ return Py_BuildValue("O&", PyMac_BuildFixed, GetPortSpExtra(itself_color));
+ /* XXXX Add more, as needed */
+ /* This one is so we can compare grafports: */
+ if ( strcmp(name, "_id") == 0 )
+ return Py_BuildValue("l", (long)self->ob_itself);
+ }""")
+ Output("#endif")
+
+class MyBMObjectDefinition(GlobalObjectDefinition):
+ def outputCheckNewArg(self):
+ Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+ def outputStructMembers(self):
+ # We need to more items: a pointer to privately allocated data
+ # and a python object we're referring to.
+ Output("%s ob_itself;", self.itselftype)
+ Output("PyObject *referred_object;")
+ Output("BitMap *referred_bitmap;")
+ def outputInitStructMembers(self):
+ Output("it->ob_itself = %sitself;", self.argref)
+ Output("it->referred_object = NULL;")
+ Output("it->referred_bitmap = NULL;")
+ def outputCleanupStructMembers(self):
+ Output("Py_XDECREF(self->referred_object);")
+ Output("if (self->referred_bitmap) free(self->referred_bitmap);")
+ def outputGetattrHook(self):
+ Output("""if ( strcmp(name, "baseAddr") == 0 )
+ return PyInt_FromLong((long)self->ob_itself->baseAddr);
+ if ( strcmp(name, "rowBytes") == 0 )
+ return PyInt_FromLong((long)self->ob_itself->rowBytes);
+ if ( strcmp(name, "bounds") == 0 )
+ return Py_BuildValue("O&", PyMac_BuildRect, &self->ob_itself->bounds);
+ /* XXXX Add more, as needed */
+ if ( strcmp(name, "bitmap_data") == 0 )
+ return PyString_FromStringAndSize((char *)self->ob_itself, sizeof(BitMap));
+ if ( strcmp(name, "pixmap_data") == 0 )
+ return PyString_FromStringAndSize((char *)self->ob_itself, sizeof(PixMap));
+ """)
+
+# This object is instanciated once, and will access qd globals.
+class QDGlobalsAccessObjectDefinition(ObjectDefinition):
+ def outputStructMembers(self):
+ pass
+ def outputNew(self):
+ Output()
+ Output("%sPyObject *%s_New(void)", self.static, self.prefix)
+ OutLbrace()
+ Output("%s *it;", self.objecttype)
+ Output("it = PyObject_NEW(%s, &%s);", self.objecttype, self.typename)
+ Output("if (it == NULL) return NULL;")
+ Output("return (PyObject *)it;")
+ OutRbrace()
+ def outputConvert(self):
+ pass
+ def outputCleanupStructMembers(self):
+ pass
+
+ def outputGetattrHook(self):
+ Output("#if !ACCESSOR_CALLS_ARE_FUNCTIONS")
+ Output("""
+ if ( strcmp(name, "arrow") == 0 )
+ return PyString_FromStringAndSize((char *)&qd.arrow, sizeof(qd.arrow));
+ if ( strcmp(name, "black") == 0 )
+ return PyString_FromStringAndSize((char *)&qd.black, sizeof(qd.black));
+ if ( strcmp(name, "white") == 0 )
+ return PyString_FromStringAndSize((char *)&qd.white, sizeof(qd.white));
+ if ( strcmp(name, "gray") == 0 )
+ return PyString_FromStringAndSize((char *)&qd.gray, sizeof(qd.gray));
+ if ( strcmp(name, "ltGray") == 0 )
+ return PyString_FromStringAndSize((char *)&qd.ltGray, sizeof(qd.ltGray));
+ if ( strcmp(name, "dkGray") == 0 )
+ return PyString_FromStringAndSize((char *)&qd.dkGray, sizeof(qd.dkGray));
+ if ( strcmp(name, "screenBits") == 0 )
+ return BMObj_New(&qd.screenBits);
+ if ( strcmp(name, "thePort") == 0 )
+ return GrafObj_New(qd.thePort);
+ if ( strcmp(name, "randSeed") == 0 )
+ return Py_BuildValue("l", &qd.randSeed);
+ """)
+ Output("#else")
+ Output("""
+ if ( strcmp(name, "arrow") == 0 ) {
+ Cursor rv;
+ GetQDGlobalsArrow(&rv);
+ return PyString_FromStringAndSize((char *)&rv, sizeof(rv));
+ }
+ if ( strcmp(name, "black") == 0 ) {
+ Pattern rv;
+ GetQDGlobalsBlack(&rv);
+ return PyString_FromStringAndSize((char *)&rv, sizeof(rv));
+ }
+ if ( strcmp(name, "white") == 0 ) {
+ Pattern rv;
+ GetQDGlobalsWhite(&rv);
+ return PyString_FromStringAndSize((char *)&rv, sizeof(rv));
+ }
+ if ( strcmp(name, "gray") == 0 ) {
+ Pattern rv;
+ GetQDGlobalsGray(&rv);
+ return PyString_FromStringAndSize((char *)&rv, sizeof(rv));
+ }
+ if ( strcmp(name, "ltGray") == 0 ) {
+ Pattern rv;
+ GetQDGlobalsLightGray(&rv);
+ return PyString_FromStringAndSize((char *)&rv, sizeof(rv));
+ }
+ if ( strcmp(name, "dkGray") == 0 ) {
+ Pattern rv;
+ GetQDGlobalsDarkGray(&rv);
+ return PyString_FromStringAndSize((char *)&rv, sizeof(rv));
+ }
+ if ( strcmp(name, "screenBits") == 0 ) {
+ BitMap rv;
+ GetQDGlobalsScreenBits(&rv);
+ return BMObj_NewCopied(&rv);
+ }
+ if ( strcmp(name, "thePort") == 0 )
+ return GrafObj_New(GetQDGlobalsThePort());
+ if ( strcmp(name, "randSeed") == 0 )
+ return Py_BuildValue("l", GetQDGlobalsRandomSeed());
+ """)
+ Output("#endif")
+
+# Create the generator groups and link them
+module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff, variablestuff)
+##r_object = Region_ObjectDefinition('Region', 'QdRgn', 'RgnHandle')
+##po_object = Polygon_ObjectDefinition('Polygon', 'QdPgn', 'PolyHandle')
+##module.addobject(r_object)
+##module.addobject(po_object)
+gr_object = MyGRObjectDefinition("GrafPort", "GrafObj", "GrafPtr")
+module.addobject(gr_object)
+bm_object = MyBMObjectDefinition("BitMap", "BMObj", "BitMapPtr")
+module.addobject(bm_object)
+qd_object = QDGlobalsAccessObjectDefinition("QDGlobalsAccess", "QDGA", "XXXX")
+module.addobject(qd_object)
+
+
+# Create the generator classes used to populate the lists
+Function = OSErrFunctionGenerator
+Method = OSErrMethodGenerator
+
+# Create and populate the lists
+functions = []
+methods = []
+execfile(INPUTFILE)
+execfile(EXTRAFILE)
+
+# add the populated lists to the generator groups
+# (in a different wordl the scan program would generate this)
+for f in functions: module.add(f)
+##for f in r_methods: r_object.add(f)
+##for f in po_methods: po_object.add(f)
+
+# Manual generator: get data out of a bitmap
+getdata_body = """
+int from, length;
+char *cp;
+
+if ( !PyArg_ParseTuple(_args, "ii", &from, &length) )
+ return NULL;
+cp = _self->ob_itself->baseAddr+from;
+return PyString_FromStringAndSize(cp, length);
+"""
+f = ManualGenerator("getdata", getdata_body)
+f.docstring = lambda: """(int start, int size) -> string. Return bytes from the bitmap"""
+bm_object.add(f)
+
+# Manual generator: store data in a bitmap
+putdata_body = """
+int from, length;
+char *cp, *icp;
+
+if ( !PyArg_ParseTuple(_args, "is#", &from, &icp, &length) )
+ return NULL;
+cp = _self->ob_itself->baseAddr+from;
+memcpy(cp, icp, length);
+Py_INCREF(Py_None);
+return Py_None;
+"""
+f = ManualGenerator("putdata", putdata_body)
+f.docstring = lambda: """(int start, string data). Store bytes into the bitmap"""
+bm_object.add(f)
+
+#
+# We manually generate a routine to create a BitMap from python data.
+#
+BitMap_body = """
+BitMap *ptr;
+PyObject *source;
+Rect bounds;
+int rowbytes;
+char *data;
+
+if ( !PyArg_ParseTuple(_args, "O!iO&", &PyString_Type, &source, &rowbytes, PyMac_GetRect,
+ &bounds) )
+ return NULL;
+data = PyString_AsString(source);
+if ((ptr=(BitMap *)malloc(sizeof(BitMap))) == NULL )
+ return PyErr_NoMemory();
+ptr->baseAddr = (Ptr)data;
+ptr->rowBytes = rowbytes;
+ptr->bounds = bounds;
+if ( (_res = BMObj_New(ptr)) == NULL ) {
+ free(ptr);
+ return NULL;
+}
+((BitMapObject *)_res)->referred_object = source;
+Py_INCREF(source);
+((BitMapObject *)_res)->referred_bitmap = ptr;
+return _res;
+"""
+
+f = ManualGenerator("BitMap", BitMap_body)
+f.docstring = lambda: """Take (string, int, Rect) argument and create BitMap"""
+module.add(f)
+
+#
+# And again, for turning a correctly-formatted structure into the object
+#
+RawBitMap_body = """
+BitMap *ptr;
+PyObject *source;
+
+if ( !PyArg_ParseTuple(_args, "O!", &PyString_Type, &source) )
+ return NULL;
+if ( PyString_Size(source) != sizeof(BitMap) && PyString_Size(source) != sizeof(PixMap) ) {
+ PyErr_BadArgument();
+ return NULL;
+}
+ptr = (BitMapPtr)PyString_AsString(source);
+if ( (_res = BMObj_New(ptr)) == NULL ) {
+ return NULL;
+}
+((BitMapObject *)_res)->referred_object = source;
+Py_INCREF(source);
+return _res;
+"""
+
+f = ManualGenerator("RawBitMap", RawBitMap_body)
+f.docstring = lambda: """Take string BitMap and turn into BitMap object"""
+module.add(f)
+
+# generate output (open the output file as late as possible)
+SetOutputFileName(OUTPUTFILE)
+module.generate()
+SetOutputFile() # Close it
--- /dev/null
+
+/* ========================== Module Scrap ========================== */
+
+#include "Python.h"
+
+
+
+#include "macglue.h"
+#include "pymactoolbox.h"
+
+#ifdef WITHOUT_FRAMEWORKS
+#include <Scrap.h>
+#else
+#include <Carbon/Carbon.h>
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+/*
+** Generate ScrapInfo records
+*/
+static PyObject *
+SCRRec_New(itself)
+ ScrapStuff *itself;
+{
+
+ return Py_BuildValue("lO&hhO&", itself->scrapSize,
+ ResObj_New, itself->scrapHandle, itself->scrapCount, itself->scrapState,
+ PyMac_BuildStr255, itself->scrapName);
+}
+#endif
+
+static PyObject *Scrap_Error;
+
+static PyObject *Scrap_LoadScrap(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = LoadScrap();
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Scrap_UnloadScrap(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = UnloadScrap();
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Scrap_InfoScrap(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ ScrapStuffPtr _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = InfoScrap();
+ _res = Py_BuildValue("O&",
+ SCRRec_New, _rv);
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Scrap_GetScrap(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ long _rv;
+ Handle destination;
+ ScrapFlavorType flavorType;
+ SInt32 offset;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, &destination,
+ PyMac_GetOSType, &flavorType))
+ return NULL;
+ _rv = GetScrap(destination,
+ flavorType,
+ &offset);
+ _res = Py_BuildValue("ll",
+ _rv,
+ offset);
+ return _res;
+}
+#endif
+
+
+static PyObject *Scrap_ZeroScrap(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+#if TARGET_API_MAC_CARBON
+ {
+ ScrapRef scrap;
+
+ _err = ClearCurrentScrap();
+ if (_err != noErr) return PyMac_Error(_err);
+ _err = GetCurrentScrap(&scrap);
+ }
+#else
+ _err = ZeroScrap();
+#endif
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Scrap_PutScrap(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ SInt32 sourceBufferByteCount;
+ ScrapFlavorType flavorType;
+ char *sourceBuffer__in__;
+ int sourceBuffer__len__;
+ int sourceBuffer__in_len__;
+#if TARGET_API_MAC_CARBON
+ ScrapRef scrap;
+#endif
+
+ if (!PyArg_ParseTuple(_args, "O&s#",
+ PyMac_GetOSType, &flavorType,
+ &sourceBuffer__in__, &sourceBuffer__in_len__))
+ return NULL;
+ sourceBufferByteCount = sourceBuffer__in_len__;
+ sourceBuffer__len__ = sourceBuffer__in_len__;
+#if TARGET_API_MAC_CARBON
+ _err = GetCurrentScrap(&scrap);
+ if (_err != noErr) return PyMac_Error(_err);
+ _err = PutScrapFlavor(scrap, flavorType, 0, sourceBufferByteCount, sourceBuffer__in__);
+#else
+ _err = PutScrap(sourceBufferByteCount,
+ flavorType,
+ sourceBuffer__in__);
+#endif
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ sourceBuffer__error__: ;
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *Scrap_ClearCurrentScrap(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = ClearCurrentScrap();
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *Scrap_CallInScrapPromises(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = CallInScrapPromises();
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyMethodDef Scrap_methods[] = {
+ {"LoadScrap", (PyCFunction)Scrap_LoadScrap, 1,
+ "() -> None"},
+ {"UnloadScrap", (PyCFunction)Scrap_UnloadScrap, 1,
+ "() -> None"},
+
+#if !TARGET_API_MAC_CARBON
+ {"InfoScrap", (PyCFunction)Scrap_InfoScrap, 1,
+ "() -> (ScrapStuffPtr _rv)"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"GetScrap", (PyCFunction)Scrap_GetScrap, 1,
+ "(Handle destination, ScrapFlavorType flavorType) -> (long _rv, SInt32 offset)"},
+#endif
+
+ {"ZeroScrap", (PyCFunction)Scrap_ZeroScrap, 1,
+ "() -> None"},
+
+ {"PutScrap", (PyCFunction)Scrap_PutScrap, 1,
+ "(ScrapFlavorType flavorType, Buffer sourceBuffer) -> None"},
+
+#if TARGET_API_MAC_CARBON
+ {"ClearCurrentScrap", (PyCFunction)Scrap_ClearCurrentScrap, 1,
+ "() -> None"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"CallInScrapPromises", (PyCFunction)Scrap_CallInScrapPromises, 1,
+ "() -> None"},
+#endif
+ {NULL, NULL, 0}
+};
+
+
+
+
+void initScrap()
+{
+ PyObject *m;
+ PyObject *d;
+
+
+
+
+ m = Py_InitModule("Scrap", Scrap_methods);
+ d = PyModule_GetDict(m);
+ Scrap_Error = PyMac_GetOSErrException();
+ if (Scrap_Error == NULL ||
+ PyDict_SetItemString(d, "Error", Scrap_Error) != 0)
+ return;
+}
+
+/* ======================== End module Scrap ======================== */
+
--- /dev/null
+
+/* =========================== Module Snd =========================== */
+
+#include "Python.h"
+
+
+
+#include "macglue.h"
+#include "pymactoolbox.h"
+
+#ifdef WITHOUT_FRAMEWORKS
+#include <Sound.h>
+#include <OSUtils.h> /* for Set(Current)A5 */
+#else
+#include <Carbon/Carbon.h>
+#endif
+
+
+/* Create a SndCommand object (an (int, int, int) tuple) */
+static PyObject *
+SndCmd_New(SndCommand *pc)
+{
+ return Py_BuildValue("hhl", pc->cmd, pc->param1, pc->param2);
+}
+
+/* Convert a SndCommand argument */
+static int
+SndCmd_Convert(PyObject *v, SndCommand *pc)
+{
+ int len;
+ pc->param1 = 0;
+ pc->param2 = 0;
+ if (PyTuple_Check(v)) {
+ if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2))
+ return 1;
+ PyErr_Clear();
+ return PyArg_ParseTuple(v, "Hhs#", &pc->cmd, &pc->param1, &pc->param2, &len);
+ }
+ return PyArg_Parse(v, "H", &pc->cmd);
+}
+
+static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */
+static pascal void SPB_completion(SPBPtr my_spb); /* Forward */
+#if !TARGET_API_MAC_CARBON
+static pascal void SPB_interrupt(SPBPtr my_spb); /* Forward */
+#endif
+
+static PyObject *Snd_Error;
+
+/* --------------------- Object type SndChannel --------------------- */
+
+staticforward PyTypeObject SndChannel_Type;
+
+#define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type)
+
+typedef struct SndChannelObject {
+ PyObject_HEAD
+ SndChannelPtr ob_itself;
+ /* Members used to implement callbacks: */
+ PyObject *ob_callback;
+ long ob_A5;
+ SndCommand ob_cmd;
+} SndChannelObject;
+
+static PyObject *SndCh_New(SndChannelPtr itself)
+{
+ SndChannelObject *it;
+ it = PyObject_NEW(SndChannelObject, &SndChannel_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_callback = NULL;
+ it->ob_A5 = SetCurrentA5();
+ return (PyObject *)it;
+}
+static SndCh_Convert(PyObject *v, SndChannelPtr *p_itself)
+{
+ if (!SndCh_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "SndChannel required");
+ return 0;
+ }
+ *p_itself = ((SndChannelObject *)v)->ob_itself;
+ return 1;
+}
+
+static void SndCh_dealloc(SndChannelObject *self)
+{
+ SndDisposeChannel(self->ob_itself, 1);
+ Py_XDECREF(self->ob_callback);
+ PyMem_DEL(self);
+}
+
+static PyObject *SndCh_SndDoCommand(SndChannelObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SndCommand cmd;
+ Boolean noWait;
+ if (!PyArg_ParseTuple(_args, "O&b",
+ SndCmd_Convert, &cmd,
+ &noWait))
+ return NULL;
+ _err = SndDoCommand(_self->ob_itself,
+ &cmd,
+ noWait);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *SndCh_SndDoImmediate(SndChannelObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SndCommand cmd;
+ if (!PyArg_ParseTuple(_args, "O&",
+ SndCmd_Convert, &cmd))
+ return NULL;
+ _err = SndDoImmediate(_self->ob_itself,
+ &cmd);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *SndCh_SndPlay(SndChannelObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SndListHandle sndHandle;
+ Boolean async;
+ if (!PyArg_ParseTuple(_args, "O&b",
+ ResObj_Convert, &sndHandle,
+ &async))
+ return NULL;
+ _err = SndPlay(_self->ob_itself,
+ sndHandle,
+ async);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *SndCh_SndStartFilePlay(SndChannelObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ short fRefNum;
+ short resNum;
+ long bufferSize;
+ Boolean async;
+ if (!PyArg_ParseTuple(_args, "hhlb",
+ &fRefNum,
+ &resNum,
+ &bufferSize,
+ &async))
+ return NULL;
+ _err = SndStartFilePlay(_self->ob_itself,
+ fRefNum,
+ resNum,
+ bufferSize,
+ 0,
+ 0,
+ 0,
+ async);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *SndCh_SndPauseFilePlay(SndChannelObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = SndPauseFilePlay(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *SndCh_SndStopFilePlay(SndChannelObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ Boolean quietNow;
+ if (!PyArg_ParseTuple(_args, "b",
+ &quietNow))
+ return NULL;
+ _err = SndStopFilePlay(_self->ob_itself,
+ quietNow);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *SndCh_SndChannelStatus(SndChannelObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ short theLength;
+ SCStatus theStatus__out__;
+ if (!PyArg_ParseTuple(_args, "h",
+ &theLength))
+ return NULL;
+ _err = SndChannelStatus(_self->ob_itself,
+ theLength,
+ &theStatus__out__);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("s#",
+ (char *)&theStatus__out__, (int)sizeof(SCStatus));
+ theStatus__error__: ;
+ return _res;
+}
+
+static PyObject *SndCh_SndGetInfo(SndChannelObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ OSType selector;
+ void * infoPtr;
+ if (!PyArg_ParseTuple(_args, "O&w",
+ PyMac_GetOSType, &selector,
+ &infoPtr))
+ return NULL;
+ _err = SndGetInfo(_self->ob_itself,
+ selector,
+ infoPtr);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *SndCh_SndSetInfo(SndChannelObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ OSType selector;
+ void * infoPtr;
+ if (!PyArg_ParseTuple(_args, "O&w",
+ PyMac_GetOSType, &selector,
+ &infoPtr))
+ return NULL;
+ _err = SndSetInfo(_self->ob_itself,
+ selector,
+ infoPtr);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyMethodDef SndCh_methods[] = {
+ {"SndDoCommand", (PyCFunction)SndCh_SndDoCommand, 1,
+ "(SndCommand cmd, Boolean noWait) -> None"},
+ {"SndDoImmediate", (PyCFunction)SndCh_SndDoImmediate, 1,
+ "(SndCommand cmd) -> None"},
+ {"SndPlay", (PyCFunction)SndCh_SndPlay, 1,
+ "(SndListHandle sndHandle, Boolean async) -> None"},
+
+#if !TARGET_API_MAC_CARBON
+ {"SndStartFilePlay", (PyCFunction)SndCh_SndStartFilePlay, 1,
+ "(short fRefNum, short resNum, long bufferSize, Boolean async) -> None"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"SndPauseFilePlay", (PyCFunction)SndCh_SndPauseFilePlay, 1,
+ "() -> None"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"SndStopFilePlay", (PyCFunction)SndCh_SndStopFilePlay, 1,
+ "(Boolean quietNow) -> None"},
+#endif
+ {"SndChannelStatus", (PyCFunction)SndCh_SndChannelStatus, 1,
+ "(short theLength) -> (SCStatus theStatus)"},
+ {"SndGetInfo", (PyCFunction)SndCh_SndGetInfo, 1,
+ "(OSType selector, void * infoPtr) -> None"},
+ {"SndSetInfo", (PyCFunction)SndCh_SndSetInfo, 1,
+ "(OSType selector, void * infoPtr) -> None"},
+ {NULL, NULL, 0}
+};
+
+static PyMethodChain SndCh_chain = { SndCh_methods, NULL };
+
+static PyObject *SndCh_getattr(SndChannelObject *self, char *name)
+{
+ return Py_FindMethodInChain(&SndCh_chain, (PyObject *)self, name);
+}
+
+#define SndCh_setattr NULL
+
+#define SndCh_compare NULL
+
+#define SndCh_repr NULL
+
+#define SndCh_hash NULL
+
+staticforward PyTypeObject SndChannel_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "SndChannel", /*tp_name*/
+ sizeof(SndChannelObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) SndCh_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) SndCh_getattr, /*tp_getattr*/
+ (setattrfunc) SndCh_setattr, /*tp_setattr*/
+ (cmpfunc) SndCh_compare, /*tp_compare*/
+ (reprfunc) SndCh_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) SndCh_hash, /*tp_hash*/
+};
+
+/* ------------------- End object type SndChannel ------------------- */
+
+
+/* ------------------------ Object type SPB ------------------------- */
+
+staticforward PyTypeObject SPB_Type;
+
+#define SPBObj_Check(x) ((x)->ob_type == &SPB_Type)
+
+typedef struct SPBObject {
+ PyObject_HEAD
+ /* Members used to implement callbacks: */
+ PyObject *ob_completion;
+ PyObject *ob_interrupt;
+ PyObject *ob_thiscallback;
+ long ob_A5;
+ SPB ob_spb;
+} SPBObject;
+
+static PyObject *SPBObj_New(void)
+{
+ SPBObject *it;
+ it = PyObject_NEW(SPBObject, &SPB_Type);
+ if (it == NULL) return NULL;
+ it->ob_completion = NULL;
+ it->ob_interrupt = NULL;
+ it->ob_thiscallback = NULL;
+ it->ob_A5 = SetCurrentA5();
+ memset((char *)&it->ob_spb, 0, sizeof(it->ob_spb));
+ it->ob_spb.userLong = (long)it;
+ return (PyObject *)it;
+}
+static SPBObj_Convert(PyObject *v, SPBPtr *p_itself)
+{
+ if (!SPBObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "SPB required");
+ return 0;
+ }
+ *p_itself = &((SPBObject *)v)->ob_spb;
+ return 1;
+}
+
+static void SPBObj_dealloc(SPBObject *self)
+{
+ /* Cleanup of self->ob_itself goes here */
+ self->ob_spb.userLong = 0;
+ self->ob_thiscallback = 0;
+ Py_XDECREF(self->ob_completion);
+ Py_XDECREF(self->ob_interrupt);
+ PyMem_DEL(self);
+}
+
+static PyMethodDef SPBObj_methods[] = {
+ {NULL, NULL, 0}
+};
+
+static PyMethodChain SPBObj_chain = { SPBObj_methods, NULL };
+
+static PyObject *SPBObj_getattr(SPBObject *self, char *name)
+{
+
+ if (strcmp(name, "inRefNum") == 0)
+ return Py_BuildValue("l", self->ob_spb.inRefNum);
+ else if (strcmp(name, "count") == 0)
+ return Py_BuildValue("l", self->ob_spb.count);
+ else if (strcmp(name, "milliseconds") == 0)
+ return Py_BuildValue("l", self->ob_spb.milliseconds);
+ else if (strcmp(name, "error") == 0)
+ return Py_BuildValue("h", self->ob_spb.error);
+ return Py_FindMethodInChain(&SPBObj_chain, (PyObject *)self, name);
+}
+
+static int SPBObj_setattr(SPBObject *self, char *name, PyObject *value)
+{
+
+ int rv = 0;
+
+ if (strcmp(name, "inRefNum") == 0)
+ rv = PyArg_Parse(value, "l", &self->ob_spb.inRefNum);
+ else if (strcmp(name, "count") == 0)
+ rv = PyArg_Parse(value, "l", &self->ob_spb.count);
+ else if (strcmp(name, "milliseconds") == 0)
+ rv = PyArg_Parse(value, "l", &self->ob_spb.milliseconds);
+ else if (strcmp(name, "buffer") == 0)
+ rv = PyArg_Parse(value, "w#", &self->ob_spb.bufferPtr, &self->ob_spb.bufferLength);
+ else if (strcmp(name, "completionRoutine") == 0) {
+ self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion);
+ self->ob_completion = value;
+ Py_INCREF(value);
+ rv = 1;
+#if !TARGET_API_MAC_CARBON
+ } else if (strcmp(name, "interruptRoutine") == 0) {
+ self->ob_spb.completionRoutine = NewSIInterruptUPP(SPB_interrupt);
+ self->ob_interrupt = value;
+ Py_INCREF(value);
+ rv = 1;
+#endif
+ }
+ if ( rv ) return 0;
+ else return -1;
+}
+
+#define SPBObj_compare NULL
+
+#define SPBObj_repr NULL
+
+#define SPBObj_hash NULL
+
+staticforward PyTypeObject SPB_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "SPB", /*tp_name*/
+ sizeof(SPBObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) SPBObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) SPBObj_getattr, /*tp_getattr*/
+ (setattrfunc) SPBObj_setattr, /*tp_setattr*/
+ (cmpfunc) SPBObj_compare, /*tp_compare*/
+ (reprfunc) SPBObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) SPBObj_hash, /*tp_hash*/
+};
+
+/* ---------------------- End object type SPB ----------------------- */
+
+
+static PyObject *Snd_SPB(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ return SPBObj_New();
+}
+
+static PyObject *Snd_SysBeep(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short duration;
+ if (!PyArg_ParseTuple(_args, "h",
+ &duration))
+ return NULL;
+ SysBeep(duration);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Snd_SndNewChannel(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SndChannelPtr chan = 0;
+ short synth;
+ long init;
+ PyObject* userRoutine;
+ if (!PyArg_ParseTuple(_args, "hlO",
+ &synth,
+ &init,
+ &userRoutine))
+ return NULL;
+ if (userRoutine != Py_None && !PyCallable_Check(userRoutine))
+ {
+ PyErr_SetString(PyExc_TypeError, "callback must be callable");
+ goto userRoutine__error__;
+ }
+ _err = SndNewChannel(&chan,
+ synth,
+ init,
+ NewSndCallBackUPP(SndCh_UserRoutine));
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ SndCh_New, chan);
+ if (_res != NULL && userRoutine != Py_None)
+ {
+ SndChannelObject *p = (SndChannelObject *)_res;
+ p->ob_itself->userInfo = (long)p;
+ Py_INCREF(userRoutine);
+ p->ob_callback = userRoutine;
+ }
+ userRoutine__error__: ;
+ return _res;
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Snd_SndControl(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ short id;
+ SndCommand cmd;
+ if (!PyArg_ParseTuple(_args, "h",
+ &id))
+ return NULL;
+ _err = SndControl(id,
+ &cmd);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ SndCmd_New, &cmd);
+ return _res;
+}
+#endif
+
+static PyObject *Snd_SndSoundManagerVersion(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ NumVersion _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = SndSoundManagerVersion();
+ _res = Py_BuildValue("O&",
+ PyMac_BuildNumVersion, _rv);
+ return _res;
+}
+
+static PyObject *Snd_SndManagerStatus(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ short theLength;
+ SMStatus theStatus__out__;
+ if (!PyArg_ParseTuple(_args, "h",
+ &theLength))
+ return NULL;
+ _err = SndManagerStatus(theLength,
+ &theStatus__out__);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("s#",
+ (char *)&theStatus__out__, (int)sizeof(SMStatus));
+ theStatus__error__: ;
+ return _res;
+}
+
+static PyObject *Snd_SndGetSysBeepState(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short sysBeepState;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ SndGetSysBeepState(&sysBeepState);
+ _res = Py_BuildValue("h",
+ sysBeepState);
+ return _res;
+}
+
+static PyObject *Snd_SndSetSysBeepState(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ short sysBeepState;
+ if (!PyArg_ParseTuple(_args, "h",
+ &sysBeepState))
+ return NULL;
+ _err = SndSetSysBeepState(sysBeepState);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Snd_MACEVersion(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ NumVersion _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = MACEVersion();
+ _res = Py_BuildValue("O&",
+ PyMac_BuildNumVersion, _rv);
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Snd_Comp3to1(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ char *buffer__in__;
+ char *buffer__out__;
+ long buffer__len__;
+ int buffer__in_len__;
+ StateBlock *state__in__;
+ StateBlock state__out__;
+ int state__in_len__;
+ unsigned long numChannels;
+ unsigned long whichChannel;
+ if (!PyArg_ParseTuple(_args, "s#s#ll",
+ &buffer__in__, &buffer__in_len__,
+ (char **)&state__in__, &state__in_len__,
+ &numChannels,
+ &whichChannel))
+ return NULL;
+ if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
+ {
+ PyErr_NoMemory();
+ goto buffer__error__;
+ }
+ buffer__len__ = buffer__in_len__;
+ if (state__in_len__ != sizeof(StateBlock))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
+ goto state__error__;
+ }
+ Comp3to1(buffer__in__, buffer__out__, (long)buffer__len__,
+ state__in__, &state__out__,
+ numChannels,
+ whichChannel);
+ _res = Py_BuildValue("s#s#",
+ buffer__out__, (int)buffer__len__,
+ (char *)&state__out__, (int)sizeof(StateBlock));
+ state__error__: ;
+ free(buffer__out__);
+ buffer__error__: ;
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Snd_Exp1to3(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ char *buffer__in__;
+ char *buffer__out__;
+ long buffer__len__;
+ int buffer__in_len__;
+ StateBlock *state__in__;
+ StateBlock state__out__;
+ int state__in_len__;
+ unsigned long numChannels;
+ unsigned long whichChannel;
+ if (!PyArg_ParseTuple(_args, "s#s#ll",
+ &buffer__in__, &buffer__in_len__,
+ (char **)&state__in__, &state__in_len__,
+ &numChannels,
+ &whichChannel))
+ return NULL;
+ if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
+ {
+ PyErr_NoMemory();
+ goto buffer__error__;
+ }
+ buffer__len__ = buffer__in_len__;
+ if (state__in_len__ != sizeof(StateBlock))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
+ goto state__error__;
+ }
+ Exp1to3(buffer__in__, buffer__out__, (long)buffer__len__,
+ state__in__, &state__out__,
+ numChannels,
+ whichChannel);
+ _res = Py_BuildValue("s#s#",
+ buffer__out__, (int)buffer__len__,
+ (char *)&state__out__, (int)sizeof(StateBlock));
+ state__error__: ;
+ free(buffer__out__);
+ buffer__error__: ;
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Snd_Comp6to1(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ char *buffer__in__;
+ char *buffer__out__;
+ long buffer__len__;
+ int buffer__in_len__;
+ StateBlock *state__in__;
+ StateBlock state__out__;
+ int state__in_len__;
+ unsigned long numChannels;
+ unsigned long whichChannel;
+ if (!PyArg_ParseTuple(_args, "s#s#ll",
+ &buffer__in__, &buffer__in_len__,
+ (char **)&state__in__, &state__in_len__,
+ &numChannels,
+ &whichChannel))
+ return NULL;
+ if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
+ {
+ PyErr_NoMemory();
+ goto buffer__error__;
+ }
+ buffer__len__ = buffer__in_len__;
+ if (state__in_len__ != sizeof(StateBlock))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
+ goto state__error__;
+ }
+ Comp6to1(buffer__in__, buffer__out__, (long)buffer__len__,
+ state__in__, &state__out__,
+ numChannels,
+ whichChannel);
+ _res = Py_BuildValue("s#s#",
+ buffer__out__, (int)buffer__len__,
+ (char *)&state__out__, (int)sizeof(StateBlock));
+ state__error__: ;
+ free(buffer__out__);
+ buffer__error__: ;
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Snd_Exp1to6(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ char *buffer__in__;
+ char *buffer__out__;
+ long buffer__len__;
+ int buffer__in_len__;
+ StateBlock *state__in__;
+ StateBlock state__out__;
+ int state__in_len__;
+ unsigned long numChannels;
+ unsigned long whichChannel;
+ if (!PyArg_ParseTuple(_args, "s#s#ll",
+ &buffer__in__, &buffer__in_len__,
+ (char **)&state__in__, &state__in_len__,
+ &numChannels,
+ &whichChannel))
+ return NULL;
+ if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
+ {
+ PyErr_NoMemory();
+ goto buffer__error__;
+ }
+ buffer__len__ = buffer__in_len__;
+ if (state__in_len__ != sizeof(StateBlock))
+ {
+ PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
+ goto state__error__;
+ }
+ Exp1to6(buffer__in__, buffer__out__, (long)buffer__len__,
+ state__in__, &state__out__,
+ numChannels,
+ whichChannel);
+ _res = Py_BuildValue("s#s#",
+ buffer__out__, (int)buffer__len__,
+ (char *)&state__out__, (int)sizeof(StateBlock));
+ state__error__: ;
+ free(buffer__out__);
+ buffer__error__: ;
+ return _res;
+}
+#endif
+
+static PyObject *Snd_GetSysBeepVolume(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long level;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetSysBeepVolume(&level);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ level);
+ return _res;
+}
+
+static PyObject *Snd_SetSysBeepVolume(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long level;
+ if (!PyArg_ParseTuple(_args, "l",
+ &level))
+ return NULL;
+ _err = SetSysBeepVolume(level);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Snd_GetDefaultOutputVolume(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long level;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetDefaultOutputVolume(&level);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ level);
+ return _res;
+}
+
+static PyObject *Snd_SetDefaultOutputVolume(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long level;
+ if (!PyArg_ParseTuple(_args, "l",
+ &level))
+ return NULL;
+ _err = SetDefaultOutputVolume(level);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Snd_GetSoundHeaderOffset(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SndListHandle sndHandle;
+ long offset;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &sndHandle))
+ return NULL;
+ _err = GetSoundHeaderOffset(sndHandle,
+ &offset);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ offset);
+ return _res;
+}
+
+static PyObject *Snd_GetCompressionInfo(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ short compressionID;
+ OSType format;
+ short numChannels;
+ short sampleSize;
+ CompressionInfo cp__out__;
+ if (!PyArg_ParseTuple(_args, "hO&hh",
+ &compressionID,
+ PyMac_GetOSType, &format,
+ &numChannels,
+ &sampleSize))
+ return NULL;
+ _err = GetCompressionInfo(compressionID,
+ format,
+ numChannels,
+ sampleSize,
+ &cp__out__);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("s#",
+ (char *)&cp__out__, (int)sizeof(CompressionInfo));
+ cp__error__: ;
+ return _res;
+}
+
+static PyObject *Snd_SetSoundPreference(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ OSType theType;
+ Str255 name;
+ Handle settings;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetOSType, &theType,
+ ResObj_Convert, &settings))
+ return NULL;
+ _err = SetSoundPreference(theType,
+ name,
+ settings);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildStr255, name);
+ return _res;
+}
+
+static PyObject *Snd_GetSoundPreference(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ OSType theType;
+ Str255 name;
+ Handle settings;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetOSType, &theType,
+ ResObj_Convert, &settings))
+ return NULL;
+ _err = GetSoundPreference(theType,
+ name,
+ settings);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildStr255, name);
+ return _res;
+}
+
+static PyObject *Snd_GetCompressionName(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ OSType compressionType;
+ Str255 compressionName;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetOSType, &compressionType))
+ return NULL;
+ _err = GetCompressionName(compressionType,
+ compressionName);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildStr255, compressionName);
+ return _res;
+}
+
+static PyObject *Snd_SPBVersion(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ NumVersion _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = SPBVersion();
+ _res = Py_BuildValue("O&",
+ PyMac_BuildNumVersion, _rv);
+ return _res;
+}
+
+static PyObject *Snd_SPBSignInDevice(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ short deviceRefNum;
+ Str255 deviceName;
+ if (!PyArg_ParseTuple(_args, "hO&",
+ &deviceRefNum,
+ PyMac_GetStr255, deviceName))
+ return NULL;
+ _err = SPBSignInDevice(deviceRefNum,
+ deviceName);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Snd_SPBSignOutDevice(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ short deviceRefNum;
+ if (!PyArg_ParseTuple(_args, "h",
+ &deviceRefNum))
+ return NULL;
+ _err = SPBSignOutDevice(deviceRefNum);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Snd_SPBGetIndexedDevice(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ short count;
+ Str255 deviceName;
+ Handle deviceIconHandle;
+ if (!PyArg_ParseTuple(_args, "h",
+ &count))
+ return NULL;
+ _err = SPBGetIndexedDevice(count,
+ deviceName,
+ &deviceIconHandle);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&O&",
+ PyMac_BuildStr255, deviceName,
+ ResObj_New, deviceIconHandle);
+ return _res;
+}
+
+static PyObject *Snd_SPBOpenDevice(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ Str255 deviceName;
+ short permission;
+ long inRefNum;
+ if (!PyArg_ParseTuple(_args, "O&h",
+ PyMac_GetStr255, deviceName,
+ &permission))
+ return NULL;
+ _err = SPBOpenDevice(deviceName,
+ permission,
+ &inRefNum);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ inRefNum);
+ return _res;
+}
+
+static PyObject *Snd_SPBCloseDevice(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long inRefNum;
+ if (!PyArg_ParseTuple(_args, "l",
+ &inRefNum))
+ return NULL;
+ _err = SPBCloseDevice(inRefNum);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Snd_SPBRecord(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SPBPtr inParamPtr;
+ Boolean asynchFlag;
+ if (!PyArg_ParseTuple(_args, "O&b",
+ SPBObj_Convert, &inParamPtr,
+ &asynchFlag))
+ return NULL;
+ _err = SPBRecord(inParamPtr,
+ asynchFlag);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Snd_SPBRecordToFile(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ short fRefNum;
+ SPBPtr inParamPtr;
+ Boolean asynchFlag;
+ if (!PyArg_ParseTuple(_args, "hO&b",
+ &fRefNum,
+ SPBObj_Convert, &inParamPtr,
+ &asynchFlag))
+ return NULL;
+ _err = SPBRecordToFile(fRefNum,
+ inParamPtr,
+ asynchFlag);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *Snd_SPBPauseRecording(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long inRefNum;
+ if (!PyArg_ParseTuple(_args, "l",
+ &inRefNum))
+ return NULL;
+ _err = SPBPauseRecording(inRefNum);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Snd_SPBResumeRecording(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long inRefNum;
+ if (!PyArg_ParseTuple(_args, "l",
+ &inRefNum))
+ return NULL;
+ _err = SPBResumeRecording(inRefNum);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Snd_SPBStopRecording(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long inRefNum;
+ if (!PyArg_ParseTuple(_args, "l",
+ &inRefNum))
+ return NULL;
+ _err = SPBStopRecording(inRefNum);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Snd_SPBGetRecordingStatus(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long inRefNum;
+ short recordingStatus;
+ short meterLevel;
+ unsigned long totalSamplesToRecord;
+ unsigned long numberOfSamplesRecorded;
+ unsigned long totalMsecsToRecord;
+ unsigned long numberOfMsecsRecorded;
+ if (!PyArg_ParseTuple(_args, "l",
+ &inRefNum))
+ return NULL;
+ _err = SPBGetRecordingStatus(inRefNum,
+ &recordingStatus,
+ &meterLevel,
+ &totalSamplesToRecord,
+ &numberOfSamplesRecorded,
+ &totalMsecsToRecord,
+ &numberOfMsecsRecorded);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("hhllll",
+ recordingStatus,
+ meterLevel,
+ totalSamplesToRecord,
+ numberOfSamplesRecorded,
+ totalMsecsToRecord,
+ numberOfMsecsRecorded);
+ return _res;
+}
+
+static PyObject *Snd_SPBGetDeviceInfo(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long inRefNum;
+ OSType infoType;
+ void * infoData;
+ if (!PyArg_ParseTuple(_args, "lO&w",
+ &inRefNum,
+ PyMac_GetOSType, &infoType,
+ &infoData))
+ return NULL;
+ _err = SPBGetDeviceInfo(inRefNum,
+ infoType,
+ infoData);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Snd_SPBSetDeviceInfo(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long inRefNum;
+ OSType infoType;
+ void * infoData;
+ if (!PyArg_ParseTuple(_args, "lO&w",
+ &inRefNum,
+ PyMac_GetOSType, &infoType,
+ &infoData))
+ return NULL;
+ _err = SPBSetDeviceInfo(inRefNum,
+ infoType,
+ infoData);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Snd_SPBMillisecondsToBytes(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long inRefNum;
+ long milliseconds;
+ if (!PyArg_ParseTuple(_args, "l",
+ &inRefNum))
+ return NULL;
+ _err = SPBMillisecondsToBytes(inRefNum,
+ &milliseconds);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ milliseconds);
+ return _res;
+}
+
+static PyObject *Snd_SPBBytesToMilliseconds(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ long inRefNum;
+ long byteCount;
+ if (!PyArg_ParseTuple(_args, "l",
+ &inRefNum))
+ return NULL;
+ _err = SPBBytesToMilliseconds(inRefNum,
+ &byteCount);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ byteCount);
+ return _res;
+}
+
+static PyMethodDef Snd_methods[] = {
+ {"SPB", (PyCFunction)Snd_SPB, 1,
+ NULL},
+ {"SysBeep", (PyCFunction)Snd_SysBeep, 1,
+ "(short duration) -> None"},
+ {"SndNewChannel", (PyCFunction)Snd_SndNewChannel, 1,
+ "(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)"},
+
+#if !TARGET_API_MAC_CARBON
+ {"SndControl", (PyCFunction)Snd_SndControl, 1,
+ "(short id) -> (SndCommand cmd)"},
+#endif
+ {"SndSoundManagerVersion", (PyCFunction)Snd_SndSoundManagerVersion, 1,
+ "() -> (NumVersion _rv)"},
+ {"SndManagerStatus", (PyCFunction)Snd_SndManagerStatus, 1,
+ "(short theLength) -> (SMStatus theStatus)"},
+ {"SndGetSysBeepState", (PyCFunction)Snd_SndGetSysBeepState, 1,
+ "() -> (short sysBeepState)"},
+ {"SndSetSysBeepState", (PyCFunction)Snd_SndSetSysBeepState, 1,
+ "(short sysBeepState) -> None"},
+
+#if !TARGET_API_MAC_CARBON
+ {"MACEVersion", (PyCFunction)Snd_MACEVersion, 1,
+ "() -> (NumVersion _rv)"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"Comp3to1", (PyCFunction)Snd_Comp3to1, 1,
+ "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"Exp1to3", (PyCFunction)Snd_Exp1to3, 1,
+ "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"Comp6to1", (PyCFunction)Snd_Comp6to1, 1,
+ "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"Exp1to6", (PyCFunction)Snd_Exp1to6, 1,
+ "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
+#endif
+ {"GetSysBeepVolume", (PyCFunction)Snd_GetSysBeepVolume, 1,
+ "() -> (long level)"},
+ {"SetSysBeepVolume", (PyCFunction)Snd_SetSysBeepVolume, 1,
+ "(long level) -> None"},
+ {"GetDefaultOutputVolume", (PyCFunction)Snd_GetDefaultOutputVolume, 1,
+ "() -> (long level)"},
+ {"SetDefaultOutputVolume", (PyCFunction)Snd_SetDefaultOutputVolume, 1,
+ "(long level) -> None"},
+ {"GetSoundHeaderOffset", (PyCFunction)Snd_GetSoundHeaderOffset, 1,
+ "(SndListHandle sndHandle) -> (long offset)"},
+ {"GetCompressionInfo", (PyCFunction)Snd_GetCompressionInfo, 1,
+ "(short compressionID, OSType format, short numChannels, short sampleSize) -> (CompressionInfo cp)"},
+ {"SetSoundPreference", (PyCFunction)Snd_SetSoundPreference, 1,
+ "(OSType theType, Handle settings) -> (Str255 name)"},
+ {"GetSoundPreference", (PyCFunction)Snd_GetSoundPreference, 1,
+ "(OSType theType, Handle settings) -> (Str255 name)"},
+ {"GetCompressionName", (PyCFunction)Snd_GetCompressionName, 1,
+ "(OSType compressionType) -> (Str255 compressionName)"},
+ {"SPBVersion", (PyCFunction)Snd_SPBVersion, 1,
+ "() -> (NumVersion _rv)"},
+ {"SPBSignInDevice", (PyCFunction)Snd_SPBSignInDevice, 1,
+ "(short deviceRefNum, Str255 deviceName) -> None"},
+ {"SPBSignOutDevice", (PyCFunction)Snd_SPBSignOutDevice, 1,
+ "(short deviceRefNum) -> None"},
+ {"SPBGetIndexedDevice", (PyCFunction)Snd_SPBGetIndexedDevice, 1,
+ "(short count) -> (Str255 deviceName, Handle deviceIconHandle)"},
+ {"SPBOpenDevice", (PyCFunction)Snd_SPBOpenDevice, 1,
+ "(Str255 deviceName, short permission) -> (long inRefNum)"},
+ {"SPBCloseDevice", (PyCFunction)Snd_SPBCloseDevice, 1,
+ "(long inRefNum) -> None"},
+ {"SPBRecord", (PyCFunction)Snd_SPBRecord, 1,
+ "(SPBPtr inParamPtr, Boolean asynchFlag) -> None"},
+
+#if !TARGET_API_MAC_CARBON
+ {"SPBRecordToFile", (PyCFunction)Snd_SPBRecordToFile, 1,
+ "(short fRefNum, SPBPtr inParamPtr, Boolean asynchFlag) -> None"},
+#endif
+ {"SPBPauseRecording", (PyCFunction)Snd_SPBPauseRecording, 1,
+ "(long inRefNum) -> None"},
+ {"SPBResumeRecording", (PyCFunction)Snd_SPBResumeRecording, 1,
+ "(long inRefNum) -> None"},
+ {"SPBStopRecording", (PyCFunction)Snd_SPBStopRecording, 1,
+ "(long inRefNum) -> None"},
+ {"SPBGetRecordingStatus", (PyCFunction)Snd_SPBGetRecordingStatus, 1,
+ "(long inRefNum) -> (short recordingStatus, short meterLevel, unsigned long totalSamplesToRecord, unsigned long numberOfSamplesRecorded, unsigned long totalMsecsToRecord, unsigned long numberOfMsecsRecorded)"},
+ {"SPBGetDeviceInfo", (PyCFunction)Snd_SPBGetDeviceInfo, 1,
+ "(long inRefNum, OSType infoType, void * infoData) -> None"},
+ {"SPBSetDeviceInfo", (PyCFunction)Snd_SPBSetDeviceInfo, 1,
+ "(long inRefNum, OSType infoType, void * infoData) -> None"},
+ {"SPBMillisecondsToBytes", (PyCFunction)Snd_SPBMillisecondsToBytes, 1,
+ "(long inRefNum) -> (long milliseconds)"},
+ {"SPBBytesToMilliseconds", (PyCFunction)Snd_SPBBytesToMilliseconds, 1,
+ "(long inRefNum) -> (long byteCount)"},
+ {NULL, NULL, 0}
+};
+
+
+
+/* Routine passed to Py_AddPendingCall -- call the Python callback */
+static int
+SndCh_CallCallBack(void *arg)
+{
+ SndChannelObject *p = (SndChannelObject *)arg;
+ PyObject *args;
+ PyObject *res;
+ args = Py_BuildValue("(O(hhl))",
+ p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2);
+ res = PyEval_CallObject(p->ob_callback, args);
+ Py_DECREF(args);
+ if (res == NULL)
+ return -1;
+ Py_DECREF(res);
+ return 0;
+}
+
+/* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */
+static pascal void
+SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd)
+{
+ SndChannelObject *p = (SndChannelObject *)(chan->userInfo);
+ if (p->ob_callback != NULL) {
+ long A5 = SetA5(p->ob_A5);
+ p->ob_cmd = *cmd;
+ Py_AddPendingCall(SndCh_CallCallBack, (void *)p);
+ SetA5(A5);
+ }
+}
+
+/* SPB callbacks - Schedule callbacks to Python */
+static int
+SPB_CallCallBack(void *arg)
+{
+ SPBObject *p = (SPBObject *)arg;
+ PyObject *args;
+ PyObject *res;
+
+ if ( p->ob_thiscallback == 0 ) return 0;
+ args = Py_BuildValue("(O)", p);
+ res = PyEval_CallObject(p->ob_thiscallback, args);
+ p->ob_thiscallback = 0;
+ Py_DECREF(args);
+ if (res == NULL)
+ return -1;
+ Py_DECREF(res);
+ return 0;
+}
+
+static pascal void
+SPB_completion(SPBPtr my_spb)
+{
+ SPBObject *p = (SPBObject *)(my_spb->userLong);
+
+ if (p && p->ob_completion) {
+ long A5 = SetA5(p->ob_A5);
+ p->ob_thiscallback = p->ob_completion; /* Hope we cannot get two at the same time */
+ Py_AddPendingCall(SPB_CallCallBack, (void *)p);
+ SetA5(A5);
+ }
+}
+
+#if !TARGET_API_MAC_CARBON
+static pascal void
+SPB_interrupt(SPBPtr my_spb)
+{
+ SPBObject *p = (SPBObject *)(my_spb->userLong);
+
+ if (p && p->ob_interrupt) {
+ long A5 = SetA5(p->ob_A5);
+ p->ob_thiscallback = p->ob_interrupt; /* Hope we cannot get two at the same time */
+ Py_AddPendingCall(SPB_CallCallBack, (void *)p);
+ SetA5(A5);
+ }
+}
+#endif
+
+
+void initSnd(void)
+{
+ PyObject *m;
+ PyObject *d;
+
+
+
+
+
+ m = Py_InitModule("Snd", Snd_methods);
+ d = PyModule_GetDict(m);
+ Snd_Error = PyMac_GetOSErrException();
+ if (Snd_Error == NULL ||
+ PyDict_SetItemString(d, "Error", Snd_Error) != 0)
+ return;
+ SndChannel_Type.ob_type = &PyType_Type;
+ Py_INCREF(&SndChannel_Type);
+ if (PyDict_SetItemString(d, "SndChannelType", (PyObject *)&SndChannel_Type) != 0)
+ Py_FatalError("can't initialize SndChannelType");
+ SPB_Type.ob_type = &PyType_Type;
+ Py_INCREF(&SPB_Type);
+ if (PyDict_SetItemString(d, "SPBType", (PyObject *)&SPB_Type) != 0)
+ Py_FatalError("can't initialize SPBType");
+}
+
+/* ========================= End module Snd ========================= */
+
--- /dev/null
+# This script generates the Sound interface for Python.
+# It uses the "bgen" package to generate C code.
+# It execs the file sndgen.py which contain the function definitions
+# (sndgen.py was generated by sndscan.py, scanning the <Sound.h> header file).
+
+from macsupport import *
+
+
+# define our own function and module generators
+
+class SndMixIn: pass
+
+class SndFunction(SndMixIn, OSErrFunctionGenerator): pass
+class SndMethod(SndMixIn, OSErrMethodGenerator): pass
+
+
+# includestuff etc. are imported from macsupport
+
+includestuff = includestuff + """
+#ifdef WITHOUT_FRAMEWORKS
+#include <Sound.h>
+#include <OSUtils.h> /* for Set(Current)A5 */
+#else
+#include <Carbon/Carbon.h>
+#endif
+"""
+
+initstuff = initstuff + """
+"""
+
+
+# define types used for arguments (in addition to standard and macsupport types)
+
+class SndChannelPtrType(OpaqueByValueType):
+ def declare(self, name):
+ # Initializing all SndChannelPtr objects to 0 saves
+ # special-casing NewSndChannel(), where it is formally an
+ # input-output parameter but we treat it as output-only
+ # (since Python users are not supposed to allocate memory)
+ Output("SndChannelPtr %s = 0;", name)
+
+SndChannelPtr = SndChannelPtrType('SndChannelPtr', 'SndCh')
+
+SndCommand = OpaqueType('SndCommand', 'SndCmd')
+SndCommand_ptr = OpaqueType('SndCommand', 'SndCmd')
+SndListHandle = OpaqueByValueType("SndListHandle", "ResObj")
+SPBPtr = OpaqueByValueType("SPBPtr", "SPBObj")
+
+#
+# NOTE: the following is pretty dangerous. For void pointers we pass buffer addresses
+# but we have no way to check that the buffer is big enough. This is the same problem
+# as in C, though (but Pythoneers may not be suspecting this...)
+void_ptr = Type("void *", "w")
+
+class SndCallBackType(InputOnlyType):
+ def __init__(self):
+ Type.__init__(self, 'PyObject*', 'O')
+ def getargsCheck(self, name):
+ Output("if (%s != Py_None && !PyCallable_Check(%s))", name, name)
+ OutLbrace()
+ Output('PyErr_SetString(PyExc_TypeError, "callback must be callable");')
+ Output("goto %s__error__;", name)
+ OutRbrace()
+ def passInput(self, name):
+ return "NewSndCallBackUPP(SndCh_UserRoutine)"
+ def cleanup(self, name):
+ # XXX This knows it is executing inside the SndNewChannel wrapper
+ Output("if (_res != NULL && %s != Py_None)", name)
+ OutLbrace()
+ Output("SndChannelObject *p = (SndChannelObject *)_res;")
+ Output("p->ob_itself->userInfo = (long)p;")
+ Output("Py_INCREF(%s);", name)
+ Output("p->ob_callback = %s;", name)
+ OutRbrace()
+ DedentLevel()
+ Output(" %s__error__: ;", name)
+ IndentLevel()
+
+SndCallBackProcPtr = SndCallBackType()
+SndCallBackUPP = SndCallBackProcPtr
+
+SndCompletionProcPtr = FakeType('(SndCompletionProcPtr)0') # XXX
+SndCompletionUPP = SndCompletionProcPtr
+
+##InOutBuf128 = FixedInputOutputBufferType(128)
+StateBlock = StructInputOutputBufferType('StateBlock')
+
+AudioSelectionPtr = FakeType('0') # XXX
+
+ProcPtr = FakeType('0') # XXX
+FilePlayCompletionUPP = FakeType('0') # XXX
+
+SCStatus = StructOutputBufferType('SCStatus')
+SMStatus = StructOutputBufferType('SMStatus')
+CompressionInfo = StructOutputBufferType('CompressionInfo')
+
+includestuff = includestuff + """
+
+/* Create a SndCommand object (an (int, int, int) tuple) */
+static PyObject *
+SndCmd_New(SndCommand *pc)
+{
+ return Py_BuildValue("hhl", pc->cmd, pc->param1, pc->param2);
+}
+
+/* Convert a SndCommand argument */
+static int
+SndCmd_Convert(PyObject *v, SndCommand *pc)
+{
+ int len;
+ pc->param1 = 0;
+ pc->param2 = 0;
+ if (PyTuple_Check(v)) {
+ if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2))
+ return 1;
+ PyErr_Clear();
+ return PyArg_ParseTuple(v, "Hhs#", &pc->cmd, &pc->param1, &pc->param2, &len);
+ }
+ return PyArg_Parse(v, "H", &pc->cmd);
+}
+
+static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */
+static pascal void SPB_completion(SPBPtr my_spb); /* Forward */
+#if !TARGET_API_MAC_CARBON
+static pascal void SPB_interrupt(SPBPtr my_spb); /* Forward */
+#endif
+"""
+
+
+finalstuff = finalstuff + """
+/* Routine passed to Py_AddPendingCall -- call the Python callback */
+static int
+SndCh_CallCallBack(void *arg)
+{
+ SndChannelObject *p = (SndChannelObject *)arg;
+ PyObject *args;
+ PyObject *res;
+ args = Py_BuildValue("(O(hhl))",
+ p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2);
+ res = PyEval_CallObject(p->ob_callback, args);
+ Py_DECREF(args);
+ if (res == NULL)
+ return -1;
+ Py_DECREF(res);
+ return 0;
+}
+
+/* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */
+static pascal void
+SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd)
+{
+ SndChannelObject *p = (SndChannelObject *)(chan->userInfo);
+ if (p->ob_callback != NULL) {
+ long A5 = SetA5(p->ob_A5);
+ p->ob_cmd = *cmd;
+ Py_AddPendingCall(SndCh_CallCallBack, (void *)p);
+ SetA5(A5);
+ }
+}
+
+/* SPB callbacks - Schedule callbacks to Python */
+static int
+SPB_CallCallBack(void *arg)
+{
+ SPBObject *p = (SPBObject *)arg;
+ PyObject *args;
+ PyObject *res;
+
+ if ( p->ob_thiscallback == 0 ) return 0;
+ args = Py_BuildValue("(O)", p);
+ res = PyEval_CallObject(p->ob_thiscallback, args);
+ p->ob_thiscallback = 0;
+ Py_DECREF(args);
+ if (res == NULL)
+ return -1;
+ Py_DECREF(res);
+ return 0;
+}
+
+static pascal void
+SPB_completion(SPBPtr my_spb)
+{
+ SPBObject *p = (SPBObject *)(my_spb->userLong);
+
+ if (p && p->ob_completion) {
+ long A5 = SetA5(p->ob_A5);
+ p->ob_thiscallback = p->ob_completion; /* Hope we cannot get two at the same time */
+ Py_AddPendingCall(SPB_CallCallBack, (void *)p);
+ SetA5(A5);
+ }
+}
+
+#if !TARGET_API_MAC_CARBON
+static pascal void
+SPB_interrupt(SPBPtr my_spb)
+{
+ SPBObject *p = (SPBObject *)(my_spb->userLong);
+
+ if (p && p->ob_interrupt) {
+ long A5 = SetA5(p->ob_A5);
+ p->ob_thiscallback = p->ob_interrupt; /* Hope we cannot get two at the same time */
+ Py_AddPendingCall(SPB_CallCallBack, (void *)p);
+ SetA5(A5);
+ }
+}
+#endif
+"""
+
+
+# create the module and object definition and link them
+
+class SndObjectDefinition(ObjectDefinition):
+
+ def outputStructMembers(self):
+ ObjectDefinition.outputStructMembers(self)
+ Output("/* Members used to implement callbacks: */")
+ Output("PyObject *ob_callback;")
+ Output("long ob_A5;");
+ Output("SndCommand ob_cmd;")
+
+ def outputInitStructMembers(self):
+ ObjectDefinition.outputInitStructMembers(self)
+ Output("it->ob_callback = NULL;")
+ Output("it->ob_A5 = SetCurrentA5();");
+
+ def outputCleanupStructMembers(self):
+ ObjectDefinition.outputCleanupStructMembers(self)
+ Output("Py_XDECREF(self->ob_callback);")
+
+ def outputFreeIt(self, itselfname):
+ Output("SndDisposeChannel(%s, 1);", itselfname)
+
+#
+
+class SpbObjectDefinition(ObjectDefinition):
+
+ def outputStructMembers(self):
+ Output("/* Members used to implement callbacks: */")
+ Output("PyObject *ob_completion;")
+ Output("PyObject *ob_interrupt;")
+ Output("PyObject *ob_thiscallback;");
+ Output("long ob_A5;")
+ Output("SPB ob_spb;")
+
+ def outputNew(self):
+ Output()
+ Output("%sPyObject *%s_New(void)", self.static, self.prefix)
+ OutLbrace()
+ Output("%s *it;", self.objecttype)
+ self.outputCheckNewArg()
+ Output("it = PyObject_NEW(%s, &%s);", self.objecttype, self.typename)
+ Output("if (it == NULL) return NULL;")
+ self.outputInitStructMembers()
+ Output("return (PyObject *)it;")
+ OutRbrace()
+
+ def outputInitStructMembers(self):
+ Output("it->ob_completion = NULL;")
+ Output("it->ob_interrupt = NULL;")
+ Output("it->ob_thiscallback = NULL;")
+ Output("it->ob_A5 = SetCurrentA5();")
+ Output("memset((char *)&it->ob_spb, 0, sizeof(it->ob_spb));")
+ Output("it->ob_spb.userLong = (long)it;")
+
+ def outputCleanupStructMembers(self):
+ ObjectDefinition.outputCleanupStructMembers(self)
+ Output("self->ob_spb.userLong = 0;")
+ Output("self->ob_thiscallback = 0;")
+ Output("Py_XDECREF(self->ob_completion);")
+ Output("Py_XDECREF(self->ob_interrupt);")
+
+ def outputConvert(self):
+ Output("%s%s_Convert(PyObject *v, %s *p_itself)", self.static, self.prefix, self.itselftype)
+ OutLbrace()
+ self.outputCheckConvertArg()
+ Output("if (!%s_Check(v))", self.prefix)
+ OutLbrace()
+ Output('PyErr_SetString(PyExc_TypeError, "%s required");', self.name)
+ Output("return 0;")
+ OutRbrace()
+ Output("*p_itself = &((%s *)v)->ob_spb;", self.objecttype)
+ Output("return 1;")
+ OutRbrace()
+
+ def outputSetattr(self):
+ Output()
+ Output("static int %s_setattr(%s *self, char *name, PyObject *value)",
+ self.prefix, self.objecttype)
+ OutLbrace()
+ self.outputSetattrBody()
+ OutRbrace()
+
+ def outputSetattrBody(self):
+ Output("""
+ int rv = 0;
+
+ if (strcmp(name, "inRefNum") == 0)
+ rv = PyArg_Parse(value, "l", &self->ob_spb.inRefNum);
+ else if (strcmp(name, "count") == 0)
+ rv = PyArg_Parse(value, "l", &self->ob_spb.count);
+ else if (strcmp(name, "milliseconds") == 0)
+ rv = PyArg_Parse(value, "l", &self->ob_spb.milliseconds);
+ else if (strcmp(name, "buffer") == 0)
+ rv = PyArg_Parse(value, "w#", &self->ob_spb.bufferPtr, &self->ob_spb.bufferLength);
+ else if (strcmp(name, "completionRoutine") == 0) {
+ self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion);
+ self->ob_completion = value;
+ Py_INCREF(value);
+ rv = 1;
+#if !TARGET_API_MAC_CARBON
+ } else if (strcmp(name, "interruptRoutine") == 0) {
+ self->ob_spb.completionRoutine = NewSIInterruptUPP(SPB_interrupt);
+ self->ob_interrupt = value;
+ Py_INCREF(value);
+ rv = 1;
+#endif
+ }
+ if ( rv ) return 0;
+ else return -1;""")
+
+ def outputGetattrHook(self):
+ Output("""
+ if (strcmp(name, "inRefNum") == 0)
+ return Py_BuildValue("l", self->ob_spb.inRefNum);
+ else if (strcmp(name, "count") == 0)
+ return Py_BuildValue("l", self->ob_spb.count);
+ else if (strcmp(name, "milliseconds") == 0)
+ return Py_BuildValue("l", self->ob_spb.milliseconds);
+ else if (strcmp(name, "error") == 0)
+ return Py_BuildValue("h", self->ob_spb.error);""")
+
+
+
+sndobject = SndObjectDefinition('SndChannel', 'SndCh', 'SndChannelPtr')
+spbobject = SpbObjectDefinition('SPB', 'SPBObj', 'SPBPtr')
+spbgenerator = ManualGenerator("SPB", "return SPBObj_New();")
+module = MacModule('Snd', 'Snd', includestuff, finalstuff, initstuff)
+module.addobject(sndobject)
+module.addobject(spbobject)
+module.add(spbgenerator)
+
+
+# create lists of functions and object methods
+
+functions = []
+sndmethods = []
+
+
+# populate the lists
+
+execfile('sndgen.py')
+
+
+# add the functions and methods to the module and object, respectively
+
+for f in functions: module.add(f)
+for f in sndmethods: sndobject.add(f)
+
+
+# generate output
+
+SetOutputFileName('Sndmodule.c')
+module.generate()
--- /dev/null
+
+/* ========================== Module waste ========================== */
+
+#include "Python.h"
+
+
+
+#include "macglue.h"
+#include "pymactoolbox.h"
+
+#include <WASTE.h>
+#include <WEObjectHandlers.h>
+#include <WETabs.h>
+
+/* Exported by Qdmodule.c: */
+extern PyObject *QdRGB_New(RGBColor *);
+extern int QdRGB_Convert(PyObject *, RGBColor *);
+
+/* Exported by AEModule.c: */
+extern PyObject *AEDesc_New(AppleEvent *);
+extern int AEDesc_Convert(PyObject *, AppleEvent *);
+
+/* Forward declaration */
+staticforward PyObject *WEOObj_New(WEObjectReference);
+staticforward PyObject *ExistingwasteObj_New(WEReference);
+
+/*
+** Parse/generate TextStyle records
+*/
+static
+PyObject *TextStyle_New(itself)
+ TextStylePtr itself;
+{
+
+ return Py_BuildValue("lllO&", (long)itself->tsFont, (long)itself->tsFace, (long)itself->tsSize, QdRGB_New,
+ &itself->tsColor);
+}
+
+static
+TextStyle_Convert(v, p_itself)
+ PyObject *v;
+ TextStylePtr p_itself;
+{
+ long font, face, size;
+
+ if( !PyArg_ParseTuple(v, "lllO&", &font, &face, &size, QdRGB_Convert, &p_itself->tsColor) )
+ return 0;
+ p_itself->tsFont = (short)font;
+ p_itself->tsFace = (Style)face;
+ p_itself->tsSize = (short)size;
+ return 1;
+}
+
+/*
+** Parse/generate RunInfo records
+*/
+static
+PyObject *RunInfo_New(itself)
+ WERunInfo *itself;
+{
+
+ return Py_BuildValue("llhhO&O&", itself->runStart, itself->runEnd, itself->runHeight,
+ itself->runAscent, TextStyle_New, &itself->runStyle, WEOObj_New, itself->runObject);
+}
+
+/* Conversion of long points and rects */
+int
+LongRect_Convert(PyObject *v, LongRect *r)
+{
+ return PyArg_Parse(v, "(llll)", &r->left, &r->top, &r->right, &r->bottom);
+}
+
+PyObject *
+LongRect_New(LongRect *r)
+{
+ return Py_BuildValue("(llll)", r->left, r->top, r->right, r->bottom);
+}
+
+
+LongPt_Convert(PyObject *v, LongPt *p)
+{
+ return PyArg_Parse(v, "(ll)", &p->h, &p->v);
+}
+
+PyObject *
+LongPt_New(LongPt *p)
+{
+ return Py_BuildValue("(ll)", p->h, p->v);
+}
+
+/* Stuff for the callbacks: */
+static PyObject *callbackdict;
+WENewObjectUPP upp_new_handler;
+WEDisposeObjectUPP upp_dispose_handler;
+WEDrawObjectUPP upp_draw_handler;
+WEClickObjectUPP upp_click_handler;
+
+static OSErr
+any_handler(WESelector what, WEObjectReference who, PyObject *args, PyObject **rv)
+{
+ FlavorType tp;
+ PyObject *key, *func;
+
+ if ( args == NULL ) return errAECorruptData;
+
+ tp = WEGetObjectType(who);
+
+ if( (key=Py_BuildValue("O&O&", PyMac_BuildOSType, tp, PyMac_BuildOSType, what)) == NULL)
+ return errAECorruptData;
+ if( (func = PyDict_GetItem(callbackdict, key)) == NULL ) {
+ Py_DECREF(key);
+ return errAEHandlerNotFound;
+ }
+ Py_INCREF(func);
+ *rv = PyEval_CallObject(func, args);
+ Py_DECREF(func);
+ Py_DECREF(key);
+ if ( *rv == NULL ) {
+ PySys_WriteStderr("--Exception in callback: ");
+ PyErr_Print();
+ return errAEReplyNotArrived;
+ }
+ return 0;
+}
+
+static pascal OSErr
+my_new_handler(Point *objectSize, WEObjectReference objref)
+{
+ PyObject *args=NULL, *rv=NULL;
+ OSErr err;
+
+ args=Py_BuildValue("(O&)", WEOObj_New, objref);
+ err = any_handler(weNewHandler, objref, args, &rv);
+ if (!err) {
+ if (!PyMac_GetPoint(rv, objectSize) )
+ err = errAECoercionFail;
+ }
+ if ( args ) Py_DECREF(args);
+ if ( rv ) Py_DECREF(rv);
+ return err;
+}
+
+static pascal OSErr
+my_dispose_handler(WEObjectReference objref)
+{
+ PyObject *args=NULL, *rv=NULL;
+ OSErr err;
+
+ args=Py_BuildValue("(O&)", WEOObj_New, objref);
+ err = any_handler(weDisposeHandler, objref, args, &rv);
+ if ( args ) Py_DECREF(args);
+ if ( rv ) Py_DECREF(rv);
+ return err;
+}
+
+static pascal OSErr
+my_draw_handler(const Rect *destRect, WEObjectReference objref)
+{
+ PyObject *args=NULL, *rv=NULL;
+ OSErr err;
+
+ args=Py_BuildValue("O&O&", PyMac_BuildRect, destRect, WEOObj_New, objref);
+ err = any_handler(weDrawHandler, objref, args, &rv);
+ if ( args ) Py_DECREF(args);
+ if ( rv ) Py_DECREF(rv);
+ return err;
+}
+
+static pascal Boolean
+my_click_handler(Point hitPt, EventModifiers modifiers,
+ unsigned long clickTime, WEObjectReference objref)
+{
+ PyObject *args=NULL, *rv=NULL;
+ int retvalue;
+ OSErr err;
+
+ args=Py_BuildValue("O&llO&", PyMac_BuildPoint, hitPt,
+ (long)modifiers, (long)clickTime, WEOObj_New, objref);
+ err = any_handler(weClickHandler, objref, args, &rv);
+ if (!err)
+ retvalue = PyInt_AsLong(rv);
+ else
+ retvalue = 0;
+ if ( args ) Py_DECREF(args);
+ if ( rv ) Py_DECREF(rv);
+ return retvalue;
+}
+
+
+
+static PyObject *waste_Error;
+
+/* ------------------------ Object type WEO ------------------------- */
+
+PyTypeObject WEO_Type;
+
+#define WEOObj_Check(x) ((x)->ob_type == &WEO_Type)
+
+typedef struct WEOObject {
+ PyObject_HEAD
+ WEObjectReference ob_itself;
+} WEOObject;
+
+PyObject *WEOObj_New(WEObjectReference itself)
+{
+ WEOObject *it;
+ if (itself == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ it = PyObject_NEW(WEOObject, &WEO_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ return (PyObject *)it;
+}
+WEOObj_Convert(PyObject *v, WEObjectReference *p_itself)
+{
+ if (!WEOObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "WEO required");
+ return 0;
+ }
+ *p_itself = ((WEOObject *)v)->ob_itself;
+ return 1;
+}
+
+static void WEOObj_dealloc(WEOObject *self)
+{
+ /* Cleanup of self->ob_itself goes here */
+ PyMem_DEL(self);
+}
+
+static PyObject *WEOObj_WEGetObjectType(WEOObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ FlavorType _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEGetObjectType(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildOSType, _rv);
+ return _res;
+}
+
+static PyObject *WEOObj_WEGetObjectDataHandle(WEOObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Handle _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEGetObjectDataHandle(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *WEOObj_WEGetObjectSize(WEOObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Point _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEGetObjectSize(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildPoint, _rv);
+ return _res;
+}
+
+static PyObject *WEOObj_WEGetObjectOwner(WEOObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WEReference _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEGetObjectOwner(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ ExistingwasteObj_New, _rv);
+ return _res;
+}
+
+static PyObject *WEOObj_WEGetObjectRefCon(WEOObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEGetObjectRefCon(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *WEOObj_WESetObjectRefCon(WEOObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 refCon;
+ if (!PyArg_ParseTuple(_args, "l",
+ &refCon))
+ return NULL;
+ WESetObjectRefCon(_self->ob_itself,
+ refCon);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyMethodDef WEOObj_methods[] = {
+ {"WEGetObjectType", (PyCFunction)WEOObj_WEGetObjectType, 1,
+ "() -> (FlavorType _rv)"},
+ {"WEGetObjectDataHandle", (PyCFunction)WEOObj_WEGetObjectDataHandle, 1,
+ "() -> (Handle _rv)"},
+ {"WEGetObjectSize", (PyCFunction)WEOObj_WEGetObjectSize, 1,
+ "() -> (Point _rv)"},
+ {"WEGetObjectOwner", (PyCFunction)WEOObj_WEGetObjectOwner, 1,
+ "() -> (WEReference _rv)"},
+ {"WEGetObjectRefCon", (PyCFunction)WEOObj_WEGetObjectRefCon, 1,
+ "() -> (SInt32 _rv)"},
+ {"WESetObjectRefCon", (PyCFunction)WEOObj_WESetObjectRefCon, 1,
+ "(SInt32 refCon) -> None"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain WEOObj_chain = { WEOObj_methods, NULL };
+
+static PyObject *WEOObj_getattr(WEOObject *self, char *name)
+{
+ return Py_FindMethodInChain(&WEOObj_chain, (PyObject *)self, name);
+}
+
+#define WEOObj_setattr NULL
+
+#define WEOObj_compare NULL
+
+#define WEOObj_repr NULL
+
+#define WEOObj_hash NULL
+
+PyTypeObject WEO_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "WEO", /*tp_name*/
+ sizeof(WEOObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) WEOObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) WEOObj_getattr, /*tp_getattr*/
+ (setattrfunc) WEOObj_setattr, /*tp_setattr*/
+ (cmpfunc) WEOObj_compare, /*tp_compare*/
+ (reprfunc) WEOObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) WEOObj_hash, /*tp_hash*/
+};
+
+/* ---------------------- End object type WEO ----------------------- */
+
+
+/* ----------------------- Object type waste ------------------------ */
+
+PyTypeObject waste_Type;
+
+#define wasteObj_Check(x) ((x)->ob_type == &waste_Type)
+
+typedef struct wasteObject {
+ PyObject_HEAD
+ WEReference ob_itself;
+} wasteObject;
+
+PyObject *wasteObj_New(WEReference itself)
+{
+ wasteObject *it;
+ if (itself == NULL) {
+ PyErr_SetString(waste_Error,"Cannot create null WE");
+ return NULL;
+ }
+ it = PyObject_NEW(wasteObject, &waste_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ WESetInfo(weRefCon, (void *)&it, itself);
+ return (PyObject *)it;
+}
+wasteObj_Convert(PyObject *v, WEReference *p_itself)
+{
+ if (!wasteObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "waste required");
+ return 0;
+ }
+ *p_itself = ((wasteObject *)v)->ob_itself;
+ return 1;
+}
+
+static void wasteObj_dealloc(wasteObject *self)
+{
+ WEDispose(self->ob_itself);
+ PyMem_DEL(self);
+}
+
+static PyObject *wasteObj_WEGetText(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Handle _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEGetText(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetChar(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 _rv;
+ SInt32 offset;
+ if (!PyArg_ParseTuple(_args, "l",
+ &offset))
+ return NULL;
+ _rv = WEGetChar(offset,
+ _self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetTextLength(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEGetTextLength(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetHeight(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ SInt32 startLine;
+ SInt32 endLine;
+ if (!PyArg_ParseTuple(_args, "ll",
+ &startLine,
+ &endLine))
+ return NULL;
+ _rv = WEGetHeight(startLine,
+ endLine,
+ _self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetSelection(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 selStart;
+ SInt32 selEnd;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ WEGetSelection(&selStart,
+ &selEnd,
+ _self->ob_itself);
+ _res = Py_BuildValue("ll",
+ selStart,
+ selEnd);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetDestRect(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ LongRect destRect;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ WEGetDestRect(&destRect,
+ _self->ob_itself);
+ _res = Py_BuildValue("O&",
+ LongRect_New, &destRect);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetViewRect(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ LongRect viewRect;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ WEGetViewRect(&viewRect,
+ _self->ob_itself);
+ _res = Py_BuildValue("O&",
+ LongRect_New, &viewRect);
+ return _res;
+}
+
+static PyObject *wasteObj_WEIsActive(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEIsActive(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEOffsetToLine(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ SInt32 offset;
+ if (!PyArg_ParseTuple(_args, "l",
+ &offset))
+ return NULL;
+ _rv = WEOffsetToLine(offset,
+ _self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetLineRange(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 lineIndex;
+ SInt32 lineStart;
+ SInt32 lineEnd;
+ if (!PyArg_ParseTuple(_args, "l",
+ &lineIndex))
+ return NULL;
+ WEGetLineRange(lineIndex,
+ &lineStart,
+ &lineEnd,
+ _self->ob_itself);
+ _res = Py_BuildValue("ll",
+ lineStart,
+ lineEnd);
+ return _res;
+}
+
+static PyObject *wasteObj_WECountLines(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WECountLines(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEOffsetToRun(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ SInt32 offset;
+ if (!PyArg_ParseTuple(_args, "l",
+ &offset))
+ return NULL;
+ _rv = WEOffsetToRun(offset,
+ _self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetRunRange(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 runIndex;
+ SInt32 runStart;
+ SInt32 runEnd;
+ if (!PyArg_ParseTuple(_args, "l",
+ &runIndex))
+ return NULL;
+ WEGetRunRange(runIndex,
+ &runStart,
+ &runEnd,
+ _self->ob_itself);
+ _res = Py_BuildValue("ll",
+ runStart,
+ runEnd);
+ return _res;
+}
+
+static PyObject *wasteObj_WECountRuns(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WECountRuns(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetClickCount(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ UInt16 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEGetClickCount(_self->ob_itself);
+ _res = Py_BuildValue("H",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WESetSelection(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 selStart;
+ SInt32 selEnd;
+ if (!PyArg_ParseTuple(_args, "ll",
+ &selStart,
+ &selEnd))
+ return NULL;
+ WESetSelection(selStart,
+ selEnd,
+ _self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WESetDestRect(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ LongRect destRect;
+ if (!PyArg_ParseTuple(_args, "O&",
+ LongRect_Convert, &destRect))
+ return NULL;
+ WESetDestRect(&destRect,
+ _self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WESetViewRect(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ LongRect viewRect;
+ if (!PyArg_ParseTuple(_args, "O&",
+ LongRect_Convert, &viewRect))
+ return NULL;
+ WESetViewRect(&viewRect,
+ _self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEContinuousStyle(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ WEStyleMode mode;
+ TextStyle ts;
+ if (!PyArg_ParseTuple(_args, "H",
+ &mode))
+ return NULL;
+ _rv = WEContinuousStyle(&mode,
+ &ts,
+ _self->ob_itself);
+ _res = Py_BuildValue("bHO&",
+ _rv,
+ mode,
+ TextStyle_New, &ts);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetRunInfo(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 offset;
+ WERunInfo runInfo;
+ if (!PyArg_ParseTuple(_args, "l",
+ &offset))
+ return NULL;
+ WEGetRunInfo(offset,
+ &runInfo,
+ _self->ob_itself);
+ _res = Py_BuildValue("O&",
+ RunInfo_New, &runInfo);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetRunDirection(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ SInt32 offset;
+ if (!PyArg_ParseTuple(_args, "l",
+ &offset))
+ return NULL;
+ _rv = WEGetRunDirection(offset,
+ _self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetOffset(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ LongPt thePoint;
+ WEEdge edge;
+ if (!PyArg_ParseTuple(_args, "O&",
+ LongPt_Convert, &thePoint))
+ return NULL;
+ _rv = WEGetOffset(&thePoint,
+ &edge,
+ _self->ob_itself);
+ _res = Py_BuildValue("lB",
+ _rv,
+ edge);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetPoint(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 offset;
+ SInt16 direction;
+ LongPt thePoint;
+ SInt16 lineHeight;
+ if (!PyArg_ParseTuple(_args, "lh",
+ &offset,
+ &direction))
+ return NULL;
+ WEGetPoint(offset,
+ direction,
+ &thePoint,
+ &lineHeight,
+ _self->ob_itself);
+ _res = Py_BuildValue("O&h",
+ LongPt_New, &thePoint,
+ lineHeight);
+ return _res;
+}
+
+static PyObject *wasteObj_WEFindWord(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 offset;
+ WEEdge edge;
+ SInt32 wordStart;
+ SInt32 wordEnd;
+ if (!PyArg_ParseTuple(_args, "lB",
+ &offset,
+ &edge))
+ return NULL;
+ WEFindWord(offset,
+ edge,
+ &wordStart,
+ &wordEnd,
+ _self->ob_itself);
+ _res = Py_BuildValue("ll",
+ wordStart,
+ wordEnd);
+ return _res;
+}
+
+static PyObject *wasteObj_WEFindLine(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 offset;
+ WEEdge edge;
+ SInt32 lineStart;
+ SInt32 lineEnd;
+ if (!PyArg_ParseTuple(_args, "lB",
+ &offset,
+ &edge))
+ return NULL;
+ WEFindLine(offset,
+ edge,
+ &lineStart,
+ &lineEnd,
+ _self->ob_itself);
+ _res = Py_BuildValue("ll",
+ lineStart,
+ lineEnd);
+ return _res;
+}
+
+static PyObject *wasteObj_WEFindParagraph(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 offset;
+ WEEdge edge;
+ SInt32 paragraphStart;
+ SInt32 paragraphEnd;
+ if (!PyArg_ParseTuple(_args, "lB",
+ &offset,
+ &edge))
+ return NULL;
+ WEFindParagraph(offset,
+ edge,
+ ¶graphStart,
+ ¶graphEnd,
+ _self->ob_itself);
+ _res = Py_BuildValue("ll",
+ paragraphStart,
+ paragraphEnd);
+ return _res;
+}
+
+static PyObject *wasteObj_WECopyRange(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SInt32 rangeStart;
+ SInt32 rangeEnd;
+ Handle hText;
+ StScrpHandle hStyles;
+ WESoupHandle hSoup;
+ if (!PyArg_ParseTuple(_args, "llO&O&O&",
+ &rangeStart,
+ &rangeEnd,
+ OptResObj_Convert, &hText,
+ OptResObj_Convert, &hStyles,
+ OptResObj_Convert, &hSoup))
+ return NULL;
+ _err = WECopyRange(rangeStart,
+ rangeEnd,
+ hText,
+ hStyles,
+ hSoup,
+ _self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetAlignment(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WEAlignment _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEGetAlignment(_self->ob_itself);
+ _res = Py_BuildValue("B",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WESetAlignment(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WEAlignment alignment;
+ if (!PyArg_ParseTuple(_args, "B",
+ &alignment))
+ return NULL;
+ WESetAlignment(alignment,
+ _self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetDirection(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WEDirection _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEGetDirection(_self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WESetDirection(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WEDirection direction;
+ if (!PyArg_ParseTuple(_args, "h",
+ &direction))
+ return NULL;
+ WESetDirection(direction,
+ _self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WECalText(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = WECalText(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEUpdate(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle updateRgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &updateRgn))
+ return NULL;
+ WEUpdate(updateRgn,
+ _self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEScroll(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 hOffset;
+ SInt32 vOffset;
+ if (!PyArg_ParseTuple(_args, "ll",
+ &hOffset,
+ &vOffset))
+ return NULL;
+ WEScroll(hOffset,
+ vOffset,
+ _self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WESelView(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ WESelView(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEActivate(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ WEActivate(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEDeactivate(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ WEDeactivate(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEKey(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 key;
+ EventModifiers modifiers;
+ if (!PyArg_ParseTuple(_args, "hH",
+ &key,
+ &modifiers))
+ return NULL;
+ WEKey(key,
+ modifiers,
+ _self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEClick(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Point hitPt;
+ EventModifiers modifiers;
+ UInt32 clickTime;
+ if (!PyArg_ParseTuple(_args, "O&Hl",
+ PyMac_GetPoint, &hitPt,
+ &modifiers,
+ &clickTime))
+ return NULL;
+ WEClick(hitPt,
+ modifiers,
+ clickTime,
+ _self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEAdjustCursor(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Point mouseLoc;
+ RgnHandle mouseRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &mouseLoc,
+ ResObj_Convert, &mouseRgn))
+ return NULL;
+ _rv = WEAdjustCursor(mouseLoc,
+ mouseRgn,
+ _self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEIdle(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ UInt32 maxSleep;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ WEIdle(&maxSleep,
+ _self->ob_itself);
+ _res = Py_BuildValue("l",
+ maxSleep);
+ return _res;
+}
+
+static PyObject *wasteObj_WEInsert(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ char *pText__in__;
+ long pText__len__;
+ int pText__in_len__;
+ StScrpHandle hStyles;
+ WESoupHandle hSoup;
+ if (!PyArg_ParseTuple(_args, "s#O&O&",
+ &pText__in__, &pText__in_len__,
+ OptResObj_Convert, &hStyles,
+ OptResObj_Convert, &hSoup))
+ return NULL;
+ pText__len__ = pText__in_len__;
+ _err = WEInsert(pText__in__, pText__len__,
+ hStyles,
+ hSoup,
+ _self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ pText__error__: ;
+ return _res;
+}
+
+static PyObject *wasteObj_WEDelete(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = WEDelete(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WESetStyle(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WEStyleMode mode;
+ TextStyle ts;
+ if (!PyArg_ParseTuple(_args, "HO&",
+ &mode,
+ TextStyle_Convert, &ts))
+ return NULL;
+ _err = WESetStyle(mode,
+ &ts,
+ _self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEUseStyleScrap(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ StScrpHandle hStyles;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &hStyles))
+ return NULL;
+ _err = WEUseStyleScrap(hStyles,
+ _self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEUseText(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ Handle hText;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &hText))
+ return NULL;
+ _err = WEUseText(hText,
+ _self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEUndo(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = WEUndo(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEClearUndo(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ WEClearUndo(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetUndoInfo(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WEActionKind _rv;
+ Boolean redoFlag;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEGetUndoInfo(&redoFlag,
+ _self->ob_itself);
+ _res = Py_BuildValue("hb",
+ _rv,
+ redoFlag);
+ return _res;
+}
+
+static PyObject *wasteObj_WEIsTyping(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEIsTyping(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEBeginAction(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = WEBeginAction(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEEndAction(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WEActionKind actionKind;
+ if (!PyArg_ParseTuple(_args, "h",
+ &actionKind))
+ return NULL;
+ _err = WEEndAction(actionKind,
+ _self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetModCount(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ UInt32 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEGetModCount(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEResetModCount(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ WEResetModCount(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEInsertObject(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FlavorType objectType;
+ Handle objectDataHandle;
+ Point objectSize;
+ if (!PyArg_ParseTuple(_args, "O&O&O&",
+ PyMac_GetOSType, &objectType,
+ ResObj_Convert, &objectDataHandle,
+ PyMac_GetPoint, &objectSize))
+ return NULL;
+ _err = WEInsertObject(objectType,
+ objectDataHandle,
+ objectSize,
+ _self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetSelectedObject(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WEObjectReference obj;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = WEGetSelectedObject(&obj,
+ _self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ WEOObj_New, obj);
+ return _res;
+}
+
+static PyObject *wasteObj_WEFindNextObject(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ SInt32 offset;
+ WEObjectReference obj;
+ if (!PyArg_ParseTuple(_args, "l",
+ &offset))
+ return NULL;
+ _rv = WEFindNextObject(offset,
+ &obj,
+ _self->ob_itself);
+ _res = Py_BuildValue("lO&",
+ _rv,
+ WEOObj_New, obj);
+ return _res;
+}
+
+static PyObject *wasteObj_WEUseSoup(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WESoupHandle hSoup;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &hSoup))
+ return NULL;
+ _err = WEUseSoup(hSoup,
+ _self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WECut(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = WECut(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WECopy(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = WECopy(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEPaste(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = WEPaste(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WECanPaste(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WECanPaste(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetHiliteRgn(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle _rv;
+ SInt32 rangeStart;
+ SInt32 rangeEnd;
+ if (!PyArg_ParseTuple(_args, "ll",
+ &rangeStart,
+ &rangeEnd))
+ return NULL;
+ _rv = WEGetHiliteRgn(rangeStart,
+ rangeEnd,
+ _self->ob_itself);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WECharByte(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 _rv;
+ SInt32 offset;
+ if (!PyArg_ParseTuple(_args, "l",
+ &offset))
+ return NULL;
+ _rv = WECharByte(offset,
+ _self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WECharType(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 _rv;
+ SInt32 offset;
+ if (!PyArg_ParseTuple(_args, "l",
+ &offset))
+ return NULL;
+ _rv = WECharType(offset,
+ _self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEStopInlineSession(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ WEStopInlineSession(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEFeatureFlag(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 _rv;
+ SInt16 feature;
+ SInt16 action;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &feature,
+ &action))
+ return NULL;
+ _rv = WEFeatureFlag(feature,
+ action,
+ _self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetUserInfo(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WESelector tag;
+ SInt32 userInfo;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetOSType, &tag))
+ return NULL;
+ _err = WEGetUserInfo(tag,
+ &userInfo,
+ _self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ userInfo);
+ return _res;
+}
+
+static PyObject *wasteObj_WESetUserInfo(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ WESelector tag;
+ SInt32 userInfo;
+ if (!PyArg_ParseTuple(_args, "O&l",
+ PyMac_GetOSType, &tag,
+ &userInfo))
+ return NULL;
+ _err = WESetUserInfo(tag,
+ userInfo,
+ _self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEInstallTabHooks(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = WEInstallTabHooks(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WERemoveTabHooks(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = WERemoveTabHooks(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *wasteObj_WEIsTabHooks(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEIsTabHooks(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WEGetTabSize(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt16 _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WEGetTabSize(_self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *wasteObj_WESetTabSize(wasteObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SInt16 tabWidth;
+ if (!PyArg_ParseTuple(_args, "h",
+ &tabWidth))
+ return NULL;
+ _err = WESetTabSize(tabWidth,
+ _self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyMethodDef wasteObj_methods[] = {
+ {"WEGetText", (PyCFunction)wasteObj_WEGetText, 1,
+ "() -> (Handle _rv)"},
+ {"WEGetChar", (PyCFunction)wasteObj_WEGetChar, 1,
+ "(SInt32 offset) -> (SInt16 _rv)"},
+ {"WEGetTextLength", (PyCFunction)wasteObj_WEGetTextLength, 1,
+ "() -> (SInt32 _rv)"},
+ {"WEGetHeight", (PyCFunction)wasteObj_WEGetHeight, 1,
+ "(SInt32 startLine, SInt32 endLine) -> (SInt32 _rv)"},
+ {"WEGetSelection", (PyCFunction)wasteObj_WEGetSelection, 1,
+ "() -> (SInt32 selStart, SInt32 selEnd)"},
+ {"WEGetDestRect", (PyCFunction)wasteObj_WEGetDestRect, 1,
+ "() -> (LongRect destRect)"},
+ {"WEGetViewRect", (PyCFunction)wasteObj_WEGetViewRect, 1,
+ "() -> (LongRect viewRect)"},
+ {"WEIsActive", (PyCFunction)wasteObj_WEIsActive, 1,
+ "() -> (Boolean _rv)"},
+ {"WEOffsetToLine", (PyCFunction)wasteObj_WEOffsetToLine, 1,
+ "(SInt32 offset) -> (SInt32 _rv)"},
+ {"WEGetLineRange", (PyCFunction)wasteObj_WEGetLineRange, 1,
+ "(SInt32 lineIndex) -> (SInt32 lineStart, SInt32 lineEnd)"},
+ {"WECountLines", (PyCFunction)wasteObj_WECountLines, 1,
+ "() -> (SInt32 _rv)"},
+ {"WEOffsetToRun", (PyCFunction)wasteObj_WEOffsetToRun, 1,
+ "(SInt32 offset) -> (SInt32 _rv)"},
+ {"WEGetRunRange", (PyCFunction)wasteObj_WEGetRunRange, 1,
+ "(SInt32 runIndex) -> (SInt32 runStart, SInt32 runEnd)"},
+ {"WECountRuns", (PyCFunction)wasteObj_WECountRuns, 1,
+ "() -> (SInt32 _rv)"},
+ {"WEGetClickCount", (PyCFunction)wasteObj_WEGetClickCount, 1,
+ "() -> (UInt16 _rv)"},
+ {"WESetSelection", (PyCFunction)wasteObj_WESetSelection, 1,
+ "(SInt32 selStart, SInt32 selEnd) -> None"},
+ {"WESetDestRect", (PyCFunction)wasteObj_WESetDestRect, 1,
+ "(LongRect destRect) -> None"},
+ {"WESetViewRect", (PyCFunction)wasteObj_WESetViewRect, 1,
+ "(LongRect viewRect) -> None"},
+ {"WEContinuousStyle", (PyCFunction)wasteObj_WEContinuousStyle, 1,
+ "(WEStyleMode mode) -> (Boolean _rv, WEStyleMode mode, TextStyle ts)"},
+ {"WEGetRunInfo", (PyCFunction)wasteObj_WEGetRunInfo, 1,
+ "(SInt32 offset) -> (WERunInfo runInfo)"},
+ {"WEGetRunDirection", (PyCFunction)wasteObj_WEGetRunDirection, 1,
+ "(SInt32 offset) -> (Boolean _rv)"},
+ {"WEGetOffset", (PyCFunction)wasteObj_WEGetOffset, 1,
+ "(LongPt thePoint) -> (SInt32 _rv, WEEdge edge)"},
+ {"WEGetPoint", (PyCFunction)wasteObj_WEGetPoint, 1,
+ "(SInt32 offset, SInt16 direction) -> (LongPt thePoint, SInt16 lineHeight)"},
+ {"WEFindWord", (PyCFunction)wasteObj_WEFindWord, 1,
+ "(SInt32 offset, WEEdge edge) -> (SInt32 wordStart, SInt32 wordEnd)"},
+ {"WEFindLine", (PyCFunction)wasteObj_WEFindLine, 1,
+ "(SInt32 offset, WEEdge edge) -> (SInt32 lineStart, SInt32 lineEnd)"},
+ {"WEFindParagraph", (PyCFunction)wasteObj_WEFindParagraph, 1,
+ "(SInt32 offset, WEEdge edge) -> (SInt32 paragraphStart, SInt32 paragraphEnd)"},
+ {"WECopyRange", (PyCFunction)wasteObj_WECopyRange, 1,
+ "(SInt32 rangeStart, SInt32 rangeEnd, Handle hText, StScrpHandle hStyles, WESoupHandle hSoup) -> None"},
+ {"WEGetAlignment", (PyCFunction)wasteObj_WEGetAlignment, 1,
+ "() -> (WEAlignment _rv)"},
+ {"WESetAlignment", (PyCFunction)wasteObj_WESetAlignment, 1,
+ "(WEAlignment alignment) -> None"},
+ {"WEGetDirection", (PyCFunction)wasteObj_WEGetDirection, 1,
+ "() -> (WEDirection _rv)"},
+ {"WESetDirection", (PyCFunction)wasteObj_WESetDirection, 1,
+ "(WEDirection direction) -> None"},
+ {"WECalText", (PyCFunction)wasteObj_WECalText, 1,
+ "() -> None"},
+ {"WEUpdate", (PyCFunction)wasteObj_WEUpdate, 1,
+ "(RgnHandle updateRgn) -> None"},
+ {"WEScroll", (PyCFunction)wasteObj_WEScroll, 1,
+ "(SInt32 hOffset, SInt32 vOffset) -> None"},
+ {"WESelView", (PyCFunction)wasteObj_WESelView, 1,
+ "() -> None"},
+ {"WEActivate", (PyCFunction)wasteObj_WEActivate, 1,
+ "() -> None"},
+ {"WEDeactivate", (PyCFunction)wasteObj_WEDeactivate, 1,
+ "() -> None"},
+ {"WEKey", (PyCFunction)wasteObj_WEKey, 1,
+ "(SInt16 key, EventModifiers modifiers) -> None"},
+ {"WEClick", (PyCFunction)wasteObj_WEClick, 1,
+ "(Point hitPt, EventModifiers modifiers, UInt32 clickTime) -> None"},
+ {"WEAdjustCursor", (PyCFunction)wasteObj_WEAdjustCursor, 1,
+ "(Point mouseLoc, RgnHandle mouseRgn) -> (Boolean _rv)"},
+ {"WEIdle", (PyCFunction)wasteObj_WEIdle, 1,
+ "() -> (UInt32 maxSleep)"},
+ {"WEInsert", (PyCFunction)wasteObj_WEInsert, 1,
+ "(Buffer pText, StScrpHandle hStyles, WESoupHandle hSoup) -> None"},
+ {"WEDelete", (PyCFunction)wasteObj_WEDelete, 1,
+ "() -> None"},
+ {"WESetStyle", (PyCFunction)wasteObj_WESetStyle, 1,
+ "(WEStyleMode mode, TextStyle ts) -> None"},
+ {"WEUseStyleScrap", (PyCFunction)wasteObj_WEUseStyleScrap, 1,
+ "(StScrpHandle hStyles) -> None"},
+ {"WEUseText", (PyCFunction)wasteObj_WEUseText, 1,
+ "(Handle hText) -> None"},
+ {"WEUndo", (PyCFunction)wasteObj_WEUndo, 1,
+ "() -> None"},
+ {"WEClearUndo", (PyCFunction)wasteObj_WEClearUndo, 1,
+ "() -> None"},
+ {"WEGetUndoInfo", (PyCFunction)wasteObj_WEGetUndoInfo, 1,
+ "() -> (WEActionKind _rv, Boolean redoFlag)"},
+ {"WEIsTyping", (PyCFunction)wasteObj_WEIsTyping, 1,
+ "() -> (Boolean _rv)"},
+ {"WEBeginAction", (PyCFunction)wasteObj_WEBeginAction, 1,
+ "() -> None"},
+ {"WEEndAction", (PyCFunction)wasteObj_WEEndAction, 1,
+ "(WEActionKind actionKind) -> None"},
+ {"WEGetModCount", (PyCFunction)wasteObj_WEGetModCount, 1,
+ "() -> (UInt32 _rv)"},
+ {"WEResetModCount", (PyCFunction)wasteObj_WEResetModCount, 1,
+ "() -> None"},
+ {"WEInsertObject", (PyCFunction)wasteObj_WEInsertObject, 1,
+ "(FlavorType objectType, Handle objectDataHandle, Point objectSize) -> None"},
+ {"WEGetSelectedObject", (PyCFunction)wasteObj_WEGetSelectedObject, 1,
+ "() -> (WEObjectReference obj)"},
+ {"WEFindNextObject", (PyCFunction)wasteObj_WEFindNextObject, 1,
+ "(SInt32 offset) -> (SInt32 _rv, WEObjectReference obj)"},
+ {"WEUseSoup", (PyCFunction)wasteObj_WEUseSoup, 1,
+ "(WESoupHandle hSoup) -> None"},
+ {"WECut", (PyCFunction)wasteObj_WECut, 1,
+ "() -> None"},
+ {"WECopy", (PyCFunction)wasteObj_WECopy, 1,
+ "() -> None"},
+ {"WEPaste", (PyCFunction)wasteObj_WEPaste, 1,
+ "() -> None"},
+ {"WECanPaste", (PyCFunction)wasteObj_WECanPaste, 1,
+ "() -> (Boolean _rv)"},
+ {"WEGetHiliteRgn", (PyCFunction)wasteObj_WEGetHiliteRgn, 1,
+ "(SInt32 rangeStart, SInt32 rangeEnd) -> (RgnHandle _rv)"},
+ {"WECharByte", (PyCFunction)wasteObj_WECharByte, 1,
+ "(SInt32 offset) -> (SInt16 _rv)"},
+ {"WECharType", (PyCFunction)wasteObj_WECharType, 1,
+ "(SInt32 offset) -> (SInt16 _rv)"},
+ {"WEStopInlineSession", (PyCFunction)wasteObj_WEStopInlineSession, 1,
+ "() -> None"},
+ {"WEFeatureFlag", (PyCFunction)wasteObj_WEFeatureFlag, 1,
+ "(SInt16 feature, SInt16 action) -> (SInt16 _rv)"},
+ {"WEGetUserInfo", (PyCFunction)wasteObj_WEGetUserInfo, 1,
+ "(WESelector tag) -> (SInt32 userInfo)"},
+ {"WESetUserInfo", (PyCFunction)wasteObj_WESetUserInfo, 1,
+ "(WESelector tag, SInt32 userInfo) -> None"},
+ {"WEInstallTabHooks", (PyCFunction)wasteObj_WEInstallTabHooks, 1,
+ "() -> None"},
+ {"WERemoveTabHooks", (PyCFunction)wasteObj_WERemoveTabHooks, 1,
+ "() -> None"},
+ {"WEIsTabHooks", (PyCFunction)wasteObj_WEIsTabHooks, 1,
+ "() -> (Boolean _rv)"},
+ {"WEGetTabSize", (PyCFunction)wasteObj_WEGetTabSize, 1,
+ "() -> (SInt16 _rv)"},
+ {"WESetTabSize", (PyCFunction)wasteObj_WESetTabSize, 1,
+ "(SInt16 tabWidth) -> None"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain wasteObj_chain = { wasteObj_methods, NULL };
+
+static PyObject *wasteObj_getattr(wasteObject *self, char *name)
+{
+ return Py_FindMethodInChain(&wasteObj_chain, (PyObject *)self, name);
+}
+
+#define wasteObj_setattr NULL
+
+#define wasteObj_compare NULL
+
+#define wasteObj_repr NULL
+
+#define wasteObj_hash NULL
+
+PyTypeObject waste_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "waste", /*tp_name*/
+ sizeof(wasteObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) wasteObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) wasteObj_getattr, /*tp_getattr*/
+ (setattrfunc) wasteObj_setattr, /*tp_setattr*/
+ (cmpfunc) wasteObj_compare, /*tp_compare*/
+ (reprfunc) wasteObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) wasteObj_hash, /*tp_hash*/
+};
+
+/* --------------------- End object type waste ---------------------- */
+
+
+static PyObject *waste_WENew(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ LongRect destRect;
+ LongRect viewRect;
+ UInt32 flags;
+ WEReference we;
+ if (!PyArg_ParseTuple(_args, "O&O&l",
+ LongRect_Convert, &destRect,
+ LongRect_Convert, &viewRect,
+ &flags))
+ return NULL;
+ _err = WENew(&destRect,
+ &viewRect,
+ flags,
+ &we);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ wasteObj_New, we);
+ return _res;
+}
+
+static PyObject *waste_WEUpdateStyleScrap(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ StScrpHandle hStyles;
+ WEFontTableHandle hFontTable;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, &hStyles,
+ ResObj_Convert, &hFontTable))
+ return NULL;
+ _err = WEUpdateStyleScrap(hStyles,
+ hFontTable);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *waste_WEInstallTSMHandlers(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = WEInstallTSMHandlers();
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *waste_WERemoveTSMHandlers(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = WERemoveTSMHandlers();
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *waste_WEHandleTSMEvent(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AppleEvent ae;
+ AppleEvent reply;
+ if (!PyArg_ParseTuple(_args, "O&",
+ AEDesc_Convert, &ae))
+ return NULL;
+ _err = WEHandleTSMEvent(&ae,
+ &reply);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ AEDesc_New, &reply);
+ return _res;
+}
+
+static PyObject *waste_WELongPointToPoint(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ LongPt lp;
+ Point p;
+ if (!PyArg_ParseTuple(_args, "O&",
+ LongPt_Convert, &lp))
+ return NULL;
+ WELongPointToPoint(&lp,
+ &p);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildPoint, p);
+ return _res;
+}
+
+static PyObject *waste_WEPointToLongPoint(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Point p;
+ LongPt lp;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetPoint, &p))
+ return NULL;
+ WEPointToLongPoint(p,
+ &lp);
+ _res = Py_BuildValue("O&",
+ LongPt_New, &lp);
+ return _res;
+}
+
+static PyObject *waste_WESetLongRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ LongRect lr;
+ SInt32 left;
+ SInt32 top;
+ SInt32 right;
+ SInt32 bottom;
+ if (!PyArg_ParseTuple(_args, "llll",
+ &left,
+ &top,
+ &right,
+ &bottom))
+ return NULL;
+ WESetLongRect(&lr,
+ left,
+ top,
+ right,
+ bottom);
+ _res = Py_BuildValue("O&",
+ LongRect_New, &lr);
+ return _res;
+}
+
+static PyObject *waste_WELongRectToRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ LongRect lr;
+ Rect r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ LongRect_Convert, &lr))
+ return NULL;
+ WELongRectToRect(&lr,
+ &r);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &r);
+ return _res;
+}
+
+static PyObject *waste_WERectToLongRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect r;
+ LongRect lr;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &r))
+ return NULL;
+ WERectToLongRect(&r,
+ &lr);
+ _res = Py_BuildValue("O&",
+ LongRect_New, &lr);
+ return _res;
+}
+
+static PyObject *waste_WEOffsetLongRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ LongRect lr;
+ SInt32 hOffset;
+ SInt32 vOffset;
+ if (!PyArg_ParseTuple(_args, "ll",
+ &hOffset,
+ &vOffset))
+ return NULL;
+ WEOffsetLongRect(&lr,
+ hOffset,
+ vOffset);
+ _res = Py_BuildValue("O&",
+ LongRect_New, &lr);
+ return _res;
+}
+
+static PyObject *waste_WELongPointInLongRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ LongPt lp;
+ LongRect lr;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ LongPt_Convert, &lp,
+ LongRect_Convert, &lr))
+ return NULL;
+ _rv = WELongPointInLongRect(&lp,
+ &lr);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *waste_STDObjectHandlers(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ OSErr err;
+ // install the sample object handlers for pictures and sounds
+#define kTypePicture 'PICT'
+#define kTypeSound 'snd '
+
+ if ( !PyArg_ParseTuple(_args, "") ) return NULL;
+
+ if ((err = WEInstallObjectHandler(kTypePicture, weNewHandler,
+ (UniversalProcPtr) NewWENewObjectProc(HandleNewPicture), NULL)) != noErr)
+ goto cleanup;
+
+ if ((err = WEInstallObjectHandler(kTypePicture, weDisposeHandler,
+ (UniversalProcPtr) NewWEDisposeObjectProc(HandleDisposePicture), NULL)) != noErr)
+ goto cleanup;
+
+ if ((err = WEInstallObjectHandler(kTypePicture, weDrawHandler,
+ (UniversalProcPtr) NewWEDrawObjectProc(HandleDrawPicture), NULL)) != noErr)
+ goto cleanup;
+
+ if ((err = WEInstallObjectHandler(kTypeSound, weNewHandler,
+ (UniversalProcPtr) NewWENewObjectProc(HandleNewSound), NULL)) != noErr)
+ goto cleanup;
+
+ if ((err = WEInstallObjectHandler(kTypeSound, weDrawHandler,
+ (UniversalProcPtr) NewWEDrawObjectProc(HandleDrawSound), NULL)) != noErr)
+ goto cleanup;
+
+ if ((err = WEInstallObjectHandler(kTypeSound, weClickHandler,
+ (UniversalProcPtr) NewWEClickObjectProc(HandleClickSound), NULL)) != noErr)
+ goto cleanup;
+ Py_INCREF(Py_None);
+ return Py_None;
+
+ cleanup:
+ return PyMac_Error(err);
+
+}
+
+static PyObject *waste_WEInstallObjectHandler(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ OSErr err;
+ FlavorType objectType;
+ WESelector selector;
+ PyObject *py_handler;
+ UniversalProcPtr handler;
+ WEReference we = NULL;
+ PyObject *key;
+
+
+ if ( !PyArg_ParseTuple(_args, "O&O&O|O&",
+ PyMac_GetOSType, &objectType,
+ PyMac_GetOSType, &selector,
+ &py_handler,
+ WEOObj_Convert, &we) ) return NULL;
+
+ if ( selector == weNewHandler ) handler = (UniversalProcPtr)upp_new_handler;
+ else if ( selector == weDisposeHandler ) handler = (UniversalProcPtr)upp_dispose_handler;
+ else if ( selector == weDrawHandler ) handler = (UniversalProcPtr)upp_draw_handler;
+ else if ( selector == weClickHandler ) handler = (UniversalProcPtr)upp_click_handler;
+ else return PyMac_Error(weUndefinedSelectorErr);
+
+ if ((key = Py_BuildValue("O&O&",
+ PyMac_BuildOSType, objectType,
+ PyMac_BuildOSType, selector)) == NULL )
+ return NULL;
+
+ PyDict_SetItem(callbackdict, key, py_handler);
+
+ err = WEInstallObjectHandler(objectType, selector, handler, we);
+ if ( err ) return PyMac_Error(err);
+ Py_INCREF(Py_None);
+ return Py_None;
+
+}
+
+static PyMethodDef waste_methods[] = {
+ {"WENew", (PyCFunction)waste_WENew, 1,
+ "(LongRect destRect, LongRect viewRect, UInt32 flags) -> (WEReference we)"},
+ {"WEUpdateStyleScrap", (PyCFunction)waste_WEUpdateStyleScrap, 1,
+ "(StScrpHandle hStyles, WEFontTableHandle hFontTable) -> None"},
+ {"WEInstallTSMHandlers", (PyCFunction)waste_WEInstallTSMHandlers, 1,
+ "() -> None"},
+ {"WERemoveTSMHandlers", (PyCFunction)waste_WERemoveTSMHandlers, 1,
+ "() -> None"},
+ {"WEHandleTSMEvent", (PyCFunction)waste_WEHandleTSMEvent, 1,
+ "(AppleEvent ae) -> (AppleEvent reply)"},
+ {"WELongPointToPoint", (PyCFunction)waste_WELongPointToPoint, 1,
+ "(LongPt lp) -> (Point p)"},
+ {"WEPointToLongPoint", (PyCFunction)waste_WEPointToLongPoint, 1,
+ "(Point p) -> (LongPt lp)"},
+ {"WESetLongRect", (PyCFunction)waste_WESetLongRect, 1,
+ "(SInt32 left, SInt32 top, SInt32 right, SInt32 bottom) -> (LongRect lr)"},
+ {"WELongRectToRect", (PyCFunction)waste_WELongRectToRect, 1,
+ "(LongRect lr) -> (Rect r)"},
+ {"WERectToLongRect", (PyCFunction)waste_WERectToLongRect, 1,
+ "(Rect r) -> (LongRect lr)"},
+ {"WEOffsetLongRect", (PyCFunction)waste_WEOffsetLongRect, 1,
+ "(SInt32 hOffset, SInt32 vOffset) -> (LongRect lr)"},
+ {"WELongPointInLongRect", (PyCFunction)waste_WELongPointInLongRect, 1,
+ "(LongPt lp, LongRect lr) -> (Boolean _rv)"},
+ {"STDObjectHandlers", (PyCFunction)waste_STDObjectHandlers, 1,
+ NULL},
+ {"WEInstallObjectHandler", (PyCFunction)waste_WEInstallObjectHandler, 1,
+ NULL},
+ {NULL, NULL, 0}
+};
+
+
+
+/* Return the object corresponding to the window, or NULL */
+
+PyObject *
+ExistingwasteObj_New(w)
+ WEReference w;
+{
+ PyObject *it = NULL;
+
+ if (w == NULL)
+ it = NULL;
+ else
+ WEGetInfo(weRefCon, (void *)&it, w);
+ if (it == NULL || ((wasteObject *)it)->ob_itself != w)
+ it = Py_None;
+ Py_INCREF(it);
+ return it;
+}
+
+
+void initwaste(void)
+{
+ PyObject *m;
+ PyObject *d;
+
+
+
+
+ m = Py_InitModule("waste", waste_methods);
+ d = PyModule_GetDict(m);
+ waste_Error = PyMac_GetOSErrException();
+ if (waste_Error == NULL ||
+ PyDict_SetItemString(d, "Error", waste_Error) != 0)
+ return;
+ WEO_Type.ob_type = &PyType_Type;
+ Py_INCREF(&WEO_Type);
+ if (PyDict_SetItemString(d, "WEOType", (PyObject *)&WEO_Type) != 0)
+ Py_FatalError("can't initialize WEOType");
+ waste_Type.ob_type = &PyType_Type;
+ Py_INCREF(&waste_Type);
+ if (PyDict_SetItemString(d, "wasteType", (PyObject *)&waste_Type) != 0)
+ Py_FatalError("can't initialize wasteType");
+
+ callbackdict = PyDict_New();
+ if (callbackdict == NULL || PyDict_SetItemString(d, "callbacks", callbackdict) != 0)
+ return;
+ upp_new_handler = NewWENewObjectProc(my_new_handler);
+ upp_dispose_handler = NewWEDisposeObjectProc(my_dispose_handler);
+ upp_draw_handler = NewWEDrawObjectProc(my_draw_handler);
+ upp_click_handler = NewWEClickObjectProc(my_click_handler);
+
+
+}
+
+/* ======================== End module waste ======================== */
+
--- /dev/null
+# This script generates a Python interface for an Apple Macintosh Manager.
+# It uses the "bgen" package to generate C code.
+# The function specifications are generated by scanning the mamager's header file,
+# using the "scantools" package (customized for this particular manager).
+
+import string
+
+# Declarations that change for each manager
+MACHEADERFILE = 'WASTE.h' # The Apple header file
+MODNAME = 'waste' # The name of the module
+OBJECTNAME = 'waste' # The basic name of the objects used here
+KIND = 'Ptr' # Usually 'Ptr' or 'Handle'
+
+# The following is *usually* unchanged but may still require tuning
+MODPREFIX = MODNAME # The prefix for module-wide routines
+OBJECTTYPE = "WEReference" # The C type used to represent them
+OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
+INPUTFILE = 'wastegen.py' # The file generated by the scanner
+TYPETESTFILE = 'wastetypetest.py' # Another file generated by the scanner
+OUTPUTFILE = "wastemodule.c" # The file generated by this program
+
+from macsupport import *
+
+# Create the type objects
+WEReference = OpaqueByValueType("WEReference", "wasteObj")
+ExistingWEReference = OpaqueByValueType("WEReference", "ExistingwasteObj")
+WEObjectReference = OpaqueByValueType("WEObjectReference", "WEOObj")
+StScrpHandle = OpaqueByValueType("StScrpHandle", "ResObj")
+RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
+EventModifiers = Type("EventModifiers", "H")
+FlavorType = OSTypeType("FlavorType")
+WESelector = OSTypeType("WESelector")
+
+OptHandle = OpaqueByValueType("Handle", "OptResObj")
+OptSoupHandle = OpaqueByValueType("WESoupHandle", "OptResObj")
+OptStScrpHandle = OpaqueByValueType("StScrpHandle", "OptResObj")
+
+WEStyleMode = Type("WEStyleMode", "H")
+WEActionKind = Type("WEActionKind", "h")
+WEAlignment = Type("WEAlignment", "B")
+WEEdge = Type("WEEdge", "B")
+WEDirection = Type("WEDirection", "h")
+WESoupHandle = OpaqueByValueType("WESoupHandle", "ResObj")
+WEFontTableHandle = OpaqueByValueType("WEFontTableHandle", "ResObj")
+WEFontTableHandle
+WERunInfo = OpaqueType("WERunInfo", "RunInfo")
+
+AppleEvent = OpaqueType('AppleEvent', 'AEDesc')
+AppleEvent_ptr = OpaqueType('AppleEvent', 'AEDesc')
+
+TextStyle = OpaqueType("TextStyle", "TextStyle")
+TextStyle_ptr = TextStyle
+LongPt = OpaqueType("LongPt", "LongPt")
+LongPt_ptr = LongPt
+LongRect = OpaqueType("LongRect", "LongRect")
+LongRect_ptr = LongRect
+
+includestuff = includestuff + """
+#include <%s>""" % MACHEADERFILE + """
+#include <WEObjectHandlers.h>
+#include <WETabs.h>
+
+/* Exported by Qdmodule.c: */
+extern PyObject *QdRGB_New(RGBColor *);
+extern int QdRGB_Convert(PyObject *, RGBColor *);
+
+/* Exported by AEModule.c: */
+extern PyObject *AEDesc_New(AppleEvent *);
+extern int AEDesc_Convert(PyObject *, AppleEvent *);
+
+/* Forward declaration */
+staticforward PyObject *WEOObj_New(WEObjectReference);
+staticforward PyObject *ExistingwasteObj_New(WEReference);
+
+/*
+** Parse/generate TextStyle records
+*/
+static
+PyObject *TextStyle_New(itself)
+ TextStylePtr itself;
+{
+
+ return Py_BuildValue("lllO&", (long)itself->tsFont, (long)itself->tsFace, (long)itself->tsSize, QdRGB_New,
+ &itself->tsColor);
+}
+
+static
+TextStyle_Convert(v, p_itself)
+ PyObject *v;
+ TextStylePtr p_itself;
+{
+ long font, face, size;
+
+ if( !PyArg_ParseTuple(v, "lllO&", &font, &face, &size, QdRGB_Convert, &p_itself->tsColor) )
+ return 0;
+ p_itself->tsFont = (short)font;
+ p_itself->tsFace = (Style)face;
+ p_itself->tsSize = (short)size;
+ return 1;
+}
+
+/*
+** Parse/generate RunInfo records
+*/
+static
+PyObject *RunInfo_New(itself)
+ WERunInfo *itself;
+{
+
+ return Py_BuildValue("llhhO&O&", itself->runStart, itself->runEnd, itself->runHeight,
+ itself->runAscent, TextStyle_New, &itself->runStyle, WEOObj_New, itself->runObject);
+}
+
+/* Conversion of long points and rects */
+int
+LongRect_Convert(PyObject *v, LongRect *r)
+{
+ return PyArg_Parse(v, "(llll)", &r->left, &r->top, &r->right, &r->bottom);
+}
+
+PyObject *
+LongRect_New(LongRect *r)
+{
+ return Py_BuildValue("(llll)", r->left, r->top, r->right, r->bottom);
+}
+
+
+LongPt_Convert(PyObject *v, LongPt *p)
+{
+ return PyArg_Parse(v, "(ll)", &p->h, &p->v);
+}
+
+PyObject *
+LongPt_New(LongPt *p)
+{
+ return Py_BuildValue("(ll)", p->h, p->v);
+}
+
+/* Stuff for the callbacks: */
+static PyObject *callbackdict;
+WENewObjectUPP upp_new_handler;
+WEDisposeObjectUPP upp_dispose_handler;
+WEDrawObjectUPP upp_draw_handler;
+WEClickObjectUPP upp_click_handler;
+
+static OSErr
+any_handler(WESelector what, WEObjectReference who, PyObject *args, PyObject **rv)
+{
+ FlavorType tp;
+ PyObject *key, *func;
+
+ if ( args == NULL ) return errAECorruptData;
+
+ tp = WEGetObjectType(who);
+
+ if( (key=Py_BuildValue("O&O&", PyMac_BuildOSType, tp, PyMac_BuildOSType, what)) == NULL)
+ return errAECorruptData;
+ if( (func = PyDict_GetItem(callbackdict, key)) == NULL ) {
+ Py_DECREF(key);
+ return errAEHandlerNotFound;
+ }
+ Py_INCREF(func);
+ *rv = PyEval_CallObject(func, args);
+ Py_DECREF(func);
+ Py_DECREF(key);
+ if ( *rv == NULL ) {
+ PySys_WriteStderr("--Exception in callback: ");
+ PyErr_Print();
+ return errAEReplyNotArrived;
+ }
+ return 0;
+}
+
+static pascal OSErr
+my_new_handler(Point *objectSize, WEObjectReference objref)
+{
+ PyObject *args=NULL, *rv=NULL;
+ OSErr err;
+
+ args=Py_BuildValue("(O&)", WEOObj_New, objref);
+ err = any_handler(weNewHandler, objref, args, &rv);
+ if (!err) {
+ if (!PyMac_GetPoint(rv, objectSize) )
+ err = errAECoercionFail;
+ }
+ if ( args ) Py_DECREF(args);
+ if ( rv ) Py_DECREF(rv);
+ return err;
+}
+
+static pascal OSErr
+my_dispose_handler(WEObjectReference objref)
+{
+ PyObject *args=NULL, *rv=NULL;
+ OSErr err;
+
+ args=Py_BuildValue("(O&)", WEOObj_New, objref);
+ err = any_handler(weDisposeHandler, objref, args, &rv);
+ if ( args ) Py_DECREF(args);
+ if ( rv ) Py_DECREF(rv);
+ return err;
+}
+
+static pascal OSErr
+my_draw_handler(const Rect *destRect, WEObjectReference objref)
+{
+ PyObject *args=NULL, *rv=NULL;
+ OSErr err;
+
+ args=Py_BuildValue("O&O&", PyMac_BuildRect, destRect, WEOObj_New, objref);
+ err = any_handler(weDrawHandler, objref, args, &rv);
+ if ( args ) Py_DECREF(args);
+ if ( rv ) Py_DECREF(rv);
+ return err;
+}
+
+static pascal Boolean
+my_click_handler(Point hitPt, EventModifiers modifiers,
+ unsigned long clickTime, WEObjectReference objref)
+{
+ PyObject *args=NULL, *rv=NULL;
+ int retvalue;
+ OSErr err;
+
+ args=Py_BuildValue("O&llO&", PyMac_BuildPoint, hitPt,
+ (long)modifiers, (long)clickTime, WEOObj_New, objref);
+ err = any_handler(weClickHandler, objref, args, &rv);
+ if (!err)
+ retvalue = PyInt_AsLong(rv);
+ else
+ retvalue = 0;
+ if ( args ) Py_DECREF(args);
+ if ( rv ) Py_DECREF(rv);
+ return retvalue;
+}
+
+
+"""
+finalstuff = finalstuff + """
+/* Return the object corresponding to the window, or NULL */
+
+PyObject *
+ExistingwasteObj_New(w)
+ WEReference w;
+{
+ PyObject *it = NULL;
+
+ if (w == NULL)
+ it = NULL;
+ else
+ WEGetInfo(weRefCon, (void *)&it, w);
+ if (it == NULL || ((wasteObject *)it)->ob_itself != w)
+ it = Py_None;
+ Py_INCREF(it);
+ return it;
+}
+"""
+
+class WEMethodGenerator(OSErrMethodGenerator):
+ """Similar to MethodGenerator, but has self as last argument"""
+
+ def parseArgumentList(self, args):
+ args, a0 = args[:-1], args[-1]
+ t0, n0, m0 = a0
+ if m0 != InMode:
+ raise ValueError, "method's 'self' must be 'InMode'"
+ self.itself = Variable(t0, "_self->ob_itself", SelfMode)
+ FunctionGenerator.parseArgumentList(self, args)
+ self.argumentList.append(self.itself)
+
+
+
+class WEObjectDefinition(GlobalObjectDefinition):
+ def outputCheckNewArg(self):
+ Output("""if (itself == NULL) {
+ PyErr_SetString(waste_Error,"Cannot create null WE");
+ return NULL;
+ }""")
+ def outputInitStructMembers(self):
+ GlobalObjectDefinition.outputInitStructMembers(self)
+ Output("WESetInfo(weRefCon, (void *)&it, itself);")
+ def outputFreeIt(self, itselfname):
+ Output("WEDispose(%s);", itselfname)
+
+class WEOObjectDefinition(GlobalObjectDefinition):
+ def outputCheckNewArg(self):
+ Output("""if (itself == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }""")
+
+variablestuff = """
+ callbackdict = PyDict_New();
+ if (callbackdict == NULL || PyDict_SetItemString(d, "callbacks", callbackdict) != 0)
+ return;
+ upp_new_handler = NewWENewObjectProc(my_new_handler);
+ upp_dispose_handler = NewWEDisposeObjectProc(my_dispose_handler);
+ upp_draw_handler = NewWEDrawObjectProc(my_draw_handler);
+ upp_click_handler = NewWEClickObjectProc(my_click_handler);
+"""
+
+
+# From here on it's basically all boiler plate...
+
+# Test types used for existence
+## execfile(TYPETESTFILE)
+
+# Create the generator groups and link them
+module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff, variablestuff)
+object = WEObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
+object2 = WEOObjectDefinition("WEO", "WEOObj", "WEObjectReference")
+module.addobject(object2)
+module.addobject(object)
+
+# Create the generator classes used to populate the lists
+Function = OSErrFunctionGenerator
+Method = WEMethodGenerator
+Method2 = OSErrMethodGenerator
+
+# Create and populate the lists
+functions = []
+methods = []
+methods2 = []
+execfile(INPUTFILE)
+
+# A function written by hand:
+stdhandlers_body = """
+ OSErr err;
+ // install the sample object handlers for pictures and sounds
+#define kTypePicture 'PICT'
+#define kTypeSound 'snd '
+
+ if ( !PyArg_ParseTuple(_args, "") ) return NULL;
+
+ if ((err = WEInstallObjectHandler(kTypePicture, weNewHandler,
+ (UniversalProcPtr) NewWENewObjectProc(HandleNewPicture), NULL)) != noErr)
+ goto cleanup;
+
+ if ((err = WEInstallObjectHandler(kTypePicture, weDisposeHandler,
+ (UniversalProcPtr) NewWEDisposeObjectProc(HandleDisposePicture), NULL)) != noErr)
+ goto cleanup;
+
+ if ((err = WEInstallObjectHandler(kTypePicture, weDrawHandler,
+ (UniversalProcPtr) NewWEDrawObjectProc(HandleDrawPicture), NULL)) != noErr)
+ goto cleanup;
+
+ if ((err = WEInstallObjectHandler(kTypeSound, weNewHandler,
+ (UniversalProcPtr) NewWENewObjectProc(HandleNewSound), NULL)) != noErr)
+ goto cleanup;
+
+ if ((err = WEInstallObjectHandler(kTypeSound, weDrawHandler,
+ (UniversalProcPtr) NewWEDrawObjectProc(HandleDrawSound), NULL)) != noErr)
+ goto cleanup;
+
+ if ((err = WEInstallObjectHandler(kTypeSound, weClickHandler,
+ (UniversalProcPtr) NewWEClickObjectProc(HandleClickSound), NULL)) != noErr)
+ goto cleanup;
+ Py_INCREF(Py_None);
+ return Py_None;
+
+cleanup:
+ return PyMac_Error(err);
+"""
+
+inshandler_body = """
+ OSErr err;
+ FlavorType objectType;
+ WESelector selector;
+ PyObject *py_handler;
+ UniversalProcPtr handler;
+ WEReference we = NULL;
+ PyObject *key;
+
+
+ if ( !PyArg_ParseTuple(_args, "O&O&O|O&",
+ PyMac_GetOSType, &objectType,
+ PyMac_GetOSType, &selector,
+ &py_handler,
+ WEOObj_Convert, &we) ) return NULL;
+
+ if ( selector == weNewHandler ) handler = (UniversalProcPtr)upp_new_handler;
+ else if ( selector == weDisposeHandler ) handler = (UniversalProcPtr)upp_dispose_handler;
+ else if ( selector == weDrawHandler ) handler = (UniversalProcPtr)upp_draw_handler;
+ else if ( selector == weClickHandler ) handler = (UniversalProcPtr)upp_click_handler;
+ else return PyMac_Error(weUndefinedSelectorErr);
+
+ if ((key = Py_BuildValue("O&O&",
+ PyMac_BuildOSType, objectType,
+ PyMac_BuildOSType, selector)) == NULL )
+ return NULL;
+
+ PyDict_SetItem(callbackdict, key, py_handler);
+
+ err = WEInstallObjectHandler(objectType, selector, handler, we);
+ if ( err ) return PyMac_Error(err);
+ Py_INCREF(Py_None);
+ return Py_None;
+"""
+
+stdhand = ManualGenerator("STDObjectHandlers", stdhandlers_body)
+inshand = ManualGenerator("WEInstallObjectHandler", inshandler_body)
+
+
+# Tab hook handlers. Could be parsed from WETabs.h, but this is just as simple.
+f = Method(OSErr, 'WEInstallTabHooks', (WEReference, 'we', InMode))
+methods.append(f)
+f = Method(OSErr, 'WERemoveTabHooks', (WEReference, 'we', InMode))
+methods.append(f)
+f = Method(Boolean, 'WEIsTabHooks', (WEReference, 'we', InMode))
+methods.append(f)
+f = Method(SInt16, 'WEGetTabSize', (WEReference, 'we', InMode))
+methods.append(f)
+f = Method(OSErr, 'WESetTabSize', (SInt16, 'tabWidth', InMode), (WEReference, 'we', InMode))
+methods.append(f)
+
+# add the populated lists to the generator groups
+# (in a different wordl the scan program would generate this)
+for f in functions: module.add(f)
+module.add(stdhand)
+module.add(inshand)
+for f in methods: object.add(f)
+for f in methods2: object2.add(f)
+
+# generate output (open the output file as late as possible)
+SetOutputFileName(OUTPUTFILE)
+module.generate()
+
--- /dev/null
+
+/* =========================== Module Win =========================== */
+
+#include "Python.h"
+
+
+
+#include "macglue.h"
+#include "pymactoolbox.h"
+
+#ifdef WITHOUT_FRAMEWORKS
+#include <Windows.h>
+#else
+#include <Carbon/Carbon.h>
+#endif
+
+#ifdef USE_TOOLBOX_OBJECT_GLUE
+extern PyObject *_WinObj_New(WindowRef);
+extern PyObject *_WinObj_WhichWindow(WindowRef);
+extern int _WinObj_Convert(PyObject *, WindowRef *);
+
+#define WinObj_New _WinObj_New
+#define WinObj_WhichWindow _WinObj_WhichWindow
+#define WinObj_Convert _WinObj_Convert
+#endif
+
+#if !ACCESSOR_CALLS_ARE_FUNCTIONS
+/* Carbon calls that we emulate in classic mode */
+#define GetWindowSpareFlag(win) (((CWindowPeek)(win))->spareFlag)
+#define GetWindowFromPort(port) ((WindowRef)(port))
+#define GetWindowPortBounds(win, rectp) (*(rectp) = ((CWindowPeek)(win))->port.portRect)
+#define IsPointerValid(p) (((long)p&3) == 0)
+#endif
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+/* Classic calls that we emulate in carbon mode */
+#define GetWindowUpdateRgn(win, rgn) GetWindowRegion((win), kWindowUpdateRgn, (rgn))
+#define GetWindowStructureRgn(win, rgn) GetWindowRegion((win), kWindowStructureRgn, (rgn))
+#define GetWindowContentRgn(win, rgn) GetWindowRegion((win), kWindowContentRgn, (rgn))
+#endif
+
+/* Function to dispose a window, with a "normal" calling sequence */
+static void
+PyMac_AutoDisposeWindow(WindowPtr w)
+{
+ DisposeWindow(w);
+}
+
+static PyObject *Win_Error;
+
+/* ----------------------- Object type Window ----------------------- */
+
+PyTypeObject Window_Type;
+
+#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
+
+typedef struct WindowObject {
+ PyObject_HEAD
+ WindowPtr ob_itself;
+ void (*ob_freeit)(WindowPtr ptr);
+} WindowObject;
+
+PyObject *WinObj_New(WindowPtr itself)
+{
+ WindowObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(WindowObject, &Window_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_freeit = NULL;
+ if (GetWRefCon(itself) == 0)
+ {
+ SetWRefCon(itself, (long)it);
+ it->ob_freeit = PyMac_AutoDisposeWindow;
+ }
+ return (PyObject *)it;
+}
+WinObj_Convert(PyObject *v, WindowPtr *p_itself)
+{
+
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
+
+ {
+ DialogRef dlg;
+ if (DlgObj_Convert(v, &dlg) && dlg) {
+ *p_itself = GetDialogWindow(dlg);
+ return 1;
+ }
+ PyErr_Clear();
+ }
+ if (!WinObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "Window required");
+ return 0;
+ }
+ *p_itself = ((WindowObject *)v)->ob_itself;
+ return 1;
+}
+
+static void WinObj_dealloc(WindowObject *self)
+{
+ if (self->ob_freeit && self->ob_itself)
+ {
+ SetWRefCon(self->ob_itself, 0);
+ self->ob_freeit(self->ob_itself);
+ }
+ self->ob_itself = NULL;
+ self->ob_freeit = NULL;
+ PyMem_DEL(self);
+}
+
+static PyObject *WinObj_GetWindowOwnerCount(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ UInt32 outCount;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetWindowOwnerCount(_self->ob_itself,
+ &outCount);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ outCount);
+ return _res;
+}
+
+static PyObject *WinObj_CloneWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = CloneWindow(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_ReshapeCustomWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = ReshapeCustomWindow(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *WinObj_GetWindowClass(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ WindowClass outClass;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetWindowClass(_self->ob_itself,
+ &outClass);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ outClass);
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowAttributes(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ WindowAttributes outAttributes;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetWindowAttributes(_self->ob_itself,
+ &outAttributes);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ outAttributes);
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_ChangeWindowAttributes(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ WindowAttributes setTheseAttributes;
+ WindowAttributes clearTheseAttributes;
+ if (!PyArg_ParseTuple(_args, "ll",
+ &setTheseAttributes,
+ &clearTheseAttributes))
+ return NULL;
+ _err = ChangeWindowAttributes(_self->ob_itself,
+ setTheseAttributes,
+ clearTheseAttributes);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_SetWinColor(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WCTabHandle newColorTable;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &newColorTable))
+ return NULL;
+ SetWinColor(_self->ob_itself,
+ newColorTable);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *WinObj_SetWindowContentColor(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ RGBColor color;
+ if (!PyArg_ParseTuple(_args, "O&",
+ QdRGB_Convert, &color))
+ return NULL;
+ _err = SetWindowContentColor(_self->ob_itself,
+ &color);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowContentColor(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ RGBColor color;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetWindowContentColor(_self->ob_itself,
+ &color);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ QdRGB_New, &color);
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowContentPattern(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ PixPatHandle outPixPat;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &outPixPat))
+ return NULL;
+ _err = GetWindowContentPattern(_self->ob_itself,
+ outPixPat);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_SetWindowContentPattern(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ PixPatHandle pixPat;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &pixPat))
+ return NULL;
+ _err = SetWindowContentPattern(_self->ob_itself,
+ pixPat);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_ScrollWindowRect(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Rect inScrollRect;
+ SInt16 inHPixels;
+ SInt16 inVPixels;
+ ScrollWindowOptions inOptions;
+ RgnHandle outExposedRgn;
+ if (!PyArg_ParseTuple(_args, "O&hhlO&",
+ PyMac_GetRect, &inScrollRect,
+ &inHPixels,
+ &inVPixels,
+ &inOptions,
+ ResObj_Convert, &outExposedRgn))
+ return NULL;
+ _err = ScrollWindowRect(_self->ob_itself,
+ &inScrollRect,
+ inHPixels,
+ inVPixels,
+ inOptions,
+ outExposedRgn);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_ScrollWindowRegion(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ RgnHandle inScrollRgn;
+ SInt16 inHPixels;
+ SInt16 inVPixels;
+ ScrollWindowOptions inOptions;
+ RgnHandle outExposedRgn;
+ if (!PyArg_ParseTuple(_args, "O&hhlO&",
+ ResObj_Convert, &inScrollRgn,
+ &inHPixels,
+ &inVPixels,
+ &inOptions,
+ ResObj_Convert, &outExposedRgn))
+ return NULL;
+ _err = ScrollWindowRegion(_self->ob_itself,
+ inScrollRgn,
+ inHPixels,
+ inVPixels,
+ inOptions,
+ outExposedRgn);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *WinObj_ClipAbove(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ ClipAbove(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_SaveOld(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ SaveOld(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_DrawNew(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean update;
+ if (!PyArg_ParseTuple(_args, "b",
+ &update))
+ return NULL;
+ DrawNew(_self->ob_itself,
+ update);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *WinObj_PaintOne(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle clobberedRgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &clobberedRgn))
+ return NULL;
+ PaintOne(_self->ob_itself,
+ clobberedRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_PaintBehind(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle clobberedRgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &clobberedRgn))
+ return NULL;
+ PaintBehind(_self->ob_itself,
+ clobberedRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_CalcVis(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ CalcVis(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_CalcVisBehind(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle clobberedRgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &clobberedRgn))
+ return NULL;
+ CalcVisBehind(_self->ob_itself,
+ clobberedRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_BringToFront(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ BringToFront(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_SendBehind(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr behindWindow;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &behindWindow))
+ return NULL;
+ SendBehind(_self->ob_itself,
+ behindWindow);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_SelectWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ SelectWindow(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_GetNextWindowOfClass(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr _rv;
+ WindowClass inWindowClass;
+ Boolean mustBeVisible;
+ if (!PyArg_ParseTuple(_args, "lb",
+ &inWindowClass,
+ &mustBeVisible))
+ return NULL;
+ _rv = GetNextWindowOfClass(_self->ob_itself,
+ inWindowClass,
+ mustBeVisible);
+ _res = Py_BuildValue("O&",
+ WinObj_New, _rv);
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_IsValidWindowPtr(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = IsValidWindowPtr(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+#endif
+
+static PyObject *WinObj_HiliteWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean fHilite;
+ if (!PyArg_ParseTuple(_args, "b",
+ &fHilite))
+ return NULL;
+ HiliteWindow(_self->ob_itself,
+ fHilite);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_SetWRefCon(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ long data;
+ if (!PyArg_ParseTuple(_args, "l",
+ &data))
+ return NULL;
+ SetWRefCon(_self->ob_itself,
+ data);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_GetWRefCon(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ long _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetWRefCon(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *WinObj_SetWindowPic(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PicHandle pic;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &pic))
+ return NULL;
+ SetWindowPic(_self->ob_itself,
+ pic);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowPic(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PicHandle _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetWindowPic(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *WinObj_GetWVariant(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetWVariant(_self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowFeatures(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ UInt32 outFeatures;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetWindowFeatures(_self->ob_itself,
+ &outFeatures);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ outFeatures);
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowRegion(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ WindowRegionCode inRegionCode;
+ RgnHandle ioWinRgn;
+ if (!PyArg_ParseTuple(_args, "HO&",
+ &inRegionCode,
+ ResObj_Convert, &ioWinRgn))
+ return NULL;
+ _err = GetWindowRegion(_self->ob_itself,
+ inRegionCode,
+ ioWinRgn);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_BeginUpdate(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ BeginUpdate(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_EndUpdate(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ EndUpdate(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_InvalWindowRgn(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ RgnHandle region;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, ®ion))
+ return NULL;
+ _err = InvalWindowRgn(_self->ob_itself,
+ region);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_InvalWindowRect(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Rect bounds;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &bounds))
+ return NULL;
+ _err = InvalWindowRect(_self->ob_itself,
+ &bounds);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_ValidWindowRgn(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ RgnHandle region;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, ®ion))
+ return NULL;
+ _err = ValidWindowRgn(_self->ob_itself,
+ region);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_ValidWindowRect(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Rect bounds;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &bounds))
+ return NULL;
+ _err = ValidWindowRect(_self->ob_itself,
+ &bounds);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_DrawGrowIcon(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ DrawGrowIcon(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_SetWTitle(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Str255 title;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetStr255, title))
+ return NULL;
+ SetWTitle(_self->ob_itself,
+ title);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_GetWTitle(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Str255 title;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetWTitle(_self->ob_itself,
+ title);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildStr255, title);
+ return _res;
+}
+
+static PyObject *WinObj_SetWindowProxyFSSpec(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ FSSpec inFile;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetFSSpec, &inFile))
+ return NULL;
+ _err = SetWindowProxyFSSpec(_self->ob_itself,
+ &inFile);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowProxyFSSpec(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ FSSpec outFile;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetWindowProxyFSSpec(_self->ob_itself,
+ &outFile);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildFSSpec, outFile);
+ return _res;
+}
+
+static PyObject *WinObj_SetWindowProxyAlias(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ AliasHandle alias;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &alias))
+ return NULL;
+ _err = SetWindowProxyAlias(_self->ob_itself,
+ alias);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowProxyAlias(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ AliasHandle alias;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetWindowProxyAlias(_self->ob_itself,
+ &alias);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ ResObj_New, alias);
+ return _res;
+}
+
+static PyObject *WinObj_SetWindowProxyCreatorAndType(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ OSType fileCreator;
+ OSType fileType;
+ SInt16 vRefNum;
+ if (!PyArg_ParseTuple(_args, "O&O&h",
+ PyMac_GetOSType, &fileCreator,
+ PyMac_GetOSType, &fileType,
+ &vRefNum))
+ return NULL;
+ _err = SetWindowProxyCreatorAndType(_self->ob_itself,
+ fileCreator,
+ fileType,
+ vRefNum);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowProxyIcon(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ IconRef outIcon;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetWindowProxyIcon(_self->ob_itself,
+ &outIcon);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ ResObj_New, outIcon);
+ return _res;
+}
+
+static PyObject *WinObj_SetWindowProxyIcon(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ IconRef icon;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &icon))
+ return NULL;
+ _err = SetWindowProxyIcon(_self->ob_itself,
+ icon);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_RemoveWindowProxy(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = RemoveWindowProxy(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_BeginWindowProxyDrag(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ DragReference outNewDrag;
+ RgnHandle outDragOutlineRgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &outDragOutlineRgn))
+ return NULL;
+ _err = BeginWindowProxyDrag(_self->ob_itself,
+ &outNewDrag,
+ outDragOutlineRgn);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ DragObj_New, outNewDrag);
+ return _res;
+}
+
+static PyObject *WinObj_EndWindowProxyDrag(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ DragReference theDrag;
+ if (!PyArg_ParseTuple(_args, "O&",
+ DragObj_Convert, &theDrag))
+ return NULL;
+ _err = EndWindowProxyDrag(_self->ob_itself,
+ theDrag);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_TrackWindowProxyFromExistingDrag(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Point startPt;
+ DragReference drag;
+ RgnHandle inDragOutlineRgn;
+ if (!PyArg_ParseTuple(_args, "O&O&O&",
+ PyMac_GetPoint, &startPt,
+ DragObj_Convert, &drag,
+ ResObj_Convert, &inDragOutlineRgn))
+ return NULL;
+ _err = TrackWindowProxyFromExistingDrag(_self->ob_itself,
+ startPt,
+ drag,
+ inDragOutlineRgn);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_TrackWindowProxyDrag(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Point startPt;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetPoint, &startPt))
+ return NULL;
+ _err = TrackWindowProxyDrag(_self->ob_itself,
+ startPt);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_IsWindowModified(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = IsWindowModified(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *WinObj_SetWindowModified(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Boolean modified;
+ if (!PyArg_ParseTuple(_args, "b",
+ &modified))
+ return NULL;
+ _err = SetWindowModified(_self->ob_itself,
+ modified);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_IsWindowPathSelectClick(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ EventRecord event;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetEventRecord, &event))
+ return NULL;
+ _rv = IsWindowPathSelectClick(_self->ob_itself,
+ &event);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *WinObj_WindowPathSelect(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ MenuHandle menu;
+ SInt32 outMenuResult;
+ if (!PyArg_ParseTuple(_args, "O&",
+ MenuObj_Convert, &menu))
+ return NULL;
+ _err = WindowPathSelect(_self->ob_itself,
+ menu,
+ &outMenuResult);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ outMenuResult);
+ return _res;
+}
+
+static PyObject *WinObj_HiliteWindowFrameForDrag(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Boolean hilited;
+ if (!PyArg_ParseTuple(_args, "b",
+ &hilited))
+ return NULL;
+ _err = HiliteWindowFrameForDrag(_self->ob_itself,
+ hilited);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_TransitionWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ WindowTransitionEffect effect;
+ WindowTransitionAction action;
+ Rect rect;
+ if (!PyArg_ParseTuple(_args, "llO&",
+ &effect,
+ &action,
+ PyMac_GetRect, &rect))
+ return NULL;
+ _err = TransitionWindow(_self->ob_itself,
+ effect,
+ action,
+ &rect);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_MacMoveWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short hGlobal;
+ short vGlobal;
+ Boolean front;
+ if (!PyArg_ParseTuple(_args, "hhb",
+ &hGlobal,
+ &vGlobal,
+ &front))
+ return NULL;
+ MacMoveWindow(_self->ob_itself,
+ hGlobal,
+ vGlobal,
+ front);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_SizeWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short w;
+ short h;
+ Boolean fUpdate;
+ if (!PyArg_ParseTuple(_args, "hhb",
+ &w,
+ &h,
+ &fUpdate))
+ return NULL;
+ SizeWindow(_self->ob_itself,
+ w,
+ h,
+ fUpdate);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_GrowWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ long _rv;
+ Point startPt;
+ Rect bBox;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &startPt,
+ PyMac_GetRect, &bBox))
+ return NULL;
+ _rv = GrowWindow(_self->ob_itself,
+ startPt,
+ &bBox);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *WinObj_DragWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Point startPt;
+ Rect boundsRect;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &startPt,
+ PyMac_GetRect, &boundsRect))
+ return NULL;
+ DragWindow(_self->ob_itself,
+ startPt,
+ &boundsRect);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_ZoomWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPartCode partCode;
+ Boolean front;
+ if (!PyArg_ParseTuple(_args, "hb",
+ &partCode,
+ &front))
+ return NULL;
+ ZoomWindow(_self->ob_itself,
+ partCode,
+ front);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_IsWindowCollapsable(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = IsWindowCollapsable(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *WinObj_IsWindowCollapsed(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = IsWindowCollapsed(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *WinObj_CollapseWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Boolean collapse;
+ if (!PyArg_ParseTuple(_args, "b",
+ &collapse))
+ return NULL;
+ _err = CollapseWindow(_self->ob_itself,
+ collapse);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowBounds(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ WindowRegionCode regionCode;
+ Rect globalBounds;
+ if (!PyArg_ParseTuple(_args, "H",
+ ®ionCode))
+ return NULL;
+ _err = GetWindowBounds(_self->ob_itself,
+ regionCode,
+ &globalBounds);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &globalBounds);
+ return _res;
+}
+
+static PyObject *WinObj_ResizeWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Point startPoint;
+ Rect sizeConstraints;
+ Rect newContentRect;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &startPoint,
+ PyMac_GetRect, &sizeConstraints))
+ return NULL;
+ _rv = ResizeWindow(_self->ob_itself,
+ startPoint,
+ &sizeConstraints,
+ &newContentRect);
+ _res = Py_BuildValue("bO&",
+ _rv,
+ PyMac_BuildRect, &newContentRect);
+ return _res;
+}
+
+static PyObject *WinObj_SetWindowBounds(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ WindowRegionCode regionCode;
+ Rect globalBounds;
+ if (!PyArg_ParseTuple(_args, "HO&",
+ ®ionCode,
+ PyMac_GetRect, &globalBounds))
+ return NULL;
+ _err = SetWindowBounds(_self->ob_itself,
+ regionCode,
+ &globalBounds);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_RepositionWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ WindowPtr parentWindow;
+ WindowPositionMethod method;
+ if (!PyArg_ParseTuple(_args, "O&l",
+ WinObj_Convert, &parentWindow,
+ &method))
+ return NULL;
+ _err = RepositionWindow(_self->ob_itself,
+ parentWindow,
+ method);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_MoveWindowStructure(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ short hGlobal;
+ short vGlobal;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &hGlobal,
+ &vGlobal))
+ return NULL;
+ _err = MoveWindowStructure(_self->ob_itself,
+ hGlobal,
+ vGlobal);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_IsWindowInStandardState(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Point idealSize;
+ Rect idealStandardState;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = IsWindowInStandardState(_self->ob_itself,
+ &idealSize,
+ &idealStandardState);
+ _res = Py_BuildValue("bO&O&",
+ _rv,
+ PyMac_BuildPoint, idealSize,
+ PyMac_BuildRect, &idealStandardState);
+ return _res;
+}
+
+static PyObject *WinObj_ZoomWindowIdeal(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ WindowPartCode partCode;
+ Point ioIdealSize;
+ if (!PyArg_ParseTuple(_args, "h",
+ &partCode))
+ return NULL;
+ _err = ZoomWindowIdeal(_self->ob_itself,
+ partCode,
+ &ioIdealSize);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildPoint, ioIdealSize);
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowIdealUserState(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Rect userState;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = GetWindowIdealUserState(_self->ob_itself,
+ &userState);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &userState);
+ return _res;
+}
+
+static PyObject *WinObj_SetWindowIdealUserState(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Rect userState;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = SetWindowIdealUserState(_self->ob_itself,
+ &userState);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &userState);
+ return _res;
+}
+
+static PyObject *WinObj_HideWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ HideWindow(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_MacShowWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ MacShowWindow(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_ShowHide(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean showFlag;
+ if (!PyArg_ParseTuple(_args, "b",
+ &showFlag))
+ return NULL;
+ ShowHide(_self->ob_itself,
+ showFlag);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_GetWindowPropertyAttributes(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ OSType propertyCreator;
+ OSType propertyTag;
+ UInt32 attributes;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetOSType, &propertyCreator,
+ PyMac_GetOSType, &propertyTag))
+ return NULL;
+ _err = GetWindowPropertyAttributes(_self->ob_itself,
+ propertyCreator,
+ propertyTag,
+ &attributes);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ attributes);
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_ChangeWindowPropertyAttributes(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ OSType propertyCreator;
+ OSType propertyTag;
+ UInt32 attributesToSet;
+ UInt32 attributesToClear;
+ if (!PyArg_ParseTuple(_args, "O&O&ll",
+ PyMac_GetOSType, &propertyCreator,
+ PyMac_GetOSType, &propertyTag,
+ &attributesToSet,
+ &attributesToClear))
+ return NULL;
+ _err = ChangeWindowPropertyAttributes(_self->ob_itself,
+ propertyCreator,
+ propertyTag,
+ attributesToSet,
+ attributesToClear);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *WinObj_TrackBox(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Point thePt;
+ WindowPartCode partCode;
+ if (!PyArg_ParseTuple(_args, "O&h",
+ PyMac_GetPoint, &thePt,
+ &partCode))
+ return NULL;
+ _rv = TrackBox(_self->ob_itself,
+ thePt,
+ partCode);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *WinObj_TrackGoAway(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ Point thePt;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetPoint, &thePt))
+ return NULL;
+ _rv = TrackGoAway(_self->ob_itself,
+ thePt);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_GetAuxWin(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ AuxWinHandle awHndl;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetAuxWin(_self->ob_itself,
+ &awHndl);
+ _res = Py_BuildValue("bO&",
+ _rv,
+ ResObj_New, awHndl);
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_GetWindowGoAwayFlag(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetWindowGoAwayFlag(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_GetWindowSpareFlag(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetWindowSpareFlag(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+#endif
+
+static PyObject *WinObj_GetWindowPort(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetWindowPort(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ GrafObj_New, _rv);
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowKind(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetWindowKind(_self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *WinObj_MacIsWindowVisible(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = MacIsWindowVisible(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *WinObj_IsWindowHilited(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = IsWindowHilited(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_IsWindowUpdatePending(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = IsWindowUpdatePending(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+#endif
+
+static PyObject *WinObj_MacGetNextWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = MacGetNextWindow(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ WinObj_New, _rv);
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowStandardState(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect rect;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetWindowStandardState(_self->ob_itself,
+ &rect);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &rect);
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowUserState(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect rect;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetWindowUserState(_self->ob_itself,
+ &rect);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &rect);
+ return _res;
+}
+
+static PyObject *WinObj_SetWindowKind(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short kind;
+ if (!PyArg_ParseTuple(_args, "h",
+ &kind))
+ return NULL;
+ SetWindowKind(_self->ob_itself,
+ kind);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_SetWindowStandardState(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect rect;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &rect))
+ return NULL;
+ SetWindowStandardState(_self->ob_itself,
+ &rect);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_SetWindowUserState(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect rect;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &rect))
+ return NULL;
+ SetWindowUserState(_self->ob_itself,
+ &rect);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_SetPortWindowPort(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ SetPortWindowPort(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowPortBounds(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect bounds;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetWindowPortBounds(_self->ob_itself,
+ &bounds);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &bounds);
+ return _res;
+}
+
+static PyObject *WinObj_IsWindowVisible(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = IsWindowVisible(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_GetWindowZoomFlag(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetWindowZoomFlag(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+#endif
+
+static PyObject *WinObj_GetWindowStructureRgn(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &r))
+ return NULL;
+ GetWindowStructureRgn(_self->ob_itself,
+ r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowContentRgn(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &r))
+ return NULL;
+ GetWindowContentRgn(_self->ob_itself,
+ r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_GetWindowUpdateRgn(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle r;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &r))
+ return NULL;
+ GetWindowUpdateRgn(_self->ob_itself,
+ r);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_GetWindowTitleWidth(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetWindowTitleWidth(_self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+#endif
+
+static PyObject *WinObj_GetNextWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetNextWindow(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ WinObj_WhichWindow, _rv);
+ return _res;
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *WinObj_CloseWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ CloseWindow(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *WinObj_MoveWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short hGlobal;
+ short vGlobal;
+ Boolean front;
+ if (!PyArg_ParseTuple(_args, "hhb",
+ &hGlobal,
+ &vGlobal,
+ &front))
+ return NULL;
+ MoveWindow(_self->ob_itself,
+ hGlobal,
+ vGlobal,
+ front);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *WinObj_ShowWindow(WindowObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ ShowWindow(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyMethodDef WinObj_methods[] = {
+ {"GetWindowOwnerCount", (PyCFunction)WinObj_GetWindowOwnerCount, 1,
+ "() -> (UInt32 outCount)"},
+ {"CloneWindow", (PyCFunction)WinObj_CloneWindow, 1,
+ "() -> None"},
+
+#if TARGET_API_MAC_CARBON
+ {"ReshapeCustomWindow", (PyCFunction)WinObj_ReshapeCustomWindow, 1,
+ "() -> None"},
+#endif
+ {"GetWindowClass", (PyCFunction)WinObj_GetWindowClass, 1,
+ "() -> (WindowClass outClass)"},
+ {"GetWindowAttributes", (PyCFunction)WinObj_GetWindowAttributes, 1,
+ "() -> (WindowAttributes outAttributes)"},
+
+#if TARGET_API_MAC_CARBON
+ {"ChangeWindowAttributes", (PyCFunction)WinObj_ChangeWindowAttributes, 1,
+ "(WindowAttributes setTheseAttributes, WindowAttributes clearTheseAttributes) -> None"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"SetWinColor", (PyCFunction)WinObj_SetWinColor, 1,
+ "(WCTabHandle newColorTable) -> None"},
+#endif
+ {"SetWindowContentColor", (PyCFunction)WinObj_SetWindowContentColor, 1,
+ "(RGBColor color) -> None"},
+ {"GetWindowContentColor", (PyCFunction)WinObj_GetWindowContentColor, 1,
+ "() -> (RGBColor color)"},
+ {"GetWindowContentPattern", (PyCFunction)WinObj_GetWindowContentPattern, 1,
+ "(PixPatHandle outPixPat) -> None"},
+ {"SetWindowContentPattern", (PyCFunction)WinObj_SetWindowContentPattern, 1,
+ "(PixPatHandle pixPat) -> None"},
+
+#if TARGET_API_MAC_CARBON
+ {"ScrollWindowRect", (PyCFunction)WinObj_ScrollWindowRect, 1,
+ "(Rect inScrollRect, SInt16 inHPixels, SInt16 inVPixels, ScrollWindowOptions inOptions, RgnHandle outExposedRgn) -> None"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"ScrollWindowRegion", (PyCFunction)WinObj_ScrollWindowRegion, 1,
+ "(RgnHandle inScrollRgn, SInt16 inHPixels, SInt16 inVPixels, ScrollWindowOptions inOptions, RgnHandle outExposedRgn) -> None"},
+#endif
+ {"ClipAbove", (PyCFunction)WinObj_ClipAbove, 1,
+ "() -> None"},
+
+#if !TARGET_API_MAC_CARBON
+ {"SaveOld", (PyCFunction)WinObj_SaveOld, 1,
+ "() -> None"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"DrawNew", (PyCFunction)WinObj_DrawNew, 1,
+ "(Boolean update) -> None"},
+#endif
+ {"PaintOne", (PyCFunction)WinObj_PaintOne, 1,
+ "(RgnHandle clobberedRgn) -> None"},
+ {"PaintBehind", (PyCFunction)WinObj_PaintBehind, 1,
+ "(RgnHandle clobberedRgn) -> None"},
+ {"CalcVis", (PyCFunction)WinObj_CalcVis, 1,
+ "() -> None"},
+ {"CalcVisBehind", (PyCFunction)WinObj_CalcVisBehind, 1,
+ "(RgnHandle clobberedRgn) -> None"},
+ {"BringToFront", (PyCFunction)WinObj_BringToFront, 1,
+ "() -> None"},
+ {"SendBehind", (PyCFunction)WinObj_SendBehind, 1,
+ "(WindowPtr behindWindow) -> None"},
+ {"SelectWindow", (PyCFunction)WinObj_SelectWindow, 1,
+ "() -> None"},
+
+#if TARGET_API_MAC_CARBON
+ {"GetNextWindowOfClass", (PyCFunction)WinObj_GetNextWindowOfClass, 1,
+ "(WindowClass inWindowClass, Boolean mustBeVisible) -> (WindowPtr _rv)"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"IsValidWindowPtr", (PyCFunction)WinObj_IsValidWindowPtr, 1,
+ "() -> (Boolean _rv)"},
+#endif
+ {"HiliteWindow", (PyCFunction)WinObj_HiliteWindow, 1,
+ "(Boolean fHilite) -> None"},
+ {"SetWRefCon", (PyCFunction)WinObj_SetWRefCon, 1,
+ "(long data) -> None"},
+ {"GetWRefCon", (PyCFunction)WinObj_GetWRefCon, 1,
+ "() -> (long _rv)"},
+ {"SetWindowPic", (PyCFunction)WinObj_SetWindowPic, 1,
+ "(PicHandle pic) -> None"},
+ {"GetWindowPic", (PyCFunction)WinObj_GetWindowPic, 1,
+ "() -> (PicHandle _rv)"},
+ {"GetWVariant", (PyCFunction)WinObj_GetWVariant, 1,
+ "() -> (short _rv)"},
+ {"GetWindowFeatures", (PyCFunction)WinObj_GetWindowFeatures, 1,
+ "() -> (UInt32 outFeatures)"},
+ {"GetWindowRegion", (PyCFunction)WinObj_GetWindowRegion, 1,
+ "(WindowRegionCode inRegionCode, RgnHandle ioWinRgn) -> None"},
+ {"BeginUpdate", (PyCFunction)WinObj_BeginUpdate, 1,
+ "() -> None"},
+ {"EndUpdate", (PyCFunction)WinObj_EndUpdate, 1,
+ "() -> None"},
+ {"InvalWindowRgn", (PyCFunction)WinObj_InvalWindowRgn, 1,
+ "(RgnHandle region) -> None"},
+ {"InvalWindowRect", (PyCFunction)WinObj_InvalWindowRect, 1,
+ "(Rect bounds) -> None"},
+ {"ValidWindowRgn", (PyCFunction)WinObj_ValidWindowRgn, 1,
+ "(RgnHandle region) -> None"},
+ {"ValidWindowRect", (PyCFunction)WinObj_ValidWindowRect, 1,
+ "(Rect bounds) -> None"},
+ {"DrawGrowIcon", (PyCFunction)WinObj_DrawGrowIcon, 1,
+ "() -> None"},
+ {"SetWTitle", (PyCFunction)WinObj_SetWTitle, 1,
+ "(Str255 title) -> None"},
+ {"GetWTitle", (PyCFunction)WinObj_GetWTitle, 1,
+ "() -> (Str255 title)"},
+ {"SetWindowProxyFSSpec", (PyCFunction)WinObj_SetWindowProxyFSSpec, 1,
+ "(FSSpec inFile) -> None"},
+ {"GetWindowProxyFSSpec", (PyCFunction)WinObj_GetWindowProxyFSSpec, 1,
+ "() -> (FSSpec outFile)"},
+ {"SetWindowProxyAlias", (PyCFunction)WinObj_SetWindowProxyAlias, 1,
+ "(AliasHandle alias) -> None"},
+ {"GetWindowProxyAlias", (PyCFunction)WinObj_GetWindowProxyAlias, 1,
+ "() -> (AliasHandle alias)"},
+ {"SetWindowProxyCreatorAndType", (PyCFunction)WinObj_SetWindowProxyCreatorAndType, 1,
+ "(OSType fileCreator, OSType fileType, SInt16 vRefNum) -> None"},
+ {"GetWindowProxyIcon", (PyCFunction)WinObj_GetWindowProxyIcon, 1,
+ "() -> (IconRef outIcon)"},
+ {"SetWindowProxyIcon", (PyCFunction)WinObj_SetWindowProxyIcon, 1,
+ "(IconRef icon) -> None"},
+ {"RemoveWindowProxy", (PyCFunction)WinObj_RemoveWindowProxy, 1,
+ "() -> None"},
+ {"BeginWindowProxyDrag", (PyCFunction)WinObj_BeginWindowProxyDrag, 1,
+ "(RgnHandle outDragOutlineRgn) -> (DragReference outNewDrag)"},
+ {"EndWindowProxyDrag", (PyCFunction)WinObj_EndWindowProxyDrag, 1,
+ "(DragReference theDrag) -> None"},
+ {"TrackWindowProxyFromExistingDrag", (PyCFunction)WinObj_TrackWindowProxyFromExistingDrag, 1,
+ "(Point startPt, DragReference drag, RgnHandle inDragOutlineRgn) -> None"},
+ {"TrackWindowProxyDrag", (PyCFunction)WinObj_TrackWindowProxyDrag, 1,
+ "(Point startPt) -> None"},
+ {"IsWindowModified", (PyCFunction)WinObj_IsWindowModified, 1,
+ "() -> (Boolean _rv)"},
+ {"SetWindowModified", (PyCFunction)WinObj_SetWindowModified, 1,
+ "(Boolean modified) -> None"},
+ {"IsWindowPathSelectClick", (PyCFunction)WinObj_IsWindowPathSelectClick, 1,
+ "(EventRecord event) -> (Boolean _rv)"},
+ {"WindowPathSelect", (PyCFunction)WinObj_WindowPathSelect, 1,
+ "(MenuHandle menu) -> (SInt32 outMenuResult)"},
+ {"HiliteWindowFrameForDrag", (PyCFunction)WinObj_HiliteWindowFrameForDrag, 1,
+ "(Boolean hilited) -> None"},
+ {"TransitionWindow", (PyCFunction)WinObj_TransitionWindow, 1,
+ "(WindowTransitionEffect effect, WindowTransitionAction action, Rect rect) -> None"},
+ {"MacMoveWindow", (PyCFunction)WinObj_MacMoveWindow, 1,
+ "(short hGlobal, short vGlobal, Boolean front) -> None"},
+ {"SizeWindow", (PyCFunction)WinObj_SizeWindow, 1,
+ "(short w, short h, Boolean fUpdate) -> None"},
+ {"GrowWindow", (PyCFunction)WinObj_GrowWindow, 1,
+ "(Point startPt, Rect bBox) -> (long _rv)"},
+ {"DragWindow", (PyCFunction)WinObj_DragWindow, 1,
+ "(Point startPt, Rect boundsRect) -> None"},
+ {"ZoomWindow", (PyCFunction)WinObj_ZoomWindow, 1,
+ "(WindowPartCode partCode, Boolean front) -> None"},
+ {"IsWindowCollapsable", (PyCFunction)WinObj_IsWindowCollapsable, 1,
+ "() -> (Boolean _rv)"},
+ {"IsWindowCollapsed", (PyCFunction)WinObj_IsWindowCollapsed, 1,
+ "() -> (Boolean _rv)"},
+ {"CollapseWindow", (PyCFunction)WinObj_CollapseWindow, 1,
+ "(Boolean collapse) -> None"},
+ {"GetWindowBounds", (PyCFunction)WinObj_GetWindowBounds, 1,
+ "(WindowRegionCode regionCode) -> (Rect globalBounds)"},
+ {"ResizeWindow", (PyCFunction)WinObj_ResizeWindow, 1,
+ "(Point startPoint, Rect sizeConstraints) -> (Boolean _rv, Rect newContentRect)"},
+ {"SetWindowBounds", (PyCFunction)WinObj_SetWindowBounds, 1,
+ "(WindowRegionCode regionCode, Rect globalBounds) -> None"},
+ {"RepositionWindow", (PyCFunction)WinObj_RepositionWindow, 1,
+ "(WindowPtr parentWindow, WindowPositionMethod method) -> None"},
+ {"MoveWindowStructure", (PyCFunction)WinObj_MoveWindowStructure, 1,
+ "(short hGlobal, short vGlobal) -> None"},
+ {"IsWindowInStandardState", (PyCFunction)WinObj_IsWindowInStandardState, 1,
+ "() -> (Boolean _rv, Point idealSize, Rect idealStandardState)"},
+ {"ZoomWindowIdeal", (PyCFunction)WinObj_ZoomWindowIdeal, 1,
+ "(WindowPartCode partCode) -> (Point ioIdealSize)"},
+ {"GetWindowIdealUserState", (PyCFunction)WinObj_GetWindowIdealUserState, 1,
+ "() -> (Rect userState)"},
+ {"SetWindowIdealUserState", (PyCFunction)WinObj_SetWindowIdealUserState, 1,
+ "() -> (Rect userState)"},
+ {"HideWindow", (PyCFunction)WinObj_HideWindow, 1,
+ "() -> None"},
+ {"MacShowWindow", (PyCFunction)WinObj_MacShowWindow, 1,
+ "() -> None"},
+ {"ShowHide", (PyCFunction)WinObj_ShowHide, 1,
+ "(Boolean showFlag) -> None"},
+
+#if TARGET_API_MAC_CARBON
+ {"GetWindowPropertyAttributes", (PyCFunction)WinObj_GetWindowPropertyAttributes, 1,
+ "(OSType propertyCreator, OSType propertyTag) -> (UInt32 attributes)"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"ChangeWindowPropertyAttributes", (PyCFunction)WinObj_ChangeWindowPropertyAttributes, 1,
+ "(OSType propertyCreator, OSType propertyTag, UInt32 attributesToSet, UInt32 attributesToClear) -> None"},
+#endif
+ {"TrackBox", (PyCFunction)WinObj_TrackBox, 1,
+ "(Point thePt, WindowPartCode partCode) -> (Boolean _rv)"},
+ {"TrackGoAway", (PyCFunction)WinObj_TrackGoAway, 1,
+ "(Point thePt) -> (Boolean _rv)"},
+
+#if !TARGET_API_MAC_CARBON
+ {"GetAuxWin", (PyCFunction)WinObj_GetAuxWin, 1,
+ "() -> (Boolean _rv, AuxWinHandle awHndl)"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"GetWindowGoAwayFlag", (PyCFunction)WinObj_GetWindowGoAwayFlag, 1,
+ "() -> (Boolean _rv)"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"GetWindowSpareFlag", (PyCFunction)WinObj_GetWindowSpareFlag, 1,
+ "() -> (Boolean _rv)"},
+#endif
+ {"GetWindowPort", (PyCFunction)WinObj_GetWindowPort, 1,
+ "() -> (CGrafPtr _rv)"},
+ {"GetWindowKind", (PyCFunction)WinObj_GetWindowKind, 1,
+ "() -> (short _rv)"},
+ {"MacIsWindowVisible", (PyCFunction)WinObj_MacIsWindowVisible, 1,
+ "() -> (Boolean _rv)"},
+ {"IsWindowHilited", (PyCFunction)WinObj_IsWindowHilited, 1,
+ "() -> (Boolean _rv)"},
+
+#if TARGET_API_MAC_CARBON
+ {"IsWindowUpdatePending", (PyCFunction)WinObj_IsWindowUpdatePending, 1,
+ "() -> (Boolean _rv)"},
+#endif
+ {"MacGetNextWindow", (PyCFunction)WinObj_MacGetNextWindow, 1,
+ "() -> (WindowPtr _rv)"},
+ {"GetWindowStandardState", (PyCFunction)WinObj_GetWindowStandardState, 1,
+ "() -> (Rect rect)"},
+ {"GetWindowUserState", (PyCFunction)WinObj_GetWindowUserState, 1,
+ "() -> (Rect rect)"},
+ {"SetWindowKind", (PyCFunction)WinObj_SetWindowKind, 1,
+ "(short kind) -> None"},
+ {"SetWindowStandardState", (PyCFunction)WinObj_SetWindowStandardState, 1,
+ "(Rect rect) -> None"},
+ {"SetWindowUserState", (PyCFunction)WinObj_SetWindowUserState, 1,
+ "(Rect rect) -> None"},
+ {"SetPortWindowPort", (PyCFunction)WinObj_SetPortWindowPort, 1,
+ "() -> None"},
+ {"GetWindowPortBounds", (PyCFunction)WinObj_GetWindowPortBounds, 1,
+ "() -> (Rect bounds)"},
+ {"IsWindowVisible", (PyCFunction)WinObj_IsWindowVisible, 1,
+ "() -> (Boolean _rv)"},
+
+#if !TARGET_API_MAC_CARBON
+ {"GetWindowZoomFlag", (PyCFunction)WinObj_GetWindowZoomFlag, 1,
+ "() -> (Boolean _rv)"},
+#endif
+ {"GetWindowStructureRgn", (PyCFunction)WinObj_GetWindowStructureRgn, 1,
+ "(RgnHandle r) -> None"},
+ {"GetWindowContentRgn", (PyCFunction)WinObj_GetWindowContentRgn, 1,
+ "(RgnHandle r) -> None"},
+ {"GetWindowUpdateRgn", (PyCFunction)WinObj_GetWindowUpdateRgn, 1,
+ "(RgnHandle r) -> None"},
+
+#if !TARGET_API_MAC_CARBON
+ {"GetWindowTitleWidth", (PyCFunction)WinObj_GetWindowTitleWidth, 1,
+ "() -> (short _rv)"},
+#endif
+ {"GetNextWindow", (PyCFunction)WinObj_GetNextWindow, 1,
+ "() -> (WindowPtr _rv)"},
+
+#if !TARGET_API_MAC_CARBON
+ {"CloseWindow", (PyCFunction)WinObj_CloseWindow, 1,
+ "() -> None"},
+#endif
+ {"MoveWindow", (PyCFunction)WinObj_MoveWindow, 1,
+ "(short hGlobal, short vGlobal, Boolean front) -> None"},
+ {"ShowWindow", (PyCFunction)WinObj_ShowWindow, 1,
+ "() -> None"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain WinObj_chain = { WinObj_methods, NULL };
+
+static PyObject *WinObj_getattr(WindowObject *self, char *name)
+{
+ return Py_FindMethodInChain(&WinObj_chain, (PyObject *)self, name);
+}
+
+#define WinObj_setattr NULL
+
+static int WinObj_compare(WindowObject *self, WindowObject *other)
+{
+ if ( self->ob_itself > other->ob_itself ) return 1;
+ if ( self->ob_itself < other->ob_itself ) return -1;
+ return 0;
+}
+
+static PyObject * WinObj_repr(WindowObject *self)
+{
+ char buf[100];
+ sprintf(buf, "<Window object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
+ return PyString_FromString(buf);
+}
+
+static int WinObj_hash(WindowObject *self)
+{
+ return (int)self->ob_itself;
+}
+
+PyTypeObject Window_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "Window", /*tp_name*/
+ sizeof(WindowObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) WinObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) WinObj_getattr, /*tp_getattr*/
+ (setattrfunc) WinObj_setattr, /*tp_setattr*/
+ (cmpfunc) WinObj_compare, /*tp_compare*/
+ (reprfunc) WinObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) WinObj_hash, /*tp_hash*/
+};
+
+/* --------------------- End object type Window --------------------- */
+
+
+static PyObject *Win_GetNewCWindow(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr _rv;
+ short windowID;
+ WindowPtr behind;
+ if (!PyArg_ParseTuple(_args, "hO&",
+ &windowID,
+ WinObj_Convert, &behind))
+ return NULL;
+ _rv = GetNewCWindow(windowID,
+ (void *)0,
+ behind);
+ _res = Py_BuildValue("O&",
+ WinObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Win_NewWindow(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr _rv;
+ Rect boundsRect;
+ Str255 title;
+ Boolean visible;
+ short theProc;
+ WindowPtr behind;
+ Boolean goAwayFlag;
+ long refCon;
+ if (!PyArg_ParseTuple(_args, "O&O&bhO&bl",
+ PyMac_GetRect, &boundsRect,
+ PyMac_GetStr255, title,
+ &visible,
+ &theProc,
+ WinObj_Convert, &behind,
+ &goAwayFlag,
+ &refCon))
+ return NULL;
+ _rv = NewWindow((void *)0,
+ &boundsRect,
+ title,
+ visible,
+ theProc,
+ behind,
+ goAwayFlag,
+ refCon);
+ _res = Py_BuildValue("O&",
+ WinObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Win_GetNewWindow(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr _rv;
+ short windowID;
+ WindowPtr behind;
+ if (!PyArg_ParseTuple(_args, "hO&",
+ &windowID,
+ WinObj_Convert, &behind))
+ return NULL;
+ _rv = GetNewWindow(windowID,
+ (void *)0,
+ behind);
+ _res = Py_BuildValue("O&",
+ WinObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Win_NewCWindow(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr _rv;
+ Rect boundsRect;
+ Str255 title;
+ Boolean visible;
+ short procID;
+ WindowPtr behind;
+ Boolean goAwayFlag;
+ long refCon;
+ if (!PyArg_ParseTuple(_args, "O&O&bhO&bl",
+ PyMac_GetRect, &boundsRect,
+ PyMac_GetStr255, title,
+ &visible,
+ &procID,
+ WinObj_Convert, &behind,
+ &goAwayFlag,
+ &refCon))
+ return NULL;
+ _rv = NewCWindow((void *)0,
+ &boundsRect,
+ title,
+ visible,
+ procID,
+ behind,
+ goAwayFlag,
+ refCon);
+ _res = Py_BuildValue("O&",
+ WinObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Win_CreateNewWindow(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ WindowClass windowClass;
+ WindowAttributes attributes;
+ Rect contentBounds;
+ WindowPtr outWindow;
+ if (!PyArg_ParseTuple(_args, "llO&",
+ &windowClass,
+ &attributes,
+ PyMac_GetRect, &contentBounds))
+ return NULL;
+ _err = CreateNewWindow(windowClass,
+ attributes,
+ &contentBounds,
+ &outWindow);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ WinObj_WhichWindow, outWindow);
+ return _res;
+}
+
+static PyObject *Win_CreateWindowFromResource(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ SInt16 resID;
+ WindowPtr outWindow;
+ if (!PyArg_ParseTuple(_args, "h",
+ &resID))
+ return NULL;
+ _err = CreateWindowFromResource(resID,
+ &outWindow);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ WinObj_WhichWindow, outWindow);
+ return _res;
+}
+
+static PyObject *Win_ShowFloatingWindows(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = ShowFloatingWindows();
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Win_HideFloatingWindows(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = HideFloatingWindows();
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Win_AreFloatingWindowsVisible(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = AreFloatingWindowsVisible();
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Win_SetDeskCPat(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PixPatHandle deskPixPat;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &deskPixPat))
+ return NULL;
+ SetDeskCPat(deskPixPat);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *Win_CheckUpdate(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ EventRecord theEvent;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CheckUpdate(&theEvent);
+ _res = Py_BuildValue("bO&",
+ _rv,
+ PyMac_BuildEventRecord, &theEvent);
+ return _res;
+}
+
+static PyObject *Win_MacFindWindow(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPartCode _rv;
+ Point thePoint;
+ WindowPtr window;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetPoint, &thePoint))
+ return NULL;
+ _rv = MacFindWindow(thePoint,
+ &window);
+ _res = Py_BuildValue("hO&",
+ _rv,
+ WinObj_WhichWindow, window);
+ return _res;
+}
+
+static PyObject *Win_FrontWindow(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = FrontWindow();
+ _res = Py_BuildValue("O&",
+ WinObj_WhichWindow, _rv);
+ return _res;
+}
+
+static PyObject *Win_FrontNonFloatingWindow(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = FrontNonFloatingWindow();
+ _res = Py_BuildValue("O&",
+ WinObj_WhichWindow, _rv);
+ return _res;
+}
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *Win_GetFrontWindowOfClass(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr _rv;
+ WindowClass inWindowClass;
+ Boolean mustBeVisible;
+ if (!PyArg_ParseTuple(_args, "lb",
+ &inWindowClass,
+ &mustBeVisible))
+ return NULL;
+ _rv = GetFrontWindowOfClass(inWindowClass,
+ mustBeVisible);
+ _res = Py_BuildValue("O&",
+ WinObj_New, _rv);
+ return _res;
+}
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+static PyObject *Win_FindWindowOfClass(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Point where;
+ WindowClass inWindowClass;
+ WindowPtr outWindow;
+ WindowPartCode outWindowPart;
+ if (!PyArg_ParseTuple(_args, "O&l",
+ PyMac_GetPoint, &where,
+ &inWindowClass))
+ return NULL;
+ _err = FindWindowOfClass(&where,
+ inWindowClass,
+ &outWindow,
+ &outWindowPart);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&h",
+ WinObj_WhichWindow, outWindow,
+ outWindowPart);
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Win_InitWindows(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ InitWindows();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Win_GetWMgrPort(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ GrafPtr wPort;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetWMgrPort(&wPort);
+ _res = Py_BuildValue("O&",
+ GrafObj_New, wPort);
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Win_GetCWMgrPort(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CGrafPtr wMgrCPort;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetCWMgrPort(&wMgrCPort);
+ _res = Py_BuildValue("O&",
+ GrafObj_New, wMgrCPort);
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Win_InitFloatingWindows(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = InitFloatingWindows();
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Win_InvalRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect badRect;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &badRect))
+ return NULL;
+ InvalRect(&badRect);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Win_InvalRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle badRgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &badRgn))
+ return NULL;
+ InvalRgn(badRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Win_ValidRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect goodRect;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetRect, &goodRect))
+ return NULL;
+ ValidRect(&goodRect);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+#if !TARGET_API_MAC_CARBON
+
+static PyObject *Win_ValidRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle goodRgn;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &goodRgn))
+ return NULL;
+ ValidRgn(goodRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *Win_CollapseAllWindows(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ Boolean collapse;
+ if (!PyArg_ParseTuple(_args, "b",
+ &collapse))
+ return NULL;
+ _err = CollapseAllWindows(collapse);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Win_PinRect(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ long _rv;
+ Rect theRect;
+ Point thePt;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetRect, &theRect,
+ PyMac_GetPoint, &thePt))
+ return NULL;
+ _rv = PinRect(&theRect,
+ thePt);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *Win_GetGrayRgn(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetGrayRgn();
+ _res = Py_BuildValue("O&",
+ ResObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Win_GetWindowFromPort(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ WindowPtr _rv;
+ CGrafPtr port;
+ if (!PyArg_ParseTuple(_args, "O&",
+ GrafObj_Convert, &port))
+ return NULL;
+ _rv = GetWindowFromPort(port);
+ _res = Py_BuildValue("O&",
+ WinObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Win_WhichWindow(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ long ptr;
+
+ if ( !PyArg_ParseTuple(_args, "i", &ptr) )
+ return NULL;
+ return WinObj_WhichWindow((WindowPtr)ptr);
+
+}
+
+static PyObject *Win_FindWindow(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short _rv;
+ Point thePoint;
+ WindowPtr theWindow;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetPoint, &thePoint))
+ return NULL;
+ _rv = FindWindow(thePoint,
+ &theWindow);
+ _res = Py_BuildValue("hO&",
+ _rv,
+ WinObj_WhichWindow, theWindow);
+ return _res;
+}
+
+static PyMethodDef Win_methods[] = {
+ {"GetNewCWindow", (PyCFunction)Win_GetNewCWindow, 1,
+ "(short windowID, WindowPtr behind) -> (WindowPtr _rv)"},
+ {"NewWindow", (PyCFunction)Win_NewWindow, 1,
+ "(Rect boundsRect, Str255 title, Boolean visible, short theProc, WindowPtr behind, Boolean goAwayFlag, long refCon) -> (WindowPtr _rv)"},
+ {"GetNewWindow", (PyCFunction)Win_GetNewWindow, 1,
+ "(short windowID, WindowPtr behind) -> (WindowPtr _rv)"},
+ {"NewCWindow", (PyCFunction)Win_NewCWindow, 1,
+ "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon) -> (WindowPtr _rv)"},
+ {"CreateNewWindow", (PyCFunction)Win_CreateNewWindow, 1,
+ "(WindowClass windowClass, WindowAttributes attributes, Rect contentBounds) -> (WindowPtr outWindow)"},
+ {"CreateWindowFromResource", (PyCFunction)Win_CreateWindowFromResource, 1,
+ "(SInt16 resID) -> (WindowPtr outWindow)"},
+ {"ShowFloatingWindows", (PyCFunction)Win_ShowFloatingWindows, 1,
+ "() -> None"},
+ {"HideFloatingWindows", (PyCFunction)Win_HideFloatingWindows, 1,
+ "() -> None"},
+ {"AreFloatingWindowsVisible", (PyCFunction)Win_AreFloatingWindowsVisible, 1,
+ "() -> (Boolean _rv)"},
+
+#if !TARGET_API_MAC_CARBON
+ {"SetDeskCPat", (PyCFunction)Win_SetDeskCPat, 1,
+ "(PixPatHandle deskPixPat) -> None"},
+#endif
+ {"CheckUpdate", (PyCFunction)Win_CheckUpdate, 1,
+ "() -> (Boolean _rv, EventRecord theEvent)"},
+ {"MacFindWindow", (PyCFunction)Win_MacFindWindow, 1,
+ "(Point thePoint) -> (WindowPartCode _rv, WindowPtr window)"},
+ {"FrontWindow", (PyCFunction)Win_FrontWindow, 1,
+ "() -> (WindowPtr _rv)"},
+ {"FrontNonFloatingWindow", (PyCFunction)Win_FrontNonFloatingWindow, 1,
+ "() -> (WindowPtr _rv)"},
+
+#if TARGET_API_MAC_CARBON
+ {"GetFrontWindowOfClass", (PyCFunction)Win_GetFrontWindowOfClass, 1,
+ "(WindowClass inWindowClass, Boolean mustBeVisible) -> (WindowPtr _rv)"},
+#endif
+
+#if TARGET_API_MAC_CARBON
+ {"FindWindowOfClass", (PyCFunction)Win_FindWindowOfClass, 1,
+ "(Point where, WindowClass inWindowClass) -> (WindowPtr outWindow, WindowPartCode outWindowPart)"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"InitWindows", (PyCFunction)Win_InitWindows, 1,
+ "() -> None"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"GetWMgrPort", (PyCFunction)Win_GetWMgrPort, 1,
+ "() -> (GrafPtr wPort)"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"GetCWMgrPort", (PyCFunction)Win_GetCWMgrPort, 1,
+ "() -> (CGrafPtr wMgrCPort)"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"InitFloatingWindows", (PyCFunction)Win_InitFloatingWindows, 1,
+ "() -> None"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"InvalRect", (PyCFunction)Win_InvalRect, 1,
+ "(Rect badRect) -> None"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"InvalRgn", (PyCFunction)Win_InvalRgn, 1,
+ "(RgnHandle badRgn) -> None"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"ValidRect", (PyCFunction)Win_ValidRect, 1,
+ "(Rect goodRect) -> None"},
+#endif
+
+#if !TARGET_API_MAC_CARBON
+ {"ValidRgn", (PyCFunction)Win_ValidRgn, 1,
+ "(RgnHandle goodRgn) -> None"},
+#endif
+ {"CollapseAllWindows", (PyCFunction)Win_CollapseAllWindows, 1,
+ "(Boolean collapse) -> None"},
+ {"PinRect", (PyCFunction)Win_PinRect, 1,
+ "(Rect theRect, Point thePt) -> (long _rv)"},
+ {"GetGrayRgn", (PyCFunction)Win_GetGrayRgn, 1,
+ "() -> (RgnHandle _rv)"},
+ {"GetWindowFromPort", (PyCFunction)Win_GetWindowFromPort, 1,
+ "(CGrafPtr port) -> (WindowPtr _rv)"},
+ {"WhichWindow", (PyCFunction)Win_WhichWindow, 1,
+ "Resolve an integer WindowPtr address to a Window object"},
+ {"FindWindow", (PyCFunction)Win_FindWindow, 1,
+ "(Point thePoint) -> (short _rv, WindowPtr theWindow)"},
+ {NULL, NULL, 0}
+};
+
+
+
+/* Return the object corresponding to the window, or NULL */
+
+PyObject *
+WinObj_WhichWindow(WindowPtr w)
+{
+ PyObject *it;
+
+ if (w == NULL) {
+ it = Py_None;
+ Py_INCREF(it);
+ } else {
+ it = (PyObject *) GetWRefCon(w);
+ if (it == NULL || !IsPointerValid((Ptr)it) || ((WindowObject *)it)->ob_itself != w || !WinObj_Check(it)) {
+ it = WinObj_New(w);
+ ((WindowObject *)it)->ob_freeit = NULL;
+ } else {
+ Py_INCREF(it);
+ }
+ }
+ return it;
+}
+
+
+void initWin(void)
+{
+ PyObject *m;
+ PyObject *d;
+
+
+
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(WindowPtr, WinObj_New);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(WindowPtr, WinObj_WhichWindow);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(WindowPtr, WinObj_Convert);
+
+
+ m = Py_InitModule("Win", Win_methods);
+ d = PyModule_GetDict(m);
+ Win_Error = PyMac_GetOSErrException();
+ if (Win_Error == NULL ||
+ PyDict_SetItemString(d, "Error", Win_Error) != 0)
+ return;
+ Window_Type.ob_type = &PyType_Type;
+ Py_INCREF(&Window_Type);
+ if (PyDict_SetItemString(d, "WindowType", (PyObject *)&Window_Type) != 0)
+ Py_FatalError("can't initialize WindowType");
+}
+
+/* ========================= End module Win ========================= */
+
--- /dev/null
+# This script generates a Python interface for an Apple Macintosh Manager.
+# It uses the "bgen" package to generate C code.
+# The function specifications are generated by scanning the mamager's header file,
+# using the "scantools" package (customized for this particular manager).
+
+import string
+
+# Declarations that change for each manager
+MACHEADERFILE = 'Windows.h' # The Apple header file
+MODNAME = 'Win' # The name of the module
+OBJECTNAME = 'Window' # The basic name of the objects used here
+
+# The following is *usually* unchanged but may still require tuning
+MODPREFIX = MODNAME # The prefix for module-wide routines
+OBJECTTYPE = OBJECTNAME + 'Ptr' # The C type used to represent them
+OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
+INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
+EDITFILE = string.lower(MODPREFIX) + 'edit.py' # The manual definitions
+OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
+
+from macsupport import *
+
+# Create the type objects
+
+WindowPtr = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX)
+WindowRef = WindowPtr
+WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
+WindowPeek.passInput = lambda name: "(WindowPeek)(%s)" % name
+CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj")
+GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj")
+
+DragReference = OpaqueByValueType("DragReference", "DragObj")
+
+RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
+PicHandle = OpaqueByValueType("PicHandle", "ResObj")
+WCTabHandle = OpaqueByValueType("WCTabHandle", "ResObj")
+AuxWinHandle = OpaqueByValueType("AuxWinHandle", "ResObj")
+PixPatHandle = OpaqueByValueType("PixPatHandle", "ResObj")
+AliasHandle = OpaqueByValueType("AliasHandle", "ResObj")
+IconRef = OpaqueByValueType("IconRef", "ResObj")
+
+WindowRegionCode = Type("WindowRegionCode", "H")
+WindowClass = Type("WindowClass", "l")
+WindowAttributes = Type("WindowAttributes", "l")
+WindowPositionMethod = Type("WindowPositionMethod", "l")
+WindowTransitionEffect = Type("WindowTransitionEffect", "l")
+WindowTransitionAction = Type("WindowTransitionAction", "l")
+RGBColor = OpaqueType("RGBColor", "QdRGB")
+RGBColor_ptr = RGBColor
+ScrollWindowOptions = Type("ScrollWindowOptions", "l")
+WindowPartCode = Type("WindowPartCode", "h")
+
+PropertyCreator = OSTypeType("PropertyCreator")
+PropertyTag = OSTypeType("PropertyTag")
+
+includestuff = includestuff + """
+#ifdef WITHOUT_FRAMEWORKS
+#include <Windows.h>
+#else
+#include <Carbon/Carbon.h>
+#endif
+
+#ifdef USE_TOOLBOX_OBJECT_GLUE
+extern PyObject *_WinObj_New(WindowRef);
+extern PyObject *_WinObj_WhichWindow(WindowRef);
+extern int _WinObj_Convert(PyObject *, WindowRef *);
+
+#define WinObj_New _WinObj_New
+#define WinObj_WhichWindow _WinObj_WhichWindow
+#define WinObj_Convert _WinObj_Convert
+#endif
+
+#if !ACCESSOR_CALLS_ARE_FUNCTIONS
+/* Carbon calls that we emulate in classic mode */
+#define GetWindowSpareFlag(win) (((CWindowPeek)(win))->spareFlag)
+#define GetWindowFromPort(port) ((WindowRef)(port))
+#define GetWindowPortBounds(win, rectp) (*(rectp) = ((CWindowPeek)(win))->port.portRect)
+#define IsPointerValid(p) (((long)p&3) == 0)
+#endif
+#if ACCESSOR_CALLS_ARE_FUNCTIONS
+/* Classic calls that we emulate in carbon mode */
+#define GetWindowUpdateRgn(win, rgn) GetWindowRegion((win), kWindowUpdateRgn, (rgn))
+#define GetWindowStructureRgn(win, rgn) GetWindowRegion((win), kWindowStructureRgn, (rgn))
+#define GetWindowContentRgn(win, rgn) GetWindowRegion((win), kWindowContentRgn, (rgn))
+#endif
+
+/* Function to dispose a window, with a "normal" calling sequence */
+static void
+PyMac_AutoDisposeWindow(WindowPtr w)
+{
+ DisposeWindow(w);
+}
+"""
+
+finalstuff = finalstuff + """
+/* Return the object corresponding to the window, or NULL */
+
+PyObject *
+WinObj_WhichWindow(WindowPtr w)
+{
+ PyObject *it;
+
+ if (w == NULL) {
+ it = Py_None;
+ Py_INCREF(it);
+ } else {
+ it = (PyObject *) GetWRefCon(w);
+ if (it == NULL || !IsPointerValid((Ptr)it) || ((WindowObject *)it)->ob_itself != w || !WinObj_Check(it)) {
+ it = WinObj_New(w);
+ ((WindowObject *)it)->ob_freeit = NULL;
+ } else {
+ Py_INCREF(it);
+ }
+ }
+ return it;
+}
+"""
+
+initstuff = initstuff + """
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(WindowPtr, WinObj_New);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(WindowPtr, WinObj_WhichWindow);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(WindowPtr, WinObj_Convert);
+"""
+
+class MyObjectDefinition(GlobalObjectDefinition):
+ def outputCheckNewArg(self):
+ Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+ def outputStructMembers(self):
+ GlobalObjectDefinition.outputStructMembers(self)
+ Output("void (*ob_freeit)(%s ptr);", self.itselftype)
+ def outputInitStructMembers(self):
+ GlobalObjectDefinition.outputInitStructMembers(self)
+ Output("it->ob_freeit = NULL;")
+ Output("if (GetWRefCon(itself) == 0)")
+ OutLbrace()
+ Output("SetWRefCon(itself, (long)it);")
+ Output("it->ob_freeit = PyMac_AutoDisposeWindow;")
+ OutRbrace()
+ def outputCheckConvertArg(self):
+ Out("""
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
+ """)
+ OutLbrace()
+ Output("DialogRef dlg;")
+ OutLbrace("if (DlgObj_Convert(v, &dlg) && dlg)")
+ Output("*p_itself = GetDialogWindow(dlg);")
+ Output("return 1;")
+ OutRbrace()
+ Output("PyErr_Clear();")
+ OutRbrace()
+ def outputCleanupStructMembers(self):
+ Output("if (self->ob_freeit && self->ob_itself)")
+ OutLbrace()
+ Output("SetWRefCon(self->ob_itself, 0);")
+ Output("self->ob_freeit(self->ob_itself);")
+ OutRbrace()
+ Output("self->ob_itself = NULL;")
+ Output("self->ob_freeit = NULL;")
+
+ def outputCompare(self):
+ Output()
+ Output("static int %s_compare(%s *self, %s *other)", self.prefix, self.objecttype, self.objecttype)
+ OutLbrace()
+ Output("if ( self->ob_itself > other->ob_itself ) return 1;")
+ Output("if ( self->ob_itself < other->ob_itself ) return -1;")
+ Output("return 0;")
+ OutRbrace()
+
+ def outputHash(self):
+ Output()
+ Output("static int %s_hash(%s *self)", self.prefix, self.objecttype)
+ OutLbrace()
+ Output("return (int)self->ob_itself;")
+ OutRbrace()
+
+ def outputRepr(self):
+ Output()
+ Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
+ OutLbrace()
+ Output("char buf[100];")
+ Output("""sprintf(buf, "<Window object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
+ Output("return PyString_FromString(buf);")
+ OutRbrace()
+
+## def outputFreeIt(self, itselfname):
+## Output("DisposeWindow(%s);", itselfname)
+# From here on it's basically all boiler plate...
+
+# Create the generator groups and link them
+module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
+object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
+module.addobject(object)
+
+# Create the generator classes used to populate the lists
+Function = OSErrFunctionGenerator
+Method = OSErrMethodGenerator
+
+# Create and populate the lists
+functions = []
+methods = []
+execfile(INPUTFILE)
+
+# Add manual routines for converting integer WindowPtr's (as returned by
+# various event routines) and Dialog objects to a WindowObject.
+whichwin_body = """
+long ptr;
+
+if ( !PyArg_ParseTuple(_args, "i", &ptr) )
+ return NULL;
+return WinObj_WhichWindow((WindowPtr)ptr);
+"""
+
+f = ManualGenerator("WhichWindow", whichwin_body)
+f.docstring = lambda : "Resolve an integer WindowPtr address to a Window object"
+
+functions.append(f)
+
+# And add the routines that access the internal bits of a window struct. They
+# are currently #defined in Windows.h, they will be real routines in Copland
+# (at which time this execfile can go)
+execfile(EDITFILE)
+
+# add the populated lists to the generator groups
+# (in a different wordl the scan program would generate this)
+for f in functions: module.add(f)
+for f in methods: object.add(f)
+
+
+
+# generate output (open the output file as late as possible)
+SetOutputFileName(OUTPUTFILE)
+module.generate()
--- /dev/null
+/***********************************************************
+Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
+The Netherlands.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the names of Stichting Mathematisch
+Centrum or CWI not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+
+STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
+THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
+FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+******************************************************************/
+
+/* Construct argc and argv for main() by using Apple Events */
+/* From Jack's implementation for STDWIN */
+
+#include <stdlib.h>
+
+#include <Types.h>
+#include <Files.h>
+#include <Events.h>
+#include <Memory.h>
+#include <Processes.h>
+#include <Errors.h>
+#include <AppleEvents.h>
+#include <AEObjects.h>
+#include <Fonts.h>
+#include <TextEdit.h>
+#include <Menus.h>
+#include <Dialogs.h>
+#include <Windows.h>
+
+#if UNIVERSAL_INTERFACES_VERSION >= 0x0340
+typedef long refcontype;
+#else
+typedef unsigned long refcontype;
+#endif
+
+#include "Python.h"
+#include "macglue.h"
+
+static int arg_count;
+static char *arg_vector[256];
+FSSpec PyMac_ApplicationFSSpec;
+char PyMac_ApplicationPath[256];
+static int applocation_inited;
+
+/* Duplicate a string to the heap. We also export this since it isn't standard
+** and others use it
+*/
+#ifndef HAVE_STRDUP
+char *
+strdup(const char *src)
+{
+ char *dst = malloc(strlen(src) + 1);
+ if (dst)
+ strcpy(dst, src);
+ return dst;
+}
+#endif
+
+/* Initialize FSSpec and full name of current application */
+
+OSErr
+PyMac_init_process_location()
+{
+ ProcessSerialNumber currentPSN;
+ ProcessInfoRec info;
+ OSErr err;
+
+ if ( applocation_inited ) return 0;
+ currentPSN.highLongOfPSN = 0;
+ currentPSN.lowLongOfPSN = kCurrentProcess;
+ info.processInfoLength = sizeof(ProcessInfoRec);
+ info.processName = NULL;
+ info.processAppSpec = &PyMac_ApplicationFSSpec;
+ if ( err=GetProcessInformation(¤tPSN, &info))
+ return err;
+ if ( err=PyMac_GetFullPath(&PyMac_ApplicationFSSpec, PyMac_ApplicationPath) )
+ return err;
+ applocation_inited = 1;
+ return 0;
+}
+
+/* Check that there aren't any args remaining in the event */
+
+static OSErr
+get_missing_params(const AppleEvent *theAppleEvent)
+{
+ DescType theType;
+ Size actualSize;
+ OSErr err;
+
+ err = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
+ &theType, nil, 0, &actualSize);
+ if (err == errAEDescNotFound)
+ return noErr;
+ else
+ return errAEEventNotHandled;
+}
+
+static int got_one; /* Flag that we can stop getting events */
+
+/* Handle the Print or Quit events (by failing) */
+
+static pascal OSErr
+handle_not(const AppleEvent *theAppleEvent, AppleEvent *reply, refcontype refCon)
+{
+ #pragma unused (reply, refCon)
+ got_one = 1;
+ return errAEEventNotHandled;
+}
+
+/* Handle the Open Application event (by ignoring it) */
+
+static pascal OSErr
+handle_open_app(const AppleEvent *theAppleEvent, AppleEvent *reply, refcontype refCon)
+{
+ #pragma unused (reply, refCon)
+#if 0
+ /* Test by Jack: would removing this facilitate debugging? */
+ got_one = 1;
+#endif
+ return get_missing_params(theAppleEvent);
+}
+
+/* Handle the Open Document event, by adding an argument */
+
+static pascal OSErr
+handle_open_doc(const AppleEvent *theAppleEvent, AppleEvent *reply, refcontype refCon)
+{
+ #pragma unused (reply, refCon)
+ OSErr err;
+ AEDescList doclist;
+ AEKeyword keywd;
+ DescType rttype;
+ long i, ndocs, size;
+ FSSpec fss;
+ char path[256];
+
+ got_one = 1;
+ if (err = AEGetParamDesc(theAppleEvent,
+ keyDirectObject, typeAEList, &doclist))
+ return err;
+ if (err = get_missing_params(theAppleEvent))
+ return err;
+ if (err = AECountItems(&doclist, &ndocs))
+ return err;
+ for(i = 1; i <= ndocs; i++) {
+ err = AEGetNthPtr(&doclist, i, typeFSS,
+ &keywd, &rttype, &fss, sizeof(fss), &size);
+ if (err)
+ break;
+ PyMac_GetFullPath(&fss, path);
+ arg_vector[arg_count++] = strdup(path);
+ }
+ return err;
+}
+
+/* Install standard core event handlers */
+AEEventHandlerUPP open_doc_upp;
+AEEventHandlerUPP open_app_upp;
+AEEventHandlerUPP not_upp;
+
+static void
+set_ae_handlers()
+{
+ open_doc_upp = NewAEEventHandlerUPP(&handle_open_doc);
+ open_app_upp = NewAEEventHandlerUPP(&handle_open_app);
+ not_upp = NewAEEventHandlerUPP(&handle_not);
+
+ AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
+ open_app_upp, 0L, false);
+ AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
+ open_doc_upp, 0L, false);
+ AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
+ not_upp, 0L, false);
+ AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
+ not_upp, 0L, false);
+}
+
+/* Uninstall standard core event handlers */
+
+static void
+reset_ae_handlers()
+{
+ AERemoveEventHandler(kCoreEventClass, kAEOpenApplication,
+ open_app_upp, false);
+ AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments,
+ open_doc_upp, false);
+ AERemoveEventHandler(kCoreEventClass, kAEPrintDocuments,
+ not_upp, false);
+ AERemoveEventHandler(kCoreEventClass, kAEQuitApplication,
+ not_upp, false);
+}
+
+/* Wait for events until a core event has been handled */
+
+static void
+event_loop()
+{
+ EventRecord event;
+ int n;
+ int ok;
+
+ got_one = 0;
+ for (n = 0; n < 100 && !got_one; n++) {
+#if !TARGET_API_MAC_CARBON
+ SystemTask();
+#endif
+ ok = GetNextEvent(everyEvent, &event);
+ if (ok && event.what == kHighLevelEvent) {
+ AEProcessAppleEvent(&event);
+ }
+ }
+}
+
+/* Get the argv vector, return argc */
+
+int
+PyMac_GetArgv(pargv, noevents)
+ char ***pargv;
+ int noevents;
+{
+
+ arg_count = 0;
+ (void)PyMac_init_process_location();
+ arg_vector[arg_count++] = strdup(PyMac_ApplicationPath);
+
+ if( !noevents ) {
+ set_ae_handlers();
+ event_loop();
+ reset_ae_handlers();
+ }
+
+ arg_vector[arg_count] = NULL;
+
+ *pargv = arg_vector;
+ return arg_count;
+}
--- /dev/null
+import W
+import sys
+import Qd
+
+__version__ = "0.2"
+__author__ = "jvr"
+
+class _modulebrowser:
+
+ def __init__(self):
+ self.editmodules = []
+ self.modules = []
+ self.window = W.Window((194, 1000), "Module Browser", minsize = (194, 160), maxsize = (340, 20000))
+
+ #self.window.bevelbox = W.BevelBox((0, 0, 0, 56))
+ self.window.openbutton = W.Button((10, 8, 80, 16), "Open", self.openbuttonhit)
+ self.window.browsebutton = W.Button((100, 8, 80, 16), "Browse\xc9", self.browsebuttonhit)
+ self.window.reloadbutton = W.Button((10, 32, 80, 16), "Reload", self.reloadbuttonhit)
+ self.window.openotherbutton = W.Button((100, 32, 80, 16), "Open other\xc9", self.openother)
+
+ self.window.openbutton.enable(0)
+ self.window.reloadbutton.enable(0)
+ self.window.browsebutton.enable(0)
+ self.window.setdefaultbutton(self.window.browsebutton)
+
+ self.window.bind("cmdr", self.window.reloadbutton.push)
+ self.window.bind("cmdb", self.window.browsebutton.push)
+
+ self.window.bind("<activate>", self.activate)
+ self.window.bind("<close>", self.close)
+
+ self.window.list = W.List((-1, 56, 1, -14), [], self.listhit)
+
+ self.window.open()
+ self.checkbuttons()
+
+ def close(self):
+ global _browser
+ _browser = None
+
+ def activate(self, onoff):
+ if onoff:
+ self.makelist()
+
+ def listhit(self, isdbl):
+ self.checkbuttons()
+ if isdbl:
+ if self.window._defaultbutton:
+ self.window._defaultbutton.push()
+
+ def checkbuttons(self):
+ sel = self.window.list.getselection()
+ if sel:
+ for i in sel:
+ if self.editmodules[i]:
+ self.window.openbutton.enable(1)
+ self.window.reloadbutton.enable(1)
+ self.window.setdefaultbutton(self.window.openbutton)
+ break
+ else:
+ self.window.openbutton.enable(0)
+ self.window.reloadbutton.enable(0)
+ self.window.setdefaultbutton(self.window.browsebutton)
+ self.window.browsebutton.enable(1)
+ else:
+ #self.window.setdefaultbutton(self.window.browsebutton)
+ self.window.openbutton.enable(0)
+ self.window.reloadbutton.enable(0)
+ self.window.browsebutton.enable(0)
+
+ def openbuttonhit(self):
+ import imp
+ sel = self.window.list.getselection()
+ W.SetCursor("watch")
+ for i in sel:
+ modname = self.window.list[i]
+ try:
+ self.openscript(sys.modules[modname].__file__, modname)
+ except IOError:
+ try:
+ file, path, description = imp.find_module(modname)
+ except ImportError:
+ W.SetCursor("arrow")
+ W.Message("Can't find file for module '%s'."
+ % modname)
+ else:
+ self.openscript(path, modname)
+
+ def openscript(self, path, modname):
+ import os
+ if path[-3:] == '.py':
+ W.getapplication().openscript(path, modname=modname)
+ elif path[-4:] in ['.pyc', '.pyo']:
+ W.getapplication().openscript(path[:-1], modname=modname)
+ else:
+ W.Message("Can't edit '%s'; it might be a shared library or a .pyc file."
+ % modname)
+
+ def openother(self):
+ import imp
+ import EasyDialogs
+
+ modname = EasyDialogs.AskString("Open module:")
+ if modname:
+ try:
+ file, path, description = imp.find_module(modname)
+ except ImportError:
+ if modname in sys.builtin_module_names:
+ alerttext = "'%s' is a builtin module, which you can't edit." % modname
+ else:
+ alerttext = "No module named '%s'." % modname
+ raise W.AlertError, alerttext
+ self.openscript(path, modname)
+
+ def reloadbuttonhit(self):
+ sel = self.window.list.getselection()
+ W.SetCursor("watch")
+ for i in sel:
+ mname = self.window.list[i]
+ m = sys.modules[mname]
+ # Set the __name__ attribute of the module to its real name.
+ # reload() complains if it's __main__, which is true
+ # when it recently has been run as a script with "Run as __main__"
+ # enabled.
+ m.__name__ = mname
+ reload(m)
+
+ def browsebuttonhit(self):
+ sel = self.window.list.getselection()
+ if not sel:
+ return
+ import PyBrowser
+ for i in sel:
+ PyBrowser.Browser(sys.modules[self.window.list[i]])
+
+ def makelist(self):
+ editmodules, modules = getmoduleslist()
+ if modules == self.modules:
+ return
+ self.editmodules, self.modules = editmodules, modules
+ self.window.list.setdrawingmode(0)
+ sel = self.window.list.getselectedobjects()
+ self.window.list.set(self.modules)
+ self.window.list.setselectedobjects(sel)
+ self.window.list.setdrawingmode(1)
+
+
+def getmoduleslist():
+ import PyBrowser # for caselesssort function
+ moduleitems = sys.modules.items()
+ moduleitems = filter(lambda (name, module): module is not None, moduleitems)
+ modules = map(lambda (name, module): name, moduleitems)
+ modules = PyBrowser.caselesssort(modules)
+ editmodules = []
+ sysmodules = sys.modules
+ modulesappend = editmodules.append
+ for m in modules:
+ module = sysmodules[m]
+ try:
+ if sysmodules[m].__file__[-3:] == '.py' or \
+ sysmodules[m].__file__[-4:] in ['.pyc', '.pyo']:
+ modulesappend(1)
+ else:
+ modulesappend(0)
+ except AttributeError:
+ modulesappend(0)
+ return editmodules, modules
+
+
+
+_browser = None
+
+def ModuleBrowser():
+ global _browser
+ if _browser is not None:
+ _browser.window.select()
+ else:
+ _browser = _modulebrowser()
--- /dev/null
+import W
+import Wkeys
+import Fm
+import WASTEconst
+from types import *
+import Events
+import string
+import sys
+import traceback
+import MacOS
+import MacPrefs
+import Qd
+import PyInteractive
+
+if not hasattr(sys, 'ps1'):
+ sys.ps1 = '>>> '
+if not hasattr(sys, 'ps2'):
+ sys.ps2 = '... '
+
+def inspect(foo): # JJS 1/25/99
+ "Launch the browser on the given object. This is a general built-in function."
+ import PyBrowser
+ PyBrowser.Browser(foo)
+
+class ConsoleTextWidget(W.EditText):
+
+ def __init__(self, *args, **kwargs):
+ apply(W.EditText.__init__, (self,) + args, kwargs)
+ self._inputstart = 0
+ self._buf = ''
+ self.pyinteractive = PyInteractive.PyInteractive()
+
+ import __main__
+ self._namespace = __main__.__dict__
+ self._namespace['inspect'] = inspect # JJS 1/25/99
+
+ def insert(self, text):
+ self.checkselection()
+ self.ted.WEInsert(text, None, None)
+ self.changed = 1
+ self.selchanged = 1
+
+ def set_namespace(self, dict):
+ if type(dict) <> DictionaryType:
+ raise TypeError, "The namespace needs to be a dictionary"
+ if 'inspect' not in dict.keys(): dict['inspect'] = inspect # JJS 1/25/99
+ self._namespace = dict
+
+ def open(self):
+ W.EditText.open(self)
+ self.write('Python ' + sys.version + '\nType "copyright", "credits" or "license" for more information.\n')
+ self.write(sys.ps1)
+ self.flush()
+
+ def key(self, char, event):
+ (what, message, when, where, modifiers) = event
+ if self._enabled and not modifiers & Events.cmdKey or char in Wkeys.arrowkeys:
+ if char not in Wkeys.navigationkeys:
+ self.checkselection()
+ if char == Wkeys.enterkey:
+ char = Wkeys.returnkey
+ selstart, selend = self.getselection()
+ if char == Wkeys.backspacekey:
+ if selstart <= (self._inputstart - (selstart <> selend)):
+ return
+ self.ted.WEKey(ord(char), modifiers)
+ if char not in Wkeys.navigationkeys:
+ self.changed = 1
+ if char not in Wkeys.scrollkeys:
+ self.selchanged = 1
+ self.updatescrollbars()
+ if char == Wkeys.returnkey:
+ text = self.get()[self._inputstart:selstart]
+ text = string.join(string.split(text, "\r"), "\n")
+ saveyield = MacOS.EnableAppswitch(0)
+ self.pyinteractive.executeline(text, self, self._namespace)
+ MacOS.EnableAppswitch(saveyield)
+ selstart, selend = self.getselection()
+ self._inputstart = selstart
+
+ def domenu_save_as(self, *args):
+ import macfs
+ fss, ok = macfs.StandardPutFile('Save console text as:', 'console.txt')
+ if not ok:
+ return
+ f = open(fss.as_pathname(), 'wb')
+ f.write(self.get())
+ f.close()
+ fss.SetCreatorType(W._signature, 'TEXT')
+
+ def write(self, text):
+ self._buf = self._buf + text
+ if '\n' in self._buf:
+ self.flush()
+
+ def flush(self):
+ stuff = string.split(self._buf, '\n')
+ stuff = string.join(stuff, '\r')
+ self.setselection_at_end()
+ self.ted.WEInsert(stuff, None, None)
+ selstart, selend = self.getselection()
+ self._inputstart = selstart
+ self._buf = ""
+ self.ted.WEClearUndo()
+ self.updatescrollbars()
+
+ def selection_ok(self):
+ selstart, selend = self.getselection()
+ return not (selstart < self._inputstart or selend < self._inputstart)
+
+ def checkselection(self):
+ if not self.selection_ok():
+ self.setselection_at_end()
+
+ def setselection_at_end(self):
+ end = self.ted.WEGetTextLength()
+ self.setselection(end, end)
+ self.updatescrollbars()
+
+ def domenu_cut(self, *args):
+ if not self.selection_ok():
+ return
+ W.EditText.domenu_cut(self)
+
+ def domenu_paste(self, *args):
+ if not self.selection_ok():
+ self.setselection_at_end()
+ W.EditText.domenu_paste(self)
+
+ def domenu_clear(self, *args):
+ if not self.selection_ok():
+ return
+ W.EditText.domenu_clear(self)
+
+
+class PyConsole(W.Window):
+
+ def __init__(self, bounds, show = 1, fontsettings = ("Monaco", 0, 9, (0, 0, 0)),
+ tabsettings = (32, 0), unclosable = 0):
+ W.Window.__init__(self,
+ bounds,
+ "Python Interactive",
+ minsize = (200, 100),
+ tabbable = 0,
+ show = show)
+
+ self._unclosable = unclosable
+ consoletext = ConsoleTextWidget((-1, -1, -14, 1), inset = (6, 5),
+ fontsettings = fontsettings, tabsettings = tabsettings)
+ self._bary = W.Scrollbar((-15, 14, 16, -14), consoletext.vscroll, max = 32767)
+ self.consoletext = consoletext
+ self.namespacemenu = W.PopupMenu((-15, -1, 16, 16), [], self.consoletext.set_namespace)
+ self.namespacemenu.bind('<click>', self.makenamespacemenu)
+ self.open()
+
+ def makenamespacemenu(self, *args):
+ W.SetCursor('watch')
+ namespacelist = self.getnamespacelist()
+ self.namespacemenu.set([("Clear window", self.clearbuffer), ("Font settings\xc9", self.dofontsettings),
+ ["Namespace"] + namespacelist, ("Browse namespace\xc9", self.browsenamespace)])
+ currentname = self.consoletext._namespace["__name__"]
+ for i in range(len(namespacelist)):
+ if namespacelist[i][0] == currentname:
+ break
+ else:
+ return
+ # XXX this functionality should be generally available in Wmenus
+ submenuid = self.namespacemenu.menu.menu.GetItemMark(3)
+ menu = self.namespacemenu.menu.bar.menus[submenuid]
+ menu.menu.CheckMenuItem(i + 1, 1)
+
+ def browsenamespace(self):
+ import PyBrowser, W
+ W.SetCursor('watch')
+ PyBrowser.Browser(self.consoletext._namespace, self.consoletext._namespace["__name__"])
+
+ def clearbuffer(self):
+ import Res
+ self.consoletext.ted.WEUseText(Res.Resource(''))
+ self.consoletext.write(sys.ps1)
+ self.consoletext.flush()
+
+ def getnamespacelist(self):
+ import os
+ import __main__
+ editors = filter(lambda x: x.__class__.__name__ == "Editor", self.parent._windows.values())
+
+ namespaces = [ ("__main__",__main__.__dict__) ]
+ for ed in editors:
+ modname = os.path.splitext(ed.title)[0]
+ if sys.modules.has_key(modname):
+ module = sys.modules[modname]
+ namespaces.append((modname, module.__dict__))
+ else:
+ if ed.title[-3:] == '.py':
+ modname = ed.title[:-3]
+ else:
+ modname = ed.title
+ ed.globals["__name__"] = modname
+ namespaces.append((modname, ed.globals))
+ return namespaces
+
+ def dofontsettings(self):
+ import FontSettings
+ settings = FontSettings.FontDialog(self.consoletext.getfontsettings(),
+ self.consoletext.gettabsettings())
+ if settings:
+ fontsettings, tabsettings = settings
+ self.consoletext.setfontsettings(fontsettings)
+ self.consoletext.settabsettings(tabsettings)
+
+ def show(self, onoff = 1):
+ W.Window.show(self, onoff)
+ if onoff:
+ self.select()
+
+ def close(self):
+ if self._unclosable:
+ self.show(0)
+ return -1
+ W.Window.close(self)
+
+ def writeprefs(self):
+ prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
+ prefs.console.show = self.isvisible()
+ prefs.console.windowbounds = self.getbounds()
+ prefs.console.fontsettings = self.consoletext.getfontsettings()
+ prefs.console.tabsettings = self.consoletext.gettabsettings()
+ prefs.save()
+
+
+class OutputTextWidget(W.EditText):
+
+ def domenu_save_as(self, *args):
+ title = self._parentwindow.gettitle()
+ import macfs
+ fss, ok = macfs.StandardPutFile('Save %s text as:' % title, title + '.txt')
+ if not ok:
+ return
+ f = open(fss.as_pathname(), 'wb')
+ f.write(self.get())
+ f.close()
+ fss.SetCreatorType(W._signature, 'TEXT')
+
+
+class PyOutput:
+
+ def __init__(self, bounds, show = 1, fontsettings = ("Monaco", 0, 9, (0, 0, 0)), tabsettings = (32, 0)):
+ self.bounds = bounds
+ self.fontsettings = fontsettings
+ self.tabsettings = tabsettings
+ self.w = None
+ self.closed = 1
+ self._buf = ''
+ # should be able to set this
+ self.savestdout, self.savestderr = sys.stdout, sys.stderr
+ sys.stderr = sys.stdout = self
+ if show:
+ self.show()
+
+ def setupwidgets(self):
+ self.w = W.Window(self.bounds, "Output",
+ minsize = (200, 100),
+ tabbable = 0)
+ self.w.outputtext = OutputTextWidget((-1, -1, -14, 1), inset = (6, 5),
+ fontsettings = self.fontsettings, tabsettings = self.tabsettings, readonly = 1)
+ menuitems = [("Clear window", self.clearbuffer), ("Font settings\xc9", self.dofontsettings)]
+ self.w.popupmenu = W.PopupMenu((-15, -1, 16, 16), menuitems)
+
+ self.w._bary = W.Scrollbar((-15, 14, 16, -14), self.w.outputtext.vscroll, max = 32767)
+ self.w.bind("<close>", self.close)
+ self.w.bind("<activate>", self.activate)
+
+ def write(self, text):
+ oldyield = MacOS.EnableAppswitch(-1)
+ try:
+ self._buf = self._buf + text
+ if '\n' in self._buf:
+ self.flush()
+ finally:
+ MacOS.EnableAppswitch(oldyield)
+
+ def flush(self):
+ self.show()
+ stuff = string.split(self._buf, '\n')
+ stuff = string.join(stuff, '\r')
+ end = self.w.outputtext.ted.WEGetTextLength()
+ self.w.outputtext.setselection(end, end)
+ self.w.outputtext.ted.WEFeatureFlag(WASTEconst.weFReadOnly, 0)
+ self.w.outputtext.ted.WEInsert(stuff, None, None)
+ self._buf = ""
+ self.w.outputtext.updatescrollbars()
+ self.w.outputtext.ted.WEFeatureFlag(WASTEconst.weFReadOnly, 1)
+
+ def show(self):
+ if self.closed:
+ if not self.w:
+ self.setupwidgets()
+ self.w.open()
+ self.w.outputtext.updatescrollbars()
+ self.closed = 0
+ else:
+ self.w.show(1)
+ self.closed = 0
+ self.w.select()
+
+ def writeprefs(self):
+ if self.w is not None:
+ prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
+ prefs.output.show = self.w.isvisible()
+ prefs.output.windowbounds = self.w.getbounds()
+ prefs.output.fontsettings = self.w.outputtext.getfontsettings()
+ prefs.output.tabsettings = self.w.outputtext.gettabsettings()
+ prefs.save()
+
+ def dofontsettings(self):
+ import FontSettings
+ settings = FontSettings.FontDialog(self.w.outputtext.getfontsettings(),
+ self.w.outputtext.gettabsettings())
+ if settings:
+ fontsettings, tabsettings = settings
+ self.w.outputtext.setfontsettings(fontsettings)
+ self.w.outputtext.settabsettings(tabsettings)
+
+ def clearbuffer(self):
+ import Res
+ self.w.outputtext.set('')
+
+ def activate(self, onoff):
+ if onoff:
+ self.closed = 0
+
+ def close(self):
+ self.w.show(0)
+ self.closed = 1
+ return -1
+
+
+class SimpleStdin:
+
+ def readline(self):
+ import EasyDialogs
+ # A trick to make the input dialog box a bit more palatable
+ if hasattr(sys.stdout, '_buf'):
+ prompt = sys.stdout._buf
+ else:
+ prompt = ""
+ if not prompt:
+ prompt = "Stdin input:"
+ sys.stdout.flush()
+ rv = EasyDialogs.AskString(prompt)
+ if rv is None:
+ return ""
+ return rv + '\n'
+
+
+def installconsole(defaultshow = 1):
+ global console
+ prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
+ if not prefs.console or not hasattr(prefs.console, 'show'):
+ prefs.console.show = defaultshow
+ if not hasattr(prefs.console, "windowbounds"):
+ prefs.console.windowbounds = (450, 250)
+ if not hasattr(prefs.console, "fontsettings"):
+ prefs.console.fontsettings = ("Monaco", 0, 9, (0, 0, 0))
+ if not hasattr(prefs.console, "tabsettings"):
+ prefs.console.tabsettings = (32, 0)
+ console = PyConsole(prefs.console.windowbounds, prefs.console.show,
+ prefs.console.fontsettings, prefs.console.tabsettings, 1)
+
+def installoutput(defaultshow = 0, OutPutWindow = PyOutput):
+ global output
+
+ # quick 'n' dirty std in emulation
+ sys.stdin = SimpleStdin()
+
+ prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
+ if not prefs.output or not hasattr(prefs.output, 'show'):
+ prefs.output.show = defaultshow
+ if not hasattr(prefs.output, "windowbounds"):
+ prefs.output.windowbounds = (450, 250)
+ if not hasattr(prefs.output, "fontsettings"):
+ prefs.output.fontsettings = ("Monaco", 0, 9, (0, 0, 0))
+ if not hasattr(prefs.output, "tabsettings"):
+ prefs.output.tabsettings = (32, 0)
+ output = OutPutWindow(prefs.output.windowbounds, prefs.output.show,
+ prefs.output.fontsettings, prefs.output.tabsettings)
--- /dev/null
+import sys
+import bdb
+import types
+import os
+
+import W
+import WASTEconst
+import PyBrowser
+import Qd
+import Evt
+import Lists
+import MacOS
+_filenames = {}
+
+SIMPLE_TYPES = (
+ types.NoneType,
+ types.IntType,
+ types.LongType,
+ types.FloatType,
+ types.ComplexType,
+ types.StringType
+)
+
+
+class Debugger(bdb.Bdb):
+
+ def __init__(self, title = 'Debugger'):
+ bdb.Bdb.__init__(self)
+ self.closed = 1
+ self.title = title
+ self.breaksviewer = None
+ self.reset()
+ self.tracing = 0
+ self.tracingmonitortime = Evt.TickCount()
+ self.editors = {}
+
+ prefs = W.getapplication().getprefs()
+ if prefs.debugger:
+ for file, breaks in prefs.debugger.breaks.items():
+ for b in breaks:
+ self.set_break(file, b)
+ self.bounds, self.horpanes, self.verpanes = prefs.debugger.windowsettings
+ self.tracemagic = prefs.debugger.tracemagic
+ else:
+ self.breaks = {}
+ self.horpanes = (0.4, 0.6)
+ self.verpanes = (0.3, 0.35, 0.35)
+ self.bounds = (600, 400)
+ self.tracemagic = 0
+ self.laststacksel = None
+
+ def canonic(self, filename):
+ # override: the provided canonic() method breaks our
+ # file-less Untitled windows
+ return filename
+
+ def reset(self):
+ self.currentframe = None
+ self.file = None
+ self.laststack = None
+ self.reason = 'Not running'
+ self.continuewithoutdebugger = 0
+ bdb.Bdb.reset(self)
+ self.forget()
+
+ def start(self, bottomframe = None, running = 0):
+ W.getapplication().DebuggerQuit = bdb.BdbQuit
+ import Menu
+ Menu.HiliteMenu(0)
+ if self.closed:
+ self.setupwidgets(self.title)
+ self.closed = 0
+ if not self.w.parent.debugger_quitting:
+ self.w.select()
+ raise W.AlertError, 'There is another debugger session busy.'
+ self.reset()
+ self.botframe = bottomframe
+ if running:
+ self.set_continue()
+ self.reason = 'Running\xc9'
+ self.setstate('running')
+ else:
+ self.set_step()
+ self.reason = 'stopped'
+ self.setstate('stopped')
+ sys.settrace(self.trace_dispatch)
+
+ def stop(self):
+ self.set_quit()
+ if self.w.parent:
+ self.exit_mainloop()
+ self.resetwidgets()
+
+ def set_continue_without_debugger(self):
+ sys.settrace(None)
+ self.set_quit()
+ self.clear_tracefuncs()
+ self.continuewithoutdebugger = 1
+ if hasattr(self, "w") and self.w.parent:
+ self.exit_mainloop()
+ self.resetwidgets()
+
+ def clear_tracefuncs(self):
+ try:
+ raise 'spam'
+ except:
+ pass
+ frame = sys.exc_traceback.tb_frame
+ while frame is not None:
+ del frame.f_trace
+ frame = frame.f_back
+
+ def postmortem(self, exc_type, exc_value, traceback):
+ if self.closed:
+ self.setupwidgets(self.title)
+ self.closed = 0
+ if not self.w.parent.debugger_quitting:
+ raise W.AlertError, 'There is another debugger session busy.'
+ self.reset()
+ if traceback:
+ self.botframe = traceback.tb_frame
+ while traceback.tb_next <> None:
+ traceback = traceback.tb_next
+ frame = traceback.tb_frame
+ else:
+ self.botframe = None
+ frame = None
+ self.w.panes.bottom.buttons.killbutton.enable(1)
+ self.reason = '(dead) ' + self.formatexception(exc_type, exc_value)
+ self.w.select()
+ self.setup(frame, traceback)
+ self.setstate('dead')
+ self.showstack(self.curindex)
+ self.showframe(self.curindex)
+
+ def setupwidgets(self, title):
+ self.w = w = W.Window(self.bounds, title, minsize = (500, 300))
+
+ w.panes = W.HorizontalPanes((8, 4, -8, -8), self.horpanes)
+
+ w.panes.browserpanes = browserpanes = W.VerticalPanes(None, self.verpanes)
+
+ browserpanes.stacklist = W.Group(None)
+ browserpanes.stacklist.title = W.TextBox((4, 0, 0, 12), 'Stack')
+ browserpanes.stacklist.stack = W.List((0, 16, 0, 0), callback = self.do_stack, flags = Lists.lOnlyOne)
+
+ browserpanes.locals = W.Group(None)
+ browserpanes.locals.title = W.TextBox((4, 0, 0, 12), 'Local variables')
+ browserpanes.locals.browser = PyBrowser.BrowserWidget((0, 16, 0, 0))
+
+ browserpanes.globals = W.Group(None)
+ browserpanes.globals.title = W.TextBox((4, 0, 0, 12), 'Global variables')
+ browserpanes.globals.browser = PyBrowser.BrowserWidget((0, 16, 0, 0))
+
+ w.panes.bottom = bottom = W.Group(None)
+ bottom.src = src = W.Group((0, 52, 0, 0))
+ source = SourceViewer((1, 1, -15, -15), readonly = 1, debugger = self)
+ src.optionsmenu = W.PopupMenu((-16, 0, 16, 16), [])
+ src.optionsmenu.bind('<click>', self.makeoptionsmenu)
+
+ src._barx = W.Scrollbar((0, -16, -15, 16), source.hscroll, max = 32767)
+ src._bary = W.Scrollbar((-16, 15, 16, -15), source.vscroll, max = 32767)
+ src.source = source
+ src.frame = W.Frame((0, 0, -15, -15))
+
+ bottom.tracingmonitor = TracingMonitor((0, 23, 6, 6))
+ bottom.state = W.TextBox((12, 20, 0, 16), self.reason)
+
+ bottom.srctitle = W.TextBox((12, 36, 0, 14))
+ bottom.buttons = buttons = W.Group((12, 0, 0, 16))
+
+ buttons.runbutton = W.Button((0, 0, 50, 16), "Run", self.do_run)
+ buttons.stopbutton = W.Button((58, 0, 50, 16), "Stop", self.do_stop)
+ buttons.killbutton = W.Button((116, 0, 50, 16), "Kill", self.do_kill)
+ buttons.line = W.VerticalLine((173, 0, 0, 0))
+ buttons.stepbutton = W.Button((181, 0, 50, 16), "Step", self.do_step)
+ buttons.stepinbutton = W.Button((239, 0, 50, 16), "Step in", self.do_stepin)
+ buttons.stepoutbutton = W.Button((297, 0, 50, 16), "Step out", self.do_stepout)
+
+ w.bind('cmdr', buttons.runbutton.push)
+ w.bind('cmd.', buttons.stopbutton.push)
+ w.bind('cmdk', buttons.killbutton.push)
+ w.bind('cmds', buttons.stepbutton.push)
+ w.bind('cmdt', buttons.stepinbutton.push)
+ w.bind('cmdu', buttons.stepoutbutton.push)
+
+ w.bind('<close>', self.close)
+
+ w.open()
+ w.xxx___select(w.panes.bottom.src.source)
+
+ def makeoptionsmenu(self):
+ options = [('Clear breakpoints', self.w.panes.bottom.src.source.clearbreakpoints),
+ ('Clear all breakpoints', self.clear_all_breaks),
+ ('Edit breakpoints\xc9', self.edit_breaks), '-',
+ (self.tracemagic and
+ 'Disable __magic__ tracing' or 'Enable __magic__ tracing', self.togglemagic)]
+ self.w.panes.bottom.src.optionsmenu.set(options)
+
+ def edit_breaks(self):
+ if self.breaksviewer:
+ self.breaksviewer.select()
+ else:
+ self.breaksviewer = BreakpointsViewer(self)
+
+ def togglemagic(self):
+ self.tracemagic = not self.tracemagic
+
+ def setstate(self, state):
+ self.w.panes.bottom.tracingmonitor.reset()
+ self.w.panes.bottom.state.set(self.reason)
+ buttons = self.w.panes.bottom.buttons
+ if state == 'stopped':
+ buttons.runbutton.enable(1)
+ buttons.stopbutton.enable(0)
+ buttons.killbutton.enable(1)
+ buttons.stepbutton.enable(1)
+ buttons.stepinbutton.enable(1)
+ buttons.stepoutbutton.enable(1)
+ elif state == 'running':
+ buttons.runbutton.enable(0)
+ buttons.stopbutton.enable(1)
+ buttons.killbutton.enable(1)
+ buttons.stepbutton.enable(0)
+ buttons.stepinbutton.enable(0)
+ buttons.stepoutbutton.enable(0)
+ elif state == 'idle':
+ buttons.runbutton.enable(0)
+ buttons.stopbutton.enable(0)
+ buttons.killbutton.enable(0)
+ buttons.stepbutton.enable(0)
+ buttons.stepinbutton.enable(0)
+ buttons.stepoutbutton.enable(0)
+ elif state == 'dead':
+ buttons.runbutton.enable(0)
+ buttons.stopbutton.enable(0)
+ buttons.killbutton.enable(1)
+ buttons.stepbutton.enable(0)
+ buttons.stepinbutton.enable(0)
+ buttons.stepoutbutton.enable(0)
+ else:
+ print 'unknown state:', state
+
+ def resetwidgets(self):
+ self.reason = ''
+ self.w.panes.bottom.srctitle.set('')
+ self.w.panes.bottom.src.source.set('')
+ self.w.panes.browserpanes.stacklist.stack.set([])
+ self.w.panes.browserpanes.locals.browser.set({})
+ self.w.panes.browserpanes.globals.browser.set({})
+ self.setstate('idle')
+
+ # W callbacks
+
+ def close(self):
+ self.set_quit()
+ self.exit_mainloop()
+ self.closed = 1
+
+ self.unregister_editor(self.w.panes.bottom.src.source,
+ self.w.panes.bottom.src.source.file)
+ self.horpanes = self.w.panes.getpanesizes()
+ self.verpanes = self.w.panes.browserpanes.getpanesizes()
+ self.bounds = self.w.getbounds()
+ prefs = W.getapplication().getprefs()
+ prefs.debugger.breaks = self.breaks
+ prefs.debugger.windowsettings = self.bounds, self.horpanes, self.verpanes
+ prefs.debugger.tracemagic = self.tracemagic
+ prefs.save()
+
+ # stack list callback
+
+ def do_stack(self, isdbl):
+ sel = self.w.panes.browserpanes.stacklist.stack.getselection()
+ if isdbl:
+ if sel:
+ frame, lineno = self.stack[sel[0] + 1]
+ filename = frame.f_code.co_filename
+ editor = self.w._parentwindow.parent.openscript(filename, lineno)
+ if self.breaks.has_key(filename):
+ editor.showbreakpoints(1)
+ else:
+ if sel and sel <> self.laststacksel:
+ self.showframe(sel[0] + 1)
+ self.laststacksel = sel
+
+ def geteditor(self, filename):
+ if filename[:1] == '<' and filename[-1:] == '>':
+ editor = W.getapplication().getscript(filename[1:-1])
+ else:
+ editor = W.getapplication().getscript(filename)
+ return editor
+
+ # button callbacks
+
+ def do_run(self):
+ self.running()
+ self.set_continue()
+ self.exit_mainloop()
+
+ def do_stop(self):
+ self.set_step()
+
+ def do_kill(self):
+ self.set_quit()
+ self.exit_mainloop()
+ self.resetwidgets()
+
+ def do_step(self):
+ self.running()
+ self.set_next(self.curframe)
+ self.exit_mainloop()
+
+ def do_stepin(self):
+ self.running()
+ self.set_step()
+ self.exit_mainloop()
+
+ def do_stepout(self):
+ self.running()
+ self.set_return(self.curframe)
+ self.exit_mainloop()
+
+ def running(self):
+ W.SetCursor('watch')
+ self.reason = 'Running\xc9'
+ self.setstate('running')
+ #self.w.panes.bottom.src.source.set('')
+ #self.w.panes.browserpanes.stacklist.stack.set([])
+ #self.w.panes.browserpanes.locals.browser.set({})
+ #self.w.panes.browserpanes.globals.browser.set({})
+
+ def exit_mainloop(self):
+ self.w.parent.debugger_quitting = 1
+
+ #
+
+ def showframe(self, stackindex):
+ (frame, lineno) = self.stack[stackindex]
+ W.SetCursor('watch')
+ filename = frame.f_code.co_filename
+ if filename <> self.file:
+ editor = self.geteditor(filename)
+ if editor:
+ self.w.panes.bottom.src.source.set(editor.get(), filename)
+ else:
+ try:
+ f = open(filename, 'rb')
+ data = f.read()
+ f.close()
+ except IOError:
+ if filename[-3:] == '.py':
+ import imp
+ modname = os.path.basename(filename)[:-3]
+ try:
+ f, filename, (suff, mode, dummy) = imp.find_module(modname)
+ except ImportError:
+ self.w.panes.bottom.src.source.set("can't find file")
+ else:
+ if f:
+ f.close()
+ if f and suff == '.py':
+ f = open(filename, 'rb')
+ data = f.read()
+ f.close()
+ self.w.panes.bottom.src.source.set(data, filename)
+ else:
+ self.w.panes.bottom.src.source.set("can't find file")
+ else:
+ self.w.panes.bottom.src.source.set("can't find file")
+ else:
+ self.w.panes.bottom.src.source.set(data, filename)
+ self.file = filename
+ self.w.panes.bottom.srctitle.set('Source: ' + filename + ((lineno > 0) and (' (line %d)' % lineno) or ' '))
+ self.goto_line(lineno)
+ self.lineno = lineno
+ self.showvars((frame, lineno))
+
+ def showvars(self, (frame, lineno)):
+ if frame.f_locals is not frame.f_globals:
+ locals = frame.f_locals
+ else:
+ locals = {'Same as Globals':''}
+ filteredlocals = {}
+ for key, value in locals.items():
+ # empty key is magic for Python 1.4; '.' is magic for 1.5...
+ if not key or key[0] <> '.':
+ filteredlocals[key] = value
+ self.w.panes.browserpanes.locals.browser.set(filteredlocals)
+ self.w.panes.browserpanes.globals.browser.set(frame.f_globals)
+
+ def showstack(self, stackindex):
+ stack = []
+ for frame, lineno in self.stack[1:]:
+ filename = frame.f_code.co_filename
+ try:
+ filename = _filenames[filename]
+ except KeyError:
+ if filename[:1] + filename[-1:] <> '<>':
+ filename = os.path.basename(filename)
+ _filenames[frame.f_code.co_filename] = filename
+ funcname = frame.f_code.co_name
+ if funcname == '?':
+ funcname = '<toplevel>'
+ stack.append(filename + ': ' + funcname)
+ if stack <> self.laststack:
+ self.w.panes.browserpanes.stacklist.stack.set(stack)
+ self.laststack = stack
+ sel = [stackindex - 1]
+ self.w.panes.browserpanes.stacklist.stack.setselection(sel)
+ self.laststacksel = sel
+
+ def goto_line(self, lineno):
+ if lineno > 0:
+ self.w.panes.bottom.src.source.selectline(lineno - 1)
+ else:
+ self.w.panes.bottom.src.source.setselection(0, 0)
+
+ # bdb entry points
+
+# def user_call(self, frame, argument_list):
+# self.reason = 'Calling'
+# self.interaction(frame, None)
+
+ def user_line(self, frame):
+ # This function is called when we stop or break at this line
+ self.reason = 'Stopped'
+ self.interaction(frame, None)
+
+ def user_return(self, frame, return_value):
+ # This function is called when a return trap is set here
+ fname = frame.f_code.co_name
+ if fname <> '?':
+ self.reason = 'Returning from %s()' % frame.f_code.co_name
+ frame.f_locals['__return__'] = return_value
+ elif frame.f_back is self.botframe:
+ self.reason = 'Done'
+ else:
+ self.reason = 'Returning'
+ self.interaction(frame, None, 1)
+
+ def user_exception(self, frame, (exc_type, exc_value, exc_traceback)):
+ # This function is called when we stop or break at this line
+ self.reason = self.formatexception(exc_type, exc_value)
+ self.interaction(frame, exc_traceback)
+
+ def formatexception(self, exc_type, exc_value):
+ if exc_type == SyntaxError:
+ try:
+ value, (filename, lineno, charno, line) = exc_value
+ except:
+ pass
+ else:
+ return str(exc_type) + ': ' + str(value)
+ if type(exc_type) == types.ClassType:
+ nice = exc_type.__name__
+ else:
+ nice = str(exc_type)
+ value = str(exc_value)
+ if exc_value and value:
+ nice = nice + ": " + value
+ return nice
+
+ def forget(self):
+ self.stack = []
+ self.curindex = 0
+ self.curframe = None
+
+ def setup(self, f, t, isreturning = 0):
+ self.forget()
+ self.stack, self.curindex = self.get_stack(f, t)
+ self.curframe = self.stack[self.curindex - isreturning][0]
+
+ def interaction(self, frame, traceback, isreturning = 0):
+ saveport = Qd.GetPort()
+ self.w.select()
+ try:
+ self.setup(frame, traceback, isreturning)
+ self.setstate('stopped')
+ stackindex = self.curindex
+ if isreturning:
+ if frame.f_back is not self.botframe:
+ stackindex = stackindex - 1
+ self.showstack(stackindex)
+ self.showframe(stackindex)
+ self.w.parent.debugger_mainloop()
+ self.forget()
+ finally:
+ Qd.SetPort(saveport)
+
+ # bdb customization
+
+ def trace_dispatch(self, frame, event, arg, TickCount = Evt.TickCount):
+ if TickCount() - self.tracingmonitortime > 15:
+ self.tracingmonitortime = TickCount()
+ self.w.panes.bottom.tracingmonitor.toggle()
+ try:
+ try:
+ MacOS.EnableAppswitch(0)
+ if self.quitting:
+ # returning None is not enough, a former BdbQuit exception
+ # might have been eaten by the print statement
+ raise bdb.BdbQuit
+ if event == 'line':
+ return self.dispatch_line(frame)
+ if event == 'call':
+ return self.dispatch_call(frame, arg)
+ if event == 'return':
+ return self.dispatch_return(frame, arg)
+ if event == 'exception':
+ return self.dispatch_exception(frame, arg)
+ print 'bdb.Bdb.dispatch: unknown debugging event:', `event`
+ return self.trace_dispatch
+ finally:
+ MacOS.EnableAppswitch(-1)
+ except KeyboardInterrupt:
+ self.set_step()
+ return self.trace_dispatch
+ except bdb.BdbQuit:
+ if self.continuewithoutdebugger:
+ self.clear_tracefuncs()
+ return
+ else:
+ raise bdb.BdbQuit
+ except:
+ print 'XXX Exception during debugger interaction.', \
+ self.formatexception(sys.exc_type, sys.exc_value)
+ import traceback
+ traceback.print_exc()
+ return self.trace_dispatch
+
+ def dispatch_call(self, frame, arg):
+ if not self.tracemagic and \
+ frame.f_code.co_name[:2] == '__' == frame.f_code.co_name[-2:] and \
+ frame.f_code.co_name <> '__init__':
+ return
+ if self.botframe is None:
+ # First call of dispatch since reset()
+ self.botframe = frame.f_back # xxx !!! added f_back
+ return self.trace_dispatch
+ if not (self.stop_here(frame) or self.break_anywhere(frame)):
+ # No need to trace this function
+ return # None
+ self.user_call(frame, arg)
+ if self.quitting:
+ raise bdb.BdbQuit
+ return self.trace_dispatch
+
+ def set_continue(self):
+ # Don't stop except at breakpoints or when finished
+ self.stopframe = self.botframe
+ self.returnframe = None
+ self.quitting = 0
+ # unlike in bdb/pdb, there's a chance that breakpoints change
+ # *while* a program (this program ;-) is running. It's actually quite likely.
+ # So we don't delete frame.f_trace until the bottom frame if there are no breakpoints.
+
+ def set_break(self, filename, lineno):
+ if not self.breaks.has_key(filename):
+ self.breaks[filename] = []
+ list = self.breaks[filename]
+ if lineno in list:
+ return 'There is already a breakpoint there!'
+ list.append(lineno)
+ list.sort() # I want to keep them neatly sorted; easier for drawing
+ if hasattr(bdb, "Breakpoint"):
+ # 1.5.2b1 specific
+ bp = bdb.Breakpoint(filename, lineno, 0, None)
+ self.update_breaks(filename)
+
+ def clear_break(self, filename, lineno):
+ bdb.Bdb.clear_break(self, filename, lineno)
+ self.update_breaks(filename)
+
+ def clear_all_file_breaks(self, filename):
+ bdb.Bdb.clear_all_file_breaks(self, filename)
+ self.update_breaks(filename)
+
+ def clear_all_breaks(self):
+ bdb.Bdb.clear_all_breaks(self)
+ for editors in self.editors.values():
+ for editor in editors:
+ editor.drawbreakpoints()
+
+ # special
+
+ def toggle_break(self, filename, lineno):
+ if self.get_break(filename, lineno):
+ self.clear_break(filename, lineno)
+ else:
+ self.set_break(filename, lineno)
+
+ def clear_breaks_above(self, filename, above):
+ if not self.breaks.has_key(filename):
+ return 'There are no breakpoints in that file!'
+ for lineno in self.breaks[filename][:]:
+ if lineno > above:
+ self.breaks[filename].remove(lineno)
+ if not self.breaks[filename]:
+ del self.breaks[filename]
+
+ # editor stuff
+
+ def update_breaks(self, filename):
+ if self.breaksviewer:
+ self.breaksviewer.update()
+ if self.editors.has_key(filename):
+ for editor in self.editors[filename]:
+ if editor._debugger: # XXX
+ editor.drawbreakpoints()
+ else:
+ print 'xxx dead editor!'
+
+ def update_allbreaks(self):
+ if self.breaksviewer:
+ self.breaksviewer.update()
+ for filename in self.breaks.keys():
+ if self.editors.has_key(filename):
+ for editor in self.editors[filename]:
+ if editor._debugger: # XXX
+ editor.drawbreakpoints()
+ else:
+ print 'xxx dead editor!'
+
+ def register_editor(self, editor, filename):
+ if not filename:
+ return
+ if not self.editors.has_key(filename):
+ self.editors[filename] = [editor]
+ elif editor not in self.editors[filename]:
+ self.editors[filename].append(editor)
+
+ def unregister_editor(self, editor, filename):
+ if not filename:
+ return
+ try:
+ self.editors[filename].remove(editor)
+ if not self.editors[filename]:
+ del self.editors[filename]
+ # if this was an untitled window, clear the breaks.
+ if filename[:1] == '<' and filename[-1:] == '>' and \
+ self.breaks.has_key(filename):
+ self.clear_all_file_breaks(filename)
+ except (KeyError, ValueError):
+ pass
+
+
+class SourceViewer(W.PyEditor):
+
+ def __init__(self, *args, **kwargs):
+ apply(W.PyEditor.__init__, (self,) + args, kwargs)
+ self.bind('<click>', self.clickintercept)
+
+ def clickintercept(self, point, modifiers):
+ if self._parentwindow._currentwidget <> self and not self.pt_in_breaks(point):
+ self._parentwindow.xxx___select(self)
+ return 1
+
+ def _getviewrect(self):
+ l, t, r, b = self._bounds
+ if self._debugger:
+ return (l + 12, t + 2, r - 1, b - 2)
+ else:
+ return (l + 5, t + 2, r - 1, b - 2)
+
+ def select(self, onoff, isclick = 0):
+ if W.SelectableWidget.select(self, onoff):
+ return
+ self.SetPort()
+ #if onoff:
+ # self.ted.WEActivate()
+ #else:
+ # self.ted.WEDeactivate()
+ self.drawselframe(onoff)
+
+ def drawselframe(self, onoff):
+ pass
+
+
+class BreakpointsViewer:
+
+ def __init__(self, debugger):
+ self.debugger = debugger
+ import Lists
+ self.w = W.Window((300, 250), 'Breakpoints', minsize = (200, 200))
+ self.w.panes = W.HorizontalPanes((8, 8, -8, -32), (0.3, 0.7))
+ self.w.panes.files = W.List(None, callback = self.filehit) #, flags = Lists.lOnlyOne)
+ self.w.panes.gr = W.Group(None)
+ self.w.panes.gr.breaks = W.List((0, 0, -130, 0), callback = self.linehit) #, flags = Lists.lOnlyOne)
+ self.w.panes.gr.openbutton = W.Button((-80, 4, 0, 16), 'View\xc9', self.openbuttonhit)
+ self.w.panes.gr.deletebutton = W.Button((-80, 28, 0, 16), 'Delete', self.deletebuttonhit)
+
+ self.w.bind('<close>', self.close)
+ self.w.bind('backspace', self.w.panes.gr.deletebutton.push)
+
+ self.setup()
+ self.w.open()
+ self.w.panes.gr.openbutton.enable(0)
+ self.w.panes.gr.deletebutton.enable(0)
+ self.curfile = None
+
+ def deletebuttonhit(self):
+ if self.w._currentwidget == self.w.panes.files:
+ self.del_filename()
+ else:
+ self.del_number()
+ self.checkbuttons()
+
+ def del_number(self):
+ if self.curfile is None:
+ return
+ sel = self.w.panes.gr.breaks.getselectedobjects()
+ for lineno in sel:
+ self.debugger.clear_break(self.curfile, lineno)
+
+ def del_filename(self):
+ sel = self.w.panes.files.getselectedobjects()
+ for filename in sel:
+ self.debugger.clear_all_file_breaks(filename)
+ self.debugger.update_allbreaks()
+
+ def setup(self):
+ files = self.debugger.breaks.keys()
+ files.sort()
+ self.w.panes.files.set(files)
+
+ def close(self):
+ self.debugger.breaksviewer = None
+ self.debugger = None
+
+ def update(self):
+ sel = self.w.panes.files.getselectedobjects()
+ self.setup()
+ self.w.panes.files.setselectedobjects(sel)
+ sel = self.w.panes.files.getselection()
+ if len(sel) == 0 and self.curfile:
+ self.w.panes.files.setselectedobjects([self.curfile])
+ self.filehit(0)
+
+ def select(self):
+ self.w.select()
+
+ def selectfile(self, file):
+ self.w.panes.files.setselectedobjects([file])
+ self.filehit(0)
+
+ def openbuttonhit(self):
+ self.filehit(1)
+
+ def filehit(self, isdbl):
+ sel = self.w.panes.files.getselectedobjects()
+ if isdbl:
+ for filename in sel:
+ lineno = None
+ if filename == self.curfile:
+ linesel = self.w.panes.gr.breaks.getselectedobjects()
+ if linesel:
+ lineno = linesel[-1]
+ elif self.w.panes.gr.breaks:
+ lineno = self.w.panes.gr.breaks[0]
+ editor = self.w._parentwindow.parent.openscript(filename, lineno)
+ editor.showbreakpoints(1)
+ return
+ if len(sel) == 1:
+ file = sel[0]
+ filebreaks = self.debugger.breaks[file][:]
+ if self.curfile == file:
+ linesel = self.w.panes.gr.breaks.getselectedobjects()
+ self.w.panes.gr.breaks.set(filebreaks)
+ if self.curfile == file:
+ self.w.panes.gr.breaks.setselectedobjects(linesel)
+ self.curfile = file
+ else:
+ if len(sel) <> 0:
+ self.curfile = None
+ self.w.panes.gr.breaks.set([])
+ self.checkbuttons()
+
+ def linehit(self, isdbl):
+ if isdbl:
+ files = self.w.panes.files.getselectedobjects()
+ if len(files) <> 1:
+ return
+ filename = files[0]
+ linenos = self.w.panes.gr.breaks.getselectedobjects()
+ if not linenos:
+ return
+ lineno = linenos[-1]
+ editor = self.w._parentwindow.parent.openscript(filename, lineno)
+ editor.showbreakpoints(1)
+ self.checkbuttons()
+
+ def checkbuttons(self):
+ if self.w.panes.files.getselection():
+ self.w.panes.gr.openbutton.enable(1)
+ self.w._parentwindow.setdefaultbutton(self.w.panes.gr.openbutton)
+ if self.w._currentwidget == self.w.panes.files:
+ if self.w.panes.files.getselection():
+ self.w.panes.gr.deletebutton.enable(1)
+ else:
+ self.w.panes.gr.deletebutton.enable(0)
+ else:
+ if self.w.panes.gr.breaks.getselection():
+ self.w.panes.gr.deletebutton.enable(1)
+ else:
+ self.w.panes.gr.deletebutton.enable(0)
+ else:
+ self.w.panes.gr.openbutton.enable(0)
+ self.w.panes.gr.deletebutton.enable(0)
+
+
+class TracingMonitor(W.Widget):
+
+ def __init__(self, *args, **kwargs):
+ apply(W.Widget.__init__, (self,) + args, kwargs)
+ self.state = 0
+
+ def toggle(self):
+ if hasattr(self, "_parentwindow") and self._parentwindow is not None:
+ self.state = self.state % 2 + 1
+ port = Qd.GetPort()
+ self.SetPort()
+ self.draw()
+ Qd.SetPort(port)
+
+ def reset(self):
+ if self._parentwindow:
+ self.state = 0
+ port = Qd.GetPort()
+ self.SetPort()
+ self.draw()
+ Qd.SetPort(port)
+
+ def draw(self, visRgn = None):
+ if self.state == 2:
+ Qd.PaintOval(self._bounds)
+ else:
+ Qd.EraseOval(self._bounds)
+
+
+# convenience funcs
+
+def postmortem(exc_type, exc_value, tb):
+ d = getdebugger()
+ d.postmortem(exc_type, exc_value, tb)
+
+def start(bottomframe = None):
+ d = getdebugger()
+ d.start(bottomframe)
+
+def startfromhere():
+ d = getdebugger()
+ try:
+ raise 'spam'
+ except:
+ frame = sys.exc_traceback.tb_frame.f_back
+ d.start(frame)
+
+def startfrombottom():
+ d = getdebugger()
+ d.start(_getbottomframe(), 1)
+
+def stop():
+ d = getdebugger()
+ d.stop()
+
+def cont():
+ sys.settrace(None)
+ d = getdebugger()
+ d.set_continue_without_debugger()
+
+def _getbottomframe():
+ try:
+ raise 'spam'
+ except:
+ pass
+ frame = sys.exc_traceback.tb_frame
+ while 1:
+ if frame.f_code.co_name == 'mainloop' or frame.f_back is None:
+ break
+ frame = frame.f_back
+ return frame
+
+_debugger = None
+
+def getdebugger():
+ if not __debug__:
+ raise W.AlertError, "Can't debug in \"Optimize bytecode\" mode.\r(see \"Default startup options\" in EditPythonPreferences)"
+ global _debugger
+ if _debugger is None:
+ _debugger = Debugger()
+ return _debugger
--- /dev/null
+import aetools
+import Standard_Suite
+import Required_Suite
+import WWW_Suite
+import re
+import W
+import macfs
+import os
+import MacPrefs
+import MacOS
+import string
+
+if hasattr(WWW_Suite, "WWW_Suite"):
+ WWW = WWW_Suite.WWW_Suite
+else:
+ WWW = WWW_Suite.WorldWideWeb_suite_2c__as_defined_in_Spyglass_spec_2e_
+
+class WebBrowser(aetools.TalkTo,
+ Standard_Suite.Standard_Suite,
+ WWW):
+
+ def openfile(self, path, activate = 1):
+ if activate:
+ self.activate()
+ self.OpenURL("file:///" + string.join(string.split(path,':'), '/'))
+
+app = W.getapplication()
+
+#SIGNATURE='MSIE' # MS Explorer
+SIGNATURE='MOSS' # Netscape
+
+_titlepat = re.compile('<title>\([^<]*\)</title>')
+
+def sucktitle(path):
+ f = open(path)
+ text = f.read(1024) # assume the title is in the first 1024 bytes
+ f.close()
+ lowertext = string.lower(text)
+ matcher = _titlepat.search(lowertext)
+ if matcher:
+ return matcher.group(1)
+ return path
+
+def verifydocpath(docpath):
+ try:
+ tut = os.path.join(docpath, "tut")
+ lib = os.path.join(docpath, "lib")
+ ref = os.path.join(docpath, "ref")
+ for path in [tut, lib, ref]:
+ if not os.path.exists(path):
+ return 0
+ except:
+ return 0
+ return 1
+
+
+class TwoLineList(W.List):
+
+ LDEF_ID = 468
+
+ def createlist(self):
+ import List
+ self._calcbounds()
+ self.SetPort()
+ rect = self._bounds
+ rect = rect[0]+1, rect[1]+1, rect[2]-16, rect[3]-1
+ self._list = List.LNew(rect, (0, 0, 1, 0), (0, 28), self.LDEF_ID, self._parentwindow.wid,
+ 0, 1, 0, 1)
+ self.set(self.items)
+
+
+_resultscounter = 1
+
+class Results:
+
+ def __init__(self, hits):
+ global _resultscounter
+ hits = map(lambda (path, hits): (sucktitle(path), path, hits), hits)
+ hits.sort()
+ self.hits = hits
+ nicehits = map(
+ lambda (title, path, hits):
+ title + '\r' + string.join(
+ map(lambda (c, p): "%s (%d)" % (p, c), hits), ', '), hits)
+ nicehits.sort()
+ self.w = W.Window((440, 300), "Search results %d" % _resultscounter, minsize = (200, 100))
+ self.w.results = TwoLineList((-1, -1, 1, -14), nicehits, self.listhit)
+ self.w.open()
+ self.w.bind('return', self.listhit)
+ self.w.bind('enter', self.listhit)
+ _resultscounter = _resultscounter + 1
+ self.browser = None
+
+ def listhit(self, isdbl = 1):
+ if isdbl:
+ for i in self.w.results.getselection():
+ if self.browser is None:
+ self.browser = WebBrowser(SIGNATURE, start = 1)
+ self.browser.openfile(self.hits[i][1])
+
+class Status:
+
+ def __init__(self):
+ self.w = W.Dialog((440, 64), "Searching\xc9")
+ self.w.searching = W.TextBox((4, 4, -4, 16), "DevDev:PyPyDoc 1.5.1:ext:parseTupleAndKeywords.html")
+ self.w.hits = W.TextBox((4, 24, -4, 16), "Hits: 0")
+ self.w.canceltip = W.TextBox((4, 44, -4, 16), "Type cmd-period (.) to cancel.")
+ self.w.open()
+
+ def set(self, path, hits):
+ self.w.searching.set(path)
+ self.w.hits.set('Hits: ' + `hits`)
+ app.breathe()
+
+ def close(self):
+ self.w.close()
+
+
+def match(text, patterns, all):
+ hits = []
+ hitsappend = hits.append
+ stringcount = string.count
+ for pat in patterns:
+ c = stringcount(text, pat)
+ if c > 0:
+ hitsappend((c, pat))
+ elif all:
+ hits[:] = []
+ break
+ hits.sort()
+ hits.reverse()
+ return hits
+
+def dosearch(docpath, searchstring, settings):
+ (docpath, kind, case, word, tut, lib, ref, ext, api) = settings
+ books = [(tut, 'tut'), (lib, 'lib'), (ref, 'ref'), (ext, 'ext'), (api, 'api')]
+ if not case:
+ searchstring = string.lower(searchstring)
+
+ if kind == 1:
+ patterns = string.split(searchstring)
+ all = 1
+ elif kind == 2:
+ patterns = string.split(searchstring)
+ all = 0
+ else:
+ patterns = [searchstring]
+ all = 0 # not relevant
+
+ ospathjoin = os.path.join
+ stringlower = string.lower
+ status = Status()
+ statusset = status.set
+ _match = match
+ _open = open
+ hits = {}
+ try:
+ MacOS.EnableAppswitch(0)
+ try:
+ for do, name in books:
+ if not do:
+ continue
+ bookpath = ospathjoin(docpath, name)
+ if not os.path.exists(bookpath):
+ continue
+ files = os.listdir(bookpath)
+ for file in files:
+ fullpath = ospathjoin(bookpath, file)
+ if fullpath[-5:] <> '.html':
+ continue
+ statusset(fullpath, len(hits))
+ f = _open(fullpath)
+ text = f.read()
+ if not case:
+ text = stringlower(text)
+ f.close()
+ filehits = _match(text, patterns, all)
+ if filehits:
+ hits[fullpath] = filehits
+ finally:
+ MacOS.EnableAppswitch(-1)
+ status.close()
+ except KeyboardInterrupt:
+ pass
+ hits = hits.items()
+ hits.sort()
+ return hits
+
+
+class PyDocSearch:
+
+ def __init__(self):
+ prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
+ try:
+ (docpath, kind, case, word, tut, lib, ref, ext, api) = prefs.docsearchengine
+ except:
+ (docpath, kind, case, word, tut, lib, ref, ext, api) = prefs.docsearchengine = \
+ ("", 0, 0, 0, 1, 1, 0, 0, 0)
+
+ if docpath and not verifydocpath(docpath):
+ docpath = ""
+
+ self.w = W.Window((400, 200), "Search the Python Documentation")
+ self.w.searchtext = W.EditText((10, 10, -100, 20), callback = self.checkbuttons)
+ self.w.searchbutton = W.Button((-90, 12, 80, 16), "Search", self.search)
+ buttons = []
+
+ gutter = 10
+ width = 130
+ bookstart = width + 2 * gutter
+ self.w.phraseradio = W.RadioButton((10, 38, width, 16), "As a phrase", buttons)
+ self.w.allwordsradio = W.RadioButton((10, 58, width, 16), "All words", buttons)
+ self.w.anywordsradio = W.RadioButton((10, 78, width, 16), "Any word", buttons)
+ self.w.casesens = W.CheckBox((10, 98, width, 16), "Case sensitive")
+ self.w.wholewords = W.CheckBox((10, 118, width, 16), "Whole words")
+ self.w.tutorial = W.CheckBox((bookstart, 38, -10, 16), "Tutorial")
+ self.w.library = W.CheckBox((bookstart, 58, -10, 16), "Library reference")
+ self.w.langueref = W.CheckBox((bookstart, 78, -10, 16), "Lanuage reference manual")
+ self.w.extending = W.CheckBox((bookstart, 98, -10, 16), "Extending & embedding")
+ self.w.api = W.CheckBox((bookstart, 118, -10, 16), "C/C++ API")
+
+ self.w.setdocfolderbutton = W.Button((10, -30, 80, 16), "Set doc folder", self.setdocpath)
+
+ if docpath:
+ self.w.setdefaultbutton(self.w.searchbutton)
+ else:
+ self.w.setdefaultbutton(self.w.setdocfolderbutton)
+
+ self.docpath = docpath
+ if not docpath:
+ docpath = "(please select the Python html documentation folder)"
+ self.w.docfolder = W.TextBox((100, -28, -10, 16), docpath)
+
+ [self.w.phraseradio, self.w.allwordsradio, self.w.anywordsradio][kind].set(1)
+
+ self.w.casesens.set(case)
+ self.w.wholewords.set(word)
+ self.w.tutorial.set(tut)
+ self.w.library.set(lib)
+ self.w.langueref.set(ref)
+ self.w.extending.set(ext)
+ self.w.api.set(api)
+
+ self.w.open()
+ self.w.wholewords.enable(0)
+ self.w.bind('<close>', self.close)
+ self.w.searchbutton.enable(0)
+
+ def search(self):
+ hits = dosearch(self.docpath, self.w.searchtext.get(), self.getsettings())
+ if hits:
+ Results(hits)
+ elif hasattr(MacOS, 'SysBeep'):
+ MacOS.SysBeep(0)
+ #import PyBrowser
+ #PyBrowser.Browser(hits)
+
+ def setdocpath(self):
+ fss, ok = macfs.GetDirectory()
+ if ok:
+ docpath = fss.as_pathname()
+ if not verifydocpath(docpath):
+ W.Message("This does not seem to be a Python documentation folder...")
+ else:
+ self.docpath = docpath
+ self.w.docfolder.set(docpath)
+ self.w.setdefaultbutton(self.w.searchbutton)
+
+ def close(self):
+ prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
+ prefs.docsearchengine = self.getsettings()
+
+ def getsettings(self):
+ radiobuttons = [self.w.phraseradio, self.w.allwordsradio, self.w.anywordsradio]
+ for i in range(3):
+ if radiobuttons[i].get():
+ kind = i
+ break
+ docpath = self.docpath
+ case = self.w.casesens.get()
+ word = self.w.wholewords.get()
+ tut = self.w.tutorial.get()
+ lib = self.w.library.get()
+ ref = self.w.langueref.get()
+ ext = self.w.extending.get()
+ api = self.w.api.get()
+ return (docpath, kind, case, word, tut, lib, ref, ext, api)
+
+ def checkbuttons(self):
+ self.w.searchbutton.enable(not not self.w.searchtext.get())
--- /dev/null
+# copyright 1996-2001 Just van Rossum, Letterror. just@letterror.com
+
+# keep this (__main__) as clean as possible, since we are using
+# it like the "normal" interpreter.
+
+__version__ = '1.0.1'
+
+
+def init():
+ import MacOS
+ MacOS.EnableAppswitch(-1)
+
+ import Qd, QuickDraw
+ Qd.SetCursor(Qd.GetCursor(QuickDraw.watchCursor).data)
+
+ import Res, sys, os
+ try:
+ Res.GetResource('DITL', 468)
+ except Res.Error:
+ # we're not an applet
+ Res.FSpOpenResFile(os.path.join(sys.exec_prefix, ":Mac:Tools:IDE:PythonIDE.rsrc"), 1)
+ Res.FSpOpenResFile(os.path.join(sys.exec_prefix, ":Mac:Tools:IDE:Widgets.rsrc"), 1)
+ ide_path = os.path.join(sys.exec_prefix, ":Mac:Tools:IDE")
+ else:
+ # we're an applet
+ try:
+ Res.GetResource('CURS', 468)
+ except Res.Error:
+ Res.FSpOpenResFile(os.path.join(sys.exec_prefix, ":Mac:Tools:IDE:Widgets.rsrc"), 1)
+ ide_path = os.path.join(sys.exec_prefix, ":Mac:Tools:IDE")
+ else:
+ # we're a full blown applet
+ ide_path = sys.argv[0]
+ if ide_path not in sys.path:
+ sys.path.insert(0, ide_path)
+
+
+init()
+del init
+
+import PythonIDEMain
--- /dev/null
+# copyright 1997-2000 Just van Rossum, Letterror. just@letterror.com
+
+import Splash
+
+import FrameWork
+import Wapplication
+import W
+import os
+import macfs
+
+
+class PythonIDE(Wapplication.Application):
+
+ def __init__(self):
+ self.preffilepath = ":Python:PythonIDE preferences"
+ Wapplication.Application.__init__(self, 'Pide')
+ import AE, AppleEvents
+
+ AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEOpenApplication,
+ self.ignoreevent)
+ AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEReopenApplication,
+ self.ignoreevent)
+ AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEPrintDocuments,
+ self.ignoreevent)
+ AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEOpenDocuments,
+ self.opendocsevent)
+ AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEQuitApplication,
+ self.quitevent)
+ import PyConsole, PyEdit
+ Splash.wait()
+ Splash.uninstall_importhook()
+ PyConsole.installoutput()
+ PyConsole.installconsole()
+ import sys
+ for path in sys.argv[1:]:
+ self.opendoc(path)
+ try:
+ import Wthreading
+ except ImportError:
+ self.mainloop()
+ else:
+ if Wthreading.haveThreading:
+ self.mainthread = Wthreading.Thread("IDE event loop", self.mainloop)
+ self.mainthread.start()
+ #self.mainthread.setResistant(1)
+ Wthreading.run()
+ else:
+ self.mainloop()
+
+ def makeusermenus(self):
+ m = Wapplication.Menu(self.menubar, "File")
+ newitem = FrameWork.MenuItem(m, "New", "N", 'new')
+ openitem = FrameWork.MenuItem(m, "Open\xc9", "O", 'open')
+ FrameWork.Separator(m)
+ closeitem = FrameWork.MenuItem(m, "Close", "W", 'close')
+ saveitem = FrameWork.MenuItem(m, "Save", "S", 'save')
+ saveasitem = FrameWork.MenuItem(m, "Save as\xc9", None, 'save_as')
+ FrameWork.Separator(m)
+ saveasappletitem = FrameWork.MenuItem(m, "Save as Applet\xc9", None, 'save_as_applet')
+ FrameWork.Separator(m)
+ quititem = FrameWork.MenuItem(m, "Quit", "Q", 'quit')
+
+ m = Wapplication.Menu(self.menubar, "Edit")
+ undoitem = FrameWork.MenuItem(m, "Undo", 'Z', "undo")
+ FrameWork.Separator(m)
+ cutitem = FrameWork.MenuItem(m, "Cut", 'X', "cut")
+ copyitem = FrameWork.MenuItem(m, "Copy", "C", "copy")
+ pasteitem = FrameWork.MenuItem(m, "Paste", "V", "paste")
+ FrameWork.MenuItem(m, "Clear", None, "clear")
+ FrameWork.Separator(m)
+ selallitem = FrameWork.MenuItem(m, "Select all", "A", "selectall")
+ sellineitem = FrameWork.MenuItem(m, "Select line", "L", "selectline")
+ FrameWork.Separator(m)
+ finditem = FrameWork.MenuItem(m, "Find\xc9", "F", "find")
+ findagainitem = FrameWork.MenuItem(m, "Find again", 'G', "findnext")
+ enterselitem = FrameWork.MenuItem(m, "Enter search string", "E", "entersearchstring")
+ replaceitem = FrameWork.MenuItem(m, "Replace", None, "replace")
+ replacefinditem = FrameWork.MenuItem(m, "Replace & find again", 'T', "replacefind")
+ FrameWork.Separator(m)
+ shiftleftitem = FrameWork.MenuItem(m, "Shift left", "[", "shiftleft")
+ shiftrightitem = FrameWork.MenuItem(m, "Shift right", "]", "shiftright")
+
+ m = Wapplication.Menu(self.menubar, "Python")
+ runitem = FrameWork.MenuItem(m, "Run window", "R", 'run')
+ runselitem = FrameWork.MenuItem(m, "Run selection", None, 'runselection')
+ FrameWork.Separator(m)
+ moditem = FrameWork.MenuItem(m, "Module browser\xc9", "M", self.domenu_modulebrowser)
+ FrameWork.Separator(m)
+ mm = FrameWork.SubMenu(m, "Preferences")
+ FrameWork.MenuItem(mm, "Set Scripts folder\xc9", None, self.do_setscriptsfolder)
+ FrameWork.MenuItem(mm, "Editor default settings\xc9", None, self.do_editorprefs)
+ FrameWork.MenuItem(mm, "Set default window font\xc9", None, self.do_setwindowfont)
+
+ self.openwindowsmenu = Wapplication.Menu(self.menubar, 'Windows')
+ self.makeopenwindowsmenu()
+ self._menustocheck = [closeitem, saveitem, saveasitem, saveasappletitem,
+ undoitem, cutitem, copyitem, pasteitem,
+ selallitem, sellineitem,
+ finditem, findagainitem, enterselitem, replaceitem, replacefinditem,
+ shiftleftitem, shiftrightitem,
+ runitem, runselitem]
+
+ prefs = self.getprefs()
+ try:
+ fss, fss_changed = macfs.RawAlias(prefs.scriptsfolder).Resolve()
+ self.scriptsfolder = fss.NewAlias()
+ except:
+ path = os.path.join(os.getcwd(), ":Mac:IDE scripts")
+ if not os.path.exists(path):
+ path = os.path.join(os.getcwd(), "Scripts")
+ if not os.path.exists(path):
+ os.mkdir(path)
+ f = open(os.path.join(path, "Place your scripts here\xc9"), "w")
+ f.close()
+ fss = macfs.FSSpec(path)
+ self.scriptsfolder = fss.NewAlias()
+ self.scriptsfoldermodtime = fss.GetDates()[1]
+ else:
+ self.scriptsfoldermodtime = fss.GetDates()[1]
+ prefs.scriptsfolder = self.scriptsfolder.data
+ self._scripts = {}
+ self.scriptsmenu = None
+ self.makescriptsmenu()
+
+ def quitevent(self, theAppleEvent, theReply):
+ import AE
+ AE.AEInteractWithUser(50000000)
+ self._quit()
+
+ def suspendresume(self, onoff):
+ if onoff:
+ fss, fss_changed = self.scriptsfolder.Resolve()
+ modtime = fss.GetDates()[1]
+ if self.scriptsfoldermodtime <> modtime or fss_changed:
+ self.scriptsfoldermodtime = modtime
+ W.SetCursor('watch')
+ self.makescriptsmenu()
+
+ def ignoreevent(self, theAppleEvent, theReply):
+ pass
+
+ def opendocsevent(self, theAppleEvent, theReply):
+ W.SetCursor('watch')
+ import aetools
+ parameters, args = aetools.unpackevent(theAppleEvent)
+ docs = parameters['----']
+ if type(docs) <> type([]):
+ docs = [docs]
+ for doc in docs:
+ fss, a = doc.Resolve()
+ path = fss.as_pathname()
+ self.opendoc(path)
+
+ def opendoc(self, path):
+ fcreator, ftype = macfs.FSSpec(path).GetCreatorType()
+ if ftype == 'TEXT':
+ self.openscript(path)
+ else:
+ W.Message("Can't open file of type '%s'." % ftype)
+
+ def getabouttext(self):
+ return "About Python IDE\xc9"
+
+ def do_about(self, id, item, window, event):
+ Splash.about()
+
+ def do_setscriptsfolder(self, *args):
+ fss, ok = macfs.GetDirectory("Select Scripts Folder")
+ if ok:
+ prefs = self.getprefs()
+ alis = fss.NewAlias()
+ prefs.scriptsfolder = alis.data
+ self.scriptsfolder = alis
+ self.makescriptsmenu()
+ prefs.save()
+
+ def domenu_modulebrowser(self, *args):
+ W.SetCursor('watch')
+ import ModuleBrowser
+ ModuleBrowser.ModuleBrowser()
+
+ def domenu_open(self, *args):
+ fss, ok = macfs.StandardGetFile("TEXT")
+ if ok:
+ self.openscript(fss.as_pathname())
+
+ def domenu_new(self, *args):
+ W.SetCursor('watch')
+ import PyEdit
+ return PyEdit.Editor()
+
+ def makescriptsmenu(self):
+ W.SetCursor('watch')
+ if self._scripts:
+ for id, item in self._scripts.keys():
+ if self.menubar.menus.has_key(id):
+ m = self.menubar.menus[id]
+ m.delete()
+ self._scripts = {}
+ if self.scriptsmenu:
+ if hasattr(self.scriptsmenu, 'id') and self.menubar.menus.has_key(self.scriptsmenu.id):
+ self.scriptsmenu.delete()
+ self.scriptsmenu = FrameWork.Menu(self.menubar, "Scripts")
+ #FrameWork.MenuItem(self.scriptsmenu, "New script", None, self.domenu_new)
+ #self.scriptsmenu.addseparator()
+ fss, fss_changed = self.scriptsfolder.Resolve()
+ self.scriptswalk(fss.as_pathname(), self.scriptsmenu)
+
+ def makeopenwindowsmenu(self):
+ for i in range(len(self.openwindowsmenu.items)):
+ self.openwindowsmenu.menu.DeleteMenuItem(1)
+ self.openwindowsmenu.items = []
+ windows = []
+ self._openwindows = {}
+ for window in self._windows.keys():
+ title = window.GetWTitle()
+ if not title:
+ title = "<no title>"
+ windows.append((title, window))
+ windows.sort()
+ for title, window in windows:
+ if title == "Python Interactive": # ugly but useful hack by Joe Strout
+ shortcut = '0'
+ else:
+ shortcut = None
+ item = FrameWork.MenuItem(self.openwindowsmenu, title, shortcut, callback = self.domenu_openwindows)
+ self._openwindows[item.item] = window
+ self._openwindowscheckmark = 0
+ self.checkopenwindowsmenu()
+
+ def domenu_openwindows(self, id, item, window, event):
+ w = self._openwindows[item]
+ w.ShowWindow()
+ w.SelectWindow()
+
+ def domenu_quit(self):
+ self._quit()
+
+ def domenu_save(self, *args):
+ print "Save"
+
+ def _quit(self):
+ import PyConsole, PyEdit
+ PyConsole.console.writeprefs()
+ PyConsole.output.writeprefs()
+ PyEdit.searchengine.writeprefs()
+ for window in self._windows.values():
+ try:
+ rv = window.close() # ignore any errors while quitting
+ except:
+ rv = 0 # (otherwise, we can get stuck!)
+ if rv and rv > 0:
+ return
+ self.quitting = 1
+
+PythonIDE()
+
--- /dev/null
+import Dlg
+import Res
+
+splash = Dlg.GetNewDialog(468, -1)
+splash.DrawDialog()
+
+import Qd, TE, Fm, sys
+
+_real__import__ = None
+
+def install_importhook():
+ global _real__import__
+ import __builtin__
+ if _real__import__ is None:
+ _real__import__ = __builtin__.__import__
+ __builtin__.__import__ = my__import__
+
+def uninstall_importhook():
+ global _real__import__
+ if _real__import__ is not None:
+ import __builtin__
+ __builtin__.__import__ = _real__import__
+ _real__import__ = None
+
+_progress = 0
+
+_about_width = 440
+_about_height = 340
+
+def importing(module):
+ global _progress
+ Qd.SetPort(splash)
+ fontID = Fm.GetFNum("Python-Sans")
+ if not fontID:
+ fontID = geneva
+ Qd.TextFont(fontID)
+ Qd.TextSize(9)
+ labelrect = (35, _about_height - 35, _about_width - 35, _about_height - 19)
+ framerect = (35, _about_height - 19, _about_width - 35, _about_height - 11)
+ l, t, r, b = progrect = Qd.InsetRect(framerect, 1, 1)
+ if module:
+ TE.TETextBox('Importing: ' + module, labelrect, 0)
+ if not _progress:
+ Qd.FrameRect(framerect)
+ pos = min(r, l + ((r - l) * _progress) / 44)
+ Qd.PaintRect((l, t, pos, b))
+ _progress = _progress + 1
+ else:
+ Qd.EraseRect(labelrect)
+ Qd.PaintRect((l, t, pos, b))
+ Qd.QDFlushPortBuffer(splash.GetDialogWindow().GetWindowPort(), None)
+
+def my__import__(name, globals=None, locals=None, fromlist=None):
+ try:
+ return sys.modules[name]
+ except KeyError:
+ try:
+ importing(name)
+ except:
+ try:
+ rv = _real__import__(name)
+ finally:
+ uninstall_importhook()
+ return rv
+ return _real__import__(name)
+
+install_importhook()
+
+kHighLevelEvent = 23
+import Win
+from Fonts import *
+from QuickDraw import *
+from TextEdit import *
+import string
+import sys
+
+_keepsplashscreenopen = 0
+
+abouttext1 = """The Python Integrated Development Environment for the Macintosh\xaa
+Version: %s
+Copyright 1997-2001 Just van Rossum, Letterror. <just@letterror.com>
+Python %s
+%s
+See: <http://www.python.org/> for information and documentation."""
+
+flauwekul = [ "Goodday, Bruce.",
+ "What's new?",
+ "Nudge, nudge, say no more!",
+ "No, no sir, it's not dead. It's resting.",
+ "Albatros!",
+ "It's . . .",
+ "Is your name not Bruce, then?",
+ """But Mr F.G. Superman has a secret identity . . .
+when trouble strikes at any time . . .
+at any place . . . he is ready to become . . .
+Bicycle Repair Man!"""
+ ]
+
+def skipdoublereturns(text):
+ return string.replace(text, '\n\n', '\n')
+
+def nl2return(text):
+ return string.replace(text, '\n', '\r')
+
+def UpdateSplash(drawdialog = 0, what = 0):
+ if drawdialog:
+ splash.DrawDialog()
+ drawtext(what)
+ splash.GetDialogWindow().ValidWindowRect(splash.GetDialogPort().portRect)
+ Qd.QDFlushPortBuffer(splash.GetDialogWindow().GetWindowPort(), None)
+
+def drawtext(what = 0):
+ Qd.SetPort(splash)
+ fontID = Fm.GetFNum("Python-Sans")
+ if not fontID:
+ fontID = geneva
+ Qd.TextFont(fontID)
+ Qd.TextSize(9)
+ rect = (10, 115, _about_width - 10, _about_height - 30)
+ if not what:
+ import __main__
+ abouttxt = nl2return(abouttext1 % (
+ __main__.__version__, sys.version, skipdoublereturns(sys.copyright)))
+ else:
+ import random
+ abouttxt = nl2return(random.choice(flauwekul))
+ TE.TETextBox(abouttxt, rect, teJustCenter)
+
+UpdateSplash(1)
+
+def wait():
+ import Evt
+ import Events
+ global splash
+ try:
+ splash
+ except NameError:
+ return
+ Qd.InitCursor()
+ time = Evt.TickCount()
+ whattext = 0
+ drawtext(whattext)
+ while _keepsplashscreenopen:
+ ok, event = Evt.EventAvail(Events.highLevelEventMask)
+ if ok:
+ # got apple event, back to mainloop
+ break
+ ok, event = Evt.EventAvail(Events.mDownMask | Events.keyDownMask | Events.updateMask)
+ if ok:
+ ok, event = Evt.WaitNextEvent(Events.mDownMask | Events.keyDownMask | Events.updateMask, 30)
+ if ok:
+ (what, message, when, where, modifiers) = event
+ if what == Events.updateEvt:
+ if Win.WhichWindow(message) == splash:
+ UpdateSplash(1, whattext)
+ else:
+ break
+ if Evt.TickCount() - time > 360:
+ whattext = not whattext
+ drawtext(whattext)
+ time = Evt.TickCount()
+ del splash
+
+
+def about():
+ global splash, splashresfile, _keepsplashscreenopen
+ _keepsplashscreenopen = 1
+ splash = Dlg.GetNewDialog(468, -1)
+ splash.DrawDialog()
+ wait()
--- /dev/null
+import FrameWork
+import Win
+import Qd
+import Evt
+import MacOS
+import Events
+import traceback
+from types import *
+
+import Menu; MenuToolbox = Menu; del Menu
+
+
+class Application(FrameWork.Application):
+
+ def __init__(self, signature='Pyth'):
+ import W
+ W.setapplication(self, signature)
+ FrameWork.Application.__init__(self)
+ self._suspended = 0
+ self.quitting = 0
+ self.debugger_quitting = 1
+ self.DebuggerQuit = 'DebuggerQuitDummyException'
+ self._idlefuncs = []
+ # map certain F key codes to equivalent command-letter combos (JJS)
+ self.fkeymaps = {122:"z", 120:"x", 99:"c", 118:"v"}
+
+ def mainloop(self, mask=FrameWork.everyEvent, wait=None):
+ import W
+ self.quitting = 0
+ saveyield = MacOS.EnableAppswitch(-1)
+ try:
+ while not self.quitting:
+ try:
+ self.do1event(mask, wait)
+ except W.AlertError, detail:
+ MacOS.EnableAppswitch(-1)
+ W.Message(detail)
+ except self.DebuggerQuit:
+ MacOS.EnableAppswitch(-1)
+ except:
+ MacOS.EnableAppswitch(-1)
+ import PyEdit
+ PyEdit.tracebackwindow.traceback()
+ finally:
+ MacOS.EnableAppswitch(1)
+
+ def debugger_mainloop(self, mask=FrameWork.everyEvent, wait=None):
+ import W
+ self.debugger_quitting = 0
+ saveyield = MacOS.EnableAppswitch(-1)
+ try:
+ while not self.quitting and not self.debugger_quitting:
+ try:
+ self.do1event(mask, wait)
+ except W.AlertError, detail:
+ W.Message(detail)
+ except:
+ import PyEdit
+ PyEdit.tracebackwindow.traceback()
+ finally:
+ MacOS.EnableAppswitch(saveyield)
+
+ def breathe(self, wait=1):
+ import W
+ ok, event = Evt.WaitNextEvent(FrameWork.updateMask |
+ FrameWork.mDownMask | FrameWork.osMask |
+ FrameWork.activMask,
+ wait)
+ if ok:
+ (what, message, when, where, modifiers) = event
+ #print FrameWork.eventname[what]
+ if FrameWork.eventname[what] == 'mouseDown':
+ partcode, wid = Win.FindWindow(where)
+ if FrameWork.partname[partcode] <> 'inDesk':
+ return
+ else:
+ W.SetCursor('watch')
+ self.dispatch(event)
+
+ def refreshwindows(self, wait=1):
+ import W
+ while 1:
+ ok, event = Evt.WaitNextEvent(FrameWork.updateMask, wait)
+ if not ok:
+ break
+ self.dispatch(event)
+
+ def addidlefunc(self, func):
+ self._idlefuncs.append(func)
+
+ def removeidlefunc(self, func):
+ self._idlefuncs.remove(func)
+
+ def idle(self, event):
+ if not self._suspended:
+ if not self.do_frontWindowMethod("idle", event):
+ Qd.InitCursor()
+ if self._idlefuncs:
+ for func in self._idlefuncs:
+ try:
+ func()
+ except:
+ import sys
+ sys.stderr.write("exception in idle function %s; killed:\n" % `func`)
+ traceback.print_exc()
+ self._idlefuncs.remove(func)
+ break
+
+ def do_frontWindowMethod(self, attr, *args):
+ wid = Win.FrontWindow()
+ if wid and self._windows.has_key(wid):
+ window = self._windows[wid]
+ if hasattr(window, attr):
+ handler = getattr(window, attr)
+ apply(handler, args)
+ return 1
+
+ def appendwindow(self, wid, window):
+ self._windows[wid] = window
+ self.makeopenwindowsmenu()
+
+ def removewindow(self, wid):
+ del self._windows[wid]
+ self.makeopenwindowsmenu()
+
+ def makeopenwindowsmenu(self):
+ # dummy; could be the full version from PythonIDEMain.py
+ self._openwindows = {}
+ self._openwindowscheckmark = 0
+ if not hasattr(self, "_menustocheck"):
+ self._menustocheck = []
+
+ def do_key(self, event):
+ (what, message, when, where, modifiers) = event
+ ch = chr(message & FrameWork.charCodeMask)
+ rest = message & ~FrameWork.charCodeMask
+ keycode = (message & FrameWork.keyCodeMask) >> 8
+ if keycode in self.fkeymaps.keys(): # JJS
+ ch = self.fkeymaps[keycode]
+ modifiers = modifiers | FrameWork.cmdKey
+ wid = Win.FrontWindow()
+ if modifiers & FrameWork.cmdKey and not modifiers & FrameWork.shiftKey:
+ if wid and self._windows.has_key(wid):
+ self.checkmenus(self._windows[wid])
+ else:
+ self.checkmenus(None)
+ event = (what, ord(ch) | rest, when, where, modifiers)
+ result = MenuToolbox.MenuKey(ord(ch))
+ id = (result>>16) & 0xffff # Hi word
+ item = result & 0xffff # Lo word
+ if id:
+ self.do_rawmenu(id, item, None, event)
+ return # here! we had a menukey!
+ #else:
+ # print "XXX Command-" +`ch`
+ # See whether the front window wants it
+ if wid and self._windows.has_key(wid):
+ window = self._windows[wid]
+ try:
+ do_char = window.do_char
+ except AttributeError:
+ do_char = self.do_char
+ do_char(ch, event)
+ # else it wasn't for us, sigh...
+
+ def do_inMenuBar(self, partcode, window, event):
+ Qd.InitCursor()
+ (what, message, when, where, modifiers) = event
+ self.checkopenwindowsmenu()
+ wid = Win.FrontWindow()
+ if wid and self._windows.has_key(wid):
+ self.checkmenus(self._windows[wid])
+ else:
+ self.checkmenus(None)
+ result = MenuToolbox.MenuSelect(where)
+ id = (result>>16) & 0xffff # Hi word
+ item = result & 0xffff # Lo word
+ self.do_rawmenu(id, item, window, event)
+
+ def do_updateEvt(self, event):
+ (what, message, when, where, modifiers) = event
+ wid = Win.WhichWindow(message)
+ if wid and self._windows.has_key(wid):
+ window = self._windows[wid]
+ window.do_rawupdate(wid, event)
+ else:
+ if wid:
+ wid.HideWindow()
+ import sys
+ sys.stderr.write("XXX killed unknown (crashed?) Python window.\n")
+ else:
+ MacOS.HandleEvent(event)
+
+ def suspendresume(self, onoff):
+ pass
+
+ def do_suspendresume(self, event):
+ self._suspended = not event[1] & 1
+ FrameWork.Application.do_suspendresume(self, event)
+
+ def checkopenwindowsmenu(self):
+ if self._openwindowscheckmark:
+ self.openwindowsmenu.menu.CheckMenuItem(self._openwindowscheckmark, 0)
+ window = Win.FrontWindow()
+ if window:
+ for item, wid in self._openwindows.items():
+ if wid == window:
+ #self.pythonwindowsmenuitem.check(1)
+ self.openwindowsmenu.menu.CheckMenuItem(item, 1)
+ self._openwindowscheckmark = item
+ break
+ else:
+ self._openwindowscheckmark = 0
+ #if self._openwindows:
+ # self.pythonwindowsmenuitem.enable(1)
+ #else:
+ # self.pythonwindowsmenuitem.enable(0)
+
+ def checkmenus(self, window):
+ for item in self._menustocheck:
+ callback = item.menu.items[item.item-1][2]
+ if type(callback) <> StringType:
+ item.enable(1)
+ elif hasattr(window, "domenu_" + callback):
+ if hasattr(window, "can_" + callback):
+ canhandler = getattr(window, "can_" + callback)
+ if canhandler(item):
+ item.enable(1)
+ else:
+ item.enable(0)
+ else:
+ item.enable(1)
+ else:
+ item.enable(0)
+
+ def enablemenubar(self, onoff):
+ for m in self.menubar.menus.values():
+ if onoff:
+ m.menu.EnableMenuItem(0)
+ elif m.menu.GetMenuItemText(3) <> 'Cut': # ew...
+ m.menu.DisableMenuItem(0)
+ MenuToolbox.DrawMenuBar()
+
+ def makemenubar(self):
+ self.menubar = MenuBar(self)
+ FrameWork.AppleMenu(self.menubar, self.getabouttext(), self.do_about)
+ self.makeusermenus()
+
+ def scriptswalk(self, top, menu, done=None):
+ if done is None:
+ done = {}
+ if done.has_key(top):
+ return
+ done[top] = 1
+ import os, macfs, string
+ try:
+ names = os.listdir(top)
+ except os.error:
+ FrameWork.MenuItem(menu, '(Scripts Folder not found)', None, None)
+ return
+ savedir = os.getcwd()
+ os.chdir(top)
+ for name in names:
+ if name == "CVS":
+ continue
+ try:
+ fss, isdir, isalias = macfs.ResolveAliasFile(name)
+ except:
+ # maybe a broken alias
+ continue
+ path = fss.as_pathname()
+ if done.has_key(path):
+ continue
+ name = string.strip(name)
+ if name[-3:] == '---':
+ menu.addseparator()
+ elif isdir:
+ submenu = FrameWork.SubMenu(menu, name)
+ self.scriptswalk(path, submenu, done)
+ else:
+ creator, type = fss.GetCreatorType()
+ if type == 'TEXT':
+ if name[-3:] == '.py':
+ name = name[:-3]
+ item = FrameWork.MenuItem(menu, name, None, self.domenu_script)
+ self._scripts[(menu.id, item.item)] = path
+ done[path] = 1
+ os.chdir(savedir)
+
+ def domenu_script(self, id, item, window, event):
+ (what, message, when, where, modifiers) = event
+ path = self._scripts[(id, item)]
+ import os
+ if not os.path.exists(path):
+ self.makescriptsmenu()
+ import W
+ raise W.AlertError, "File not found."
+ if ord(Evt.GetKeys()[7]) & 4:
+ self.openscript(path)
+ else:
+ import W, MacOS, sys
+ W.SetCursor("watch")
+ sys.argv = [path]
+ #cwd = os.getcwd()
+ #os.chdir(os.path.dirname(path) + ':')
+ try:
+ # xxx if there is a script window for this file,
+ # exec in that window's namespace.
+ # xxx what to do when it's not saved???
+ # promt to save?
+ MacOS.EnableAppswitch(0)
+ execfile(path, {'__name__': '__main__', '__file__': path})
+ except W.AlertError, detail:
+ MacOS.EnableAppswitch(-1)
+ raise W.AlertError, detail
+ except KeyboardInterrupt:
+ MacOS.EnableAppswitch(-1)
+ except:
+ MacOS.EnableAppswitch(-1)
+ import PyEdit
+ PyEdit.tracebackwindow.traceback(1)
+ else:
+ MacOS.EnableAppswitch(-1)
+ #os.chdir(cwd)
+
+ def openscript(self, filename, lineno=None, charoffset=0, modname=""):
+ import os, PyEdit, W
+ editor = self.getscript(filename)
+ if editor:
+ editor.select()
+ elif os.path.exists(filename):
+ editor = PyEdit.Editor(filename)
+ elif filename[-3:] == '.py' or filename[-4:] == '.pyc':
+ import imp
+ if not modname:
+ if filename[-1] == 'c':
+ modname = os.path.basename(filename)[:-4]
+ else:
+ modname = os.path.basename(filename)[:-3]
+ try:
+ # XXX This does not work correctly with packages!
+ # XXX The docs say we should do it manually, pack, then sub, then sub2 etc.
+ # XXX It says we should use imp.load_module(), but that *reloads* a package,
+ # XXX and that's the last thing we want here.
+ f, filename, (suff, mode, dummy) = imp.find_module(modname)
+ except ImportError:
+ raise W.AlertError, "Can't find file for \"%s\"" % modname
+ else:
+ if not f:
+ raise W.AlertError, "Can't find file for \"%s\"" % modname
+ f.close()
+ if suff == '.py':
+ self.openscript(filename, lineno, charoffset)
+ return
+ else:
+ raise W.AlertError, "Can't find file for \"%s\"" % modname
+ else:
+ raise W.AlertError, "Can't find file \"%s\"" % filename
+ if lineno is not None:
+ editor.selectline(lineno, charoffset)
+ return editor
+
+ def getscript(self, filename):
+ if filename[:1] == '<' and filename[-1:] == '>':
+ filename = filename[1:-1]
+ import string
+ lowpath = string.lower(filename)
+ for wid, window in self._windows.items():
+ if hasattr(window, "path") and type(window.path) == StringType and \
+ lowpath == string.lower(window.path):
+ return window
+ elif hasattr(window, "path") and filename == wid.GetWTitle():
+ return window
+
+ def getprefs(self):
+ import MacPrefs
+ return MacPrefs.GetPrefs(self.preffilepath)
+
+ def do_editorprefs(self, *args):
+ import PyEdit
+ PyEdit.EditorDefaultSettings()
+
+ def do_setwindowfont(self, *args):
+ import FontSettings, W
+ prefs = self.getprefs()
+ settings = FontSettings.FontDialog(prefs.defaultfont)
+ if settings:
+ prefs.defaultfont, tabsettings = settings
+ raise W.AlertError, "Note that changes will only affect new windows!"
+
+
+
+class MenuBar(FrameWork.MenuBar):
+
+ possibleIDs = range(10, 256)
+
+ def getnextid(self):
+ id = self.possibleIDs[0]
+ del self.possibleIDs[0]
+ return id
+
+ def __init__(self, parent = None):
+ self.bar = MenuToolbox.GetMenuBar()
+ MenuToolbox.ClearMenuBar()
+ self.menus = {}
+ self.parent = parent
+
+ def dispatch(self, id, item, window, event):
+ if self.menus.has_key(id):
+ self.menus[id].dispatch(id, item, window, event)
+
+ def delmenu(self, id):
+ MenuToolbox.DeleteMenu(id)
+ if id in self.possibleIDs:
+ print "XXX duplicate menu ID!", id
+ self.possibleIDs.append(id)
+
+
+class Menu(FrameWork.Menu):
+
+ def dispatch(self, id, item, window, event):
+ title, shortcut, callback, kind = self.items[item-1]
+ if type(callback) == StringType:
+ callback = self._getmenuhandler(callback)
+ if callback:
+ import W
+ W.CallbackCall(callback, 0, id, item, window, event)
+
+ def _getmenuhandler(self, callback):
+ menuhandler = None
+ wid = Win.FrontWindow()
+ if wid and self.bar.parent._windows.has_key(wid):
+ window = self.bar.parent._windows[wid]
+ if hasattr(window, "domenu_" + callback):
+ menuhandler = getattr(window, "domenu_" + callback)
+ elif hasattr(self.bar.parent, "domenu_" + callback):
+ menuhandler = getattr(self.bar.parent, "domenu_" + callback)
+ elif hasattr(self.bar.parent, "domenu_" + callback):
+ menuhandler = getattr(self.bar.parent, "domenu_" + callback)
+ return menuhandler
+
--- /dev/null
+import Qd
+import TE
+import Fm
+import waste
+import WASTEconst
+import Res
+import Evt
+import Events
+import Scrap
+import string
+
+import Win
+import Wbase
+import Wkeys
+import Wcontrols
+import PyFontify
+from types import *
+import Fonts
+import TextEdit
+
+
+
+class TextBox(Wbase.Widget):
+
+ """A static text widget"""
+
+ def __init__(self, possize, text="", align=TextEdit.teJustLeft,
+ fontsettings=None,
+ backgroundcolor=(0xffff, 0xffff, 0xffff)
+ ):
+ if fontsettings is None:
+ import W
+ fontsettings = W.getdefaultfont()
+ Wbase.Widget.__init__(self, possize)
+ self.fontsettings = fontsettings
+ self.text = text
+ self.align = align
+ self._backgroundcolor = backgroundcolor
+
+ def draw(self, visRgn = None):
+ if self._visible:
+ (font, style, size, color) = self.fontsettings
+ fontid = GetFNum(font)
+ savestate = Qd.GetPenState()
+ Qd.TextFont(fontid)
+ Qd.TextFace(style)
+ Qd.TextSize(size)
+ Qd.RGBForeColor(color)
+ Qd.RGBBackColor(self._backgroundcolor)
+ TE.TETextBox(self.text, self._bounds, self.align)
+ Qd.RGBBackColor((0xffff, 0xffff, 0xffff))
+ Qd.SetPenState(savestate)
+
+ def get(self):
+ return self.text
+
+ def set(self, text):
+ self.text = text
+ if self._parentwindow and self._parentwindow.wid:
+ self.SetPort()
+ self.draw()
+
+
+class _ScrollWidget:
+
+ # to be overridden
+ def getscrollbarvalues(self):
+ return None, None
+
+ # internal method
+ def updatescrollbars(self):
+ vx, vy = self.getscrollbarvalues()
+ if self._parent._barx:
+ if vx <> None:
+ self._parent._barx.enable(1)
+ self._parent._barx.set(vx)
+ else:
+ self._parent._barx.enable(0)
+ if self._parent._bary:
+ if vy <> None:
+ self._parent._bary.enable(1)
+ self._parent._bary.set(vy)
+ else:
+ self._parent._bary.enable(0)
+
+
+UNDOLABELS = [ # Indexed by WEGetUndoInfo() value
+ None, "", "typing", "Cut", "Paste", "Clear", "Drag", "Style",
+ "Ruler", "backspace", "delete", "transform", "resize"]
+
+
+class EditText(Wbase.SelectableWidget, _ScrollWidget):
+
+ """A text edit widget, mainly for simple entry fields."""
+
+ def __init__(self, possize, text="",
+ callback=None, inset=(3, 3),
+ fontsettings=None,
+ tabsettings = (32, 0),
+ readonly = 0):
+ if fontsettings is None:
+ import W
+ fontsettings = W.getdefaultfont()
+ Wbase.SelectableWidget.__init__(self, possize)
+ self.temptext = text
+ self.ted = None
+ self.selection = None
+ self._callback = callback
+ self.changed = 0
+ self.selchanged = 0
+ self._selected = 0
+ self._enabled = 1
+ self.wrap = 1
+ self.readonly = readonly
+ self.fontsettings = fontsettings
+ self.tabsettings = tabsettings
+ if type(inset) <> TupleType:
+ self.inset = (inset, inset)
+ else:
+ self.inset = inset
+
+ def open(self):
+ if not hasattr(self._parent, "_barx"):
+ self._parent._barx = None
+ if not hasattr(self._parent, "_bary"):
+ self._parent._bary = None
+ self._calcbounds()
+ self.SetPort()
+ viewrect, destrect = self._calctextbounds()
+ flags = self._getflags()
+ self.ted = waste.WENew(destrect, viewrect, flags)
+ self.ted.WEInstallTabHooks()
+ self.ted.WESetAlignment(WASTEconst.weFlushLeft)
+ self.setfontsettings(self.fontsettings)
+ self.settabsettings(self.tabsettings)
+ self.ted.WEUseText(Res.Resource(self.temptext))
+ self.ted.WECalText()
+ if self.selection:
+ self.setselection(self.selection[0], self.selection[1])
+ self.selection = None
+ else:
+ self.selview()
+ self.temptext = None
+ self.updatescrollbars()
+ self.bind("pageup", self.scrollpageup)
+ self.bind("pagedown", self.scrollpagedown)
+ self.bind("top", self.scrolltop)
+ self.bind("bottom", self.scrollbottom)
+ self.selchanged = 0
+
+ def close(self):
+ self._parent._barx = None
+ self._parent._bary = None
+ self.ted = None
+ self.temptext = None
+ Wbase.SelectableWidget.close(self)
+
+ def gettabsettings(self):
+ return self.tabsettings
+
+ def settabsettings(self, (tabsize, tabmode)):
+ self.tabsettings = (tabsize, tabmode)
+ if hasattr(self.ted, "WESetTabSize"):
+ port = self._parentwindow.wid.GetWindowPort()
+ if tabmode:
+ (font, style, size, color) = self.getfontsettings()
+ savesettings = GetPortFontSettings(port)
+ SetPortFontSettings(port, (font, style, size))
+ tabsize = Qd.StringWidth(' ' * tabsize)
+ SetPortFontSettings(port, savesettings)
+ tabsize = max(tabsize, 1)
+ self.ted.WESetTabSize(tabsize)
+ self.SetPort()
+ Qd.EraseRect(self.ted.WEGetViewRect())
+ self.ted.WEUpdate(port.visRgn)
+
+ def getfontsettings(self):
+ import Res
+ (font, style, size, color) = self.ted.WEGetRunInfo(0)[4]
+ font = Fm.GetFontName(font)
+ return (font, style, size, color)
+
+ def setfontsettings(self, (font, style, size, color)):
+ self.SetPort()
+ if type(font) <> StringType:
+ font = Fm.GetFontName(font)
+ self.fontsettings = (font, style, size, color)
+ fontid = GetFNum(font)
+ readonly = self.ted.WEFeatureFlag(WASTEconst.weFReadOnly, -1)
+ if readonly:
+ self.ted.WEFeatureFlag(WASTEconst.weFReadOnly, 0)
+ try:
+ self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 1)
+ selstart, selend = self.ted.WEGetSelection()
+ self.ted.WESetSelection(0, self.ted.WEGetTextLength())
+ self.ted.WESetStyle(WASTEconst.weDoFace, (0, 0, 0, (0, 0, 0)))
+ self.ted.WESetStyle(WASTEconst.weDoFace |
+ WASTEconst.weDoColor |
+ WASTEconst.weDoFont |
+ WASTEconst.weDoSize,
+ (fontid, style, size, color))
+ self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 0)
+ self.ted.WECalText()
+ self.ted.WESetSelection(selstart, selend)
+ finally:
+ if readonly:
+ self.ted.WEFeatureFlag(WASTEconst.weFReadOnly, 1)
+ viewrect = self.ted.WEGetViewRect()
+ Qd.EraseRect(viewrect)
+ self.ted.WEUpdate(self._parentwindow.wid.GetWindowPort().visRgn)
+ self.selchanged = 1
+ self.updatescrollbars()
+
+ def adjust(self, oldbounds):
+ self.SetPort()
+ if self._selected and self._parentwindow._hasselframes:
+ self.GetWindow().InvalWindowRect(Qd.InsetRect(oldbounds, -3, -3))
+ self.GetWindow().InvalWindowRect(Qd.InsetRect(self._bounds, -3, -3))
+ else:
+ self.GetWindow().InvalWindowRect(oldbounds)
+ self.GetWindow().InvalWindowRect(self._bounds)
+ viewrect, destrect = self._calctextbounds()
+ self.ted.WESetViewRect(viewrect)
+ self.ted.WESetDestRect(destrect)
+ if self.wrap:
+ self.ted.WECalText()
+ if self.ted.WEGetDestRect()[3] < viewrect[1]:
+ self.selview()
+ self.updatescrollbars()
+
+ # interface -----------------------
+ # selection stuff
+ def selview(self):
+ self.ted.WESelView()
+
+ def selectall(self):
+ self.ted.WESetSelection(0, self.ted.WEGetTextLength())
+ self.selchanged = 1
+ self.updatescrollbars()
+
+ def selectline(self, lineno, charoffset = 0):
+ newselstart, newselend = self.ted.WEGetLineRange(lineno)
+ # Autoscroll makes the *end* of the selection visible, which,
+ # in the case of a whole line, is the beginning of the *next* line.
+ # So sometimes it leaves our line just above the view rect.
+ # Let's fool Waste by initially selecting one char less:
+ self.ted.WESetSelection(newselstart + charoffset, newselend-1)
+ self.ted.WESetSelection(newselstart + charoffset, newselend)
+ self.selchanged = 1
+ self.updatescrollbars()
+
+ def getselection(self):
+ if self.ted:
+ return self.ted.WEGetSelection()
+ else:
+ return self.selection
+
+ def setselection(self, selstart, selend):
+ self.selchanged = 1
+ if self.ted:
+ self.ted.WESetSelection(selstart, selend)
+ self.ted.WESelView()
+ self.updatescrollbars()
+ else:
+ self.selection = selstart, selend
+
+ def offsettoline(self, offset):
+ return self.ted.WEOffsetToLine(offset)
+
+ def countlines(self):
+ return self.ted.WECountLines()
+
+ def getselectedtext(self):
+ selstart, selend = self.ted.WEGetSelection()
+ return self.ted.WEGetText().data[selstart:selend]
+
+ def expandselection(self):
+ oldselstart, oldselend = self.ted.WEGetSelection()
+ selstart, selend = min(oldselstart, oldselend), max(oldselstart, oldselend)
+ if selstart <> selend and chr(self.ted.WEGetChar(selend-1)) == '\r':
+ selend = selend - 1
+ newselstart, dummy = self.ted.WEFindLine(selstart, 1)
+ dummy, newselend = self.ted.WEFindLine(selend, 1)
+ if oldselstart <> newselstart or oldselend <> newselend:
+ self.ted.WESetSelection(newselstart, newselend)
+ self.updatescrollbars()
+ self.selchanged = 1
+
+ def insert(self, text):
+ self.ted.WEInsert(text, None, None)
+ self.changed = 1
+ self.selchanged = 1
+
+ # text
+ def set(self, text):
+ if not self.ted:
+ self.temptext = text
+ else:
+ self.ted.WEUseText(Res.Resource(text))
+ self.ted.WECalText()
+ self.SetPort()
+ viewrect, destrect = self._calctextbounds()
+ self.ted.WESetViewRect(viewrect)
+ self.ted.WESetDestRect(destrect)
+ rgn = Qd.NewRgn()
+ Qd.RectRgn(rgn, viewrect)
+ Qd.EraseRect(viewrect)
+ self.draw(rgn)
+ #self.GetWindow().InvalWindowRect(self.ted.WEGetViewRect())
+ self.updatescrollbars()
+
+ def get(self):
+ if not self._parent:
+ return self.temptext
+ else:
+ return self.ted.WEGetText().data
+
+ # events
+ def key(self, char, event):
+ (what, message, when, where, modifiers) = event
+ if self._enabled and not modifiers & Events.cmdKey or char in Wkeys.arrowkeys:
+ self.ted.WEKey(ord(char), modifiers)
+ if char not in Wkeys.navigationkeys:
+ self.changed = 1
+ if char not in Wkeys.scrollkeys:
+ self.selchanged = 1
+ self.updatescrollbars()
+ if self._callback:
+ Wbase.CallbackCall(self._callback, 0, char, modifiers)
+
+ def click(self, point, modifiers):
+ if not self._enabled:
+ return
+ self.ted.WEClick(point, modifiers, Evt.TickCount())
+ self.selchanged = 1
+ self.updatescrollbars()
+ return 1
+
+ def idle(self):
+ self.SetPort()
+ self.ted.WEIdle()
+
+ def rollover(self, point, onoff):
+ if onoff:
+ Wbase.SetCursor("iBeam")
+
+ def activate(self, onoff):
+ self._activated = onoff
+ if self._selected and self._visible:
+ if onoff:
+ self.ted.WEActivate()
+ else:
+ self.ted.WEDeactivate()
+ if self._selected:
+ self.drawselframe(onoff)
+
+ def select(self, onoff, isclick = 0):
+ if Wbase.SelectableWidget.select(self, onoff):
+ return
+ self.SetPort()
+ if onoff:
+ self.ted.WEActivate()
+ if self._parentwindow._tabbable and not isclick:
+ self.selectall()
+ else:
+ self.ted.WEDeactivate()
+ self.drawselframe(onoff)
+
+ def draw(self, visRgn = None):
+ if self._visible:
+ if not visRgn:
+ visRgn = self._parentwindow.wid.GetWindowPort().visRgn
+ self.ted.WEUpdate(visRgn)
+ if self._selected and self._activated:
+ self.drawselframe(1)
+ Qd.FrameRect(self._bounds)
+
+ # scrolling
+ def scrollpageup(self):
+ if self._parent._bary and self._parent._bary._enabled:
+ self.vscroll("++")
+
+ def scrollpagedown(self):
+ if self._parent._bary and self._parent._bary._enabled:
+ self.vscroll("--")
+
+ def scrolltop(self):
+ if self._parent._bary and self._parent._bary._enabled:
+ self.vscroll(0)
+ if self._parent._barx and self._parent._barx._enabled:
+ self.hscroll(0)
+
+ def scrollbottom(self):
+ if self._parent._bary and self._parent._bary._enabled:
+ self.vscroll(32767)
+
+ # menu handlers
+ def domenu_copy(self, *args):
+ selbegin, selend = self.ted.WEGetSelection()
+ if selbegin == selend:
+ return
+ Scrap.ZeroScrap()
+ self.ted.WECopy()
+ self.updatescrollbars()
+
+ def domenu_cut(self, *args):
+ selbegin, selend = self.ted.WEGetSelection()
+ if selbegin == selend:
+ return
+ Scrap.ZeroScrap()
+ self.ted.WECut()
+ self.updatescrollbars()
+ self.selview()
+ self.changed = 1
+ self.selchanged = 1
+ if self._callback:
+ Wbase.CallbackCall(self._callback, 0, "", None)
+
+ def domenu_paste(self, *args):
+ if not self.ted.WECanPaste():
+ return
+ self.selview()
+ self.ted.WEPaste()
+ self.updatescrollbars()
+ self.changed = 1
+ self.selchanged = 1
+ if self._callback:
+ Wbase.CallbackCall(self._callback, 0, "", None)
+
+ def domenu_clear(self, *args):
+ self.ted.WEDelete()
+ self.selview()
+ self.updatescrollbars()
+ self.changed = 1
+ self.selchanged = 1
+ if self._callback:
+ Wbase.CallbackCall(self._callback, 0, "", None)
+
+ def domenu_undo(self, *args):
+ which, redo = self.ted.WEGetUndoInfo()
+ if not which:
+ return
+ self.ted.WEUndo()
+ self.updatescrollbars()
+ self.changed = 1
+ self.selchanged = 1
+ if self._callback:
+ Wbase.CallbackCall(self._callback, 0, "", None)
+
+ def can_undo(self, menuitem):
+ #doundo = self.ted.WEFeatureFlag(WASTEconst.weFUndo, -1)
+ #print doundo
+ #if not doundo:
+ # return 0
+ which, redo = self.ted.WEGetUndoInfo()
+ if which < len(UNDOLABELS):
+ which = UNDOLABELS[which]
+ else:
+ which = ""
+ if which == None:
+ return None
+ if redo:
+ which = "Redo "+which
+ else:
+ which = "Undo "+which
+ menuitem.settext(which)
+ return 1
+
+ def domenu_selectall(self, *args):
+ self.selectall()
+
+ # private
+ def getscrollbarvalues(self):
+ dr = self.ted.WEGetDestRect()
+ vr = self.ted.WEGetViewRect()
+ vx = Wcontrols._scalebarvalue(dr[0], dr[2], vr[0], vr[2])
+ vy = Wcontrols._scalebarvalue(dr[1], dr[3], vr[1], vr[3])
+ return vx, vy
+
+ def vscroll(self, value):
+ lineheight = self.ted.WEGetHeight(0, 1)
+ dr = self.ted.WEGetDestRect()
+ vr = self.ted.WEGetViewRect()
+ destheight = dr[3] - dr[1]
+ viewheight = vr[3] - vr[1]
+ viewoffset = maxdelta = vr[1] - dr[1]
+ mindelta = vr[3] - dr[3]
+ if value == "+":
+ delta = lineheight
+ elif value == "-":
+ delta = - lineheight
+ elif value == "++":
+ delta = viewheight - lineheight
+ elif value == "--":
+ delta = lineheight - viewheight
+ else: # in thumb
+ cur = (32767L * viewoffset) / (destheight - viewheight)
+ delta = (cur-value)*(destheight - viewheight)/32767
+ if abs(delta - viewoffset) <=2:
+ # compensate for irritating rounding error
+ delta = viewoffset
+ delta = min(maxdelta, delta)
+ delta = max(mindelta, delta)
+ self.ted.WEScroll(0, delta)
+ self.updatescrollbars()
+
+ def hscroll(self, value):
+ dr = self.ted.WEGetDestRect()
+ vr = self.ted.WEGetViewRect()
+ destwidth = dr[2] - dr[0]
+ viewwidth = vr[2] - vr[0]
+ viewoffset = maxdelta = vr[0] - dr[0]
+ mindelta = vr[2] - dr[2]
+ if value == "+":
+ delta = 32
+ elif value == "-":
+ delta = - 32
+ elif value == "++":
+ delta = 0.5 * (vr[2] - vr[0])
+ elif value == "--":
+ delta = 0.5 * (vr[0] - vr[2])
+ else: # in thumb
+ cur = (32767 * viewoffset) / (destwidth - viewwidth)
+ delta = (cur-value)*(destwidth - viewwidth)/32767
+ if abs(delta - viewoffset) <=2:
+ # compensate for irritating rounding error
+ delta = viewoffset
+ delta = min(maxdelta, delta)
+ delta = max(mindelta, delta)
+ self.ted.WEScroll(delta, 0)
+ self.updatescrollbars()
+
+ # some internals
+ def _getflags(self):
+ flags = WASTEconst.weDoAutoScroll | WASTEconst.weDoMonoStyled
+ if self.readonly:
+ flags = flags | WASTEconst.weDoReadOnly
+ else:
+ flags = flags | WASTEconst.weDoUndo
+ return flags
+
+ def _getviewrect(self):
+ return Qd.InsetRect(self._bounds, self.inset[0], self.inset[1])
+
+ def _calctextbounds(self):
+ viewrect = l, t, r, b = self._getviewrect()
+ if self.ted:
+ dl, dt, dr, db = self.ted.WEGetDestRect()
+ vl, vt, vr, vb = self.ted.WEGetViewRect()
+ yshift = t - vt
+ if (db - dt) < (b - t):
+ destrect = viewrect
+ else:
+ destrect = l, dt + yshift, r, db + yshift
+ else:
+ destrect = viewrect
+ return viewrect, destrect
+
+
+class TextEditor(EditText):
+
+ """A text edit widget."""
+
+ def __init__(self, possize, text="", callback=None, wrap=1, inset=(4, 4),
+ fontsettings=None,
+ tabsettings=(32, 0),
+ readonly=0):
+ EditText.__init__(self, possize, text, callback, inset, fontsettings, tabsettings, readonly)
+ self.wrap = wrap
+
+ def _getflags(self):
+ flags = WASTEconst.weDoAutoScroll | WASTEconst.weDoMonoStyled | \
+ WASTEconst.weDoOutlineHilite
+ if self.readonly:
+ flags = flags | WASTEconst.weDoReadOnly
+ else:
+ flags = flags | WASTEconst.weDoUndo
+ return flags
+
+ def _getviewrect(self):
+ l, t, r, b = self._bounds
+ return (l + 5, t + 2, r, b - 2)
+
+ def _calctextbounds(self):
+ if self.wrap:
+ return EditText._calctextbounds(self)
+ else:
+ viewrect = l, t, r, b = self._getviewrect()
+ if self.ted:
+ dl, dt, dr, db = self.ted.WEGetDestRect()
+ vl, vt, vr, vb = self.ted.WEGetViewRect()
+ xshift = l - vl
+ yshift = t - vt
+ if (db - dt) < (b - t):
+ yshift = t - dt
+ destrect = (dl + xshift, dt + yshift, dr + xshift, db + yshift)
+ else:
+ destrect = (l, t, r + 5000, b)
+ return viewrect, destrect
+
+ def draw(self, visRgn = None):
+ if self._visible:
+ if not visRgn:
+ visRgn = self._parentwindow.wid.GetWindowPort().visRgn
+ self.ted.WEUpdate(visRgn)
+ if self._selected and self._activated:
+ self.drawselframe(1)
+
+
+import re
+commentPat = re.compile("[ \t]*(#)")
+indentPat = re.compile("[ \t]*")
+
+
+class PyEditor(TextEditor):
+
+ """A specialized Python source edit widget"""
+
+ def __init__(self, possize, text="", callback=None, inset=(4, 4),
+ fontsettings=None,
+ tabsettings=(32, 0),
+ readonly=0,
+ debugger=None,
+ file=''):
+ TextEditor.__init__(self, possize, text, callback, 0, inset, fontsettings, tabsettings, readonly)
+ self.bind("cmd[", self.domenu_shiftleft)
+ self.bind("cmd]", self.domenu_shiftright)
+ self.bind("cmdshift[", self.domenu_uncomment)
+ self.bind("cmdshift]", self.domenu_comment)
+ self.file = file # only for debugger reference
+ self._debugger = debugger
+ if debugger:
+ debugger.register_editor(self, self.file)
+
+ def domenu_shiftleft(self):
+ self.expandselection()
+ selstart, selend = self.ted.WEGetSelection()
+ selstart, selend = min(selstart, selend), max(selstart, selend)
+ snippet = self.getselectedtext()
+ lines = string.split(snippet, '\r')
+ for i in range(len(lines)):
+ if lines[i][:1] == '\t':
+ lines[i] = lines[i][1:]
+ snippet = string.join(lines, '\r')
+ self.insert(snippet)
+ self.ted.WESetSelection(selstart, selstart + len(snippet))
+
+ def domenu_shiftright(self):
+ self.expandselection()
+ selstart, selend = self.ted.WEGetSelection()
+ selstart, selend = min(selstart, selend), max(selstart, selend)
+ snippet = self.getselectedtext()
+ lines = string.split(snippet, '\r')
+ for i in range(len(lines) - (not lines[-1])):
+ lines[i] = '\t' + lines[i]
+ snippet = string.join(lines, '\r')
+ self.insert(snippet)
+ self.ted.WESetSelection(selstart, selstart + len(snippet))
+
+ def domenu_uncomment(self):
+ self.expandselection()
+ selstart, selend = self.ted.WEGetSelection()
+ selstart, selend = min(selstart, selend), max(selstart, selend)
+ snippet = self.getselectedtext()
+ lines = string.split(snippet, '\r')
+ for i in range(len(lines)):
+ m = commentPat.match(lines[i])
+ if m:
+ pos = m.start(1)
+ lines[i] = lines[i][:pos] + lines[i][pos+1:]
+ snippet = string.join(lines, '\r')
+ self.insert(snippet)
+ self.ted.WESetSelection(selstart, selstart + len(snippet))
+
+ def domenu_comment(self):
+ self.expandselection()
+ selstart, selend = self.ted.WEGetSelection()
+ selstart, selend = min(selstart, selend), max(selstart, selend)
+ snippet = self.getselectedtext()
+ lines = string.split(snippet, '\r')
+ indent = 3000 # arbitrary large number...
+ for line in lines:
+ if string.strip(line):
+ m = indentPat.match(line)
+ if m:
+ indent = min(indent, m.regs[0][1])
+ else:
+ indent = 0
+ break
+ for i in range(len(lines) - (not lines[-1])):
+ lines[i] = lines[i][:indent] + "#" + lines[i][indent:]
+ snippet = string.join(lines, '\r')
+ self.insert(snippet)
+ self.ted.WESetSelection(selstart, selstart + len(snippet))
+
+ def setfile(self, file):
+ self.file = file
+
+ def set(self, text, file = ''):
+ oldfile = self.file
+ self.file = file
+ if self._debugger:
+ self._debugger.unregister_editor(self, oldfile)
+ self._debugger.register_editor(self, file)
+ TextEditor.set(self, text)
+
+ def close(self):
+ if self._debugger:
+ self._debugger.unregister_editor(self, self.file)
+ self._debugger = None
+ TextEditor.close(self)
+
+ def click(self, point, modifiers):
+ if not self._enabled:
+ return
+ if self._debugger and self.pt_in_breaks(point):
+ self.breakhit(point, modifiers)
+ elif self._debugger:
+ bl, bt, br, bb = self._getbreakrect()
+ Qd.EraseRect((bl, bt, br-1, bb))
+ TextEditor.click(self, point, modifiers)
+ self.drawbreakpoints()
+ else:
+ TextEditor.click(self, point, modifiers)
+ if self.ted.WEGetClickCount() >= 3:
+ # select block with our indent
+ lines = string.split(self.get(), '\r')
+ selstart, selend = self.ted.WEGetSelection()
+ lineno = self.ted.WEOffsetToLine(selstart)
+ tabs = 0
+ line = lines[lineno]
+ while line[tabs:] and line[tabs] == '\t':
+ tabs = tabs + 1
+ tabstag = '\t' * tabs
+ fromline = 0
+ toline = len(lines)
+ if tabs:
+ for i in range(lineno - 1, -1, -1):
+ line = lines[i]
+ if line[:tabs] <> tabstag:
+ fromline = i + 1
+ break
+ for i in range(lineno + 1, toline):
+ line = lines[i]
+ if line[:tabs] <> tabstag:
+ toline = i - 1
+ break
+ selstart, dummy = self.ted.WEGetLineRange(fromline)
+ dummy, selend = self.ted.WEGetLineRange(toline)
+ self.ted.WESetSelection(selstart, selend)
+
+ def breakhit(self, point, modifiers):
+ if not self.file:
+ return
+ destrect = self.ted.WEGetDestRect()
+ offset, edge = self.ted.WEGetOffset(point)
+ lineno = self.ted.WEOffsetToLine(offset) + 1
+ if point[1] <= destrect[3]:
+ self._debugger.clear_breaks_above(self.file, self.countlines())
+ self._debugger.toggle_break(self.file, lineno)
+ else:
+ self._debugger.clear_breaks_above(self.file, lineno)
+
+ def key(self, char, event):
+ (what, message, when, where, modifiers) = event
+ if modifiers & Events.cmdKey and not char in Wkeys.arrowkeys:
+ return
+ if char == '\r':
+ selstart, selend = self.ted.WEGetSelection()
+ selstart, selend = min(selstart, selend), max(selstart, selend)
+ lastchar = chr(self.ted.WEGetChar(selstart-1))
+ if lastchar <> '\r' and selstart:
+ pos, dummy = self.ted.WEFindLine(selstart, 0)
+ lineres = Res.Resource('')
+ self.ted.WECopyRange(pos, selstart, lineres, None, None)
+ line = lineres.data + '\n'
+ tabcount = self.extratabs(line)
+ self.ted.WEKey(ord('\r'), 0)
+ for i in range(tabcount):
+ self.ted.WEKey(ord('\t'), 0)
+ else:
+ self.ted.WEKey(ord('\r'), 0)
+ elif char in ')]}':
+ self.ted.WEKey(ord(char), modifiers)
+ self.balanceparens(char)
+ else:
+ self.ted.WEKey(ord(char), modifiers)
+ if char not in Wkeys.navigationkeys:
+ self.changed = 1
+ self.selchanged = 1
+ self.updatescrollbars()
+
+ def balanceparens(self, char):
+ if char == ')':
+ target = '('
+ elif char == ']':
+ target = '['
+ elif char == '}':
+ target = '{'
+ recursionlevel = 1
+ selstart, selend = self.ted.WEGetSelection()
+ count = min(selstart, selend) - 2
+ mincount = max(0, count - 2048)
+ lastquote = None
+ while count > mincount:
+ testchar = chr(self.ted.WEGetChar(count))
+ if testchar in "\"'" and chr(self.ted.WEGetChar(count - 1)) <> '\\':
+ if lastquote == testchar:
+ recursionlevel = recursionlevel - 1
+ lastquote = None
+ elif not lastquote:
+ recursionlevel = recursionlevel + 1
+ lastquote = testchar
+ elif not lastquote and testchar == char:
+ recursionlevel = recursionlevel + 1
+ elif not lastquote and testchar == target:
+ recursionlevel = recursionlevel - 1
+ if recursionlevel == 0:
+ import time
+ autoscroll = self.ted.WEFeatureFlag(WASTEconst.weFAutoScroll, -1)
+ if autoscroll:
+ self.ted.WEFeatureFlag(WASTEconst.weFAutoScroll, 0)
+ self.ted.WESetSelection(count, count + 1)
+ time.sleep(0.2)
+ self.ted.WESetSelection(selstart, selend)
+ if autoscroll:
+ self.ted.WEFeatureFlag(WASTEconst.weFAutoScroll, 1)
+ break
+ count = count - 1
+
+ def extratabs(self, line):
+ tabcount = 0
+ for c in line:
+ if c <> '\t':
+ break
+ tabcount = tabcount + 1
+ last = 0
+ cleanline = ''
+ tags = PyFontify.fontify(line)
+ # strip comments and strings
+ for tag, start, end, sublist in tags:
+ if tag in ('string', 'comment'):
+ cleanline = cleanline + line[last:start]
+ last = end
+ cleanline = cleanline + line[last:]
+ cleanline = string.strip(cleanline)
+ if cleanline and cleanline[-1] == ':':
+ tabcount = tabcount + 1
+ else:
+ # extra indent after unbalanced (, [ or {
+ for open, close in (('(', ')'), ('[', ']'), ('{', '}')):
+ count = string.count(cleanline, open)
+ if count and count > string.count(cleanline, close):
+ tabcount = tabcount + 2
+ break
+ return tabcount
+
+ def rollover(self, point, onoff):
+ if onoff:
+ if self._debugger and self.pt_in_breaks(point):
+ Wbase.SetCursor("arrow")
+ else:
+ Wbase.SetCursor("iBeam")
+
+ def draw(self, visRgn = None):
+ TextEditor.draw(self, visRgn)
+ if self._debugger:
+ self.drawbreakpoints()
+
+ def showbreakpoints(self, onoff):
+ if (not not self._debugger) <> onoff:
+ if onoff:
+ if not __debug__:
+ import W
+ raise W.AlertError, "Can't debug in \"Optimize bytecode\" mode.\r(see \"Default startup options\" in EditPythonPreferences)"
+ import PyDebugger
+ self._debugger = PyDebugger.getdebugger()
+ self._debugger.register_editor(self, self.file)
+ elif self._debugger:
+ self._debugger.unregister_editor(self, self.file)
+ self._debugger = None
+ self.adjust(self._bounds)
+
+ def togglebreakpoints(self):
+ self.showbreakpoints(not self._debugger)
+
+ def clearbreakpoints(self):
+ if self.file:
+ self._debugger.clear_all_file_breaks(self.file)
+
+ def editbreakpoints(self):
+ if self._debugger:
+ self._debugger.edit_breaks()
+ self._debugger.breaksviewer.selectfile(self.file)
+
+ def drawbreakpoints(self, eraseall = 0):
+ breakrect = bl, bt, br, bb = self._getbreakrect()
+ br = br - 1
+ self.SetPort()
+ Qd.PenPat(Qd.qd.gray)
+ Qd.PaintRect((br, bt, br + 1, bb))
+ Qd.PenNormal()
+ self._parentwindow.tempcliprect(breakrect)
+ Qd.RGBForeColor((0xffff, 0, 0))
+ try:
+ lasttop = bt
+ self_ted = self.ted
+ Qd_PaintOval = Qd.PaintOval
+ Qd_EraseRect = Qd.EraseRect
+ for lineno in self._debugger.get_file_breaks(self.file):
+ start, end = self_ted.WEGetLineRange(lineno - 1)
+ if lineno <> self_ted.WEOffsetToLine(start) + 1:
+ # breakpoints beyond our text: erase rest, and back out
+ Qd_EraseRect((bl, lasttop, br, bb))
+ break
+ (x, y), h = self_ted.WEGetPoint(start, 0)
+ bottom = y + h
+ #print y, (lasttop, bottom)
+ if bottom > lasttop:
+ Qd_EraseRect((bl, lasttop, br, y + h * eraseall))
+ lasttop = bottom
+ redbullet = bl + 2, y + 3, bl + 8, y + 9
+ Qd_PaintOval(redbullet)
+ else:
+ Qd_EraseRect((bl, lasttop, br, bb))
+ Qd.RGBForeColor((0, 0, 0))
+ finally:
+ self._parentwindow.restoreclip()
+
+ def updatescrollbars(self):
+ if self._debugger:
+ self.drawbreakpoints(1)
+ TextEditor.updatescrollbars(self)
+
+ def pt_in_breaks(self, point):
+ return Qd.PtInRect(point, self._getbreakrect())
+
+ def _getbreakrect(self):
+ if self._debugger:
+ l, t, r, b = self._bounds
+ return (l+1, t+1, l + 12, b-1)
+ else:
+ return (0, 0, 0, 0)
+
+ def _getviewrect(self):
+ l, t, r, b = self._bounds
+ if self._debugger:
+ return (l + 17, t + 2, r, b - 2)
+ else:
+ return (l + 5, t + 2, r, b - 2)
+
+ def _calctextbounds(self):
+ viewrect = l, t, r, b = self._getviewrect()
+ if self.ted:
+ dl, dt, dr, db = self.ted.WEGetDestRect()
+ vl, vt, vr, vb = self.ted.WEGetViewRect()
+ xshift = l - vl
+ yshift = t - vt
+ if (db - dt) < (b - t):
+ yshift = t - dt
+ destrect = (dl + xshift, dt + yshift, dr + xshift, db + yshift)
+ else:
+ destrect = (l, t, r + 5000, b)
+ return viewrect, destrect
+
+
+def GetFNum(fontname):
+ """Same as Fm.GetFNum(), but maps a missing font to Monaco instead of the system font."""
+ if fontname <> Fm.GetFontName(0):
+ fontid = Fm.GetFNum(fontname)
+ if fontid == 0:
+ fontid = Fonts.monaco
+ else:
+ fontid = 0
+ return fontid
+
+# b/w compat. Anyone using this?
+GetFName = Fm.GetFontName
+
+def GetPortFontSettings(port):
+ return Fm.GetFontName(port.txFont), port.txFace, port.txSize
+
+def SetPortFontSettings(port, (font, face, size)):
+ saveport = Qd.GetPort()
+ Qd.SetPort(port)
+ Qd.TextFont(GetFNum(font))
+ Qd.TextFace(face)
+ Qd.TextSize(size)
+ Qd.SetPort(saveport)
--- /dev/null
+import Qd
+import Win
+import Evt
+import Fm
+import FrameWork
+import Windows
+import Events
+import Wbase
+import Dlg
+import MacOS
+import Menu
+import struct
+import traceback
+
+from types import *
+
+
+class Window(FrameWork.Window, Wbase.SelectableWidget):
+
+ windowkind = Windows.documentProc
+
+ def __init__(self, possize, title="", minsize=None, maxsize=None,
+ tabbable=1, show=1, fontsettings=None):
+ import W
+ if fontsettings is None:
+ fontsettings = W.getdefaultfont()
+ self._fontsettings = fontsettings
+ W.SelectableWidget.__init__(self, possize)
+ self._globalbounds = l, t, r, b = self.getwindowbounds(possize, minsize)
+ self._bounds = (0, 0, r - l, b - t)
+ self._tabchain = []
+ self._currentwidget = None
+ self.title = title
+ self._parentwindow = self
+ self._tabbable = tabbable
+ self._defaultbutton = None
+ self._drawwidgetbounds = 0
+ self._show = show
+ self._lastrollover = None
+ self.hasclosebox = 1
+ # XXX the following is not really compatible with the
+ # new (system >= 7.5) window procs.
+ if minsize:
+ self._hasgrowbox = 1
+ self.windowkind = self.windowkind | 8
+ l, t = minsize
+ if maxsize:
+ r, b = maxsize[0] + 1, maxsize[1] + 1
+ else:
+ r, b = 32000, 32000
+ self.growlimit = (l, t, r, b)
+ else:
+ self._hasgrowbox = 0
+ if (self.windowkind == 0 or self.windowkind >= 8) and self.windowkind < 1000:
+ self.windowkind = self.windowkind | 4
+ FrameWork.Window.__init__(self, W.getapplication())
+
+ def gettitle(self):
+ return self.title
+
+ def settitle(self, title):
+ self.title = title
+ if self.wid:
+ self.wid.SetWTitle(title)
+
+ def getwindowbounds(self, size, minsize = None):
+ return windowbounds(size, minsize)
+
+ def getcurrentwidget(self):
+ return self._currentwidget
+
+ def show(self, onoff):
+ if onoff:
+ self.wid.ShowWindow()
+ else:
+ self.wid.HideWindow()
+
+ def isvisible(self):
+ return self.wid.IsWindowVisible()
+
+ def select(self):
+ self.wid.SelectWindow()
+ # not sure if this is the best place, I need it when
+ # an editor gets selected, and immediately scrolled
+ # to a certain line, waste scroll assumes everything
+ # to be in tact.
+ self.do_rawupdate(self.wid, "DummyEvent")
+
+ def open(self):
+ self.wid = Win.NewCWindow(self._globalbounds, self.title, self._show,
+ self.windowkind, -1, self.hasclosebox, 0)
+ self.SetPort()
+ fontname, fontstyle, fontsize, fontcolor = self._fontsettings
+ fnum = Fm.GetFNum(fontname)
+ if fnum == 0:
+ fnum = Fm.GetFNum("Geneva")
+ Qd.TextFont(fnum)
+ Qd.TextFace(fontstyle)
+ Qd.TextSize(fontsize)
+ if self._bindings.has_key("<open>"):
+ callback = self._bindings["<open>"]
+ callback()
+ for w in self._widgets:
+ w.forall_frombottom("open")
+ self._maketabchain()
+ if self._tabbable:
+ self.bind('tab', self.nextwidget)
+ self.bind('shifttab', self.previouswidget)
+ else:
+ self._hasselframes = 0
+ if self._tabchain:
+ self._tabchain[0].select(1)
+ self.do_postopen()
+
+ def close(self):
+ if not self.wid:
+ return # we are already closed
+ if self._bindings.has_key("<close>"):
+ callback = self._bindings["<close>"]
+ try:
+ rv = callback()
+ except:
+ print 'error in <close> callback'
+ traceback.print_exc()
+ else:
+ if rv:
+ return rv
+ #for key in self._widgetsdict.keys():
+ # self._removewidget(key)
+ self.forall_butself("close")
+ Wbase.SelectableWidget.close(self)
+ self._tabchain = []
+ self._currentwidget = None
+ self.wid.HideWindow()
+ self.do_postclose()
+
+ def domenu_close(self, *args):
+ self.close()
+
+ def getbounds(self):
+ return self._globalbounds
+
+ def setbounds(self, bounds):
+ l, t, r, b = bounds
+ self.move(l, t)
+ self.resize(r-l, b-t)
+
+ def move(self, x, y = None):
+ """absolute move"""
+ if y == None:
+ x, y = x
+ self.wid.MoveWindow(x, y, 0)
+
+ def resize(self, x, y = None):
+ if not self._hasgrowbox:
+ return # hands off!
+ if y == None:
+ x, y = x
+ self.SetPort()
+ self.GetWindow().InvalWindowRect(self.getgrowrect())
+ self.wid.SizeWindow(x, y, 1)
+ self._calcbounds()
+
+ def test(self, point):
+ return 1
+
+ def draw(self, visRgn = None):
+ if self._hasgrowbox:
+ self.tempcliprect(self.getgrowrect())
+ self.wid.DrawGrowIcon()
+ self.restoreclip()
+
+ def idle(self, *args):
+ self.SetPort()
+ point = Evt.GetMouse()
+ widget = self.findwidget(point, 0)
+ if self._bindings.has_key("<idle>"):
+ callback = self._bindings["<idle>"]
+ if callback():
+ return
+ if self._currentwidget is not None and hasattr(self._currentwidget, "idle"):
+ if self._currentwidget._bindings.has_key("<idle>"):
+ callback = self._currentwidget._bindings["<idle>"]
+ if callback():
+ return
+ if self._currentwidget.idle():
+ return
+ if widget is not None and hasattr(widget, "rollover"):
+ if 1: #self._lastrollover <> widget:
+ if self._lastrollover:
+ self._lastrollover.rollover(point, 0)
+ self._lastrollover = widget
+ self._lastrollover.rollover(point, 1)
+ else:
+ if self._lastrollover:
+ self._lastrollover.rollover(point, 0)
+ self._lastrollover = None
+ Wbase.SetCursor("arrow")
+
+ def xxx___select(self, widget):
+ if self._currentwidget == widget:
+ return
+ if self._bindings.has_key("<select>"):
+ callback = self._bindings["<select>"]
+ if callback(widget):
+ return
+ if widget is None:
+ if self._currentwidget is not None:
+ self._currentwidget.select(0)
+ elif type(widget) == InstanceType and widget._selectable:
+ widget.select(1)
+ elif widget == -1 or widget == 1:
+ if len(self._tabchain) <= 1:
+ return
+ temp = self._tabchain[(self._tabchain.index(self._currentwidget) + widget) % len(self._tabchain)]
+ temp.select(1)
+ else:
+ raise TypeError, "Widget is not selectable"
+
+ def setdefaultbutton(self, newdefaultbutton = None, *keys):
+ if newdefaultbutton == self._defaultbutton:
+ return
+ if self._defaultbutton:
+ self._defaultbutton._setdefault(0)
+ if not newdefaultbutton:
+ self.bind("return", None)
+ self.bind("enter", None)
+ return
+ import Wcontrols
+ if not isinstance(newdefaultbutton, Wcontrols.Button):
+ raise TypeError, "widget is not a button"
+ self._defaultbutton = newdefaultbutton
+ self._defaultbutton._setdefault(1)
+ if not keys:
+ self.bind("return", self._defaultbutton.push)
+ self.bind("enter", self._defaultbutton.push)
+ else:
+ for key in keys:
+ self.bind(key, self._defaultbutton.push)
+
+ def nextwidget(self):
+ self.xxx___select(1)
+
+ def previouswidget(self):
+ self.xxx___select(-1)
+
+ def drawwidgetbounds(self, onoff):
+ self._drawwidgetbounds = onoff
+ self.SetPort()
+ self.GetWindow().InvalWindowRect(self._bounds)
+
+ def _drawbounds(self):
+ pass
+
+ def _maketabchain(self):
+ # XXX This has to change, it's no good when we are adding or deleting widgets.
+ # XXX Perhaps we shouldn't keep a "tabchain" at all.
+ self._hasselframes = 0
+ self._collectselectablewidgets(self._widgets)
+ if self._hasselframes and len(self._tabchain) > 1:
+ self._hasselframes = 1
+ else:
+ self._hasselframes = 0
+
+ def _collectselectablewidgets(self, widgets):
+ import W
+ for w in widgets:
+ if w._selectable:
+ self._tabchain.append(w)
+ if isinstance(w, W.List):
+ self._hasselframes = 1
+ self._collectselectablewidgets(w._widgets)
+
+ def _calcbounds(self):
+ self._possize = self.wid.GetWindowPort().portRect[2:]
+ w, h = self._possize
+ self._bounds = (0, 0, w, h)
+ self.wid.GetWindowContentRgn(scratchRegion)
+ l, t, r, b = GetRgnBounds(scratchRegion)
+ self._globalbounds = l, t, l + w, t + h
+ for w in self._widgets:
+ w._calcbounds()
+
+ # FrameWork override methods
+ def do_inDrag(self, partcode, window, event):
+ where = event[3]
+ self.wid.GetWindowContentRgn(scratchRegion)
+ was_l, was_t, r, b = GetRgnBounds(scratchRegion)
+ window.DragWindow(where, self.draglimit)
+ self.wid.GetWindowContentRgn(scratchRegion)
+ is_l, is_t, r, b = GetRgnBounds(scratchRegion)
+ self._globalbounds = Qd.OffsetRect(self._globalbounds,
+ is_l - was_l, is_t - was_t)
+
+ def do_char(self, char, event):
+ import Wkeys
+ (what, message, when, where, modifiers) = event
+ key = char
+ if Wkeys.keynames.has_key(key):
+ key = Wkeys.keynames[key]
+ if modifiers & Events.shiftKey:
+ key = 'shift' + key
+ if modifiers & Events.cmdKey:
+ key = 'cmd' + key
+ if modifiers & Events.controlKey:
+ key = 'control' + key
+ if self._bindings.has_key("<key>"):
+ callback = self._bindings["<key>"]
+ if Wbase.CallbackCall(callback, 0, char, event):
+ return
+ if self._bindings.has_key(key):
+ callback = self._bindings[key]
+ Wbase.CallbackCall(callback, 0, char, event)
+ elif self._currentwidget is not None:
+ if self._currentwidget._bindings.has_key(key):
+ callback = self._currentwidget._bindings[key]
+ Wbase.CallbackCall(callback, 0, char, event)
+ else:
+ if self._currentwidget._bindings.has_key("<key>"):
+ callback = self._currentwidget._bindings["<key>"]
+ if Wbase.CallbackCall(callback, 0, char, event):
+ return
+ self._currentwidget.key(char, event)
+
+ def do_contentclick(self, point, modifiers, event):
+ widget = self.findwidget(point)
+ if widget is not None:
+ if self._bindings.has_key("<click>"):
+ callback = self._bindings["<click>"]
+ if Wbase.CallbackCall(callback, 0, point, modifiers):
+ return
+ if widget._bindings.has_key("<click>"):
+ callback = widget._bindings["<click>"]
+ if Wbase.CallbackCall(callback, 0, point, modifiers):
+ return
+ if widget._selectable:
+ widget.select(1, 1)
+ widget.click(point, modifiers)
+
+ def do_update(self, window, event):
+ Qd.EraseRgn(window.GetWindowPort().visRgn)
+ self.forall_frombottom("draw", window.GetWindowPort().visRgn)
+ if self._drawwidgetbounds:
+ self.forall_frombottom("_drawbounds")
+
+ def do_activate(self, onoff, event):
+ if not onoff:
+ if self._lastrollover:
+ self._lastrollover.rollover((0, 0), 0)
+ self._lastrollover = None
+ self.SetPort()
+ self.forall("activate", onoff)
+ self.draw()
+
+ def do_postresize(self, width, height, window):
+ self.GetWindow().InvalWindowRect(self.getgrowrect())
+ self._calcbounds()
+
+ def do_inGoAway(self, partcode, window, event):
+ where = event[3]
+ closeall = event[4] & Events.optionKey
+ if window.TrackGoAway(where):
+ if not closeall:
+ self.close()
+ else:
+ for window in self.parent._windows.values():
+ rv = window.close()
+ if rv and rv > 0:
+ return
+
+ # utilities
+ def tempcliprect(self, tempcliprect):
+ tempclip = Qd.NewRgn()
+ Qd.RectRgn(tempclip, tempcliprect)
+ self.tempclip(tempclip)
+ Qd.DisposeRgn(tempclip)
+
+ def tempclip(self, tempclip):
+ if not hasattr(self, "saveclip"):
+ self.saveclip = []
+ saveclip = Qd.NewRgn()
+ Qd.GetClip(saveclip)
+ self.saveclip.append(saveclip)
+ Qd.SetClip(tempclip)
+
+ def restoreclip(self):
+ Qd.SetClip(self.saveclip[-1])
+ Qd.DisposeRgn(self.saveclip[-1])
+ del self.saveclip[-1]
+
+ def getgrowrect(self):
+ l, t, r, b = self.wid.GetWindowPort().portRect
+ return (r - 15, b - 15, r, b)
+
+ def has_key(self, key):
+ return self._widgetsdict.has_key(key)
+
+ def __getattr__(self, attr):
+ global _successcount, _failcount, _magiccount
+ if self._widgetsdict.has_key(attr):
+ _successcount = _successcount + 1
+ return self._widgetsdict[attr]
+ if self._currentwidget is None or (attr[:7] <> 'domenu_' and
+ attr[:4] <> 'can_' and attr <> 'insert'):
+ _failcount = _failcount + 1
+ raise AttributeError, attr
+ # special case: if a domenu_xxx, can_xxx or insert method is asked for,
+ # see if the active widget supports it
+ _magiccount = _magiccount + 1
+ return getattr(self._currentwidget, attr)
+
+_successcount = 0
+_failcount = 0
+_magiccount = 0
+
+class Dialog(Window):
+
+ windowkind = Windows.movableDBoxProc
+
+ # this __init__ seems redundant, but it's not: it has less args
+ def __init__(self, possize, title = ""):
+ Window.__init__(self, possize, title)
+
+ def can_close(self, *args):
+ return 0
+
+ def getwindowbounds(self, size, minsize = None):
+ screenbounds = sl, st, sr, sb = Qd.qd.screenBits.bounds
+ w, h = size
+ l = sl + (sr - sl - w) / 2
+ t = st + (sb - st - h) / 3
+ return l, t, l + w, t + h
+
+
+class ModalDialog(Dialog):
+
+ def __init__(self, possize, title = ""):
+ Dialog.__init__(self, possize, title)
+ if title:
+ self.windowkind = Windows.movableDBoxProc
+ else:
+ self.windowkind = Windows.dBoxProc
+
+ def open(self):
+ import W
+ Dialog.open(self)
+ self.app = W.getapplication()
+ self.done = 0
+ Menu.HiliteMenu(0)
+ app = self.parent
+ app.enablemenubar(0)
+ try:
+ self.mainloop()
+ finally:
+ app.enablemenubar(1)
+
+ def close(self):
+ if not self.wid:
+ return # we are already closed
+ self.done = 1
+ del self.app
+ Dialog.close(self)
+
+ def mainloop(self):
+ saveyield = MacOS.EnableAppswitch(-1)
+ while not self.done:
+ #self.do1event()
+ self.do1event( Events.keyDownMask +
+ Events.autoKeyMask +
+ Events.activMask +
+ Events.updateMask +
+ Events.mDownMask +
+ Events.mUpMask,
+ 10)
+ MacOS.EnableAppswitch(saveyield)
+
+ def do1event(self, mask = Events.everyEvent, wait = 0):
+ ok, event = self.app.getevent(mask, wait)
+ if Dlg.IsDialogEvent(event):
+ if self.app.do_dialogevent(event):
+ return
+ if ok:
+ self.dispatch(event)
+ else:
+ self.app.idle(event)
+
+ def do_keyDown(self, event):
+ self.do_key(event)
+
+ def do_autoKey(self, event):
+ if not event[-1] & Events.cmdKey:
+ self.do_key(event)
+
+ def do_key(self, event):
+ (what, message, when, where, modifiers) = event
+ w = Win.FrontWindow()
+ if w <> self.wid:
+ return
+ c = chr(message & Events.charCodeMask)
+ if modifiers & Events.cmdKey:
+ self.app.checkmenus(self)
+ result = Menu.MenuKey(ord(c))
+ id = (result>>16) & 0xffff # Hi word
+ item = result & 0xffff # Lo word
+ if id:
+ self.app.do_rawmenu(id, item, None, event)
+ return
+ self.do_char(c, event)
+
+ def do_mouseDown(self, event):
+ (what, message, when, where, modifiers) = event
+ partcode, wid = Win.FindWindow(where)
+ #
+ # Find the correct name.
+ #
+ if FrameWork.partname.has_key(partcode):
+ name = "do_" + FrameWork.partname[partcode]
+ else:
+ name = "do_%d" % partcode
+
+ if name == "do_inDesk":
+ MacOS.HandleEvent(event)
+ return
+ if wid == self.wid:
+ try:
+ handler = getattr(self, name)
+ except AttributeError:
+ handler = self.app.do_unknownpartcode
+ else:
+ #MacOS.HandleEvent(event)
+ if name == 'do_inMenuBar':
+ handler = getattr(self.parent, name)
+ else:
+ return
+ handler(partcode, wid, event)
+
+ def dispatch(self, event):
+ (what, message, when, where, modifiers) = event
+ if FrameWork.eventname.has_key(what):
+ name = "do_" + FrameWork.eventname[what]
+ else:
+ name = "do_%d" % what
+ try:
+ handler = getattr(self, name)
+ except AttributeError:
+ try:
+ handler = getattr(self.app, name)
+ except AttributeError:
+ handler = self.app.do_unknownevent
+ handler(event)
+
+
+def FrontWindowInsert(stuff):
+ if not stuff:
+ return
+ if type(stuff) <> StringType:
+ raise TypeError, 'string expected'
+ import W
+ app = W.getapplication()
+ wid = Win.FrontWindow()
+ if wid and app._windows.has_key(wid):
+ window = app._windows[wid]
+ if hasattr(window, "insert"):
+ try:
+ window.insert(stuff)
+ return
+ except:
+ pass
+ import EasyDialogs
+ if EasyDialogs.AskYesNoCancel(
+ "Can't find window or widget to insert text into; copy to clipboard instead?",
+ 1) == 1:
+ import Scrap
+ Scrap.ZeroScrap()
+ Scrap.PutScrap('TEXT', stuff)
+
+
+# not quite based on the same function in FrameWork
+_windowcounter = 0
+
+def getnextwindowpos():
+ global _windowcounter
+ rows = 8
+ l = 4 * (rows + 1 - (_windowcounter % rows) + _windowcounter / rows)
+ t = 44 + 20 * (_windowcounter % rows)
+ _windowcounter = _windowcounter + 1
+ return l, t
+
+def windowbounds(preferredsize, minsize=None):
+ "Return sensible window bounds"
+
+ global _windowcounter
+ if len(preferredsize) == 4:
+ bounds = l, t, r, b = preferredsize
+ desktopRgn = Win.GetGrayRgn()
+ tempRgn = Qd.NewRgn()
+ Qd.RectRgn(tempRgn, bounds)
+ union = Qd.UnionRgn(tempRgn, desktopRgn, tempRgn)
+ equal = Qd.EqualRgn(tempRgn, desktopRgn)
+ Qd.DisposeRgn(tempRgn)
+ if equal:
+ return bounds
+ else:
+ preferredsize = r - l, b - t
+ if not minsize:
+ minsize = preferredsize
+ minwidth, minheight = minsize
+ width, height = preferredsize
+
+ sl, st, sr, sb = screenbounds = Qd.InsetRect(Qd.qd.screenBits.bounds, 4, 4)
+ l, t = getnextwindowpos()
+ if (l + width) > sr:
+ _windowcounter = 0
+ l, t = getnextwindowpos()
+ r = l + width
+ b = t + height
+ if (t + height) > sb:
+ b = sb
+ if (b - t) < minheight:
+ b = t + minheight
+ return l, t, r, b
+
+scratchRegion = Qd.NewRgn()
+
+# util -- move somewhere convenient???
+def GetRgnBounds(the_Rgn):
+ (t, l, b, r) = struct.unpack("hhhh", the_Rgn.data[2:10])
+ return (l, t, r, b)