cpython/Mac/Modules/dlg/_Dlgmodule.c

1597 lines
44 KiB
C
Raw Normal View History

/* ========================== Module _Dlg =========================== */
#include "Python.h"
#include "pymactoolbox.h"
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
2003-02-27 18:50:50 -04:00
PyErr_SetString(PyExc_NotImplementedError, \
"Not available in this shared library/OS version"); \
return NULL; \
}} while(0)
#include <Carbon/Carbon.h>
#ifdef USE_TOOLBOX_OBJECT_GLUE
extern PyObject *_DlgObj_New(DialogRef);
extern PyObject *_DlgObj_WhichDialog(DialogRef);
extern int _DlgObj_Convert(PyObject *, DialogRef *);
#define DlgObj_New _DlgObj_New
#define DlgObj_WhichDialog _DlgObj_WhichDialog
#define DlgObj_Convert _DlgObj_Convert
#endif
/* XXX Shouldn't this be a stack? */
static PyObject *Dlg_FilterProc_callback = NULL;
static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog,
EventRecord *event,
short *itemHit)
{
Boolean rv;
PyObject *args, *res;
PyObject *callback = Dlg_FilterProc_callback;
if (callback == NULL)
return 0; /* Default behavior */
Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
args = Py_BuildValue("O&O&", DlgObj_WhichDialog, dialog, PyMac_BuildEventRecord, event);
if (args == NULL)
res = NULL;
else {
res = PyEval_CallObject(callback, args);
Py_DECREF(args);
}
if (res == NULL) {
PySys_WriteStderr("Exception in Dialog Filter\n");
PyErr_Print();
*itemHit = -1; /* Fake return item */
return 1; /* We handled it */
}
else {
Dlg_FilterProc_callback = callback;
if (PyInt_Check(res)) {
*itemHit = PyInt_AsLong(res);
rv = 1;
}
else
rv = PyObject_IsTrue(res);
}
Py_DECREF(res);
return rv;
}
static ModalFilterUPP
Dlg_PassFilterProc(PyObject *callback)
{
PyObject *tmp = Dlg_FilterProc_callback;
static ModalFilterUPP UnivFilterUpp = NULL;
Dlg_FilterProc_callback = NULL;
if (callback == Py_None) {
Py_XDECREF(tmp);
return NULL;
}
Py_INCREF(callback);
Dlg_FilterProc_callback = callback;
Py_XDECREF(tmp);
if ( UnivFilterUpp == NULL )
UnivFilterUpp = NewModalFilterUPP(&Dlg_UnivFilterProc);
return UnivFilterUpp;
}
static PyObject *Dlg_UserItemProc_callback = NULL;
static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
short item)
{
PyObject *args, *res;
if (Dlg_UserItemProc_callback == NULL)
return; /* Default behavior */
Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
args = Py_BuildValue("O&h", DlgObj_WhichDialog, dialog, item);
if (args == NULL)
res = NULL;
else {
res = PyEval_CallObject(Dlg_UserItemProc_callback, args);
Py_DECREF(args);
}
if (res == NULL) {
PySys_WriteStderr("Exception in Dialog UserItem proc\n");
PyErr_Print();
}
Py_XDECREF(res);
return;
}
#if 0
/*
** Treating DialogObjects as WindowObjects is (I think) illegal under Carbon.
** However, as they are still identical under MacOS9 Carbon this is a problem, even
** if we neatly call GetDialogWindow() at the right places: there's one refcon field
** and it points to the DialogObject, so WinObj_WhichWindow will smartly return the
** dialog object, and therefore we still don't have a WindowObject.
** I'll leave the chaining code in place for now, with this comment to warn the
** unsuspecting victims (i.e. me, probably, in a few weeks:-)
*/
extern PyMethodChain WinObj_chain;
#endif
static PyObject *Dlg_Error;
/* ----------------------- Object type Dialog ----------------------- */
PyTypeObject Dialog_Type;
#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type || PyObject_TypeCheck((x), &Dialog_Type))
typedef struct DialogObject {
PyObject_HEAD
DialogPtr ob_itself;
} DialogObject;
PyObject *DlgObj_New(DialogPtr itself)
{
DialogObject *it;
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn merge in bad ways, so I'll have to merge that extra-carefully (probably manually.) Merged revisions 46495-46605 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r46495 | tim.peters | 2006-05-28 03:52:38 +0200 (Sun, 28 May 2006) | 2 lines Added missing svn:eol-style property to text files. ........ r46497 | tim.peters | 2006-05-28 12:41:29 +0200 (Sun, 28 May 2006) | 3 lines PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste bug in both: `className` was referenced before being checked for NULL. ........ r46499 | fredrik.lundh | 2006-05-28 14:06:46 +0200 (Sun, 28 May 2006) | 5 lines needforspeed: added Py_MEMCPY macro (currently tuned for Visual C only), and use it for string copy operations. this gives a 20% speedup on some string benchmarks. ........ r46501 | michael.hudson | 2006-05-28 17:51:40 +0200 (Sun, 28 May 2006) | 26 lines Quality control, meet exceptions.c. Fix a number of problems with the need for speed code: One is doing this sort of thing: Py_DECREF(self->field); self->field = newval; Py_INCREF(self->field); without being very sure that self->field doesn't start with a value that has a __del__, because that almost certainly can lead to segfaults. As self->args is constrained to be an exact tuple we may as well exploit this fact consistently. This leads to quite a lot of simplification (and, hey, probably better performance). Add some error checking in places lacking it. Fix some rather strange indentation in the Unicode code. Delete some trailing whitespace. More to come, I haven't fixed all the reference leaks yet... ........ r46502 | george.yoshida | 2006-05-28 18:39:09 +0200 (Sun, 28 May 2006) | 3 lines Patch #1080727: add "encoding" parameter to doctest.DocFileSuite Contributed by Bjorn Tillenius. ........ r46503 | martin.v.loewis | 2006-05-28 18:57:38 +0200 (Sun, 28 May 2006) | 4 lines Rest of patch #1490384: Commit icon source, remove claim that Erik von Blokland is the author of the installer picture. ........ r46504 | michael.hudson | 2006-05-28 19:40:29 +0200 (Sun, 28 May 2006) | 16 lines Quality control, meet exceptions.c, round two. Make some functions that should have been static static. Fix a bunch of refleaks by fixing the definition of MiddlingExtendsException. Remove all the __new__ implementations apart from BaseException_new. Rewrite most code that needs it to cope with NULL fields (such code could get excercised anyway, the __new__-removal just makes it more likely). This involved editing the code for WindowsError, which I can't test. This fixes all the refleaks in at least the start of a regrtest -R :: run. ........ r46505 | marc-andre.lemburg | 2006-05-28 19:46:58 +0200 (Sun, 28 May 2006) | 10 lines Initial version of systimes - a module to provide platform dependent performance measurements. The module is currently just a proof-of-concept implementation, but will integrated into pybench once it is stable enough. License: pybench license. Author: Marc-Andre Lemburg. ........ r46507 | armin.rigo | 2006-05-28 21:13:17 +0200 (Sun, 28 May 2006) | 15 lines ("Forward-port" of r46506) Remove various dependencies on dictionary order in the standard library tests, and one (clearly an oversight, potentially critical) in the standard library itself - base64.py. Remaining open issues: * test_extcall is an output test, messy to make robust * tarfile.py has a potential bug here, but I'm not familiar enough with this code. Filed in as SF bug #1496501. * urllib2.HTTPPasswordMgr() returns a random result if there is more than one matching root path. I'm asking python-dev for clarification... ........ r46508 | georg.brandl | 2006-05-28 22:11:45 +0200 (Sun, 28 May 2006) | 4 lines The empty string is a valid import path. (fixes #1496539) ........ r46509 | georg.brandl | 2006-05-28 22:23:12 +0200 (Sun, 28 May 2006) | 3 lines Patch #1496206: urllib2 PasswordMgr ./. default ports ........ r46510 | georg.brandl | 2006-05-28 22:57:09 +0200 (Sun, 28 May 2006) | 3 lines Fix refleaks in UnicodeError get and set methods. ........ r46511 | michael.hudson | 2006-05-28 23:19:03 +0200 (Sun, 28 May 2006) | 3 lines use the UnicodeError traversal and clearing functions in UnicodeError subclasses. ........ r46512 | thomas.wouters | 2006-05-28 23:32:12 +0200 (Sun, 28 May 2006) | 4 lines Make last patch valid C89 so Windows compilers can deal with it. ........ r46513 | georg.brandl | 2006-05-28 23:42:54 +0200 (Sun, 28 May 2006) | 3 lines Fix ref-antileak in _struct.c which eventually lead to deallocating None. ........ r46514 | georg.brandl | 2006-05-28 23:57:35 +0200 (Sun, 28 May 2006) | 4 lines Correct None refcount issue in Mac modules. (Are they still used?) ........ r46515 | armin.rigo | 2006-05-29 00:07:08 +0200 (Mon, 29 May 2006) | 3 lines A clearer error message when passing -R to regrtest.py with release builds of Python. ........ r46516 | georg.brandl | 2006-05-29 00:14:04 +0200 (Mon, 29 May 2006) | 3 lines Fix C function calling conventions in _sre module. ........ r46517 | georg.brandl | 2006-05-29 00:34:51 +0200 (Mon, 29 May 2006) | 3 lines Convert audioop over to METH_VARARGS. ........ r46518 | georg.brandl | 2006-05-29 00:38:57 +0200 (Mon, 29 May 2006) | 3 lines METH_NOARGS functions do get called with two args. ........ r46519 | georg.brandl | 2006-05-29 11:46:51 +0200 (Mon, 29 May 2006) | 4 lines Fix refleak in socketmodule. Replace bogus Py_BuildValue calls. Fix refleak in exceptions. ........ r46520 | nick.coghlan | 2006-05-29 14:43:05 +0200 (Mon, 29 May 2006) | 7 lines Apply modified version of Collin Winter's patch #1478788 Renames functional extension module to _functools and adds a Python functools module so that utility functions like update_wrapper can be added easily. ........ r46522 | georg.brandl | 2006-05-29 15:53:16 +0200 (Mon, 29 May 2006) | 3 lines Convert fmmodule to METH_VARARGS. ........ r46523 | georg.brandl | 2006-05-29 16:13:21 +0200 (Mon, 29 May 2006) | 3 lines Fix #1494605. ........ r46524 | georg.brandl | 2006-05-29 16:28:05 +0200 (Mon, 29 May 2006) | 3 lines Handle PyMem_Malloc failure in pystrtod.c. Closes #1494671. ........ r46525 | georg.brandl | 2006-05-29 16:33:55 +0200 (Mon, 29 May 2006) | 3 lines Fix compiler warning. ........ r46526 | georg.brandl | 2006-05-29 16:39:00 +0200 (Mon, 29 May 2006) | 3 lines Fix #1494787 (pyclbr counts whitespace as superclass name) ........ r46527 | bob.ippolito | 2006-05-29 17:47:29 +0200 (Mon, 29 May 2006) | 1 line simplify the struct code a bit (no functional changes) ........ r46528 | armin.rigo | 2006-05-29 19:59:47 +0200 (Mon, 29 May 2006) | 2 lines Silence a warning. ........ r46529 | georg.brandl | 2006-05-29 21:39:45 +0200 (Mon, 29 May 2006) | 3 lines Correct some value converting strangenesses. ........ r46530 | nick.coghlan | 2006-05-29 22:27:44 +0200 (Mon, 29 May 2006) | 1 line When adding a module like functools, it helps to let SVN know about the file. ........ r46531 | georg.brandl | 2006-05-29 22:52:54 +0200 (Mon, 29 May 2006) | 4 lines Patches #1497027 and #972322: try HTTP digest auth first, and watch out for handler name collisions. ........ r46532 | georg.brandl | 2006-05-29 22:57:01 +0200 (Mon, 29 May 2006) | 3 lines Add News entry for last commit. ........ r46533 | georg.brandl | 2006-05-29 23:04:52 +0200 (Mon, 29 May 2006) | 4 lines Make use of METH_O and METH_NOARGS where possible. Use Py_UnpackTuple instead of PyArg_ParseTuple where possible. ........ r46534 | georg.brandl | 2006-05-29 23:58:42 +0200 (Mon, 29 May 2006) | 3 lines Convert more modules to METH_VARARGS. ........ r46535 | georg.brandl | 2006-05-30 00:00:30 +0200 (Tue, 30 May 2006) | 3 lines Whoops. ........ r46536 | fredrik.lundh | 2006-05-30 00:42:07 +0200 (Tue, 30 May 2006) | 4 lines fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on the current behaviour ;-) ........ r46537 | bob.ippolito | 2006-05-30 00:55:48 +0200 (Tue, 30 May 2006) | 1 line struct: modulo math plus warning on all endian-explicit formats for compatibility with older struct usage (ugly) ........ r46539 | bob.ippolito | 2006-05-30 02:26:01 +0200 (Tue, 30 May 2006) | 1 line Add a length check to aifc to ensure it doesn't write a bogus file ........ r46540 | tim.peters | 2006-05-30 04:25:25 +0200 (Tue, 30 May 2006) | 10 lines deprecated_err(): Stop bizarre warning messages when the tests are run in the order: test_genexps (or any other doctest-based test) test_struct test_doctest The `warnings` module needs an advertised way to save/restore its internal filter list. ........ r46541 | tim.peters | 2006-05-30 04:26:46 +0200 (Tue, 30 May 2006) | 2 lines Whitespace normalization. ........ r46542 | tim.peters | 2006-05-30 04:30:30 +0200 (Tue, 30 May 2006) | 2 lines Set a binary svn:mime-type property on this UTF-8 encoded file. ........ r46543 | neal.norwitz | 2006-05-30 05:18:50 +0200 (Tue, 30 May 2006) | 1 line Simplify further by using AddStringConstant ........ r46544 | tim.peters | 2006-05-30 06:16:25 +0200 (Tue, 30 May 2006) | 6 lines Convert relevant dict internals to Py_ssize_t. I don't have a box with nearly enough RAM, or an OS, that could get close to tickling this, though (requires a dict w/ at least 2**31 entries). ........ r46545 | neal.norwitz | 2006-05-30 06:19:21 +0200 (Tue, 30 May 2006) | 1 line Remove stray | in comment ........ r46546 | neal.norwitz | 2006-05-30 06:25:05 +0200 (Tue, 30 May 2006) | 1 line Use Py_SAFE_DOWNCAST for safety. Fix format strings. Remove 2 more stray | in comment ........ r46547 | neal.norwitz | 2006-05-30 06:43:23 +0200 (Tue, 30 May 2006) | 1 line No DOWNCAST is required since sizeof(Py_ssize_t) >= sizeof(int) and Py_ReprEntr returns an int ........ r46548 | tim.peters | 2006-05-30 07:04:59 +0200 (Tue, 30 May 2006) | 3 lines dict_print(): Explicitly narrow the return value from a (possibly) wider variable. ........ r46549 | tim.peters | 2006-05-30 07:23:59 +0200 (Tue, 30 May 2006) | 5 lines dict_print(): So that Neal & I don't spend the rest of our lives taking turns rewriting code that works ;-), get rid of casting illusions by declaring a new variable with the obvious type. ........ r46550 | georg.brandl | 2006-05-30 09:04:55 +0200 (Tue, 30 May 2006) | 3 lines Restore exception pickle support. #1497319. ........ r46551 | georg.brandl | 2006-05-30 09:13:29 +0200 (Tue, 30 May 2006) | 3 lines Add a test case for exception pickling. args is never NULL. ........ r46552 | neal.norwitz | 2006-05-30 09:21:10 +0200 (Tue, 30 May 2006) | 1 line Don't fail if the (sub)pkgname already exist. ........ r46553 | georg.brandl | 2006-05-30 09:34:45 +0200 (Tue, 30 May 2006) | 3 lines Disallow keyword args for exceptions. ........ r46554 | neal.norwitz | 2006-05-30 09:36:54 +0200 (Tue, 30 May 2006) | 5 lines I'm impatient. I think this will fix a few more problems with the buildbots. I'm not sure this is the best approach, but I can't think of anything better. If this creates problems, feel free to revert, but I think it's safe and should make things a little better. ........ r46555 | georg.brandl | 2006-05-30 10:17:00 +0200 (Tue, 30 May 2006) | 4 lines Do the check for no keyword arguments in __init__ so that subclasses of Exception can be supplied keyword args ........ r46556 | georg.brandl | 2006-05-30 10:47:19 +0200 (Tue, 30 May 2006) | 3 lines Convert test_exceptions to unittest. ........ r46557 | andrew.kuchling | 2006-05-30 14:52:01 +0200 (Tue, 30 May 2006) | 1 line Add SoC name, and reorganize this section a bit ........ r46559 | tim.peters | 2006-05-30 17:53:34 +0200 (Tue, 30 May 2006) | 11 lines PyLong_FromString(): Continued fraction analysis (explained in a new comment) suggests there are almost certainly large input integers in all non-binary input bases for which one Python digit too few is initally allocated to hold the final result. Instead of assert-failing when that happens, allocate more space. Alas, I estimate it would take a few days to find a specific such case, so this isn't backed up by a new test (not to mention that such a case may take hours to run, since conversion time is quadratic in the number of digits, and preliminary attempts suggested that the smallest such inputs contain at least a million digits). ........ r46560 | fredrik.lundh | 2006-05-30 19:11:48 +0200 (Tue, 30 May 2006) | 3 lines changed find/rfind to return -1 for matches outside the source string ........ r46561 | bob.ippolito | 2006-05-30 19:37:54 +0200 (Tue, 30 May 2006) | 1 line Change wrapping terminology to overflow masking ........ r46562 | fredrik.lundh | 2006-05-30 19:39:58 +0200 (Tue, 30 May 2006) | 3 lines changed count to return 0 for slices outside the source string ........ r46568 | tim.peters | 2006-05-31 01:28:02 +0200 (Wed, 31 May 2006) | 2 lines Whitespace normalization. ........ r46569 | brett.cannon | 2006-05-31 04:19:54 +0200 (Wed, 31 May 2006) | 5 lines Clarify wording on default values for strptime(); defaults are used when better values cannot be inferred. Closes bug #1496315. ........ r46572 | neal.norwitz | 2006-05-31 09:43:27 +0200 (Wed, 31 May 2006) | 1 line Calculate smallest properly (it was off by one) and use proper ssize_t types for Win64 ........ r46573 | neal.norwitz | 2006-05-31 10:01:08 +0200 (Wed, 31 May 2006) | 1 line Revert last checkin, it is better to do make distclean ........ r46574 | neal.norwitz | 2006-05-31 11:02:44 +0200 (Wed, 31 May 2006) | 3 lines On 64-bit platforms running test_struct after test_tarfile would fail since the deprecation warning wouldn't be raised. ........ r46575 | thomas.heller | 2006-05-31 13:37:58 +0200 (Wed, 31 May 2006) | 3 lines PyTuple_Pack is not available in Python 2.3, but ctypes must stay compatible with that. ........ r46576 | andrew.kuchling | 2006-05-31 15:18:56 +0200 (Wed, 31 May 2006) | 1 line 'functional' module was renamed to 'functools' ........ r46577 | kristjan.jonsson | 2006-05-31 15:35:41 +0200 (Wed, 31 May 2006) | 1 line Fixup the PCBuild8 project directory. exceptions.c have moved to Objects, and the functionalmodule.c has been replaced with _functoolsmodule.c. Other minor changes to .vcproj files and .sln to fix compilation ........ r46578 | andrew.kuchling | 2006-05-31 16:08:48 +0200 (Wed, 31 May 2006) | 15 lines [Bug #1473048] SimpleXMLRPCServer and DocXMLRPCServer don't look at the path of the HTTP request at all; you can POST or GET from / or /RPC2 or /blahblahblah with the same results. Security scanners that look for /cgi-bin/phf will therefore report lots of vulnerabilities. Fix: add a .rpc_paths attribute to the SimpleXMLRPCServer class, and report a 404 error if the path isn't on the allowed list. Possibly-controversial aspect of this change: the default makes only '/' and '/RPC2' legal. Maybe this will break people's applications (though I doubt it). We could just set the default to an empty tuple, which would exactly match the current behaviour. ........ r46579 | andrew.kuchling | 2006-05-31 16:12:47 +0200 (Wed, 31 May 2006) | 1 line Mention SimpleXMLRPCServer change ........ r46580 | tim.peters | 2006-05-31 16:28:07 +0200 (Wed, 31 May 2006) | 2 lines Trimmed trailing whitespace. ........ r46581 | tim.peters | 2006-05-31 17:33:22 +0200 (Wed, 31 May 2006) | 4 lines _range_error(): Speed and simplify (there's no real need for loops here). Assert that size_t is actually big enough, and that f->size is at least one. Wrap a long line. ........ r46582 | tim.peters | 2006-05-31 17:34:37 +0200 (Wed, 31 May 2006) | 2 lines Repaired error in new comment. ........ r46584 | neal.norwitz | 2006-06-01 07:32:49 +0200 (Thu, 01 Jun 2006) | 4 lines Remove ; at end of macro. There was a compiler recently that warned about extra semi-colons. It may have been the HP C compiler. This file will trigger a bunch of those warnings now. ........ r46585 | georg.brandl | 2006-06-01 08:39:19 +0200 (Thu, 01 Jun 2006) | 3 lines Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571) ........ r46586 | georg.brandl | 2006-06-01 10:27:32 +0200 (Thu, 01 Jun 2006) | 3 lines Correctly allocate complex types with tp_alloc. (bug #1498638) ........ r46587 | georg.brandl | 2006-06-01 14:30:46 +0200 (Thu, 01 Jun 2006) | 2 lines Correctly dispatch Faults in loads (patch #1498627) ........ r46588 | georg.brandl | 2006-06-01 15:00:49 +0200 (Thu, 01 Jun 2006) | 3 lines Some code style tweaks, and remove apply. ........ r46589 | armin.rigo | 2006-06-01 15:19:12 +0200 (Thu, 01 Jun 2006) | 5 lines [ 1497053 ] Let dicts propagate the exceptions in user __eq__(). [ 1456209 ] dictresize() vulnerability ( <- backport candidate ). ........ r46590 | tim.peters | 2006-06-01 15:41:46 +0200 (Thu, 01 Jun 2006) | 2 lines Whitespace normalization. ........ r46591 | tim.peters | 2006-06-01 15:49:23 +0200 (Thu, 01 Jun 2006) | 2 lines Record bugs 1275608 and 1456209 as being fixed. ........ r46592 | tim.peters | 2006-06-01 15:56:26 +0200 (Thu, 01 Jun 2006) | 5 lines Re-enable a new empty-string test added during the NFS sprint, but disabled then because str and unicode strings gave different results. The implementations were repaired later during the sprint, but the new test remained disabled. ........ r46594 | tim.peters | 2006-06-01 17:50:44 +0200 (Thu, 01 Jun 2006) | 7 lines Armin committed his patch while I was reviewing it (I'm sure he didn't know this), so merged in some changes I made during review. Nothing material apart from changing a new `mask` local from int to Py_ssize_t. Mostly this is repairing comments that were made incorrect, and adding new comments. Also a few minor code rewrites for clarity or helpful succinctness. ........ r46599 | neal.norwitz | 2006-06-02 06:45:53 +0200 (Fri, 02 Jun 2006) | 1 line Convert docstrings to comments so regrtest -v prints method names ........ r46600 | neal.norwitz | 2006-06-02 06:50:49 +0200 (Fri, 02 Jun 2006) | 2 lines Fix memory leak found by valgrind. ........ r46601 | neal.norwitz | 2006-06-02 06:54:52 +0200 (Fri, 02 Jun 2006) | 1 line More memory leaks from valgrind ........ r46602 | neal.norwitz | 2006-06-02 08:23:00 +0200 (Fri, 02 Jun 2006) | 11 lines Patch #1357836: Prevent an invalid memory read from test_coding in case the done flag is set. In that case, the loop isn't entered. I wonder if rather than setting the done flag in the cases before the loop, if they should just exit early. This code looks like it should be refactored. Backport candidate (also the early break above if decoding_fgets fails) ........ r46603 | martin.blais | 2006-06-02 15:03:43 +0200 (Fri, 02 Jun 2006) | 1 line Fixed struct test to not use unittest. ........ r46605 | tim.peters | 2006-06-03 01:22:51 +0200 (Sat, 03 Jun 2006) | 10 lines pprint functions used to sort a dict (by key) if and only if the output required more than one line. "Small" dicts got displayed in seemingly random order (the hash-induced order produced by dict.__repr__). None of this was documented. Now pprint functions always sort dicts by key, and the docs promise it. This was proposed and agreed to during the PyCon 2006 core sprint -- I just didn't have time for it before now. ........
2006-06-08 11:42:34 -03:00
if (itself == NULL) { Py_INCREF(Py_None); return Py_None; }
it = PyObject_NEW(DialogObject, &Dialog_Type);
if (it == NULL) return NULL;
it->ob_itself = itself;
SetWRefCon(GetDialogWindow(itself), (long)it);
return (PyObject *)it;
}
int DlgObj_Convert(PyObject *v, DialogPtr *p_itself)
{
if (v == Py_None) { *p_itself = NULL; return 1; }
if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
return 1; }
if (!DlgObj_Check(v))
{
PyErr_SetString(PyExc_TypeError, "Dialog required");
return 0;
}
*p_itself = ((DialogObject *)v)->ob_itself;
return 1;
}
static void DlgObj_dealloc(DialogObject *self)
{
DisposeDialog(self->ob_itself);
self->ob_type->tp_free((PyObject *)self);
}
static PyObject *DlgObj_DrawDialog(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
#ifndef DrawDialog
PyMac_PRECHECK(DrawDialog);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
DrawDialog(_self->ob_itself);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_UpdateDialog(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
RgnHandle updateRgn;
#ifndef UpdateDialog
PyMac_PRECHECK(UpdateDialog);
#endif
if (!PyArg_ParseTuple(_args, "O&",
ResObj_Convert, &updateRgn))
return NULL;
UpdateDialog(_self->ob_itself,
updateRgn);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_HideDialogItem(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogItemIndex itemNo;
#ifndef HideDialogItem
PyMac_PRECHECK(HideDialogItem);
#endif
if (!PyArg_ParseTuple(_args, "h",
&itemNo))
return NULL;
HideDialogItem(_self->ob_itself,
itemNo);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_ShowDialogItem(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogItemIndex itemNo;
#ifndef ShowDialogItem
PyMac_PRECHECK(ShowDialogItem);
#endif
if (!PyArg_ParseTuple(_args, "h",
&itemNo))
return NULL;
ShowDialogItem(_self->ob_itself,
itemNo);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_FindDialogItem(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogItemIndexZeroBased _rv;
Point thePt;
#ifndef FindDialogItem
PyMac_PRECHECK(FindDialogItem);
#endif
if (!PyArg_ParseTuple(_args, "O&",
PyMac_GetPoint, &thePt))
return NULL;
_rv = FindDialogItem(_self->ob_itself,
thePt);
_res = Py_BuildValue("h",
_rv);
return _res;
}
static PyObject *DlgObj_DialogCut(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
#ifndef DialogCut
PyMac_PRECHECK(DialogCut);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
DialogCut(_self->ob_itself);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_DialogPaste(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
#ifndef DialogPaste
PyMac_PRECHECK(DialogPaste);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
DialogPaste(_self->ob_itself);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_DialogCopy(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
#ifndef DialogCopy
PyMac_PRECHECK(DialogCopy);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
DialogCopy(_self->ob_itself);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_DialogDelete(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
#ifndef DialogDelete
PyMac_PRECHECK(DialogDelete);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
DialogDelete(_self->ob_itself);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_GetDialogItem(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogItemIndex itemNo;
DialogItemType itemType;
Handle item;
Rect box;
#ifndef GetDialogItem
PyMac_PRECHECK(GetDialogItem);
#endif
if (!PyArg_ParseTuple(_args, "h",
&itemNo))
return NULL;
GetDialogItem(_self->ob_itself,
itemNo,
&itemType,
&item,
&box);
_res = Py_BuildValue("hO&O&",
itemType,
OptResObj_New, item,
PyMac_BuildRect, &box);
return _res;
}
static PyObject *DlgObj_SetDialogItem(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogItemIndex itemNo;
DialogItemType itemType;
Handle item;
Rect box;
#ifndef SetDialogItem
PyMac_PRECHECK(SetDialogItem);
#endif
if (!PyArg_ParseTuple(_args, "hhO&O&",
&itemNo,
&itemType,
ResObj_Convert, &item,
PyMac_GetRect, &box))
return NULL;
SetDialogItem(_self->ob_itself,
itemNo,
itemType,
item,
&box);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_SelectDialogItemText(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogItemIndex itemNo;
SInt16 strtSel;
SInt16 endSel;
#ifndef SelectDialogItemText
PyMac_PRECHECK(SelectDialogItemText);
#endif
if (!PyArg_ParseTuple(_args, "hhh",
&itemNo,
&strtSel,
&endSel))
return NULL;
SelectDialogItemText(_self->ob_itself,
itemNo,
strtSel,
endSel);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_AppendDITL(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
Handle theHandle;
DITLMethod method;
#ifndef AppendDITL
PyMac_PRECHECK(AppendDITL);
#endif
if (!PyArg_ParseTuple(_args, "O&h",
ResObj_Convert, &theHandle,
&method))
return NULL;
AppendDITL(_self->ob_itself,
theHandle,
method);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_CountDITL(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogItemIndex _rv;
#ifndef CountDITL
PyMac_PRECHECK(CountDITL);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = CountDITL(_self->ob_itself);
_res = Py_BuildValue("h",
_rv);
return _res;
}
static PyObject *DlgObj_ShortenDITL(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogItemIndex numberItems;
#ifndef ShortenDITL
PyMac_PRECHECK(ShortenDITL);
#endif
if (!PyArg_ParseTuple(_args, "h",
&numberItems))
return NULL;
ShortenDITL(_self->ob_itself,
numberItems);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_InsertDialogItem(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
DialogItemIndex afterItem;
DialogItemType itemType;
Handle itemHandle;
Rect box;
#ifndef InsertDialogItem
PyMac_PRECHECK(InsertDialogItem);
#endif
if (!PyArg_ParseTuple(_args, "hhO&O&",
&afterItem,
&itemType,
ResObj_Convert, &itemHandle,
PyMac_GetRect, &box))
return NULL;
_err = InsertDialogItem(_self->ob_itself,
afterItem,
itemType,
itemHandle,
&box);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_RemoveDialogItems(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
DialogItemIndex itemNo;
DialogItemIndex amountToRemove;
Boolean disposeItemData;
#ifndef RemoveDialogItems
PyMac_PRECHECK(RemoveDialogItems);
#endif
if (!PyArg_ParseTuple(_args, "hhb",
&itemNo,
&amountToRemove,
&disposeItemData))
return NULL;
_err = RemoveDialogItems(_self->ob_itself,
itemNo,
amountToRemove,
disposeItemData);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_StdFilterProc(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
Boolean _rv;
EventRecord event;
DialogItemIndex itemHit;
#ifndef StdFilterProc
PyMac_PRECHECK(StdFilterProc);
#endif
2003-02-27 18:50:50 -04:00
if (!PyArg_ParseTuple(_args, "O&h",
PyMac_GetEventRecord, &event,
&itemHit))
return NULL;
_rv = StdFilterProc(_self->ob_itself,
&event,
&itemHit);
_res = Py_BuildValue("bO&h",
_rv,
PyMac_BuildEventRecord, &event,
itemHit);
return _res;
}
static PyObject *DlgObj_SetDialogDefaultItem(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
DialogItemIndex newItem;
#ifndef SetDialogDefaultItem
PyMac_PRECHECK(SetDialogDefaultItem);
#endif
if (!PyArg_ParseTuple(_args, "h",
&newItem))
return NULL;
_err = SetDialogDefaultItem(_self->ob_itself,
newItem);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_SetDialogCancelItem(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
DialogItemIndex newItem;
#ifndef SetDialogCancelItem
PyMac_PRECHECK(SetDialogCancelItem);
#endif
if (!PyArg_ParseTuple(_args, "h",
&newItem))
return NULL;
_err = SetDialogCancelItem(_self->ob_itself,
newItem);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_SetDialogTracksCursor(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
Boolean tracks;
#ifndef SetDialogTracksCursor
PyMac_PRECHECK(SetDialogTracksCursor);
#endif
if (!PyArg_ParseTuple(_args, "b",
&tracks))
return NULL;
_err = SetDialogTracksCursor(_self->ob_itself,
tracks);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_AutoSizeDialog(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
#ifndef AutoSizeDialog
PyMac_PRECHECK(AutoSizeDialog);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_err = AutoSizeDialog(_self->ob_itself);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_GetDialogItemAsControl(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
SInt16 inItemNo;
ControlHandle outControl;
#ifndef GetDialogItemAsControl
PyMac_PRECHECK(GetDialogItemAsControl);
#endif
if (!PyArg_ParseTuple(_args, "h",
&inItemNo))
return NULL;
_err = GetDialogItemAsControl(_self->ob_itself,
inItemNo,
&outControl);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("O&",
CtlObj_New, outControl);
return _res;
}
static PyObject *DlgObj_MoveDialogItem(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
SInt16 inItemNo;
SInt16 inHoriz;
SInt16 inVert;
#ifndef MoveDialogItem
PyMac_PRECHECK(MoveDialogItem);
#endif
if (!PyArg_ParseTuple(_args, "hhh",
&inItemNo,
&inHoriz,
&inVert))
return NULL;
_err = MoveDialogItem(_self->ob_itself,
inItemNo,
inHoriz,
inVert);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_SizeDialogItem(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
SInt16 inItemNo;
SInt16 inWidth;
SInt16 inHeight;
#ifndef SizeDialogItem
PyMac_PRECHECK(SizeDialogItem);
#endif
if (!PyArg_ParseTuple(_args, "hhh",
&inItemNo,
&inWidth,
&inHeight))
return NULL;
_err = SizeDialogItem(_self->ob_itself,
inItemNo,
inWidth,
inHeight);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_AppendDialogItemList(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
SInt16 ditlID;
DITLMethod method;
#ifndef AppendDialogItemList
PyMac_PRECHECK(AppendDialogItemList);
#endif
if (!PyArg_ParseTuple(_args, "hh",
&ditlID,
&method))
return NULL;
_err = AppendDialogItemList(_self->ob_itself,
ditlID,
method);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_SetDialogTimeout(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
SInt16 inButtonToPress;
UInt32 inSecondsToWait;
#ifndef SetDialogTimeout
PyMac_PRECHECK(SetDialogTimeout);
#endif
if (!PyArg_ParseTuple(_args, "hl",
&inButtonToPress,
&inSecondsToWait))
return NULL;
_err = SetDialogTimeout(_self->ob_itself,
inButtonToPress,
inSecondsToWait);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_GetDialogTimeout(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
SInt16 outButtonToPress;
UInt32 outSecondsToWait;
UInt32 outSecondsRemaining;
#ifndef GetDialogTimeout
PyMac_PRECHECK(GetDialogTimeout);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_err = GetDialogTimeout(_self->ob_itself,
&outButtonToPress,
&outSecondsToWait,
&outSecondsRemaining);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("hll",
outButtonToPress,
outSecondsToWait,
outSecondsRemaining);
return _res;
}
static PyObject *DlgObj_SetModalDialogEventMask(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
EventMask inMask;
#ifndef SetModalDialogEventMask
PyMac_PRECHECK(SetModalDialogEventMask);
#endif
if (!PyArg_ParseTuple(_args, "H",
&inMask))
return NULL;
_err = SetModalDialogEventMask(_self->ob_itself,
inMask);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_GetModalDialogEventMask(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
EventMask outMask;
#ifndef GetModalDialogEventMask
PyMac_PRECHECK(GetModalDialogEventMask);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_err = GetModalDialogEventMask(_self->ob_itself,
&outMask);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("H",
outMask);
return _res;
}
static PyObject *DlgObj_GetDialogWindow(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
WindowPtr _rv;
#ifndef GetDialogWindow
PyMac_PRECHECK(GetDialogWindow);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = GetDialogWindow(_self->ob_itself);
_res = Py_BuildValue("O&",
WinObj_New, _rv);
return _res;
}
static PyObject *DlgObj_GetDialogTextEditHandle(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
TEHandle _rv;
#ifndef GetDialogTextEditHandle
PyMac_PRECHECK(GetDialogTextEditHandle);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = GetDialogTextEditHandle(_self->ob_itself);
_res = Py_BuildValue("O&",
ResObj_New, _rv);
return _res;
}
static PyObject *DlgObj_GetDialogDefaultItem(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
SInt16 _rv;
#ifndef GetDialogDefaultItem
PyMac_PRECHECK(GetDialogDefaultItem);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = GetDialogDefaultItem(_self->ob_itself);
_res = Py_BuildValue("h",
_rv);
return _res;
}
static PyObject *DlgObj_GetDialogCancelItem(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
SInt16 _rv;
#ifndef GetDialogCancelItem
PyMac_PRECHECK(GetDialogCancelItem);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = GetDialogCancelItem(_self->ob_itself);
_res = Py_BuildValue("h",
_rv);
return _res;
}
static PyObject *DlgObj_GetDialogKeyboardFocusItem(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
SInt16 _rv;
#ifndef GetDialogKeyboardFocusItem
PyMac_PRECHECK(GetDialogKeyboardFocusItem);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = GetDialogKeyboardFocusItem(_self->ob_itself);
_res = Py_BuildValue("h",
_rv);
return _res;
}
static PyObject *DlgObj_SetPortDialogPort(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
#ifndef SetPortDialogPort
PyMac_PRECHECK(SetPortDialogPort);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
SetPortDialogPort(_self->ob_itself);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *DlgObj_GetDialogPort(DialogObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
CGrafPtr _rv;
#ifndef GetDialogPort
PyMac_PRECHECK(GetDialogPort);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = GetDialogPort(_self->ob_itself);
_res = Py_BuildValue("O&",
GrafObj_New, _rv);
return _res;
}
static PyMethodDef DlgObj_methods[] = {
{"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
PyDoc_STR("() -> None")},
{"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
PyDoc_STR("(RgnHandle updateRgn) -> None")},
{"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
PyDoc_STR("(DialogItemIndex itemNo) -> None")},
{"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
PyDoc_STR("(DialogItemIndex itemNo) -> None")},
{"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
PyDoc_STR("(Point thePt) -> (DialogItemIndexZeroBased _rv)")},
{"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
PyDoc_STR("() -> None")},
{"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
PyDoc_STR("() -> None")},
{"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
PyDoc_STR("() -> None")},
{"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
PyDoc_STR("() -> None")},
{"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
PyDoc_STR("(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)")},
{"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
PyDoc_STR("(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None")},
{"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
PyDoc_STR("(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None")},
{"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
PyDoc_STR("(Handle theHandle, DITLMethod method) -> None")},
{"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
PyDoc_STR("() -> (DialogItemIndex _rv)")},
{"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
PyDoc_STR("(DialogItemIndex numberItems) -> None")},
{"InsertDialogItem", (PyCFunction)DlgObj_InsertDialogItem, 1,
PyDoc_STR("(DialogItemIndex afterItem, DialogItemType itemType, Handle itemHandle, Rect box) -> None")},
{"RemoveDialogItems", (PyCFunction)DlgObj_RemoveDialogItems, 1,
PyDoc_STR("(DialogItemIndex itemNo, DialogItemIndex amountToRemove, Boolean disposeItemData) -> None")},
{"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
2003-02-27 18:50:50 -04:00
PyDoc_STR("(EventRecord event, DialogItemIndex itemHit) -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)")},
{"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
PyDoc_STR("(DialogItemIndex newItem) -> None")},
{"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
PyDoc_STR("(DialogItemIndex newItem) -> None")},
{"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
PyDoc_STR("(Boolean tracks) -> None")},
{"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1,
PyDoc_STR("() -> None")},
{"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1,
PyDoc_STR("(SInt16 inItemNo) -> (ControlHandle outControl)")},
{"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1,
PyDoc_STR("(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None")},
{"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1,
PyDoc_STR("(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None")},
{"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1,
PyDoc_STR("(SInt16 ditlID, DITLMethod method) -> None")},
{"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1,
PyDoc_STR("(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None")},
{"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1,
PyDoc_STR("() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)")},
{"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1,
PyDoc_STR("(EventMask inMask) -> None")},
{"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1,
PyDoc_STR("() -> (EventMask outMask)")},
{"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
PyDoc_STR("() -> (WindowPtr _rv)")},
{"GetDialogTextEditHandle", (PyCFunction)DlgObj_GetDialogTextEditHandle, 1,
PyDoc_STR("() -> (TEHandle _rv)")},
{"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
PyDoc_STR("() -> (SInt16 _rv)")},
{"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
PyDoc_STR("() -> (SInt16 _rv)")},
{"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
PyDoc_STR("() -> (SInt16 _rv)")},
{"SetPortDialogPort", (PyCFunction)DlgObj_SetPortDialogPort, 1,
PyDoc_STR("() -> None")},
{"GetDialogPort", (PyCFunction)DlgObj_GetDialogPort, 1,
PyDoc_STR("() -> (CGrafPtr _rv)")},
{NULL, NULL, 0}
};
#define DlgObj_getsetlist NULL
static int DlgObj_compare(DialogObject *self, DialogObject *other)
{
if ( self->ob_itself > other->ob_itself ) return 1;
if ( self->ob_itself < other->ob_itself ) return -1;
return 0;
}
#define DlgObj_repr NULL
static int DlgObj_hash(DialogObject *self)
{
return (int)self->ob_itself;
}
#define DlgObj_tp_init 0
#define DlgObj_tp_alloc PyType_GenericAlloc
static PyObject *DlgObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
{
PyObject *_self;
DialogPtr itself;
char *kw[] = {"itself", 0};
if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, DlgObj_Convert, &itself)) return NULL;
if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL;
((DialogObject *)_self)->ob_itself = itself;
return _self;
}
#define DlgObj_tp_free PyObject_Del
PyTypeObject Dialog_Type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"_Dlg.Dialog", /*tp_name*/
sizeof(DialogObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor) DlgObj_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc)0, /*tp_getattr*/
(setattrfunc)0, /*tp_setattr*/
(cmpfunc) DlgObj_compare, /*tp_compare*/
(reprfunc) DlgObj_repr, /*tp_repr*/
(PyNumberMethods *)0, /* tp_as_number */
(PySequenceMethods *)0, /* tp_as_sequence */
(PyMappingMethods *)0, /* tp_as_mapping */
(hashfunc) DlgObj_hash, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
PyObject_GenericGetAttr, /*tp_getattro*/
PyObject_GenericSetAttr, /*tp_setattro */
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
0, /*tp_doc*/
0, /*tp_traverse*/
0, /*tp_clear*/
0, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
0, /*tp_iter*/
0, /*tp_iternext*/
DlgObj_methods, /* tp_methods */
0, /*tp_members*/
DlgObj_getsetlist, /*tp_getset*/
0, /*tp_base*/
0, /*tp_dict*/
0, /*tp_descr_get*/
0, /*tp_descr_set*/
0, /*tp_dictoffset*/
DlgObj_tp_init, /* tp_init */
DlgObj_tp_alloc, /* tp_alloc */
DlgObj_tp_new, /* tp_new */
DlgObj_tp_free, /* tp_free */
};
/* --------------------- End object type Dialog --------------------- */
static PyObject *Dlg_NewDialog(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogPtr _rv;
Rect boundsRect;
Str255 title;
Boolean visible;
SInt16 procID;
WindowPtr behind;
Boolean goAwayFlag;
SInt32 refCon;
Handle items;
#ifndef NewDialog
PyMac_PRECHECK(NewDialog);
#endif
if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
PyMac_GetRect, &boundsRect,
PyMac_GetStr255, title,
&visible,
&procID,
WinObj_Convert, &behind,
&goAwayFlag,
&refCon,
ResObj_Convert, &items))
return NULL;
_rv = NewDialog((void *)0,
&boundsRect,
title,
visible,
procID,
behind,
goAwayFlag,
refCon,
items);
_res = Py_BuildValue("O&",
DlgObj_New, _rv);
return _res;
}
static PyObject *Dlg_GetNewDialog(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogPtr _rv;
SInt16 dialogID;
WindowPtr behind;
#ifndef GetNewDialog
PyMac_PRECHECK(GetNewDialog);
#endif
if (!PyArg_ParseTuple(_args, "hO&",
&dialogID,
WinObj_Convert, &behind))
return NULL;
_rv = GetNewDialog(dialogID,
(void *)0,
behind);
_res = Py_BuildValue("O&",
DlgObj_New, _rv);
return _res;
}
static PyObject *Dlg_NewColorDialog(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogPtr _rv;
Rect boundsRect;
Str255 title;
Boolean visible;
SInt16 procID;
WindowPtr behind;
Boolean goAwayFlag;
SInt32 refCon;
Handle items;
#ifndef NewColorDialog
PyMac_PRECHECK(NewColorDialog);
#endif
if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
PyMac_GetRect, &boundsRect,
PyMac_GetStr255, title,
&visible,
&procID,
WinObj_Convert, &behind,
&goAwayFlag,
&refCon,
ResObj_Convert, &items))
return NULL;
_rv = NewColorDialog((void *)0,
&boundsRect,
title,
visible,
procID,
behind,
goAwayFlag,
refCon,
items);
_res = Py_BuildValue("O&",
DlgObj_New, _rv);
return _res;
}
static PyObject *Dlg_ModalDialog(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
PyObject* modalFilter;
DialogItemIndex itemHit;
#ifndef ModalDialog
PyMac_PRECHECK(ModalDialog);
#endif
if (!PyArg_ParseTuple(_args, "O",
&modalFilter))
return NULL;
ModalDialog(Dlg_PassFilterProc(modalFilter),
&itemHit);
_res = Py_BuildValue("h",
itemHit);
return _res;
}
static PyObject *Dlg_IsDialogEvent(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
Boolean _rv;
EventRecord theEvent;
#ifndef IsDialogEvent
PyMac_PRECHECK(IsDialogEvent);
#endif
if (!PyArg_ParseTuple(_args, "O&",
PyMac_GetEventRecord, &theEvent))
return NULL;
_rv = IsDialogEvent(&theEvent);
_res = Py_BuildValue("b",
_rv);
return _res;
}
static PyObject *Dlg_DialogSelect(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
Boolean _rv;
EventRecord theEvent;
DialogPtr theDialog;
DialogItemIndex itemHit;
#ifndef DialogSelect
PyMac_PRECHECK(DialogSelect);
#endif
if (!PyArg_ParseTuple(_args, "O&",
PyMac_GetEventRecord, &theEvent))
return NULL;
_rv = DialogSelect(&theEvent,
&theDialog,
&itemHit);
_res = Py_BuildValue("bO&h",
_rv,
DlgObj_WhichDialog, theDialog,
itemHit);
return _res;
}
static PyObject *Dlg_Alert(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogItemIndex _rv;
SInt16 alertID;
PyObject* modalFilter;
#ifndef Alert
PyMac_PRECHECK(Alert);
#endif
if (!PyArg_ParseTuple(_args, "hO",
&alertID,
&modalFilter))
return NULL;
_rv = Alert(alertID,
Dlg_PassFilterProc(modalFilter));
_res = Py_BuildValue("h",
_rv);
return _res;
}
static PyObject *Dlg_StopAlert(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogItemIndex _rv;
SInt16 alertID;
PyObject* modalFilter;
#ifndef StopAlert
PyMac_PRECHECK(StopAlert);
#endif
if (!PyArg_ParseTuple(_args, "hO",
&alertID,
&modalFilter))
return NULL;
_rv = StopAlert(alertID,
Dlg_PassFilterProc(modalFilter));
_res = Py_BuildValue("h",
_rv);
return _res;
}
static PyObject *Dlg_NoteAlert(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogItemIndex _rv;
SInt16 alertID;
PyObject* modalFilter;
#ifndef NoteAlert
PyMac_PRECHECK(NoteAlert);
#endif
if (!PyArg_ParseTuple(_args, "hO",
&alertID,
&modalFilter))
return NULL;
_rv = NoteAlert(alertID,
Dlg_PassFilterProc(modalFilter));
_res = Py_BuildValue("h",
_rv);
return _res;
}
static PyObject *Dlg_CautionAlert(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogItemIndex _rv;
SInt16 alertID;
PyObject* modalFilter;
#ifndef CautionAlert
PyMac_PRECHECK(CautionAlert);
#endif
if (!PyArg_ParseTuple(_args, "hO",
&alertID,
&modalFilter))
return NULL;
_rv = CautionAlert(alertID,
Dlg_PassFilterProc(modalFilter));
_res = Py_BuildValue("h",
_rv);
return _res;
}
static PyObject *Dlg_ParamText(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
Str255 param0;
Str255 param1;
Str255 param2;
Str255 param3;
#ifndef ParamText
PyMac_PRECHECK(ParamText);
#endif
if (!PyArg_ParseTuple(_args, "O&O&O&O&",
PyMac_GetStr255, param0,
PyMac_GetStr255, param1,
PyMac_GetStr255, param2,
PyMac_GetStr255, param3))
return NULL;
ParamText(param0,
param1,
param2,
param3);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Dlg_GetDialogItemText(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
Handle item;
Str255 text;
#ifndef GetDialogItemText
PyMac_PRECHECK(GetDialogItemText);
#endif
if (!PyArg_ParseTuple(_args, "O&",
ResObj_Convert, &item))
return NULL;
GetDialogItemText(item,
text);
_res = Py_BuildValue("O&",
PyMac_BuildStr255, text);
return _res;
}
static PyObject *Dlg_SetDialogItemText(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
Handle item;
Str255 text;
#ifndef SetDialogItemText
PyMac_PRECHECK(SetDialogItemText);
#endif
if (!PyArg_ParseTuple(_args, "O&O&",
ResObj_Convert, &item,
PyMac_GetStr255, text))
return NULL;
SetDialogItemText(item,
text);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Dlg_GetAlertStage(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
SInt16 _rv;
#ifndef GetAlertStage
PyMac_PRECHECK(GetAlertStage);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = GetAlertStage();
_res = Py_BuildValue("h",
_rv);
return _res;
}
static PyObject *Dlg_SetDialogFont(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
SInt16 fontNum;
#ifndef SetDialogFont
PyMac_PRECHECK(SetDialogFont);
#endif
if (!PyArg_ParseTuple(_args, "h",
&fontNum))
return NULL;
SetDialogFont(fontNum);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Dlg_ResetAlertStage(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
#ifndef ResetAlertStage
PyMac_PRECHECK(ResetAlertStage);
#endif
if (!PyArg_ParseTuple(_args, ""))
return NULL;
ResetAlertStage();
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Dlg_GetParamText(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
Str255 param0;
Str255 param1;
Str255 param2;
Str255 param3;
#ifndef GetParamText
PyMac_PRECHECK(GetParamText);
#endif
if (!PyArg_ParseTuple(_args, "O&O&O&O&",
PyMac_GetStr255, param0,
PyMac_GetStr255, param1,
PyMac_GetStr255, param2,
PyMac_GetStr255, param3))
return NULL;
GetParamText(param0,
param1,
param2,
param3);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Dlg_NewFeaturesDialog(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogPtr _rv;
Rect inBoundsRect;
Str255 inTitle;
Boolean inIsVisible;
SInt16 inProcID;
WindowPtr inBehind;
Boolean inGoAwayFlag;
SInt32 inRefCon;
Handle inItemListHandle;
UInt32 inFlags;
#ifndef NewFeaturesDialog
PyMac_PRECHECK(NewFeaturesDialog);
#endif
if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l",
PyMac_GetRect, &inBoundsRect,
PyMac_GetStr255, inTitle,
&inIsVisible,
&inProcID,
WinObj_Convert, &inBehind,
&inGoAwayFlag,
&inRefCon,
ResObj_Convert, &inItemListHandle,
&inFlags))
return NULL;
_rv = NewFeaturesDialog((void *)0,
&inBoundsRect,
inTitle,
inIsVisible,
inProcID,
inBehind,
inGoAwayFlag,
inRefCon,
inItemListHandle,
inFlags);
_res = Py_BuildValue("O&",
DlgObj_New, _rv);
return _res;
}
static PyObject *Dlg_GetDialogFromWindow(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
DialogPtr _rv;
WindowPtr window;
#ifndef GetDialogFromWindow
PyMac_PRECHECK(GetDialogFromWindow);
#endif
if (!PyArg_ParseTuple(_args, "O&",
WinObj_Convert, &window))
return NULL;
_rv = GetDialogFromWindow(window);
_res = Py_BuildValue("O&",
DlgObj_New, _rv);
return _res;
}
static PyObject *Dlg_SetUserItemHandler(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
PyObject *new = NULL;
if (!PyArg_ParseTuple(_args, "|O", &new))
return NULL;
if (Dlg_UserItemProc_callback && new && new != Py_None) {
PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
return NULL;
}
if (new == NULL || new == Py_None) {
new = NULL;
_res = Py_None;
Py_INCREF(Py_None);
} else {
Py_INCREF(new);
_res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemUPP(Dlg_UnivUserItemProc));
}
Dlg_UserItemProc_callback = new;
return _res;
}
static PyMethodDef Dlg_methods[] = {
{"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
PyDoc_STR("(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)")},
{"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
PyDoc_STR("(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)")},
{"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
PyDoc_STR("(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)")},
{"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
PyDoc_STR("(PyObject* modalFilter) -> (DialogItemIndex itemHit)")},
{"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
PyDoc_STR("(EventRecord theEvent) -> (Boolean _rv)")},
{"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
PyDoc_STR("(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)")},
{"Alert", (PyCFunction)Dlg_Alert, 1,
PyDoc_STR("(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)")},
{"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
PyDoc_STR("(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)")},
{"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
PyDoc_STR("(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)")},
{"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
PyDoc_STR("(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)")},
{"ParamText", (PyCFunction)Dlg_ParamText, 1,
PyDoc_STR("(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None")},
{"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
PyDoc_STR("(Handle item) -> (Str255 text)")},
{"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
PyDoc_STR("(Handle item, Str255 text) -> None")},
{"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
PyDoc_STR("() -> (SInt16 _rv)")},
{"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
PyDoc_STR("(SInt16 fontNum) -> None")},
{"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
PyDoc_STR("() -> None")},
{"GetParamText", (PyCFunction)Dlg_GetParamText, 1,
PyDoc_STR("(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None")},
{"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
PyDoc_STR("(Rect inBoundsRect, Str255 inTitle, Boolean inIsVisible, SInt16 inProcID, WindowPtr inBehind, Boolean inGoAwayFlag, SInt32 inRefCon, Handle inItemListHandle, UInt32 inFlags) -> (DialogPtr _rv)")},
{"GetDialogFromWindow", (PyCFunction)Dlg_GetDialogFromWindow, 1,
PyDoc_STR("(WindowPtr window) -> (DialogPtr _rv)")},
{"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
PyDoc_STR(NULL)},
{NULL, NULL, 0}
};
/* Return the WindowPtr corresponding to a DialogObject */
#if 0
WindowPtr
DlgObj_ConvertToWindow(PyObject *self)
{
if ( DlgObj_Check(self) )
return GetDialogWindow(((DialogObject *)self)->ob_itself);
return NULL;
}
#endif
/* Return the object corresponding to the dialog, or None */
PyObject *
DlgObj_WhichDialog(DialogPtr d)
{
PyObject *it;
if (d == NULL) {
it = Py_None;
Py_INCREF(it);
} else {
WindowPtr w = GetDialogWindow(d);
it = (PyObject *) GetWRefCon(w);
if (it == NULL || ((DialogObject *)it)->ob_itself != d || !DlgObj_Check(it)) {
#if 0
/* Should do this, but we don't have an ob_freeit for dialogs yet. */
it = WinObj_New(w);
((WindowObject *)it)->ob_freeit = NULL;
#else
it = Py_None;
Py_INCREF(it);
#endif
} else {
Py_INCREF(it);
}
}
return it;
}
void init_Dlg(void)
{
PyObject *m;
PyObject *d;
PyMac_INIT_TOOLBOX_OBJECT_NEW(DialogPtr, DlgObj_New);
PyMac_INIT_TOOLBOX_OBJECT_NEW(DialogPtr, DlgObj_WhichDialog);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DialogPtr, DlgObj_Convert);
m = Py_InitModule("_Dlg", Dlg_methods);
d = PyModule_GetDict(m);
Dlg_Error = PyMac_GetOSErrException();
if (Dlg_Error == NULL ||
PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
return;
Dialog_Type.ob_type = &PyType_Type;
if (PyType_Ready(&Dialog_Type) < 0) return;
Py_INCREF(&Dialog_Type);
PyModule_AddObject(m, "Dialog", (PyObject *)&Dialog_Type);
/* Backward-compatible name */
Py_INCREF(&Dialog_Type);
PyModule_AddObject(m, "DialogType", (PyObject *)&Dialog_Type);
}
/* ======================== End module _Dlg ========================= */