annotate Mac/Python/macglue.c @ 15842:f6cd36498a50 legacy-trunk

Document extensions to .pth files.
author Martin v. Löwis <martin@v.loewis.de>
date Sat, 13 Jan 2001 09:54:41 +0000
parents 3b643653e078
children 679f826b24ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2224
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
1 /***********************************************************
5079
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4522
diff changeset
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
2224
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
3 The Netherlands.
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
4
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
5 All Rights Reserved
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
6
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
8 documentation for any purpose and without fee is hereby granted,
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
9 provided that the above copyright notice appear in all copies and that
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
10 both that copyright notice and this permission notice appear in
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
13 distribution of the software without specific, written prior permission.
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
14
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
22
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
23 ******************************************************************/
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24
4024
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
25 #ifdef __CFM68K__
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
26 /* cfm68k InterfaceLib exports GetEventQueue, but Events.h doesn't know this
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
27 ** and defines it as GetEvQHdr (which is correct for PPC). This fix is for
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
28 ** CW9, check that the workaround is still needed for the next release.
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
29 */
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
30 #define GetEvQHdr GetEventQueue
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
31 #endif /* __CFM68K__ */
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
32
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
33 #include <Events.h>
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
34
13608
a901c2c0166b Test for TARGET_API_MAC_CARBON with #if in stead of #ifdef.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13604
diff changeset
35 #if TARGET_API_MAC_CARBON
12833
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
36 /* Unfortunately this call is probably slower... */
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
37 #define LMGetTicks() TickCount()
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
38 #endif
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
39
4024
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
40 #ifdef __CFM68K__
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
41 #undef GetEventQueue
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
42 #endif /* __CFM68K__ */
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
43
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 #include "Python.h"
2337
71e60871c681 ported to Think C
Guido van Rossum <guido@python.org>
parents: 2333
diff changeset
45
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 #include "macglue.h"
2350
a2054933775b Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2337
diff changeset
47 #include "marshal.h"
a2054933775b Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2337
diff changeset
48 #include "import.h"
5737
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
49 #include "importdl.h"
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
51 #include "pythonresources.h"
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
52
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53 #include <OSUtils.h> /* for Set(Current)A5 */
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
54 #include <Files.h>
2312
40aec48cd1e2 Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents: 2276
diff changeset
55 #include <StandardFile.h>
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 #include <Resources.h>
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57 #include <Memory.h>
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58 #include <Windows.h>
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
59 #include <Traps.h>
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
60 #include <Processes.h>
2382
6450d8828d2b added applet initialization;
Guido van Rossum <guido@python.org>
parents: 2350
diff changeset
61 #include <Fonts.h>
6450d8828d2b added applet initialization;
Guido van Rossum <guido@python.org>
parents: 2350
diff changeset
62 #include <Menus.h>
2747
e41669a1dea0 Added code to obtain sys.path from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 2668
diff changeset
63 #include <TextUtils.h>
2443
2dcf7538347a Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents: 2429
diff changeset
64 #ifdef __MWERKS__
2dcf7538347a Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents: 2429
diff changeset
65 #include <SIOUX.h>
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
66 extern void SIOUXSetupMenus(void);
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
67 extern void SIOUXDoAboutBox(void);
2443
2dcf7538347a Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents: 2429
diff changeset
68 #endif
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
69 #ifdef USE_GUSI
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
70 /* Functions we redefine because they're in obscure libraries */
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
71 extern void SpinCursor(short x);
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
72 extern void RotateCursor(short x);
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
73 extern pascal void PLstrcpy(unsigned char *, unsigned char *);
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
74 extern pascal int PLstrcmp(unsigned char *, unsigned char *);
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
75 extern pascal unsigned char *PLstrrchr(unsigned char *, unsigned char);
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
76
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
77 #endif
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
78
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
79 #ifdef USE_GUSI1
3431
26bec9e22e5d Added code to make fsspecs work for gusi-python
Jack Jansen <jack.jansen@cwi.nl>
parents: 3278
diff changeset
80 #include <TFileSpec.h> /* For Path2FSSpec */
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
81 #include <GUSI.h>
3431
26bec9e22e5d Added code to make fsspecs work for gusi-python
Jack Jansen <jack.jansen@cwi.nl>
parents: 3278
diff changeset
82 #endif
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
83 #include <LowMem.h>
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
84
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
85 /* The ID of the Sioux apple menu */
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
86 #define SIOUX_APPLEID 32000
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
87
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
88 #include <signal.h>
2350
a2054933775b Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2337
diff changeset
89 #include <stdio.h>
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
90
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
91 /*
3914
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
92 ** When less than this amount of stackspace is left we
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
93 ** raise a MemoryError.
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
94 */
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
95 #ifndef MINIMUM_STACK_SIZE
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
96 #ifdef __powerc
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
97 #define MINIMUM_STACK_SIZE 8192
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
98 #else
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
99 #define MINIMUM_STACK_SIZE 4096
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
100 #endif
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
101 #endif
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
102
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
103 /*
2443
2dcf7538347a Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents: 2429
diff changeset
104 ** We have to be careful, since we can't handle
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
105 ** things like updates (and they'll keep coming back if we don't
2443
2dcf7538347a Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents: 2429
diff changeset
106 ** handle them). Note that we don't know who has windows open, so
2dcf7538347a Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents: 2429
diff changeset
107 ** even handing updates off to SIOUX under MW isn't going to work.
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
108 */
6162
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
109 #define MAINLOOP_EVENTMASK (mDownMask|keyDownMask|osMask|activMask)
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
110
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
111 #include <signal.h>
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
112
2224
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
113 /* XXX We should include Errors.h here, but it has a name conflict
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
114 ** with the python errors.h. */
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
115 #define fnfErr -43
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
116
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
117 /* Declared in macfsmodule.c: */
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
118 extern FSSpec *mfs_GetFSSpecFSSpec(PyObject *);
13542
ddd6138c9e6f ANSIfication step 1: get rid of Py_PROTO and Py_FPROTO.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12855
diff changeset
119 extern PyObject *newmfssobject(FSSpec *);
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
120
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
121 /* Interrupt code variables: */
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
122 static int interrupted; /* Set to true when cmd-. seen */
13542
ddd6138c9e6f ANSIfication step 1: get rid of Py_PROTO and Py_FPROTO.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12855
diff changeset
123 static RETSIGTYPE intcatcher(int);
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
124
13542
ddd6138c9e6f ANSIfication step 1: get rid of Py_PROTO and Py_FPROTO.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12855
diff changeset
125 static int PyMac_Yield(void);
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
126
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
127 /*
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
128 ** These are the real scheduling parameters that control what we check
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
129 ** in the event loop, and how often we check. The values are initialized
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
130 ** from pyMac_SchedParamStruct.
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
131 */
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
132
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
133 struct real_sched_param_struct {
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
134 int check_interrupt; /* if true check for command-dot */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
135 int process_events; /* if nonzero enable evt processing, this mask */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
136 int besocial; /* if nonzero be a little social with CPU */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
137 unsigned long check_interval; /* how often to check, in ticks */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
138 unsigned long bg_yield; /* yield so long when in background */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
139 /* these are computed from previous and clock and such */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
140 int enabled; /* check_interrupt OR process_event OR yield */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
141 unsigned long next_check; /* when to check/yield next, in ticks */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
142 };
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
143
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
144 static struct real_sched_param_struct schedparams =
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
145 { 1, MAINLOOP_EVENTMASK, 1, 15, 15, 1, 0};
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
146
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
147 /*
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
148 ** Workaround for sioux/gusi combo: set when we are exiting
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
149 */
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
150 int PyMac_ConsoleIsDead;
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
151
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
152 /*
5732
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
153 ** Sioux menu bar, saved early so we can restore it
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
154 */
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
155 static Handle sioux_mbar;
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
156
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
157 /*
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
158 ** Some stuff for our GetDirectory and PromptGetFile routines
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
159 */
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
160 struct hook_args {
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
161 int selectcur_hit; /* Set to true when "select current" selected */
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
162 char *prompt; /* The prompt */
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
163 };
13608
a901c2c0166b Test for TARGET_API_MAC_CARBON with #if in stead of #ifdef.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13604
diff changeset
164 #if TARGET_API_MAC_CARBON
12833
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
165 /* The StandardFile hooks don't exist in Carbon. This breaks GetDirectory,
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
166 ** but the macfsn code will replace it by a NavServices version anyway.
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
167 */
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
168 #define myhook_upp NULL
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
169 #else
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
170 static DlgHookYDUPP myhook_upp;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
171 static int upp_inited = 0;
12833
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
172 #endif
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
173
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
174 /*
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
175 ** The python-code event handler
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
176 */
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
177 static PyObject *python_event_handler;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
178
11529
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 8790
diff changeset
179 /*
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 8790
diff changeset
180 ** Set to true if we're appearance-compliant
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 8790
diff changeset
181 */
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 8790
diff changeset
182 int PyMac_AppearanceCompliant;
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 8790
diff changeset
183
13701
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
184 /*
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
185 ** Find out what the current script is.
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
186 ** Donated by Fredrik Lund.
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
187 */
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
188 char *PyMac_getscript()
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
189 {
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
190 int font, script, lang;
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
191 font = 0;
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
192 font = GetSysFont();
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
193 script = FontToScript(font);
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
194 switch (script) {
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
195 case smRoman:
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
196 lang = GetScriptVariable(script, smScriptLang);
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
197 if (lang == langIcelandic)
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
198 return "mac-iceland";
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
199 else if (lang == langTurkish)
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
200 return "mac-turkish";
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
201 else if (lang == langGreek)
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
202 return "mac-greek";
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
203 else
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
204 return "mac-roman";
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
205 break;
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
206 case smJapanese:
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
207 return "mac-japan";
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
208 case smGreek:
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
209 return "mac-greek";
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
210 case smCyrillic:
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
211 return "mac-cyrillic";
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
212 default:
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
213 return "mac-roman"; /* better than nothing */
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
214 }
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
215 }
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
216
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
217
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
218 #ifdef USE_GUSI1
3433
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
219 /*
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
220 ** GUSI (1.6.0 and earlier, at the least) do not set the MacOS idea of
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
221 ** the working directory. Hence, we call this routine after each call
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
222 ** to chdir() to rectify things.
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
223 */
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
224 void
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
225 PyMac_FixGUSIcd()
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
226 {
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
227 WDPBRec pb;
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
228 FSSpec curdirfss;
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
229
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
230 if ( Path2FSSpec(":x", &curdirfss) != noErr )
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
231 return;
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
232
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
233 /* Set MacOS "working directory" */
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
234 pb.ioNamePtr= "\p";
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
235 pb.ioVRefNum= curdirfss.vRefNum;
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
236 pb.ioWDDirID= curdirfss.parID;
5270
de9d0c5249b0 Changed the few old routine names still used to the new ones
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
237 if (PBHSetVolSync(&pb) != noErr)
3433
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
238 return;
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
239 }
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
240 #endif
4013
aa9548885b3f Dummy SpinCursor() if __CFM68K__ is defined
Jack Jansen <jack.jansen@cwi.nl>
parents: 3914
diff changeset
241
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
242 #ifdef USE_GUSI
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4215
diff changeset
243 /*
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4215
diff changeset
244 ** SpinCursor (needed by GUSI) drags in heaps of stuff, so we
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4215
diff changeset
245 ** provide a dummy here.
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4215
diff changeset
246 */
4018
Jack Jansen <jack.jansen@cwi.nl>
parents: 4013
diff changeset
247 void SpinCursor(short x) { /* Dummy */ }
7438
cd11690cb14b - Universal Headers 3 mods
Jack Jansen <jack.jansen@cwi.nl>
parents: 6461
diff changeset
248 void RotateCursor(short x) { /* Dummy */ }
4018
Jack Jansen <jack.jansen@cwi.nl>
parents: 4013
diff changeset
249
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
250 /*
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
251 ** Replacement GUSI Spin function
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
252 */
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
253 #ifdef USE_GUSI1
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
254 static int
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
255 PyMac_GUSISpin(spin_msg msg, long arg)
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
256 {
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
257 static Boolean inForeground = true;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
258 int maxsleep = 6; /* 6 ticks is "normal" sleeptime */
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
259
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
260 if (PyMac_ConsoleIsDead) return 0;
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
261 #if 0
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
262 if (inForeground)
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
263 SpinCursor(msg == SP_AUTO_SPIN ? short(arg) : 1);
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
264 #endif
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
265
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
266 if (interrupted) return -1;
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
267
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
268 if ( msg == SP_AUTO_SPIN )
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
269 maxsleep = 0;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
270 if ( msg==SP_SLEEP||msg==SP_SELECT )
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
271 maxsleep = arg;
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
272
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
273 PyMac_DoYield(maxsleep, 0); /* XXXX or is it safe to call python here? */
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
274
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
275 return 0;
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
276 }
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
277
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
278 void
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
279 PyMac_SetGUSISpin() {
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
280 GUSISetHook(GUSI_SpinHook, (GUSIHook)PyMac_GUSISpin);
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
281 }
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
282 #endif
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
283
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
284 /* Called at exit() time thru atexit(), to stop event processing */
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
285 void
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
286 PyMac_StopGUSISpin() {
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
287 PyMac_ConsoleIsDead = 1;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
288 }
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
289
15825
4328ffe647bf Disabled a few other routines that are available in CarbonLib.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15786
diff changeset
290 #if !TARGET_API_MAC_CARBON
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
291 /*
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
292 ** Replacement routines for the PLstr... functions so we don't need
15825
4328ffe647bf Disabled a few other routines that are available in CarbonLib.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15786
diff changeset
293 ** StdCLib.
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
294 */
11548
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
295 pascal void
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
296 PLstrcpy(unsigned char *to, unsigned char *fr)
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
297 {
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
298 memcpy(to, fr, fr[0]+1);
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
299 }
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
300
11548
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
301 pascal int
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
302 PLstrcmp(unsigned char *s1, unsigned char *s2)
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
303 {
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
304 int res;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
305 int l = s1[0] < s2[0] ? s1[0] : s2[0];
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
306
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
307 res = memcmp(s1+1, s2+1, l);
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
308 if ( res != 0 )
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
309 return res;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
310
8790
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
311 if ( s1[0] < s2[0] )
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
312 return -1;
8790
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
313 else if ( s1[0] > s2[0] )
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
314 return 1;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
315 else
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
316 return 0;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
317 }
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
318
11548
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
319 pascal unsigned char *
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
320 PLstrrchr(unsigned char *str, unsigned char chr)
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
321 {
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
322 unsigned char *ptr = 0;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
323 unsigned char *p;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
324
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
325 for(p=str+1; p<str+str[0]; p++)
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
326 if ( *p == chr )
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
327 ptr = p;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
328 return ptr;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
329 }
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
330
15825
4328ffe647bf Disabled a few other routines that are available in CarbonLib.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15786
diff changeset
331 #endif /* !TARGET_API_MAC_CARBON */
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
332 #endif /* USE_GUSI */
3433
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
333
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
334
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
335 /* Convert C to Pascal string. Returns pointer to static buffer. */
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
336 unsigned char *
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
337 Pstring(char *str)
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
338 {
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
339 static Str255 buf;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
340 int len;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
341
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
342 len = strlen(str);
2209
4053d4cb50e0 renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents: 2183
diff changeset
343 if (len > 255)
4053d4cb50e0 renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents: 2183
diff changeset
344 len = 255;
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
345 buf[0] = (unsigned char)len;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
346 strncpy((char *)buf+1, str, len);
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
347 return buf;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
348 }
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
349
15786
83e146974b72 Don't need to define c2pstrcpy() on Carbon: it's in CarbonLib.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15529
diff changeset
350 #if !TARGET_API_MAC_CARBON
15529
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
351 void
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
352 c2pstrcpy(unsigned char *dst, const char *src)
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
353 {
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
354 int len;
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
355
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
356 len = strlen(src);
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
357 if ( len > 255 ) len = 255;
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
358 strncpy((char *)dst+1, src, len);
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
359 dst[0] = len;
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
360 }
15825
4328ffe647bf Disabled a few other routines that are available in CarbonLib.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15786
diff changeset
361 #endif /* !TARGET_API_MAC_CARBON */
15529
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
362
2382
6450d8828d2b added applet initialization;
Guido van Rossum <guido@python.org>
parents: 2350
diff changeset
363 /* Like strerror() but for Mac OS error numbers */
6450d8828d2b added applet initialization;
Guido van Rossum <guido@python.org>
parents: 2350
diff changeset
364 char *PyMac_StrError(int err)
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
365 {
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
366 static char buf[256];
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
367 Handle h;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
368 char *str;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
369
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
370 h = GetResource('Estr', err);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
371 if ( h ) {
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
372 HLock(h);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
373 str = (char *)*h;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
374 memcpy(buf, str+1, (unsigned char)str[0]);
2324
faaece7ccd6e null-terminate the error string in macstrerror
Guido van Rossum <guido@python.org>
parents: 2312
diff changeset
375 buf[(unsigned char)str[0]] = '\0';
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
376 HUnlock(h);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
377 ReleaseResource(h);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
378 } else {
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
379 sprintf(buf, "Mac OS error code %d", err);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
380 }
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
381 return buf;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
382 }
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
383
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
384 /* Exception object shared by all Mac specific modules for Mac OS errors */
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
385 PyObject *PyMac_OSErrException;
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
386
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
387 /* Initialize and return PyMac_OSErrException */
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
388 PyObject *
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
389 PyMac_GetOSErrException()
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
390 {
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
391 if (PyMac_OSErrException == NULL)
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
392 PyMac_OSErrException = PyString_FromString("Mac OS Error");
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
393 return PyMac_OSErrException;
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
394 }
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
395
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
396 /* Set a MAC-specific error from errno, and return NULL; return None if no error */
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
397 PyObject *
2136
c57b5c50a2d2 rename2 changes
Guido van Rossum <guido@python.org>
parents: 2035
diff changeset
398 PyErr_Mac(PyObject *eobj, int err)
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
399 {
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
400 char *msg;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
401 PyObject *v;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
402
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
403 if (err == 0 && !PyErr_Occurred()) {
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
404 Py_INCREF(Py_None);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
405 return Py_None;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
406 }
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
407 if (err == -1 && PyErr_Occurred())
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
408 return NULL;
2382
6450d8828d2b added applet initialization;
Guido van Rossum <guido@python.org>
parents: 2350
diff changeset
409 msg = PyMac_StrError(err);
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
410 v = Py_BuildValue("(is)", err, msg);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
411 PyErr_SetObject(eobj, v);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
412 Py_DECREF(v);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
413 return NULL;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
414 }
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
415
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
416 /* Call PyErr_Mac with PyMac_OSErrException */
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
417 PyObject *
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
418 PyMac_Error(OSErr err)
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
419 {
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
420 return PyErr_Mac(PyMac_GetOSErrException(), err);
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
421 }
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
422
3786
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
423 #ifdef USE_STACKCHECK
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
424 /* Check for stack overflow */
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
425 int
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
426 PyOS_CheckStack()
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
427 {
14197
2787e93817c6 Cheaper implementation of PyOS_CheckStack: only call StackSpace once and keep a sentinel in a static variable.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13701
diff changeset
428 char here;
2787e93817c6 Cheaper implementation of PyOS_CheckStack: only call StackSpace once and keep a sentinel in a static variable.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13701
diff changeset
429 static char *sentinel = 0;
14476
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
430 static PyThreadState *thread_for_sentinel = 0;
3786
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
431
14197
2787e93817c6 Cheaper implementation of PyOS_CheckStack: only call StackSpace once and keep a sentinel in a static variable.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13701
diff changeset
432 if ( sentinel == 0 ) {
2787e93817c6 Cheaper implementation of PyOS_CheckStack: only call StackSpace once and keep a sentinel in a static variable.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13701
diff changeset
433 sentinel = &here - StackSpace() + MINIMUM_STACK_SIZE;
2787e93817c6 Cheaper implementation of PyOS_CheckStack: only call StackSpace once and keep a sentinel in a static variable.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13701
diff changeset
434 }
14476
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
435 if ( thread_for_sentinel == 0 ) {
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
436 thread_for_sentinel = PyThreadState_Get();
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
437 }
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
438 if ( &here < sentinel ) {
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
439 if (thread_for_sentinel == PyThreadState_Get()) {
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
440 return -1;
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
441 #if 0
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
442 } else {
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
443 /* Else we are unsure... */
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
444 fprintf(stderr, "Stackcheck in other thread (was %x now %x)\n", thread_for_sentinel,PyThreadState_Get());
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
445 #endif
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
446 }
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
447 }
3786
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
448 return 0;
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
449 }
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
450 #endif /* USE_STACKCHECK */
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
451
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
452 /* The catcher routine (which may not be used for all compilers) */
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
453 static RETSIGTYPE
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
454 intcatcher(sig)
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
455 int sig;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
456 {
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
457 interrupted = 1;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
458 signal(SIGINT, intcatcher);
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
459 }
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
460
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
461 void
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
462 PyOS_InitInterrupts()
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
463 {
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
464 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
465 signal(SIGINT, intcatcher);
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
466 }
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
467
5962
23e014839ab0 Added (dummy) PyOS_FiniInterrupts
Jack Jansen <jack.jansen@cwi.nl>
parents: 5744
diff changeset
468 void
23e014839ab0 Added (dummy) PyOS_FiniInterrupts
Jack Jansen <jack.jansen@cwi.nl>
parents: 5744
diff changeset
469 PyOS_FiniInterrupts()
23e014839ab0 Added (dummy) PyOS_FiniInterrupts
Jack Jansen <jack.jansen@cwi.nl>
parents: 5744
diff changeset
470 {
23e014839ab0 Added (dummy) PyOS_FiniInterrupts
Jack Jansen <jack.jansen@cwi.nl>
parents: 5744
diff changeset
471 }
23e014839ab0 Added (dummy) PyOS_FiniInterrupts
Jack Jansen <jack.jansen@cwi.nl>
parents: 5744
diff changeset
472
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
473 /*
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
474 ** This routine scans the event queue looking for cmd-.
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
475 ** This is the only way to get an interrupt under THINK (since it
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
476 ** doesn't do SIGINT handling), but is also used under MW, when
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
477 ** the full-fledged event loop is disabled. This way, we can at least
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
478 ** interrupt a runaway python program.
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
479 */
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
480 static void
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
481 scan_event_queue(flush)
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
482 int flush;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
483 {
13608
a901c2c0166b Test for TARGET_API_MAC_CARBON with #if in stead of #ifdef.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13604
diff changeset
484 #if TARGET_API_MAC_CARBON
15839
3b643653e078 Fixed Carbon command-dot handling. There is still a problem, though, and you may have to hit it repeatedly.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15825
diff changeset
485 if ( CheckEventQueueForUserCancel() )
3b643653e078 Fixed Carbon command-dot handling. There is still a problem, though, and you may have to hit it repeatedly.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15825
diff changeset
486 interrupted = 1;
12833
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
487 #else
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
488 register EvQElPtr q;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
489
7438
cd11690cb14b - Universal Headers 3 mods
Jack Jansen <jack.jansen@cwi.nl>
parents: 6461
diff changeset
490 q = (EvQElPtr) LMGetEventQueue()->qHead;
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
491
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
492 for (; q; q = (EvQElPtr)q->qLink) {
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
493 if (q->evtQWhat == keyDown &&
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
494 (char)q->evtQMessage == '.' &&
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
495 (q->evtQModifiers & cmdKey) != 0) {
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
496 if ( flush )
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
497 FlushEvents(keyDownMask, 0);
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
498 interrupted = 1;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
499 break;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
500 }
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
501 }
12833
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
502 #endif
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
503 }
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
504
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
505 int
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
506 PyErr_CheckSignals()
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
507 {
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
508 if (schedparams.enabled) {
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
509 if ( (unsigned long)LMGetTicks() > schedparams.next_check ) {
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
510 if ( PyMac_Yield() < 0)
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
511 return -1;
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
512 schedparams.next_check = (unsigned long)LMGetTicks()
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
513 + schedparams.check_interval;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
514 if (interrupted) {
5732
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
515 scan_event_queue(1); /* Eat events up to cmd-. */
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
516 interrupted = 0;
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
517 PyErr_SetNone(PyExc_KeyboardInterrupt);
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
518 return -1;
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
519 }
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
520 }
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
521 }
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
522 return 0;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
523 }
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
524
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
525 int
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
526 PyOS_InterruptOccurred()
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
527 {
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
528 scan_event_queue(1);
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
529 return interrupted;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
530 }
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
531 /* Check whether we are in the foreground */
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
532 static int
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
533 PyMac_InForeground(void)
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
534 {
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
535 static ProcessSerialNumber ours;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
536 static inited;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
537 ProcessSerialNumber curfg;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
538 Boolean eq;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
539
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
540 if ( inited == 0 ) {
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
541 (void)GetCurrentProcess(&ours);
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
542 inited = 1;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
543 }
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
544 if ( GetFrontProcess(&curfg) < 0 )
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
545 eq = 1;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
546 else if ( SameProcess(&ours, &curfg, &eq) < 0 )
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
547 eq = 1;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
548 return (int)eq;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
549
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
550 }
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
551
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
552 int
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
553 PyMac_SetEventHandler(PyObject *evh)
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
554 {
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
555 if ( evh && python_event_handler ) {
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
556 PyErr_SetString(PyExc_RuntimeError, "Python event handler already set");
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
557 return 0;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
558 }
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
559 if ( python_event_handler )
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
560 Py_DECREF(python_event_handler);
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
561 if ( evh )
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
562 Py_INCREF(evh);
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
563 python_event_handler = evh;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
564 return 1;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
565 }
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
566
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
567 /*
2276
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
568 ** Handle an event, either one found in the mainloop eventhandler or
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
569 ** one passed back from the python program.
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
570 */
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
571 void
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
572 PyMac_HandleEventIntern(evp)
2276
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
573 EventRecord *evp;
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
574 {
13608
a901c2c0166b Test for TARGET_API_MAC_CARBON with #if in stead of #ifdef.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13604
diff changeset
575 #if !TARGET_API_MAC_CARBON
6162
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
576 if ( evp->what == mouseDown ) {
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
577 WindowPtr wp;
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
578
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
579 if ( FindWindow(evp->where, &wp) == inSysWindow ) {
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
580 SystemClick(evp, wp);
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
581 return;
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
582 }
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
583 }
12833
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
584 #endif
2276
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
585 #ifdef __MWERKS__
3248
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
586 {
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
587 int siouxdidit;
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
588
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
589 /* If SIOUX wants it we're done */
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
590 siouxdidit = SIOUXHandleOneEvent(evp);
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
591 if ( siouxdidit )
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
592 return;
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
593 }
2276
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
594 #else
6162
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
595 /* Other compilers are just unlucky... */
2276
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
596 #endif /* !__MWERKS__ */
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
597 }
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
598
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
599 /*
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
600 ** Handle an event, either through HandleEvent or by passing it to the Python
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
601 ** event handler.
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
602 */
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
603 int
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
604 PyMac_HandleEvent(evp)
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
605 EventRecord *evp;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
606 {
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
607 PyObject *rv;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
608
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
609 if ( python_event_handler ) {
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
610 rv = PyObject_CallFunction(python_event_handler, "(O&)",
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
611 PyMac_BuildEventRecord, evp);
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
612 if ( rv )
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
613 Py_DECREF(rv);
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
614 else
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
615 return -1; /* Propagate exception */
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
616 } else {
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
617 PyMac_HandleEventIntern(evp);
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
618 }
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
619 return 0;
2276
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
620 }
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
621
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
622 /*
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
623 ** Yield the CPU to other tasks without processing events.
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
624 */
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
625 int
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
626 PyMac_DoYield(int maxsleep, int maycallpython)
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
627 {
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
628 EventRecord ev;
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
629 int gotone;
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
630 long latest_time_ready;
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
631 static int in_here = 0;
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
632
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
633 in_here++;
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
634 /*
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
635 ** First check for interrupts, if wanted.
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
636 ** This sets a flag that will be picked up at an appropriate
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
637 ** moment in the mainloop.
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
638 */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
639 if (schedparams.check_interrupt)
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
640 scan_event_queue(0);
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
641
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
642 /* XXXX Implementing an idle routine goes here */
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
643
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
644 /*
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
645 ** Check which of the eventloop cases we have:
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
646 ** - process events
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
647 ** - don't process events but do yield
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
648 ** - do neither
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
649 */
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
650 if( in_here > 1 || !schedparams.process_events ||
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
651 (python_event_handler && !maycallpython) ) {
13608
a901c2c0166b Test for TARGET_API_MAC_CARBON with #if in stead of #ifdef.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13604
diff changeset
652 #if !TARGET_API_MAC_CARBON
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
653 if ( maxsleep >= 0 ) {
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
654 SystemTask();
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
655 }
12833
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
656 #endif
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
657 } else {
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
658 latest_time_ready = LMGetTicks() + maxsleep;
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
659 do {
6162
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
660 /* XXXX Hack by Jack.
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
661 ** In time.sleep() you can click to another application
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
662 ** once only. If you come back to Python you cannot get away
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
663 ** again.
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
664 **/
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
665 gotone = WaitNextEvent(schedparams.process_events, &ev, maxsleep, NULL);
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
666 /* Get out quickly if nothing interesting is happening */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
667 if ( !gotone || ev.what == nullEvent )
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
668 break;
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
669 if ( PyMac_HandleEvent(&ev) < 0 ) {
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
670 in_here--;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
671 return -1;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
672 }
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
673 maxsleep = latest_time_ready - LMGetTicks();
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
674 } while ( maxsleep > 0 );
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
675 }
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
676 in_here--;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
677 return 0;
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
678 }
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
679
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
680 /*
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
681 ** Process events and/or yield the CPU to other tasks if opportune
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
682 */
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
683 int
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
684 PyMac_Yield() {
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
685 unsigned long maxsleep;
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
686
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
687 if( PyMac_InForeground() )
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
688 maxsleep = 0;
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
689 else
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
690 maxsleep = schedparams.bg_yield;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
691
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
692 return PyMac_DoYield(maxsleep, 1);
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
693 }
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
694
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
695 /*
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
696 ** Return current scheduler parameters
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
697 */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
698 void
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
699 PyMac_GetSchedParams(PyMacSchedParams *sp)
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
700 {
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
701 sp->check_interrupt = schedparams.check_interrupt;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
702 sp->process_events = schedparams.process_events;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
703 sp->besocial = schedparams.besocial;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
704 sp->check_interval = schedparams.check_interval / 60.0;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
705 sp->bg_yield = schedparams.bg_yield / 60.0;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
706 }
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
707
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
708 /*
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
709 ** Set current scheduler parameters
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
710 */
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
711 void
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
712 PyMac_SetSchedParams(PyMacSchedParams *sp)
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
713 {
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
714 schedparams.check_interrupt = sp->check_interrupt;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
715 schedparams.process_events = sp->process_events;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
716 schedparams.besocial = sp->besocial;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
717 schedparams.check_interval = (unsigned long)(sp->check_interval*60);
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
718 schedparams.bg_yield = (unsigned long)(sp->bg_yield*60);
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
719 if ( schedparams.check_interrupt || schedparams.process_events ||
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
720 schedparams.besocial )
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
721 schedparams.enabled = 1;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
722 else
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
723 schedparams.enabled = 0;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
724 schedparams.next_check = 0; /* Check immedeately */
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
725 }
5732
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
726
2350
a2054933775b Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2337
diff changeset
727 /*
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
728 ** Install our menu bar.
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
729 */
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
730 void
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
731 PyMac_InitMenuBar()
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
732 {
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
733 MenuHandle applemenu;
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
734
5732
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
735 if ( (sioux_mbar=GetMenuBar()) == NULL ) {
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
736 /* Sioux menu not installed yet. Do so */
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
737 SIOUXSetupMenus();
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
738 if ( (sioux_mbar=GetMenuBar()) == NULL )
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
739 return;
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
740 }
5270
de9d0c5249b0 Changed the few old routine names still used to the new ones
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
741 if ( (applemenu=GetMenuHandle(SIOUX_APPLEID)) == NULL ) return;
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
742 SetMenuItemText(applemenu, 1, "\pAbout Python...");
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
743 }
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
744
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
745 /*
5732
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
746 ** Restore sioux menu bar
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
747 */
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
748 void
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
749 PyMac_RestoreMenuBar()
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
750 {
5737
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
751 if ( sioux_mbar ) {
5732
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
752 SetMenuBar(sioux_mbar);
5737
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
753 DrawMenuBar();
7438
cd11690cb14b - Universal Headers 3 mods
Jack Jansen <jack.jansen@cwi.nl>
parents: 6461
diff changeset
754 } else
cd11690cb14b - Universal Headers 3 mods
Jack Jansen <jack.jansen@cwi.nl>
parents: 6461
diff changeset
755 PyMac_InitMenuBar();
5732
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
756 }
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
757
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
758
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
759 /*
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
760 ** Our replacement about box
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
761 */
8790
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
762
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
763 #include "patchlevel.h"
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
764
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
765 void
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
766 SIOUXDoAboutBox(void)
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
767 {
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
768 DialogPtr theDialog;
8790
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
769 WindowPtr theWindow;
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
770 short item;
8790
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
771 short fontID;
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
772
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
773 if( (theDialog = GetNewDialog(ABOUT_ID, NULL, (WindowPtr)-1)) == NULL )
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
774 return;
4325
12c3865aeaa0 Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
775 theWindow = GetDialogWindow(theDialog);
8790
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
776 SetPortWindowPort(theWindow);
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
777 GetFNum("\pPython-Sans", &fontID);
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
778 if (fontID == 0)
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
779 fontID = kFontIDGeneva;
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
780 TextFont(fontID);
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
781 TextSize(9);
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
782 ParamText(Pstring(PATCHLEVEL), "\p", "\p", "\p");
4325
12c3865aeaa0 Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
783 ShowWindow(theWindow);
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
784 ModalDialog(NULL, &item);
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
785 DisposeDialog(theDialog);
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
786 }
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
787
5737
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
788 #if 0
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
789 int
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
790 PyMac_FileExists(char *name)
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
791 {
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
792 FSSpec fss;
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
793
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
794 if ( FSMakeFSSpec(0, 0, Pstring(name), &fss) == noErr )
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
795 return 1;
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
796 return 0;
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
797 }
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
798 #endif
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
799
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
800 /*
2403
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
801 ** Helper routine for GetDirectory
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
802 */
2412
75ae104f7e6c ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents: 2403
diff changeset
803 static pascal short
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
804 myhook_proc(short item, DialogPtr theDialog, struct hook_args *dataptr)
2403
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
805 {
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
806 if ( item == sfHookFirstCall && dataptr->prompt) {
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
807 Handle prompth;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
808 short type;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
809 Rect rect;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
810
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
811 GetDialogItem(theDialog, PROMPT_ITEM, &type, &prompth, &rect);
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
812 if ( prompth )
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
813 SetDialogItemText(prompth, (unsigned char *)dataptr->prompt);
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
814 } else
2403
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
815 if ( item == SELECTCUR_ITEM ) {
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
816 item = sfItemCancelButton;
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
817 dataptr->selectcur_hit = 1;
2403
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
818 }
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
819 return item;
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
820 }
13608
a901c2c0166b Test for TARGET_API_MAC_CARBON with #if in stead of #ifdef.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13604
diff changeset
821 #if !TARGET_API_MAC_CARBON
2403
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
822 /*
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
823 ** Ask the user for a directory. I still can't understand
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
824 ** why Apple doesn't provide a standard solution for this...
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
825 */
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
826 int
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
827 PyMac_GetDirectory(dirfss, prompt)
2403
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
828 FSSpec *dirfss;
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
829 char *prompt;
2403
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
830 {
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
831 static SFTypeList list = {'fldr', 0, 0, 0};
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
832 static Point where = {-1, -1};
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
833 StandardFileReply reply;
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
834 struct hook_args hook_args;
2403
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
835
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
836 if ( !upp_inited ) {
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
837 myhook_upp = NewDlgHookYDProc(myhook_proc);
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
838 upp_inited = 1;
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
839 }
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
840 if ( prompt && *prompt )
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
841 hook_args.prompt = (char *)Pstring(prompt);
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
842 else
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
843 hook_args.prompt = NULL;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
844 hook_args.selectcur_hit = 0;
2412
75ae104f7e6c ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents: 2403
diff changeset
845 CustomGetFile((FileFilterYDUPP)0, 1, list, &reply, GETDIR_ID, where, myhook_upp,
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
846 NULL, NULL, NULL, (void *)&hook_args);
2403
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
847
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
848 reply.sfFile.name[0] = 0;
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
849 if( FSMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, dirfss) )
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
850 return 0;
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
851 return hook_args.selectcur_hit;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
852 }
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
853
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
854 /*
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
855 ** Slightly extended StandardGetFile: accepts a prompt */
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
856 void PyMac_PromptGetFile(short numTypes, ConstSFTypeListPtr typeList,
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
857 StandardFileReply *reply, char *prompt)
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
858 {
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
859 static Point where = {-1, -1};
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
860 struct hook_args hook_args;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
861
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
862 if ( !upp_inited ) {
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
863 myhook_upp = NewDlgHookYDProc(myhook_proc);
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
864 upp_inited = 1;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
865 }
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
866 if ( prompt && *prompt )
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
867 hook_args.prompt = (char *)Pstring(prompt);
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
868 else
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
869 hook_args.prompt = NULL;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
870 hook_args.selectcur_hit = 0;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
871 CustomGetFile((FileFilterYDUPP)0, numTypes, typeList, reply, GETFILEPROMPT_ID, where,
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
872 myhook_upp, NULL, NULL, NULL, (void *)&hook_args);
2403
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
873 }
13604
483e75efc111 PyMac_PromptGetFile and PyMac_GetDirectory don't exist in carbonpython.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13547
diff changeset
874 #endif /* TARGET_API_MAC_CARBON */
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
875
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
876 /* Convert a 4-char string object argument to an OSType value */
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
877 int
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
878 PyMac_GetOSType(PyObject *v, OSType *pr)
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
879 {
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
880 if (!PyString_Check(v) || PyString_Size(v) != 4) {
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
881 PyErr_SetString(PyExc_TypeError,
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
882 "OSType arg must be string of 4 chars");
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
883 return 0;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
884 }
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
885 memcpy((char *)pr, PyString_AsString(v), 4);
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
886 return 1;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
887 }
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
888
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
889 /* Convert an OSType value to a 4-char string object */
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
890 PyObject *
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
891 PyMac_BuildOSType(OSType t)
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
892 {
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
893 return PyString_FromStringAndSize((char *)&t, 4);
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
894 }
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
895
3914
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
896 /* Convert an NumVersion value to a 4-element tuple */
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
897 PyObject *
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
898 PyMac_BuildNumVersion(NumVersion t)
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
899 {
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
900 return Py_BuildValue("(hhhh)", t.majorRev, t.minorAndBugRev, t.stage, t.nonRelRev);
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
901 }
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
902
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
903
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
904 /* Convert a Python string object to a Str255 */
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
905 int
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
906 PyMac_GetStr255(PyObject *v, Str255 pbuf)
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
907 {
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
908 int len;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
909 if (!PyString_Check(v) || (len = PyString_Size(v)) > 255) {
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
910 PyErr_SetString(PyExc_TypeError,
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
911 "Str255 arg must be string of at most 255 chars");
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
912 return 0;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
913 }
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
914 pbuf[0] = len;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
915 memcpy((char *)(pbuf+1), PyString_AsString(v), len);
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
916 return 1;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
917 }
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
918
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
919 /* Convert a Str255 to a Python string object */
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
920 PyObject *
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
921 PyMac_BuildStr255(Str255 s)
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
922 {
11591
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
923 if ( s == NULL ) {
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
924 PyErr_SetString(PyExc_SystemError, "Str255 pointer is NULL");
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
925 return NULL;
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
926 }
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
927 return PyString_FromStringAndSize((char *)&s[1], (int)s[0]);
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
928 }
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
929
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
930 PyObject *
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
931 PyMac_BuildOptStr255(Str255 s)
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
932 {
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
933 if ( s == NULL ) {
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
934 Py_INCREF(Py_None);
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
935 return Py_None;
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
936 }
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
937 return PyString_FromStringAndSize((char *)&s[1], (int)s[0]);
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
938 }
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
939
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
940
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
941 /*
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
942 ** Convert a Python object to an FSSpec.
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
943 ** The object may either be a full pathname or a triple
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
944 ** (vrefnum, dirid, path).
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
945 ** NOTE: This routine will fail on pre-sys7 machines.
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
946 ** The caller is responsible for not calling this routine
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
947 ** in those cases (which is fine, since everyone calling
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
948 ** this is probably sys7 dependent anyway).
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
949 */
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
950 int
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
951 PyMac_GetFSSpec(PyObject *v, FSSpec *fs)
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
952 {
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
953 Str255 path;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
954 short refnum;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
955 long parid;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
956 OSErr err;
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
957 FSSpec *fs2;
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
958
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
959 /* first check whether it already is an FSSpec */
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
960 fs2 = mfs_GetFSSpecFSSpec(v);
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
961 if ( fs2 ) {
2403
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
962 (void)FSMakeFSSpec(fs2->vRefNum, fs2->parID, fs2->name, fs);
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
963 return 1;
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
964 }
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
965 if ( PyString_Check(v) ) {
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
966 /* It's a pathname */
2209
4053d4cb50e0 renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents: 2183
diff changeset
967 if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) )
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
968 return 0;
3433
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
969 refnum = 0; /* XXXX Should get CurWD here?? */
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
970 parid = 0;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
971 } else {
2209
4053d4cb50e0 renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents: 2183
diff changeset
972 if( !PyArg_Parse(v, "(hlO&); FSSpec should be fullpath or (vrefnum,dirid,path)",
4053d4cb50e0 renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents: 2183
diff changeset
973 &refnum, &parid, PyMac_GetStr255, &path)) {
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
974 return 0;
2209
4053d4cb50e0 renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents: 2183
diff changeset
975 }
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
976 }
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
977 err = FSMakeFSSpec(refnum, parid, path, fs);
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
978 if ( err && err != fnfErr ) {
11676
489483b65b3a If there's an error in an fsspec argument raise MacOS.Error, not ValueError.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11591
diff changeset
979 PyMac_Error(err);
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
980 return 0;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
981 }
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
982 return 1;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
983 }
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
984
11548
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
985 /* Convert FSSpec to PyObject */
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
986 PyObject *PyMac_BuildFSSpec(FSSpec *v)
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
987 {
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
988 return newmfssobject(v);
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
989 }
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
990
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
991 /* Convert a Python object to a Rect.
2255
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
992 The object must be a (left, top, right, bottom) tuple.
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
993 (This differs from the order in the struct but is consistent with
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
994 the arguments to SetRect(), and also with STDWIN). */
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
995 int
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
996 PyMac_GetRect(PyObject *v, Rect *r)
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
997 {
2255
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
998 return PyArg_Parse(v, "(hhhh)", &r->left, &r->top, &r->right, &r->bottom);
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
999 }
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1000
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1001 /* Convert a Rect to a Python object */
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
1002 PyObject *
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1003 PyMac_BuildRect(Rect *r)
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
1004 {
2255
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
1005 return Py_BuildValue("(hhhh)", r->left, r->top, r->right, r->bottom);
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1006 }
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1007
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1008
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1009 /* Convert a Python object to a Point.
2255
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
1010 The object must be a (h, v) tuple.
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
1011 (This differs from the order in the struct but is consistent with
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
1012 the arguments to SetPoint(), and also with STDWIN). */
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1013 int
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1014 PyMac_GetPoint(PyObject *v, Point *p)
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1015 {
2255
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
1016 return PyArg_Parse(v, "(hh)", &p->h, &p->v);
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
1017 }
2224
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
1018
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1019 /* Convert a Point to a Python object */
2224
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
1020 PyObject *
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1021 PyMac_BuildPoint(Point p)
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1022 {
2255
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
1023 return Py_BuildValue("(hh)", p.h, p.v);
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1024 }
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1025
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1026
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1027 /* Convert a Python object to an EventRecord.
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1028 The object must be a (what, message, when, (v, h), modifiers) tuple. */
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1029 int
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1030 PyMac_GetEventRecord(PyObject *v, EventRecord *e)
2224
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
1031 {
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1032 return PyArg_Parse(v, "(hll(hh)h)",
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1033 &e->what,
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1034 &e->message,
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1035 &e->when,
2255
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
1036 &e->where.h,
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1037 &e->where.v,
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1038 &e->modifiers);
2224
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
1039 }
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1040
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1041 /* Convert a Rect to an EventRecord object */
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1042 PyObject *
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1043 PyMac_BuildEventRecord(EventRecord *e)
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1044 {
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1045 return Py_BuildValue("(hll(hh)h)",
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1046 e->what,
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1047 e->message,
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1048 e->when,
2255
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
1049 e->where.h,
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1050 e->where.v,
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1051 e->modifiers);
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1052 }
3278
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1053
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1054 /* Convert Python object to Fixed */
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1055 int
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1056 PyMac_GetFixed(PyObject *v, Fixed *f)
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1057 {
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1058 double d;
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1059
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1060 if( !PyArg_Parse(v, "d", &d))
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1061 return 0;
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1062 *f = (Fixed)(d * 0x10000);
3655
f89fa7e95b84 PyMac_GetFixed() didn't return 1 on success
Jack Jansen <jack.jansen@cwi.nl>
parents: 3478
diff changeset
1063 return 1;
3278
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1064 }
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1065
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1066 /* Convert a Point to a Python object */
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1067 PyObject *
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1068 PyMac_BuildFixed(Fixed f)
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1069 {
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1070 double d;
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1071
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1072 d = f;
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1073 d = d / 0x10000;
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1074 return Py_BuildValue("d", d);
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1075 }
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1076
8104
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1077 /* Convert wide to/from Python int or (hi, lo) tuple. XXXX Should use Python longs */
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1078 int
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1079 PyMac_Getwide(PyObject *v, wide *rv)
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1080 {
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1081 if (PyInt_Check(v)) {
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1082 rv->hi = 0;
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1083 rv->lo = PyInt_AsLong(v);
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1084 if( rv->lo & 0x80000000 )
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1085 rv->hi = -1;
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1086 return 1;
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1087 }
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1088 return PyArg_Parse(v, "(ll)", &rv->hi, &rv->lo);
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1089 }
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1090
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1091
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1092 PyObject *
8113
e2d33c0732bf Incorrect argument for PyMacBuildwide()
Jack Jansen <jack.jansen@cwi.nl>
parents: 8104
diff changeset
1093 PyMac_Buildwide(wide *w)
8104
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1094 {
8113
e2d33c0732bf Incorrect argument for PyMacBuildwide()
Jack Jansen <jack.jansen@cwi.nl>
parents: 8104
diff changeset
1095 if ( (w->hi == 0 && (w->lo & 0x80000000) == 0) ||
e2d33c0732bf Incorrect argument for PyMacBuildwide()
Jack Jansen <jack.jansen@cwi.nl>
parents: 8104
diff changeset
1096 (w->hi == -1 && (w->lo & 0x80000000) ) )
e2d33c0732bf Incorrect argument for PyMacBuildwide()
Jack Jansen <jack.jansen@cwi.nl>
parents: 8104
diff changeset
1097 return PyInt_FromLong(w->lo);
e2d33c0732bf Incorrect argument for PyMacBuildwide()
Jack Jansen <jack.jansen@cwi.nl>
parents: 8104
diff changeset
1098 return Py_BuildValue("(ll)", w->hi, w->lo);
8104
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1099 }