Mercurial > cpython-lru_cache-weakref
annotate Mac/Python/macglue.c @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | d25a0ccbfd6b |
| children | d6b292a33cfe |
| rev | line source |
|---|---|
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
1 /*********************************************************** |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
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 | 24 |
| 4024 | 25 #ifdef __CFM68K__ |
| 26 /* cfm68k InterfaceLib exports GetEventQueue, but Events.h doesn't know this | |
| 27 ** and defines it as GetEvQHdr (which is correct for PPC). This fix is for | |
| 28 ** CW9, check that the workaround is still needed for the next release. | |
| 29 */ | |
| 30 #define GetEvQHdr GetEventQueue | |
| 31 #endif /* __CFM68K__ */ | |
| 32 | |
| 33 #include <Events.h> | |
| 34 | |
| 35 #ifdef __CFM68K__ | |
| 36 #undef GetEventQueue | |
| 37 #endif /* __CFM68K__ */ | |
| 38 | |
| 2035 | 39 #include "Python.h" |
| 2337 | 40 |
| 2035 | 41 #include "macglue.h" |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
42 #include "marshal.h" |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
43 #include "import.h" |
| 2035 | 44 |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
45 #include "pythonresources.h" |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
46 |
| 2035 | 47 #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
|
48 #include <Files.h> |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
49 #include <StandardFile.h> |
| 2035 | 50 #include <Resources.h> |
| 51 #include <Memory.h> | |
| 52 #include <Windows.h> | |
| 53 #include <Desk.h> | |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
54 #include <Traps.h> |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
55 #include <Processes.h> |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
56 #include <Fonts.h> |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
57 #include <Menus.h> |
|
2747
e41669a1dea0
Added code to obtain sys.path from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents:
2668
diff
changeset
|
58 #include <TextUtils.h> |
|
2265
4bcc92916fab
added <OSEvents.h> for Think C
Guido van Rossum <guido@python.org>
parents:
2262
diff
changeset
|
59 #ifdef THINK_C |
|
4bcc92916fab
added <OSEvents.h> for Think C
Guido van Rossum <guido@python.org>
parents:
2262
diff
changeset
|
60 #include <OSEvents.h> /* For EvQElPtr */ |
|
4bcc92916fab
added <OSEvents.h> for Think C
Guido van Rossum <guido@python.org>
parents:
2262
diff
changeset
|
61 #endif |
|
2443
2dcf7538347a
Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents:
2429
diff
changeset
|
62 #ifdef __MWERKS__ |
|
2dcf7538347a
Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents:
2429
diff
changeset
|
63 #include <SIOUX.h> |
|
2dcf7538347a
Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents:
2429
diff
changeset
|
64 #endif |
|
3431
26bec9e22e5d
Added code to make fsspecs work for gusi-python
Jack Jansen <jack.jansen@cwi.nl>
parents:
3278
diff
changeset
|
65 #ifdef USE_GUSI |
|
26bec9e22e5d
Added code to make fsspecs work for gusi-python
Jack Jansen <jack.jansen@cwi.nl>
parents:
3278
diff
changeset
|
66 #include <TFileSpec.h> /* For Path2FSSpec */ |
|
3433
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
67 #include <LowMem.h> /* For SetSFCurDir, etc */ |
| 4197 | 68 #include <GUSI.h> |
|
3431
26bec9e22e5d
Added code to make fsspecs work for gusi-python
Jack Jansen <jack.jansen@cwi.nl>
parents:
3278
diff
changeset
|
69 #endif |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
70 |
|
4215
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
71 /* 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
|
72 #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
|
73 |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
74 #ifndef HAVE_UNIVERSAL_HEADERS |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
75 #define GetResourceSizeOnDisk(x) SizeResource(x) |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
76 typedef DlgHookYDProcPtr DlgHookYDUPP; |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
77 #define NewDlgHookYDProc(userRoutine) ((DlgHookYDUPP) (userRoutine)) |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
78 typedef FileFilterYDProcPtr FileFilterYDUPP; |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
79 #endif |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
80 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
81 #include <signal.h> |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
82 #include <stdio.h> |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
83 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
84 /* |
|
3914
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
85 ** 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
|
86 ** raise a MemoryError. |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
87 */ |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
88 #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
|
89 #ifdef __powerc |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
90 #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
|
91 #else |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
92 #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
|
93 #endif |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
94 #endif |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
95 |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
96 /* |
|
2443
2dcf7538347a
Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents:
2429
diff
changeset
|
97 ** 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
|
98 ** 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
|
99 ** 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
|
100 ** 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
|
101 */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
102 #define MAINLOOP_EVENTMASK (mDownMask|keyDownMask|osMask) |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
103 |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
104 #include <signal.h> |
| 2035 | 105 |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
106 /* 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
|
107 ** with the python errors.h. */ |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
108 #define fnfErr -43 |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
109 |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
110 /* Declared in macfsmodule.c: */ |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
111 extern FSSpec *mfs_GetFSSpecFSSpec(); |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
112 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
113 /* Interrupt code variables: */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
114 static int interrupted; /* Set to true when cmd-. seen */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
115 static RETSIGTYPE intcatcher Py_PROTO((int)); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
116 |
| 4197 | 117 static void PyMac_DoYield Py_PROTO((int)); |
| 118 | |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
119 /* |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
120 ** We attempt to be a good citizen by giving up the CPU periodically. |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
121 ** When in the foreground we do this less often and for shorter periods |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
122 ** than when in the background. At this time we also check for events and |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
123 ** pass them off to SIOUX, if compiling with mwerks. |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
124 ** The counts here are in ticks of 1/60th second. |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
125 ** XXXX The initial values here are not based on anything. |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
126 ** FG-python gives up the cpu for 1/60th 5 times per second, |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
127 ** BG-python for .2 second 10 times per second. |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
128 */ |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
129 static long interval_fg = 12; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
130 static long interval_bg = 6; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
131 static long yield_fg = 1; |
|
4325
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
132 static long yield_bg = 2; |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
133 static long lastyield; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
134 static int in_foreground; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
135 |
|
2429
efb0685a6c91
return old value of PyMac_DoYieldEnabled; -1 means do not even check for interrupts
Guido van Rossum <guido@python.org>
parents:
2426
diff
changeset
|
136 /* |
|
efb0685a6c91
return old value of PyMac_DoYieldEnabled; -1 means do not even check for interrupts
Guido van Rossum <guido@python.org>
parents:
2426
diff
changeset
|
137 ** When > 0, do full scanning for events (program is not event aware) |
|
efb0685a6c91
return old value of PyMac_DoYieldEnabled; -1 means do not even check for interrupts
Guido van Rossum <guido@python.org>
parents:
2426
diff
changeset
|
138 ** when == 0, only scan for Command-period |
|
efb0685a6c91
return old value of PyMac_DoYieldEnabled; -1 means do not even check for interrupts
Guido van Rossum <guido@python.org>
parents:
2426
diff
changeset
|
139 ** when < 0, don't do any event scanning |
|
efb0685a6c91
return old value of PyMac_DoYieldEnabled; -1 means do not even check for interrupts
Guido van Rossum <guido@python.org>
parents:
2426
diff
changeset
|
140 */ |
|
efb0685a6c91
return old value of PyMac_DoYieldEnabled; -1 means do not even check for interrupts
Guido van Rossum <guido@python.org>
parents:
2426
diff
changeset
|
141 int PyMac_DoYieldEnabled = 1; |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
142 |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
143 /* |
| 4197 | 144 ** Workaround for sioux/gusi combo: set when we are exiting |
| 145 */ | |
| 146 int PyMac_ConsoleIsDead; | |
| 147 | |
| 148 /* | |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
149 ** 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
|
150 */ |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
151 struct hook_args { |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
152 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
|
153 char *prompt; /* The prompt */ |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
154 }; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
155 static DlgHookYDUPP myhook_upp; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
156 static int upp_inited = 0; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
157 |
|
3433
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
158 #ifdef USE_GUSI |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
159 /* |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
160 ** 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
|
161 ** 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
|
162 ** 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
|
163 */ |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
164 void |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
165 PyMac_FixGUSIcd() |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
166 { |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
167 WDPBRec pb; |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
168 FSSpec curdirfss; |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
169 |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
170 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
|
171 return; |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
172 |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
173 /* 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
|
174 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
|
175 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
|
176 pb.ioWDDirID= curdirfss.parID; |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
177 if (PBHSetVol(&pb, 0) != noErr) |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
178 return; |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
179 } |
|
4013
aa9548885b3f
Dummy SpinCursor() if __CFM68K__ is defined
Jack Jansen <jack.jansen@cwi.nl>
parents:
3914
diff
changeset
|
180 |
|
4238
6c86d9136c09
- Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
4215
diff
changeset
|
181 /* |
|
6c86d9136c09
- Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
4215
diff
changeset
|
182 ** 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
|
183 ** provide a dummy here. |
|
6c86d9136c09
- Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
4215
diff
changeset
|
184 */ |
| 4018 | 185 void SpinCursor(short x) { /* Dummy */ } |
| 186 | |
| 4197 | 187 /* |
| 188 ** Replacement GUSI Spin function | |
| 189 */ | |
| 190 static int | |
| 191 PyMac_GUSISpin(spin_msg msg, long arg) | |
| 192 { | |
| 193 static Boolean inForeground = true; | |
| 194 int maysleep; | |
| 195 | |
| 196 if (PyMac_ConsoleIsDead) return 0; | |
| 197 #if 0 | |
| 198 if (inForeground) | |
| 199 SpinCursor(msg == SP_AUTO_SPIN ? short(arg) : 1); | |
| 200 #endif | |
| 201 | |
| 202 if (interrupted) return -1; | |
| 203 | |
| 204 if ( msg == SP_AUTO_SPIN || ((msg==SP_SLEEP||msg==SP_SELECT) && arg <= yield_fg)) | |
| 205 maysleep = 0; | |
| 206 else | |
| 207 maysleep = 0; | |
| 208 | |
| 209 PyMac_DoYield(maysleep); | |
| 210 | |
| 211 return 0; | |
| 212 } | |
| 213 | |
| 214 void | |
| 215 PyMac_SetGUSISpin() { | |
| 216 GUSISetHook(GUSI_SpinHook, (GUSIHook)PyMac_GUSISpin); | |
| 217 } | |
| 218 | |
|
3433
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
219 #endif |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
220 |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
221 |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
222 /* 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
|
223 unsigned char * |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
224 Pstring(char *str) |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
225 { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
226 static Str255 buf; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
227 int len; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
228 |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
229 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
|
230 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
|
231 len = 255; |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
232 buf[0] = (unsigned char)len; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
233 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
|
234 return buf; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
235 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
236 |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
237 /* Like strerror() but for Mac OS error numbers */ |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
238 char *PyMac_StrError(int err) |
| 2035 | 239 { |
| 240 static char buf[256]; | |
| 241 Handle h; | |
| 242 char *str; | |
| 243 | |
| 244 h = GetResource('Estr', err); | |
| 245 if ( h ) { | |
| 246 HLock(h); | |
| 247 str = (char *)*h; | |
| 248 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
|
249 buf[(unsigned char)str[0]] = '\0'; |
| 2035 | 250 HUnlock(h); |
| 251 ReleaseResource(h); | |
| 252 } else { | |
| 253 sprintf(buf, "Mac OS error code %d", err); | |
| 254 } | |
| 255 return buf; | |
| 256 } | |
| 257 | |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
258 /* 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
|
259 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
|
260 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
261 /* 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
|
262 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
263 PyMac_GetOSErrException() |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
264 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
265 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
|
266 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
|
267 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
|
268 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
269 |
| 2035 | 270 /* Set a MAC-specific error from errno, and return NULL; return None if no error */ |
| 271 PyObject * | |
| 2136 | 272 PyErr_Mac(PyObject *eobj, int err) |
| 2035 | 273 { |
| 274 char *msg; | |
| 275 PyObject *v; | |
| 276 | |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
277 if (err == 0 && !PyErr_Occurred()) { |
| 2035 | 278 Py_INCREF(Py_None); |
| 279 return Py_None; | |
| 280 } | |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
281 if (err == -1 && PyErr_Occurred()) |
|
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
282 return NULL; |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
283 msg = PyMac_StrError(err); |
| 2035 | 284 v = Py_BuildValue("(is)", err, msg); |
| 285 PyErr_SetObject(eobj, v); | |
| 286 Py_DECREF(v); | |
| 287 return NULL; | |
| 288 } | |
| 289 | |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
290 /* 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
|
291 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
292 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
|
293 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
294 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
|
295 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
296 |
|
3786
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
297 #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
|
298 /* 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
|
299 int |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
300 PyOS_CheckStack() |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
301 { |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
302 long left; |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
303 |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
304 left = StackSpace(); |
|
3914
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
305 if ( left < MINIMUM_STACK_SIZE ) |
|
3786
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
306 return -1; |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
307 return 0; |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
308 } |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
309 #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
|
310 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
311 /* 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
|
312 static RETSIGTYPE |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
313 intcatcher(sig) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
314 int sig; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
315 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
316 interrupted = 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
317 signal(SIGINT, intcatcher); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
318 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
319 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
320 void |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
321 PyOS_InitInterrupts() |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
322 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
323 if (signal(SIGINT, SIG_IGN) != SIG_IGN) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
324 signal(SIGINT, intcatcher); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
325 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
326 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
327 /* |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
328 ** 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
|
329 ** 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
|
330 ** 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
|
331 ** 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
|
332 ** interrupt a runaway python program. |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
333 */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
334 static void |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
335 scan_event_queue(flush) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
336 int flush; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
337 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
338 register EvQElPtr q; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
339 |
| 4018 | 340 q = (EvQElPtr) GetEventQueue()->qHead; |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
341 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
342 for (; q; q = (EvQElPtr)q->qLink) { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
343 if (q->evtQWhat == keyDown && |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
344 (char)q->evtQMessage == '.' && |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
345 (q->evtQModifiers & cmdKey) != 0) { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
346 if ( flush ) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
347 FlushEvents(keyDownMask, 0); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
348 interrupted = 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
349 break; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
350 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
351 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
352 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
353 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
354 int |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
355 PyOS_InterruptOccurred() |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
356 { |
|
2429
efb0685a6c91
return old value of PyMac_DoYieldEnabled; -1 means do not even check for interrupts
Guido van Rossum <guido@python.org>
parents:
2426
diff
changeset
|
357 if (PyMac_DoYieldEnabled < 0) |
|
efb0685a6c91
return old value of PyMac_DoYieldEnabled; -1 means do not even check for interrupts
Guido van Rossum <guido@python.org>
parents:
2426
diff
changeset
|
358 return 0; |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
359 #ifdef THINK_C |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
360 scan_event_queue(1); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
361 #endif |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
362 PyMac_Yield(); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
363 if (interrupted) { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
364 interrupted = 0; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
365 return 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
366 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
367 return 0; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
368 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
369 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
370 /* intrpeek() is like intrcheck(), but it doesn't flush the events. The |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
371 ** idea is that you call intrpeek() somewhere in a busy-wait loop, and return |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
372 ** None as soon as it returns 1. The mainloop will then pick up the cmd-. soon |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
373 ** thereafter. |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
374 */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
375 static int |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
376 intrpeek() |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
377 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
378 #ifdef THINK_C |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
379 scan_event_queue(0); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
380 #endif |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
381 return interrupted; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
382 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
383 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
384 /* Check whether we are in the foreground */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
385 int |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
386 PyMac_InForeground() |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
387 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
388 static ProcessSerialNumber ours; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
389 static inited; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
390 ProcessSerialNumber curfg; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
391 Boolean eq; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
392 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
393 if ( inited == 0 ) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
394 (void)GetCurrentProcess(&ours); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
395 inited = 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
396 if ( GetFrontProcess(&curfg) < 0 ) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
397 eq = 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
398 else if ( SameProcess(&ours, &curfg, &eq) < 0 ) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
399 eq = 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
400 return (int)eq; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
401 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
402 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
403 |
| 2035 | 404 /* |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
405 ** Set yield timeouts |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
406 */ |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
407 void |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
408 PyMac_SetYield(long fgi, long fgy, long bgi, long bgy) |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
409 { |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
410 interval_fg = fgi; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
411 yield_fg = fgy; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
412 interval_bg = bgi; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
413 yield_bg = bgy; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
414 } |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
415 |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
416 /* |
|
2276
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
417 ** 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
|
418 ** 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
|
419 */ |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
420 void |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
421 PyMac_HandleEvent(evp) |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
422 EventRecord *evp; |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
423 { |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
424 |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
425 #ifdef __MWERKS__ |
|
3248
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
426 { |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
427 int siouxdidit; |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
428 |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
429 /* If SIOUX wants it we're done */ |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
430 siouxdidit = SIOUXHandleOneEvent(evp); |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
431 if ( siouxdidit ) |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
432 return; |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
433 } |
|
2276
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
434 #else |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
435 /* Other compilers are just unlucky: we only weed out clicks in other applications */ |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
436 if ( evp->what == mouseDown ) { |
| 3052 | 437 WindowPtr wp; |
| 438 | |
|
3248
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
439 if ( FindWindow(evp->where, &wp) == inSysWindow ) { |
|
2276
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
440 SystemClick(evp, wp); |
|
3248
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
441 return; |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
442 } |
|
2276
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
443 } |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
444 #endif /* !__MWERKS__ */ |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
445 } |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
446 |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
447 /* |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
448 ** Yield the CPU to other tasks. |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
449 */ |
| 4018 | 450 static void |
| 4197 | 451 PyMac_DoYield(int maysleep) |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
452 { |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
453 EventRecord ev; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
454 long yield; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
455 static int no_waitnextevent = -1; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
456 int gotone; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
457 |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
458 if ( no_waitnextevent < 0 ) { |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
459 no_waitnextevent = (NGetTrapAddress(_WaitNextEvent, ToolTrap) == |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
460 NGetTrapAddress(_Unimplemented, ToolTrap)); |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
461 } |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
462 |
| 4197 | 463 lastyield = TickCount(); |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
464 #ifndef THINK_C |
| 4197 | 465 /* Under think this has been done before in intrcheck() or intrpeek() */ |
| 466 if (PyMac_DoYieldEnabled >= 0) | |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
467 scan_event_queue(0); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
468 #endif |
| 4197 | 469 if (PyMac_DoYieldEnabled == 0) |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
470 return; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
471 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
472 in_foreground = PyMac_InForeground(); |
| 4197 | 473 if ( maysleep ) { |
| 474 if ( in_foreground ) | |
| 475 yield = yield_fg; | |
| 476 else | |
| 477 yield = yield_bg; | |
| 478 } else { | |
| 479 yield = 0; | |
| 480 } | |
| 481 | |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
482 while ( 1 ) { |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
483 if ( no_waitnextevent ) { |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
484 SystemTask(); |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
485 gotone = GetNextEvent(MAINLOOP_EVENTMASK, &ev); |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
486 } else { |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
487 gotone = WaitNextEvent(MAINLOOP_EVENTMASK, &ev, yield, NULL); |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
488 } |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
489 /* Get out quickly if nothing interesting is happening */ |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
490 if ( !gotone || ev.what == nullEvent ) |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
491 break; |
|
2276
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
492 PyMac_HandleEvent(&ev); |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
493 } |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
494 } |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
495 |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
496 /* |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
497 ** Yield the CPU to other tasks if opportune |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
498 */ |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
499 void |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
500 PyMac_Yield() { |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
501 long iv; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
502 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
503 if ( in_foreground ) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
504 iv = interval_fg; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
505 else |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
506 iv = interval_bg; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
507 if ( TickCount() > lastyield + iv ) |
| 4197 | 508 PyMac_DoYield(1); |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
509 } |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
510 |
| 4197 | 511 #ifdef USE_MACTCP |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
512 /* |
| 2035 | 513 ** Idle routine for busy-wait loops. |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
514 ** Gives up CPU, handles events and returns true if an interrupt is pending |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
515 ** (but not actually handled yet). |
| 2035 | 516 */ |
| 517 int | |
| 518 PyMac_Idle() | |
| 519 { | |
| 4197 | 520 PyMac_DoYield(1); |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
521 return intrpeek(); |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
522 } |
| 4197 | 523 #endif |
| 524 | |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
525 /* |
|
4215
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
526 ** 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
|
527 */ |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
528 void |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
529 PyMac_InitMenuBar() |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
530 { |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
531 Handle bar; |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
532 MenuHandle applemenu; |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
533 |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
534 if ( (bar=GetMenuBar()) == NULL ) return; |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
535 if ( (applemenu=GetMHandle(SIOUX_APPLEID)) == NULL ) return; |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
536 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
|
537 } |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
538 |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
539 /* |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
540 ** 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
|
541 */ |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
542 void |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
543 SIOUXDoAboutBox(void) |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
544 { |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
545 DialogPtr theDialog; |
|
4325
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
546 WindowRef theWindow; |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
547 CGrafPtr thePort; |
|
4215
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
548 short item; |
|
4325
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
549 short xpos, ypos, width, height, swidth, sheight; |
|
4215
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
550 |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
551 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
|
552 return; |
|
4325
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
553 theWindow = GetDialogWindow(theDialog); |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
554 thePort = GetWindowPort(theWindow); |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
555 width = thePort->portRect.right - thePort->portRect.left; |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
556 height = thePort->portRect.bottom - thePort->portRect.top; |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
557 swidth = qd.screenBits.bounds.right - qd.screenBits.bounds.left; |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
558 sheight = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top - LMGetMBarHeight(); |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
559 xpos = (swidth-width)/2; |
|
4329
a240be5be6b4
About boxes should be at 20% of screen height, not halfway
Jack Jansen <jack.jansen@cwi.nl>
parents:
4325
diff
changeset
|
560 ypos = (sheight-height)/5 + LMGetMBarHeight(); |
|
4325
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
561 MoveWindow(theWindow, xpos, ypos, 0); |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
562 ShowWindow(theWindow); |
|
4215
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
563 ModalDialog(NULL, &item); |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
564 DisposeDialog(theDialog); |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
565 } |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
566 |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
567 /* |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
568 ** Returns true if the argument has a resource fork, and it contains |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
569 ** a 'PYC ' resource of the correct name |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
570 */ |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
571 int |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
572 PyMac_FindResourceModule(module, filename) |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
573 char *module; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
574 char *filename; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
575 { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
576 FSSpec fss; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
577 FInfo finfo; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
578 short oldrh, filerh; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
579 int ok; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
580 Handle h; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
581 |
|
4522
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
582 if ( strcmp(filename, PyMac_ApplicationPath) == 0 ) { |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
583 /* |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
584 ** Special case: the application itself. Use a shortcut to |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
585 ** forestall opening and closing the application numerous times |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
586 ** (which is dead slow when running from CDROM) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
587 */ |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
588 oldrh = CurResFile(); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
589 UseResFile(PyMac_AppRefNum); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
590 filerh = -1; |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
591 } else { |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
592 if ( FSMakeFSSpec(0, 0, Pstring(filename), &fss) != noErr ) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
593 return 0; /* It doesn't exist */ |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
594 if ( FSpGetFInfo(&fss, &finfo) != noErr ) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
595 return 0; /* shouldn't happen, I guess */ |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
596 oldrh = CurResFile(); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
597 filerh = FSpOpenResFile(&fss, fsRdPerm); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
598 if ( filerh == -1 ) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
599 return 0; |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
600 UseResFile(filerh); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
601 } |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
602 SetResLoad(0); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
603 h = Get1NamedResource('PYC ', Pstring(module)); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
604 SetResLoad(1); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
605 ok = (h != NULL); |
|
4522
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
606 if ( filerh != -1 ) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
607 CloseResFile(filerh); |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
608 UseResFile(oldrh); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
609 return ok; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
610 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
611 |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
612 /* |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
613 ** Load the specified module from a resource |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
614 */ |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
615 PyObject * |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
616 PyMac_LoadResourceModule(module, filename) |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
617 char *module; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
618 char *filename; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
619 { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
620 FSSpec fss; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
621 FInfo finfo; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
622 short oldrh, filerh; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
623 Handle h; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
624 OSErr err; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
625 PyObject *m, *co; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
626 long num, size; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
627 |
|
4522
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
628 if ( strcmp(filename, PyMac_ApplicationPath) == 0 ) { |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
629 /* |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
630 ** Special case: the application itself. Use a shortcut to |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
631 ** forestall opening and closing the application numerous times |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
632 ** (which is dead slow when running from CDROM) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
633 */ |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
634 oldrh = CurResFile(); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
635 UseResFile(PyMac_AppRefNum); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
636 filerh = -1; |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
637 } else { |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
638 if ( (err=FSMakeFSSpec(0, 0, Pstring(filename), &fss)) != noErr ) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
639 goto error; |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
640 if ( (err=FSpGetFInfo(&fss, &finfo)) != noErr ) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
641 goto error; |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
642 oldrh = CurResFile(); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
643 filerh = FSpOpenResFile(&fss, fsRdPerm); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
644 if ( filerh == -1 ) { |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
645 err = ResError(); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
646 goto error; |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
647 } |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
648 UseResFile(filerh); |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
649 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
650 h = Get1NamedResource('PYC ', Pstring(module)); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
651 if ( h == NULL ) { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
652 err = ResError(); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
653 goto error; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
654 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
655 HLock(h); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
656 /* |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
657 ** XXXX The next few lines are intimately tied to the format of pyc |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
658 ** files. I'm not sure whether this code should be here or in import.c -- Jack |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
659 */ |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
660 size = GetHandleSize(h); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
661 if ( size < 8 ) { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
662 PyErr_SetString(PyExc_ImportError, "Resource too small"); |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
663 co = NULL; |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
664 } else { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
665 num = (*h)[0] & 0xff; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
666 num = num | (((*h)[1] & 0xff) << 8); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
667 num = num | (((*h)[2] & 0xff) << 16); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
668 num = num | (((*h)[3] & 0xff) << 24); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
669 if ( num != PyImport_GetMagicNumber() ) { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
670 PyErr_SetString(PyExc_ImportError, "Bad MAGIC in resource"); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
671 co = NULL; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
672 } else { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
673 co = PyMarshal_ReadObjectFromString((*h)+8, size-8); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
674 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
675 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
676 HUnlock(h); |
|
4522
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
677 if ( filerh != -1 ) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
678 CloseResFile(filerh); |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
679 UseResFile(oldrh); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
680 if ( co ) { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
681 m = PyImport_ExecCodeModule(module, co); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
682 Py_DECREF(co); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
683 } else { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
684 m = NULL; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
685 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
686 return m; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
687 error: |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
688 { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
689 char buf[512]; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
690 |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
691 sprintf(buf, "%s: %s", filename, PyMac_StrError(err)); |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
692 PyErr_SetString(PyExc_ImportError, buf); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
693 return NULL; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
694 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
695 } |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
696 |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
697 /* |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
698 ** 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
|
699 */ |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
700 static pascal short |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
701 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
|
702 { |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
703 if ( item == sfHookFirstCall && dataptr->prompt) { |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
704 Handle prompth; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
705 short type; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
706 Rect rect; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
707 |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
708 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
|
709 if ( prompth ) |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
710 SetDialogItemText(prompth, (unsigned char *)dataptr->prompt); |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
711 } else |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
712 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
|
713 item = sfItemCancelButton; |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
714 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
|
715 } |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
716 return item; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
717 } |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
718 |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
719 /* |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
720 ** 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
|
721 ** 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
|
722 */ |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
723 int |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
724 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
|
725 FSSpec *dirfss; |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
726 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
|
727 { |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
728 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
|
729 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
|
730 StandardFileReply reply; |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
731 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
|
732 |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
733 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
|
734 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
|
735 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
|
736 } |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
737 if ( prompt && *prompt ) |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
738 hook_args.prompt = (char *)Pstring(prompt); |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
739 else |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
740 hook_args.prompt = NULL; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
741 hook_args.selectcur_hit = 0; |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
742 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
|
743 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
|
744 |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
745 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
|
746 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
|
747 return 0; |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
748 return hook_args.selectcur_hit; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
749 } |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
750 |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
751 /* |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
752 ** Slightly extended StandardGetFile: accepts a prompt */ |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
753 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
|
754 StandardFileReply *reply, char *prompt) |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
755 { |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
756 static Point where = {-1, -1}; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
757 struct hook_args hook_args; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
758 |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
759 if ( !upp_inited ) { |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
760 myhook_upp = NewDlgHookYDProc(myhook_proc); |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
761 upp_inited = 1; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
762 } |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
763 if ( prompt && *prompt ) |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
764 hook_args.prompt = (char *)Pstring(prompt); |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
765 else |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
766 hook_args.prompt = NULL; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
767 hook_args.selectcur_hit = 0; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
768 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
|
769 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
|
770 } |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
771 |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
772 /* 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
|
773 int |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
774 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
|
775 { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
776 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
|
777 PyErr_SetString(PyExc_TypeError, |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
778 "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
|
779 return 0; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
780 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
781 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
|
782 return 1; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
783 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
784 |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
785 /* 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
|
786 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
787 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
|
788 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
789 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
|
790 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
791 |
|
3914
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
792 /* 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
|
793 PyObject * |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
794 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
|
795 { |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
796 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
|
797 } |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
798 |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
799 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
800 /* 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
|
801 int |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
802 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
|
803 { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
804 int len; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
805 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
|
806 PyErr_SetString(PyExc_TypeError, |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
807 "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
|
808 return 0; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
809 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
810 pbuf[0] = len; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
811 memcpy((char *)(pbuf+1), PyString_AsString(v), len); |
| 2035 | 812 return 1; |
| 813 } | |
| 814 | |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
815 /* 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
|
816 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
817 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
|
818 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
819 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
|
820 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
821 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
822 |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
823 /* |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
824 ** 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
|
825 ** 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
|
826 ** (vrefnum, dirid, path). |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
827 ** 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
|
828 ** 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
|
829 ** 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
|
830 ** 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
|
831 */ |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
832 int |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
833 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
|
834 { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
835 Str255 path; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
836 short refnum; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
837 long parid; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
838 OSErr err; |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
839 FSSpec *fs2; |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
840 |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
841 /* 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
|
842 fs2 = mfs_GetFSSpecFSSpec(v); |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
843 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
|
844 (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
|
845 return 1; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
846 } |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
847 if ( PyString_Check(v) ) { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
848 /* 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
|
849 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
|
850 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
|
851 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
|
852 parid = 0; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
853 } else { |
|
2209
4053d4cb50e0
renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents:
2183
diff
changeset
|
854 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
|
855 &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
|
856 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
|
857 } |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
858 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
859 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
|
860 if ( err && err != fnfErr ) { |
|
2209
4053d4cb50e0
renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents:
2183
diff
changeset
|
861 PyErr_Mac(PyExc_ValueError, err); |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
862 return 0; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
863 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
864 return 1; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
865 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
866 |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
867 |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
868 /* 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
|
869 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
|
870 (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
|
871 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
|
872 int |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
873 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
|
874 { |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
875 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
|
876 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
877 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
878 /* Convert a Rect to a Python object */ |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
879 PyObject * |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
880 PyMac_BuildRect(Rect *r) |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
881 { |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
882 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
|
883 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
884 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
885 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
886 /* 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
|
887 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
|
888 (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
|
889 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
|
890 int |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
891 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
|
892 { |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
893 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
|
894 } |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
895 |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
896 /* Convert a Point to a Python object */ |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
897 PyObject * |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
898 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
|
899 { |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
900 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
|
901 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
902 |
|
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 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
|
905 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
|
906 int |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
907 PyMac_GetEventRecord(PyObject *v, EventRecord *e) |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
908 { |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
909 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
|
910 &e->what, |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
911 &e->message, |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
912 &e->when, |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
913 &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
|
914 &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
|
915 &e->modifiers); |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
916 } |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
917 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
918 /* 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
|
919 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
920 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
|
921 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
922 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
|
923 e->what, |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
924 e->message, |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
925 e->when, |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
926 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
|
927 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
|
928 e->modifiers); |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
929 } |
|
3278
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
930 |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
931 /* Convert Python object to Fixed */ |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
932 int |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
933 PyMac_GetFixed(PyObject *v, Fixed *f) |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
934 { |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
935 double d; |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
936 |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
937 if( !PyArg_Parse(v, "d", &d)) |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
938 return 0; |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
939 *f = (Fixed)(d * 0x10000); |
|
3655
f89fa7e95b84
PyMac_GetFixed() didn't return 1 on success
Jack Jansen <jack.jansen@cwi.nl>
parents:
3478
diff
changeset
|
940 return 1; |
|
3278
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
941 } |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
942 |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
943 /* Convert a Point to a Python object */ |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
944 PyObject * |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
945 PyMac_BuildFixed(Fixed f) |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
946 { |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
947 double d; |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
948 |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
949 d = f; |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
950 d = d / 0x10000; |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
951 return Py_BuildValue("d", d); |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
952 } |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
953 |
