1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
34 /* Stdwin itself is a module, not a separate object type.
35 Object types defined here:
37 dp: a drawing structure (only one can exist at a time)
43 /* Rules for translating C stdwin function calls into Python stwin:
44 - All names drop their initial letter 'w'
45 - Functions with a window as first parameter are methods of window objects
46 - There is no equivalent for wclose(); just delete the window object
47 (all references to it!) (XXX maybe this is a bad idea)
48 - w.begindrawing() returns a drawing object
49 - There is no equivalent for wenddrawing(win); just delete the drawing
50 object (all references to it!) (XXX maybe this is a bad idea)
51 - Functions that may only be used inside wbegindrawing / wendddrawing
52 are methods of the drawing object; this includes the text measurement
53 functions (which however have doubles as module functions).
54 - Methods of the drawing object drop an initial 'draw' from their name
55 if they have it, e.g., wdrawline() --> d.line()
56 - The obvious type conversions: int --> intobject; string --> stringobject
57 - A text parameter followed by a length parameter is only a text (string)
59 - A point or other pair of horizontal and vertical coordinates is always
60 a pair of integers in Python
61 - Two points forming a rectangle or endpoints of a line segment are a
62 pair of points in Python
63 - The arguments to d.elarc() are three points.
64 - The functions wgetclip() and wsetclip() are translated into
65 stdwin.getcutbuffer() and stdwin.setcutbuffer(); 'clip' is really
66 a bad word for what these functions do (clipping has a different
67 meaning in the drawing world), while cutbuffer is standard X jargon.
68 XXX This must change again in the light of changes to stdwin!
69 - For textedit, similar rules hold, but they are less strict.
80 #include ":::stdwin:H:stdwin.h"
81 #else /* !macintosh */
84 #endif /* !macintosh */
90 static type_lock StdwinLock
; /* Lock held when interpreter not locked */
92 #define BGN_STDWIN Py_BEGIN_ALLOW_THREADS acquire_lock(StdwinLock, 1);
93 #define RET_STDWIN release_lock(StdwinLock); Py_BLOCK_THREADS
94 #define END_STDWIN release_lock(StdwinLock); Py_END_ALLOW_THREADS
98 #define BGN_STDWIN Py_BEGIN_ALLOW_THREADS
99 #define RET_STDWIN Py_BLOCK_THREADS
100 #define END_STDWIN Py_END_ALLOW_THREADS
104 #define getintarg(v,a) PyArg_Parse(v, "i", a)
105 #define getlongarg(v,a) PyArg_Parse(v, "l", a)
106 #define getstrarg(v,a) PyArg_Parse(v, "s", a)
107 #define getpointarg(v, a) PyArg_Parse(v, "(ii)", a, (a)+1)
108 #define get3pointarg(v, a) PyArg_Parse(v, "((ii)(ii)(ii))", \
109 a, a+1, a+2, a+3, a+4, a+5)
110 #define getrectarg(v, a) PyArg_Parse(v, "((ii)(ii))", a, a+1, a+2, a+3)
111 #define getrectintarg(v, a) PyArg_Parse(v, "(((ii)(ii))i)", \
112 a, a+1, a+2, a+3, a+4)
113 #define getpointintarg(v, a) PyArg_Parse(v, "((ii)i)", a, a+1, a+2)
114 #define getrectpointarg(v, a) PyArg_Parse(v, "(((ii)(ii))(ii))", \
115 a, a+1, a+2, a+3, a+4, a+5)
117 static PyObject
*StdwinError
; /* Exception stdwin.error */
119 /* Window and menu object types declared here because of forward references */
125 PyObject
*w_attr
; /* Attributes dictionary */
128 staticforward PyTypeObject Windowtype
;
130 #define is_windowobject(wp) ((wp)->ob_type == &Windowtype)
136 PyObject
*m_attr
; /* Attributes dictionary */
139 staticforward PyTypeObject Menutype
;
141 #define is_menuobject(mp) ((mp)->ob_type == &Menutype)
146 PyObject
*b_attr
; /* Attributes dictionary */
149 staticforward PyTypeObject Bitmaptype
;
151 #define is_bitmapobject(mp) ((mp)->ob_type == &Bitmaptype)
154 /* Strongly stdwin-specific argument handlers */
162 if (!PyArg_Parse(v
, "(Oi)", &mp
, &ep
->u
.m
.item
))
164 if (!is_menuobject(mp
))
165 return PyErr_BadArgument();
166 ep
->u
.m
.id
= mp
->m_id
;
175 PyObject
*wp
, *detail
;
177 if (!PyArg_Parse(v
, "(iOO)", &ep
->type
, &wp
, &detail
))
179 if (is_windowobject(wp
))
180 ep
->window
= ((windowobject
*)wp
) -> w_win
;
181 else if (wp
== Py_None
)
184 return PyErr_BadArgument();
188 if (!PyArg_Parse(detail
, "c", &c
))
194 return getintarg(detail
, &ep
->u
.command
);
196 if (!getrectarg(detail
, a
))
198 ep
->u
.area
.left
= a
[0];
199 ep
->u
.area
.top
= a
[1];
200 ep
->u
.area
.right
= a
[2];
201 ep
->u
.area
.bottom
= a
[3];
206 return PyArg_Parse(detail
, "((ii)iii)",
207 &ep
->u
.where
.h
, &ep
->u
.where
.v
,
212 return getmenudetail(detail
, ep
);
214 return PyArg_Parse(detail
, "(ii)",
215 &ep
->u
.key
.code
, &ep
->u
.key
.mask
);
222 /* Return construction tools */
228 return Py_BuildValue("(ii)", a
, b
);
235 return Py_BuildValue("((ii)(ii))", a
, b
, c
, d
);
239 /* Drawing objects */
246 static drawingobject
*Drawing
; /* Set to current drawing object, or NULL */
248 /* Drawing methods */
254 if (dp
->d_ref
!= NULL
) {
255 wenddrawing(dp
->d_ref
->w_win
);
257 Py_DECREF(dp
->d_ref
);
268 if (dp
->d_ref
!= NULL
) {
269 wenddrawing(dp
->d_ref
->w_win
);
271 Py_DECREF(dp
->d_ref
);
278 drawing_generic(dp
, args
, func
)
281 void (*func
) Py_FPROTO((int, int, int, int));
284 if (!getrectarg(args
, a
))
286 (*func
)(a
[0], a
[1], a
[2], a
[3]);
292 drawing_line(dp
, args
)
296 return drawing_generic(dp
, args
, wdrawline
);
300 drawing_xorline(dp
, args
)
304 return drawing_generic(dp
, args
, wxorline
);
308 drawing_circle(dp
, args
)
313 if (!getpointintarg(args
, a
))
315 wdrawcircle(a
[0], a
[1], a
[2]);
321 drawing_fillcircle(dp
, args
)
326 if (!getpointintarg(args
, a
))
328 wfillcircle(a
[0], a
[1], a
[2]);
334 drawing_xorcircle(dp
, args
)
339 if (!getpointintarg(args
, a
))
341 wxorcircle(a
[0], a
[1], a
[2]);
347 drawing_elarc(dp
, args
)
352 if (!get3pointarg(args
, a
))
354 wdrawelarc(a
[0], a
[1], a
[2], a
[3], a
[4], a
[5]);
360 drawing_fillelarc(dp
, args
)
365 if (!get3pointarg(args
, a
))
367 wfillelarc(a
[0], a
[1], a
[2], a
[3], a
[4], a
[5]);
373 drawing_xorelarc(dp
, args
)
378 if (!get3pointarg(args
, a
))
380 wxorelarc(a
[0], a
[1], a
[2], a
[3], a
[4], a
[5]);
386 drawing_box(dp
, args
)
390 return drawing_generic(dp
, args
, wdrawbox
);
394 drawing_erase(dp
, args
)
398 return drawing_generic(dp
, args
, werase
);
402 drawing_paint(dp
, args
)
406 return drawing_generic(dp
, args
, wpaint
);
410 drawing_invert(dp
, args
)
414 return drawing_generic(dp
, args
, winvert
);
418 getpointsarray(v
, psize
)
423 PyObject
* (*getitem
) Py_PROTO((PyObject
*, int));
429 else if (PyList_Check(v
)) {
431 getitem
= PyList_GetItem
;
433 else if (PyTuple_Check(v
)) {
435 getitem
= PyTuple_GetItem
;
439 (void) PyErr_BadArgument();
443 points
= PyMem_NEW(POINT
, n
);
444 if (points
== NULL
) {
445 (void) PyErr_NoMemory();
449 for (i
= 0; i
< n
; i
++) {
450 PyObject
*w
= (*getitem
)(v
, i
);
452 if (!getpointarg(w
, a
)) {
465 drawing_poly(dp
, args
)
470 POINT
*points
= getpointsarray(args
, &n
);
473 wdrawpoly(n
, points
);
480 drawing_fillpoly(dp
, args
)
485 POINT
*points
= getpointsarray(args
, &n
);
488 wfillpoly(n
, points
);
495 drawing_xorpoly(dp
, args
)
500 POINT
*points
= getpointsarray(args
, &n
);
510 drawing_cliprect(dp
, args
)
514 return drawing_generic(dp
, args
, wcliprect
);
518 drawing_noclip(dp
, args
)
522 if (!PyArg_NoArgs(args
))
530 drawing_shade(dp
, args
)
535 if (!getrectintarg(args
, a
))
537 wshade(a
[0], a
[1], a
[2], a
[3], a
[4]);
543 drawing_text(dp
, args
)
549 if (!PyArg_Parse(args
, "((ii)t#)", &h
, &v
, &text
, &size
))
551 wdrawtext(h
, v
, text
, size
);
556 /* The following four are also used as stdwin functions */
559 drawing_lineheight(dp
, args
)
563 if (!PyArg_NoArgs(args
))
565 return PyInt_FromLong((long)wlineheight());
569 drawing_baseline(dp
, args
)
573 if (!PyArg_NoArgs(args
))
575 return PyInt_FromLong((long)wbaseline());
579 drawing_textwidth(dp
, args
)
585 if (!PyArg_Parse(args
, "t#", &text
, &size
))
587 return PyInt_FromLong((long)wtextwidth(text
, size
));
591 drawing_textbreak(dp
, args
)
597 if (!PyArg_Parse(args
, "(t#i)", &text
, &size
, &width
))
599 return PyInt_FromLong((long)wtextbreak(text
, size
, width
));
603 drawing_setfont(self
, args
)
610 if (args
== NULL
|| !PyTuple_Check(args
)) {
611 if (!PyArg_Parse(args
, "z", &font
))
615 int n
= PyTuple_Size(args
);
617 if (!PyArg_Parse(args
, "(zi)", &font
, &size
))
620 else if (!PyArg_Parse(args
, "(zic)", &font
, &size
, &style
)) {
622 if (!PyArg_Parse(args
, "(zci)", &font
, &style
, &size
))
627 if (!wsetfont(font
)) {
628 PyErr_SetString(StdwinError
, "font not found");
656 drawing_getbgcolor(self
, args
)
660 if (!PyArg_NoArgs(args
))
662 return PyInt_FromLong((long)wgetbgcolor());
666 drawing_getfgcolor(self
, args
)
670 if (!PyArg_NoArgs(args
))
672 return PyInt_FromLong((long)wgetfgcolor());
676 drawing_setbgcolor(self
, args
)
681 if (!getlongarg(args
, &color
))
683 wsetbgcolor((COLOR
)color
);
689 drawing_setfgcolor(self
, args
)
694 if (!getlongarg(args
, &color
))
696 wsetfgcolor((COLOR
)color
);
704 drawing_bitmap(self
, args
)
710 PyObject
*mask
= NULL
;
711 if (!PyArg_Parse(args
, "((ii)O)", &h
, &v
, &bp
)) {
713 if (!PyArg_Parse(args
, "((ii)OO)", &h
, &v
, &bp
, &mask
))
717 else if (!is_bitmapobject(mask
)) {
722 if (!is_bitmapobject(bp
)) {
726 if (((bitmapobject
*)bp
)->b_bitmap
== NULL
||
727 mask
!= NULL
&& ((bitmapobject
*)mask
)->b_bitmap
== NULL
) {
728 PyErr_SetString(StdwinError
, "bitmap object already close");
732 wdrawbitmap(h
, v
, ((bitmapobject
*)bp
)->b_bitmap
, ALLBITS
);
735 ((bitmapobject
*)bp
)->b_bitmap
,
736 ((bitmapobject
*)bp
)->b_bitmap
);
741 #endif /* HAVE_BITMAPS */
743 static PyMethodDef drawing_methods
[] = {
745 {"bitmap", (PyCFunction
)drawing_bitmap
},
747 {"box", (PyCFunction
)drawing_box
},
748 {"circle", (PyCFunction
)drawing_circle
},
749 {"cliprect", (PyCFunction
)drawing_cliprect
},
750 {"close", (PyCFunction
)drawing_close
},
751 {"elarc", (PyCFunction
)drawing_elarc
},
752 {"enddrawing", (PyCFunction
)drawing_close
},
753 {"erase", (PyCFunction
)drawing_erase
},
754 {"fillcircle", (PyCFunction
)drawing_fillcircle
},
755 {"fillelarc", (PyCFunction
)drawing_fillelarc
},
756 {"fillpoly", (PyCFunction
)drawing_fillpoly
},
757 {"invert", (PyCFunction
)drawing_invert
},
758 {"line", (PyCFunction
)drawing_line
},
759 {"noclip", (PyCFunction
)drawing_noclip
},
760 {"paint", (PyCFunction
)drawing_paint
},
761 {"poly", (PyCFunction
)drawing_poly
},
762 {"shade", (PyCFunction
)drawing_shade
},
763 {"text", (PyCFunction
)drawing_text
},
764 {"xorcircle", (PyCFunction
)drawing_xorcircle
},
765 {"xorelarc", (PyCFunction
)drawing_xorelarc
},
766 {"xorline", (PyCFunction
)drawing_xorline
},
767 {"xorpoly", (PyCFunction
)drawing_xorpoly
},
769 /* Text measuring methods: */
770 {"baseline", (PyCFunction
)drawing_baseline
},
771 {"lineheight", (PyCFunction
)drawing_lineheight
},
772 {"textbreak", (PyCFunction
)drawing_textbreak
},
773 {"textwidth", (PyCFunction
)drawing_textwidth
},
775 /* Font setting methods: */
776 {"setfont", (PyCFunction
)drawing_setfont
},
779 {"getbgcolor", (PyCFunction
)drawing_getbgcolor
},
780 {"getfgcolor", (PyCFunction
)drawing_getfgcolor
},
781 {"setbgcolor", (PyCFunction
)drawing_setbgcolor
},
782 {"setfgcolor", (PyCFunction
)drawing_setfgcolor
},
784 {NULL
, NULL
} /* sentinel */
788 drawing_getattr(dp
, name
)
792 if (dp
->d_ref
== NULL
) {
793 PyErr_SetString(StdwinError
, "drawing object already closed");
796 return Py_FindMethod(drawing_methods
, (PyObject
*)dp
, name
);
799 PyTypeObject Drawingtype
= {
800 PyObject_HEAD_INIT(&PyType_Type
)
802 "drawing", /*tp_name*/
803 sizeof(drawingobject
), /*tp_size*/
806 (destructor
)drawing_dealloc
, /*tp_dealloc*/
808 (getattrfunc
)drawing_getattr
, /*tp_getattr*/
815 /* Text(edit) objects */
821 PyObject
*t_attr
; /* Attributes dictionary */
824 staticforward PyTypeObject Texttype
;
827 newtextobject(wp
, left
, top
, right
, bottom
)
829 int left
, top
, right
, bottom
;
832 tp
= PyObject_NEW(textobject
, &Texttype
);
838 tp
->t_text
= tecreate(wp
->w_win
, left
, top
, right
, bottom
);
839 if (tp
->t_text
== NULL
) {
841 return (textobject
*) PyErr_NoMemory();
846 /* Text(edit) methods */
852 if (tp
->t_text
!= NULL
)
854 Py_XDECREF(tp
->t_attr
);
855 Py_XDECREF(tp
->t_ref
);
864 if (tp
->t_text
!= NULL
) {
868 if (tp
->t_attr
!= NULL
) {
869 Py_DECREF(tp
->t_attr
);
872 if (tp
->t_ref
!= NULL
) {
873 Py_DECREF(tp
->t_ref
);
881 text_arrow(self
, args
)
886 if (!getintarg(args
, &code
))
888 tearrow(self
->t_text
, code
);
894 text_draw(self
, args
)
898 register TEXTEDIT
*tp
= self
->t_text
;
900 int left
, top
, right
, bottom
;
901 if (!getrectarg(args
, a
))
903 if (Drawing
!= NULL
) {
904 PyErr_SetString(StdwinError
, "already drawing");
907 /* Clip to text area and ignore if area is empty */
908 left
= tegetleft(tp
);
910 right
= tegetright(tp
);
911 bottom
= tegetbottom(tp
);
912 if (a
[0] < left
) a
[0] = left
;
913 if (a
[1] < top
) a
[1] = top
;
914 if (a
[2] > right
) a
[2] = right
;
915 if (a
[3] > bottom
) a
[3] = bottom
;
916 if (a
[0] < a
[2] && a
[1] < a
[3]) {
917 wbegindrawing(self
->t_ref
->w_win
);
918 tedrawnew(tp
, a
[0], a
[1], a
[2], a
[3]);
919 wenddrawing(self
->t_ref
->w_win
);
926 text_event(self
, args
)
930 register TEXTEDIT
*tp
= self
->t_text
;
932 if (!geteventarg(args
, &e
))
934 if (e
.type
== WE_MOUSE_DOWN
) {
935 /* Cheat at the margins */
937 wgetdocsize(e
.window
, &width
, &height
);
938 if (e
.u
.where
.h
< 0 && tegetleft(tp
) == 0)
940 else if (e
.u
.where
.h
> width
&& tegetright(tp
) == width
)
942 if (e
.u
.where
.v
< 0 && tegettop(tp
) == 0)
944 else if (e
.u
.where
.v
> height
&& tegetright(tp
) == height
)
945 e
.u
.where
.v
= height
;
947 return PyInt_FromLong((long) teevent(tp
, &e
));
951 text_getfocus(self
, args
)
955 if (!PyArg_NoArgs(args
))
957 return makepoint(tegetfoc1(self
->t_text
), tegetfoc2(self
->t_text
));
961 text_getfocustext(self
, args
)
967 if (!PyArg_NoArgs(args
))
969 f1
= tegetfoc1(self
->t_text
);
970 f2
= tegetfoc2(self
->t_text
);
971 text
= tegettext(self
->t_text
);
972 return PyString_FromStringAndSize(text
+ f1
, f2
-f1
);
976 text_getrect(self
, args
)
980 if (!PyArg_NoArgs(args
))
982 return makerect(tegetleft(self
->t_text
),
983 tegettop(self
->t_text
),
984 tegetright(self
->t_text
),
985 tegetbottom(self
->t_text
));
989 text_gettext(self
, args
)
993 if (!PyArg_NoArgs(args
))
995 return PyString_FromStringAndSize(tegettext(self
->t_text
),
996 tegetlen(self
->t_text
));
1000 text_move(self
, args
)
1005 if (!getrectarg(args
, a
))
1007 temovenew(self
->t_text
, a
[0], a
[1], a
[2], a
[3]);
1013 text_replace(self
, args
)
1018 if (!getstrarg(args
, &text
))
1020 tereplace(self
->t_text
, text
);
1026 text_setactive(self
, args
)
1031 if (!getintarg(args
, &flag
))
1033 tesetactive(self
->t_text
, flag
);
1039 text_setfocus(self
, args
)
1044 if (!getpointarg(args
, a
))
1046 tesetfocus(self
->t_text
, a
[0], a
[1]);
1052 text_settext(self
, args
)
1059 if (!PyArg_Parse(args
, "t#", &text
, &size
))
1061 if ((buf
= PyMem_NEW(char, size
)) == NULL
) {
1062 return PyErr_NoMemory();
1064 memcpy(buf
, text
, size
);
1065 tesetbuf(self
->t_text
, buf
, size
); /* Becomes owner of buffer */
1071 text_setview(self
, args
)
1076 if (args
== Py_None
)
1077 tenoview(self
->t_text
);
1079 if (!getrectarg(args
, a
))
1081 tesetview(self
->t_text
, a
[0], a
[1], a
[2], a
[3]);
1087 static PyMethodDef text_methods
[] = {
1088 {"arrow", (PyCFunction
)text_arrow
},
1089 {"close", (PyCFunction
)text_close
},
1090 {"draw", (PyCFunction
)text_draw
},
1091 {"event", (PyCFunction
)text_event
},
1092 {"getfocus", (PyCFunction
)text_getfocus
},
1093 {"getfocustext",(PyCFunction
)text_getfocustext
},
1094 {"getrect", (PyCFunction
)text_getrect
},
1095 {"gettext", (PyCFunction
)text_gettext
},
1096 {"move", (PyCFunction
)text_move
},
1097 {"replace", (PyCFunction
)text_replace
},
1098 {"setactive", (PyCFunction
)text_setactive
},
1099 {"setfocus", (PyCFunction
)text_setfocus
},
1100 {"settext", (PyCFunction
)text_settext
},
1101 {"setview", (PyCFunction
)text_setview
},
1102 {NULL
, NULL
} /* sentinel */
1106 text_getattr(tp
, name
)
1111 if (tp
->t_ref
== NULL
) {
1112 PyErr_SetString(StdwinError
, "text object already closed");
1115 if (strcmp(name
, "__dict__") == 0) {
1120 else if (tp
->t_attr
!= NULL
) {
1121 v
= PyDict_GetItemString(tp
->t_attr
, name
);
1127 return Py_FindMethod(text_methods
, (PyObject
*)tp
, name
);
1131 text_setattr(tp
, name
, v
)
1136 if (tp
->t_attr
== NULL
) {
1137 tp
->t_attr
= PyDict_New();
1138 if (tp
->t_attr
== NULL
)
1142 int rv
= PyDict_DelItemString(tp
->t_attr
, name
);
1144 PyErr_SetString(PyExc_AttributeError
,
1145 "delete non-existing text object attribute");
1149 return PyDict_SetItemString(tp
->t_attr
, name
, v
);
1152 statichere PyTypeObject Texttype
= {
1153 PyObject_HEAD_INIT(&PyType_Type
)
1155 "textedit", /*tp_name*/
1156 sizeof(textobject
), /*tp_size*/
1159 (destructor
)text_dealloc
, /*tp_dealloc*/
1161 (getattrfunc
)text_getattr
, /*tp_getattr*/
1162 (setattrfunc
)text_setattr
, /*tp_setattr*/
1170 #define IDOFFSET 10 /* Menu IDs we use start here */
1171 #define MAXNMENU 200 /* Max #menus we allow */
1172 static menuobject
*menulist
[MAXNMENU
];
1174 static menuobject
*newmenuobject
Py_PROTO((char *));
1176 newmenuobject(title
)
1182 for (id
= 0; id
< MAXNMENU
; id
++) {
1183 if (menulist
[id
] == NULL
)
1186 if (id
>= MAXNMENU
) {
1187 PyErr_SetString(StdwinError
, "creating too many menus");
1190 menu
= wmenucreate(id
+ IDOFFSET
, title
);
1192 return (menuobject
*) PyErr_NoMemory();
1193 mp
= PyObject_NEW(menuobject
, &Menutype
);
1196 mp
->m_id
= id
+ IDOFFSET
;
1212 int id
= mp
->m_id
- IDOFFSET
;
1213 if (id
>= 0 && id
< MAXNMENU
&& menulist
[id
] == mp
) {
1214 menulist
[id
] = NULL
;
1216 if (mp
->m_menu
!= NULL
)
1217 wmenudelete(mp
->m_menu
);
1218 Py_XDECREF(mp
->m_attr
);
1223 menu_close(mp
, args
)
1227 int id
= mp
->m_id
- IDOFFSET
;
1228 if (id
>= 0 && id
< MAXNMENU
&& menulist
[id
] == mp
) {
1229 menulist
[id
] = NULL
;
1232 if (mp
->m_menu
!= NULL
)
1233 wmenudelete(mp
->m_menu
);
1235 Py_XDECREF(mp
->m_attr
);
1242 menu_additem(self
, args
)
1248 if (PyTuple_Check(args
)) {
1250 if (!PyArg_Parse(args
, "(sc)", &text
, &c
))
1254 else if (!getstrarg(args
, &text
))
1256 wmenuadditem(self
->m_menu
, text
, shortcut
);
1262 menu_setitem(self
, args
)
1268 if (!PyArg_Parse(args
, "(is)", &index
, &text
))
1270 wmenusetitem(self
->m_menu
, index
, text
);
1276 menu_enable(self
, args
)
1282 if (!PyArg_Parse(args
, "(ii)", &index
, &flag
))
1284 wmenuenable(self
->m_menu
, index
, flag
);
1290 menu_check(self
, args
)
1296 if (!PyArg_Parse(args
, "(ii)", &index
, &flag
))
1298 wmenucheck(self
->m_menu
, index
, flag
);
1303 static PyMethodDef menu_methods
[] = {
1304 {"additem", (PyCFunction
)menu_additem
},
1305 {"setitem", (PyCFunction
)menu_setitem
},
1306 {"enable", (PyCFunction
)menu_enable
},
1307 {"check", (PyCFunction
)menu_check
},
1308 {"close", (PyCFunction
)menu_close
},
1309 {NULL
, NULL
} /* sentinel */
1313 menu_getattr(mp
, name
)
1318 if (mp
->m_menu
== NULL
) {
1319 PyErr_SetString(StdwinError
, "menu object already closed");
1322 if (strcmp(name
, "__dict__") == 0) {
1327 else if (mp
->m_attr
!= NULL
) {
1328 v
= PyDict_GetItemString(mp
->m_attr
, name
);
1334 return Py_FindMethod(menu_methods
, (PyObject
*)mp
, name
);
1338 menu_setattr(mp
, name
, v
)
1343 if (mp
->m_attr
== NULL
) {
1344 mp
->m_attr
= PyDict_New();
1345 if (mp
->m_attr
== NULL
)
1349 int rv
= PyDict_DelItemString(mp
->m_attr
, name
);
1351 PyErr_SetString(PyExc_AttributeError
,
1352 "delete non-existing menu object attribute");
1356 return PyDict_SetItemString(mp
->m_attr
, name
, v
);
1359 statichere PyTypeObject Menutype
= {
1360 PyObject_HEAD_INIT(&PyType_Type
)
1363 sizeof(menuobject
), /*tp_size*/
1366 (destructor
)menu_dealloc
, /*tp_dealloc*/
1368 (getattrfunc
)menu_getattr
, /*tp_getattr*/
1369 (setattrfunc
)menu_setattr
, /*tp_setattr*/
1377 /* Bitmaps objects */
1379 static bitmapobject
*newbitmapobject
Py_PROTO((int, int));
1380 static bitmapobject
*
1381 newbitmapobject(width
, height
)
1386 bitmap
= wnewbitmap(width
, height
);
1388 return (bitmapobject
*) PyErr_NoMemory();
1389 bp
= PyObject_NEW(bitmapobject
, &Bitmaptype
);
1391 bp
->b_bitmap
= bitmap
;
1395 wfreebitmap(bitmap
);
1399 /* Bitmap methods */
1405 if (bp
->b_bitmap
!= NULL
)
1406 wfreebitmap(bp
->b_bitmap
);
1407 Py_XDECREF(bp
->b_attr
);
1412 bitmap_close(bp
, args
)
1416 if (bp
->b_bitmap
!= NULL
)
1417 wfreebitmap(bp
->b_bitmap
);
1418 bp
->b_bitmap
= NULL
;
1419 Py_XDECREF(bp
->b_attr
);
1426 bitmap_setbit(self
, args
)
1431 if (!getpointintarg(args
, a
))
1433 wsetbit(self
->b_bitmap
, a
[0], a
[1], a
[2]);
1439 bitmap_getbit(self
, args
)
1444 if (!getpointarg(args
, a
))
1446 return PyInt_FromLong((long) wgetbit(self
->b_bitmap
, a
[0], a
[1]));
1450 bitmap_getsize(self
, args
)
1455 if (!PyArg_NoArgs(args
))
1457 wgetbitmapsize(self
->b_bitmap
, &width
, &height
);
1458 return Py_BuildValue("(ii)", width
, height
);
1461 static PyMethodDef bitmap_methods
[] = {
1462 {"close", (PyCFunction
)bitmap_close
},
1463 {"getsize", (PyCFunction
)bitmap_getsize
},
1464 {"getbit", (PyCFunction
)bitmap_getbit
},
1465 {"setbit", (PyCFunction
)bitmap_setbit
},
1466 {NULL
, NULL
} /* sentinel */
1470 bitmap_getattr(bp
, name
)
1475 if (bp
->b_bitmap
== NULL
) {
1476 PyErr_SetString(StdwinError
, "bitmap object already closed");
1479 if (strcmp(name
, "__dict__") == 0) {
1484 else if (bp
->b_attr
!= NULL
) {
1485 v
= PyDict_GetItemString(bp
->b_attr
, name
);
1491 return Py_FindMethod(bitmap_methods
, (PyObject
*)bp
, name
);
1495 bitmap_setattr(bp
, name
, v
)
1500 if (bp
->b_attr
== NULL
) {
1501 bp
->b_attr
= PyDict_New();
1502 if (bp
->b_attr
== NULL
)
1506 int rv
= PyDict_DelItemString(bp
->b_attr
, name
);
1508 PyErr_SetString(PyExc_AttributeError
,
1509 "delete non-existing bitmap object attribute");
1513 return PyDict_SetItemString(bp
->b_attr
, name
, v
);
1516 statichere PyTypeObject Bitmaptype
= {
1517 PyObject_HEAD_INIT(&PyType_Type
)
1519 "bitmap", /*tp_name*/
1520 sizeof(bitmapobject
), /*tp_size*/
1523 (destructor
)bitmap_dealloc
, /*tp_dealloc*/
1525 (getattrfunc
)bitmap_getattr
, /*tp_getattr*/
1526 (setattrfunc
)bitmap_setattr
, /*tp_setattr*/
1531 #endif /* HAVE_BITMAPS */
1537 static windowobject
*windowlist
[MAXNWIN
];
1539 /* Window methods */
1545 if (wp
->w_win
!= NULL
) {
1546 int tag
= wgettag(wp
->w_win
);
1547 if (tag
>= 0 && tag
< MAXNWIN
)
1548 windowlist
[tag
] = NULL
;
1550 fprintf(stderr
, "XXX help! tag %d in window_dealloc\n",
1554 Py_DECREF(wp
->w_title
);
1555 if (wp
->w_attr
!= NULL
)
1556 Py_DECREF(wp
->w_attr
);
1561 window_close(wp
, args
)
1565 if (wp
->w_win
!= NULL
) {
1566 int tag
= wgettag(wp
->w_win
);
1567 if (tag
>= 0 && tag
< MAXNWIN
)
1568 windowlist
[tag
] = NULL
;
1577 window_begindrawing(wp
, args
)
1582 if (!PyArg_NoArgs(args
))
1584 if (Drawing
!= NULL
) {
1585 PyErr_SetString(StdwinError
, "already drawing");
1588 dp
= PyObject_NEW(drawingobject
, &Drawingtype
);
1594 wbegindrawing(wp
->w_win
);
1595 return (PyObject
*)dp
;
1599 window_change(wp
, args
)
1604 if (!getrectarg(args
, a
))
1606 wchange(wp
->w_win
, a
[0], a
[1], a
[2], a
[3]);
1612 window_gettitle(wp
, args
)
1616 if (!PyArg_NoArgs(args
))
1618 Py_INCREF(wp
->w_title
);
1623 window_getwinpos(wp
, args
)
1628 if (!PyArg_NoArgs(args
))
1630 wgetwinpos(wp
->w_win
, &h
, &v
);
1631 return makepoint(h
, v
);
1635 window_getwinsize(wp
, args
)
1640 if (!PyArg_NoArgs(args
))
1642 wgetwinsize(wp
->w_win
, &width
, &height
);
1643 return makepoint(width
, height
);
1647 window_setwinpos(wp
, args
)
1652 if (!getpointarg(args
, a
))
1654 wsetwinpos(wp
->w_win
, a
[0], a
[1]);
1660 window_setwinsize(wp
, args
)
1665 if (!getpointarg(args
, a
))
1667 wsetwinsize(wp
->w_win
, a
[0], a
[1]);
1673 window_getdocsize(wp
, args
)
1678 if (!PyArg_NoArgs(args
))
1680 wgetdocsize(wp
->w_win
, &width
, &height
);
1681 return makepoint(width
, height
);
1685 window_getorigin(wp
, args
)
1690 if (!PyArg_NoArgs(args
))
1692 wgetorigin(wp
->w_win
, &width
, &height
);
1693 return makepoint(width
, height
);
1697 window_scroll(wp
, args
)
1702 if (!getrectpointarg(args
, a
))
1704 wscroll(wp
->w_win
, a
[0], a
[1], a
[2], a
[3], a
[4], a
[5]);
1710 window_setdocsize(wp
, args
)
1715 if (!getpointarg(args
, a
))
1717 wsetdocsize(wp
->w_win
, a
[0], a
[1]);
1723 window_setorigin(wp
, args
)
1728 if (!getpointarg(args
, a
))
1730 wsetorigin(wp
->w_win
, a
[0], a
[1]);
1736 window_settitle(wp
, args
)
1741 if (!PyArg_Parse(args
, "S", &title
))
1743 Py_DECREF(wp
->w_title
);
1745 wp
->w_title
= title
;
1746 wsettitle(wp
->w_win
, PyString_AsString(title
));
1752 window_show(wp
, args
)
1757 if (!getrectarg(args
, a
))
1759 wshow(wp
->w_win
, a
[0], a
[1], a
[2], a
[3]);
1765 window_settimer(wp
, args
)
1770 if (!getintarg(args
, &a
))
1772 wsettimer(wp
->w_win
, a
);
1778 window_menucreate(self
, args
)
1784 if (!getstrarg(args
, &title
))
1786 wmenusetdeflocal(1);
1787 mp
= newmenuobject(title
);
1790 wmenuattach(self
->w_win
, mp
->m_menu
);
1791 return (PyObject
*)mp
;
1795 window_textcreate(self
, args
)
1800 if (!getrectarg(args
, a
))
1802 return (PyObject
*)newtextobject(self
, a
[0], a
[1], a
[2], a
[3]);
1806 window_setselection(self
, args
)
1812 if (!PyArg_Parse(args
, "(it#)", &sel
, &text
, &size
))
1814 ok
= wsetselection(self
->w_win
, sel
, text
, size
);
1815 return PyInt_FromLong(ok
);
1819 window_setwincursor(self
, args
)
1825 if (!PyArg_Parse(args
, "z", &name
))
1830 c
= wfetchcursor(name
);
1832 PyErr_SetString(StdwinError
, "no such cursor");
1836 wsetwincursor(self
->w_win
, c
);
1842 window_setactive(self
, args
)
1846 if (!PyArg_NoArgs(args
))
1848 wsetactive(self
->w_win
);
1855 window_getxwindowid(self
, args
)
1859 long wid
= wgetxwindowid(self
->w_win
);
1860 return PyInt_FromLong(wid
);
1864 static PyMethodDef window_methods
[] = {
1865 {"begindrawing",(PyCFunction
)window_begindrawing
},
1866 {"change", (PyCFunction
)window_change
},
1867 {"close", (PyCFunction
)window_close
},
1868 {"getdocsize", (PyCFunction
)window_getdocsize
},
1869 {"getorigin", (PyCFunction
)window_getorigin
},
1870 {"gettitle", (PyCFunction
)window_gettitle
},
1871 {"getwinpos", (PyCFunction
)window_getwinpos
},
1872 {"getwinsize", (PyCFunction
)window_getwinsize
},
1873 {"menucreate", (PyCFunction
)window_menucreate
},
1874 {"scroll", (PyCFunction
)window_scroll
},
1875 {"setactive", (PyCFunction
)window_setactive
},
1876 {"setdocsize", (PyCFunction
)window_setdocsize
},
1877 {"setorigin", (PyCFunction
)window_setorigin
},
1878 {"setselection",(PyCFunction
)window_setselection
},
1879 {"settimer", (PyCFunction
)window_settimer
},
1880 {"settitle", (PyCFunction
)window_settitle
},
1881 {"setwincursor",(PyCFunction
)window_setwincursor
},
1882 {"setwinpos", (PyCFunction
)window_setwinpos
},
1883 {"setwinsize", (PyCFunction
)window_setwinsize
},
1884 {"show", (PyCFunction
)window_show
},
1885 {"textcreate", (PyCFunction
)window_textcreate
},
1887 {"getxwindowid",(PyCFunction
)window_getxwindowid
},
1889 {NULL
, NULL
} /* sentinel */
1893 window_getattr(wp
, name
)
1898 if (wp
->w_win
== NULL
) {
1899 PyErr_SetString(StdwinError
, "window already closed");
1902 if (strcmp(name
, "__dict__") == 0) {
1907 else if (wp
->w_attr
!= NULL
) {
1908 v
= PyDict_GetItemString(wp
->w_attr
, name
);
1914 return Py_FindMethod(window_methods
, (PyObject
*)wp
, name
);
1918 window_setattr(wp
, name
, v
)
1923 if (wp
->w_attr
== NULL
) {
1924 wp
->w_attr
= PyDict_New();
1925 if (wp
->w_attr
== NULL
)
1929 int rv
= PyDict_DelItemString(wp
->w_attr
, name
);
1931 PyErr_SetString(PyExc_AttributeError
,
1932 "delete non-existing menu object attribute");
1936 return PyDict_SetItemString(wp
->w_attr
, name
, v
);
1939 statichere PyTypeObject Windowtype
= {
1940 PyObject_HEAD_INIT(&PyType_Type
)
1942 "window", /*tp_name*/
1943 sizeof(windowobject
), /*tp_size*/
1946 (destructor
)window_dealloc
, /*tp_dealloc*/
1948 (getattrfunc
)window_getattr
, /*tp_getattr*/
1949 (setattrfunc
)window_setattr
, /*tp_setattr*/
1954 /* Stdwin methods */
1957 stdwin_done(sw
, args
)
1961 if (!PyArg_NoArgs(args
))
1964 /* XXX There is no protection against continued use of
1965 XXX stdwin functions or objects after this call is made.
1966 XXX Use at own risk */
1972 stdwin_open(sw
, args
)
1979 if (!PyArg_Parse(args
, "S", &title
))
1981 for (tag
= 0; tag
< MAXNWIN
; tag
++) {
1982 if (windowlist
[tag
] == NULL
)
1985 if (tag
>= MAXNWIN
) {
1986 PyErr_SetString(StdwinError
, "creating too many windows");
1989 wp
= PyObject_NEW(windowobject
, &Windowtype
);
1993 wp
->w_title
= title
;
1994 wp
->w_win
= wopen(PyString_AsString(title
), (void (*)()) NULL
);
1996 if (wp
->w_win
== NULL
) {
2000 windowlist
[tag
] = wp
;
2001 wsettag(wp
->w_win
, tag
);
2002 return (PyObject
*)wp
;
2013 int tag
= wgettag(win
);
2014 if (tag
< 0 || tag
>= MAXNWIN
|| windowlist
[tag
] == NULL
||
2015 windowlist
[tag
]->w_win
!= win
)
2018 w
= (PyObject
*)windowlist
[tag
];
2025 stdwin_get_poll_event(poll
, args
)
2030 PyObject
*u
, *v
, *w
;
2031 if (!PyArg_NoArgs(args
))
2033 if (Drawing
!= NULL
) {
2034 PyErr_SetString(StdwinError
,
2035 "cannot getevent() while drawing");
2041 if (!wpollevent(&e
)) {
2050 if (e
.type
== WE_COMMAND
&& e
.u
.command
== WC_CANCEL
) {
2051 /* Turn keyboard interrupts into exceptions */
2052 PyErr_SetNone(PyExc_KeyboardInterrupt
);
2055 if (e
.type
== WE_COMMAND
&& e
.u
.command
== WC_CLOSE
) {
2056 /* Turn WC_CLOSE commands into WE_CLOSE events */
2059 v
= window2object(e
.window
);
2064 c
[0] = e
.u
.character
;
2065 w
= PyString_FromStringAndSize(c
, 1);
2069 w
= PyInt_FromLong((long)e
.u
.command
);
2072 w
= makerect(e
.u
.area
.left
, e
.u
.area
.top
,
2073 e
.u
.area
.right
, e
.u
.area
.bottom
);
2078 w
= Py_BuildValue("((ii)iii)",
2079 e
.u
.where
.h
, e
.u
.where
.v
,
2085 if (e
.u
.m
.id
>= IDOFFSET
&&
2086 e
.u
.m
.id
< IDOFFSET
+MAXNMENU
&&
2087 menulist
[e
.u
.m
.id
- IDOFFSET
] != NULL
)
2089 w
= Py_BuildValue("(Oi)",
2090 menulist
[e
.u
.m
.id
- IDOFFSET
],
2094 /* Ghost menu event.
2095 Can occur only on the Mac if another part
2096 of the aplication has installed a menu;
2097 like the THINK C console library. */
2103 w
= Py_BuildValue("(ii)", e
.u
.key
.code
, e
.u
.key
.mask
);
2106 w
= PyInt_FromLong((long)e
.u
.sel
);
2117 u
= Py_BuildValue("(iOO)", e
.type
, v
, w
);
2124 stdwin_getevent(sw
, args
)
2128 return stdwin_get_poll_event(0, args
);
2132 stdwin_pollevent(sw
, args
)
2136 return stdwin_get_poll_event(1, args
);
2140 stdwin_setdefwinpos(sw
, args
)
2145 if (!getpointarg(args
, a
))
2147 wsetdefwinpos(a
[0], a
[1]);
2153 stdwin_setdefwinsize(sw
, args
)
2158 if (!getpointarg(args
, a
))
2160 wsetdefwinsize(a
[0], a
[1]);
2166 stdwin_setdefscrollbars(sw
, args
)
2171 if (!getpointarg(args
, a
))
2173 wsetdefscrollbars(a
[0], a
[1]);
2179 stdwin_getdefwinpos(self
, args
)
2184 if (!PyArg_NoArgs(args
))
2186 wgetdefwinpos(&h
, &v
);
2187 return makepoint(h
, v
);
2191 stdwin_getdefwinsize(self
, args
)
2196 if (!PyArg_NoArgs(args
))
2198 wgetdefwinsize(&width
, &height
);
2199 return makepoint(width
, height
);
2203 stdwin_getdefscrollbars(self
, args
)
2208 if (!PyArg_NoArgs(args
))
2210 wgetdefscrollbars(&h
, &v
);
2211 return makepoint(h
, v
);
2215 stdwin_menucreate(self
, args
)
2220 if (!getstrarg(args
, &title
))
2222 wmenusetdeflocal(0);
2223 return (PyObject
*)newmenuobject(title
);
2227 stdwin_askfile(self
, args
)
2231 char *prompt
, *dflt
;
2234 if (!PyArg_Parse(args
, "(ssi)", &prompt
, &dflt
, &new))
2236 strncpy(buf
, dflt
, sizeof buf
);
2237 buf
[sizeof buf
- 1] = '\0';
2239 ret
= waskfile(prompt
, buf
, sizeof buf
, new);
2242 PyErr_SetNone(PyExc_KeyboardInterrupt
);
2245 return PyString_FromString(buf
);
2249 stdwin_askync(self
, args
)
2255 if (!PyArg_Parse(args
, "(si)", &prompt
, &new))
2258 ret
= waskync(prompt
, new);
2261 PyErr_SetNone(PyExc_KeyboardInterrupt
);
2264 return PyInt_FromLong((long)ret
);
2268 stdwin_askstr(self
, args
)
2272 char *prompt
, *dflt
;
2275 if (!PyArg_Parse(args
, "(ss)", &prompt
, &dflt
))
2277 strncpy(buf
, dflt
, sizeof buf
);
2278 buf
[sizeof buf
- 1] = '\0';
2280 ret
= waskstr(prompt
, buf
, sizeof buf
);
2283 PyErr_SetNone(PyExc_KeyboardInterrupt
);
2286 return PyString_FromString(buf
);
2290 stdwin_message(self
, args
)
2295 if (!getstrarg(args
, &msg
))
2305 stdwin_fleep(self
, args
)
2309 if (!PyArg_NoArgs(args
))
2317 stdwin_setcutbuffer(self
, args
)
2323 if (!PyArg_Parse(args
, "(it#)", &i
, &str
, &size
))
2325 wsetcutbuffer(i
, str
, size
);
2331 stdwin_getactive(self
, args
)
2335 return window2object(wgetactive());
2339 stdwin_getcutbuffer(self
, args
)
2346 if (!getintarg(args
, &i
))
2348 str
= wgetcutbuffer(i
, &len
);
2353 return PyString_FromStringAndSize(str
, len
);
2357 stdwin_rotatecutbuffers(self
, args
)
2362 if (!getintarg(args
, &i
))
2364 wrotatecutbuffers(i
);
2370 stdwin_getselection(self
, args
)
2377 if (!getintarg(args
, &sel
))
2379 data
= wgetselection(sel
, &len
);
2384 return PyString_FromStringAndSize(data
, len
);
2388 stdwin_resetselection(self
, args
)
2393 if (!getintarg(args
, &sel
))
2395 wresetselection(sel
);
2401 stdwin_fetchcolor(self
, args
)
2407 if (!getstrarg(args
, &colorname
))
2409 color
= wfetchcolor(colorname
);
2411 if (color
== BADCOLOR
) {
2412 PyErr_SetString(StdwinError
, "color name not found");
2416 return PyInt_FromLong((long)color
);
2420 stdwin_getscrsize(self
, args
)
2425 if (!PyArg_NoArgs(args
))
2427 wgetscrsize(&width
, &height
);
2428 return makepoint(width
, height
);
2432 stdwin_getscrmm(self
, args
)
2437 if (!PyArg_NoArgs(args
))
2439 wgetscrmm(&width
, &height
);
2440 return makepoint(width
, height
);
2445 stdwin_connectionnumber(self
, args
)
2449 if (!PyArg_NoArgs(args
))
2451 return PyInt_FromLong((long) wconnectionnumber());
2456 stdwin_listfontnames(self
, args
)
2464 if (!PyArg_Parse(args
, "z", &pattern
))
2466 fontnames
= wlistfontnames(pattern
, &count
);
2467 list
= PyList_New(count
);
2470 for (i
= 0; i
< count
; i
++) {
2471 PyObject
*v
= PyString_FromString(fontnames
[i
]);
2477 PyList_SetItem(list
, i
, v
);
2485 stdwin_newbitmap(self
, args
)
2491 if (!PyArg_Parse(args
, "(ii)", &width
, &height
))
2493 return (PyObject
*)newbitmapobject(width
, height
);
2497 static PyMethodDef stdwin_methods
[] = {
2498 {"askfile", stdwin_askfile
},
2499 {"askstr", stdwin_askstr
},
2500 {"askync", stdwin_askync
},
2501 {"done", stdwin_done
},
2502 {"fetchcolor", stdwin_fetchcolor
},
2504 {"fileno", stdwin_connectionnumber
},
2505 {"connectionnumber", stdwin_connectionnumber
},
2507 {"fleep", stdwin_fleep
},
2508 {"getactive", stdwin_getactive
},
2509 {"getcutbuffer", stdwin_getcutbuffer
},
2510 {"getdefscrollbars", stdwin_getdefscrollbars
},
2511 {"getdefwinpos", stdwin_getdefwinpos
},
2512 {"getdefwinsize", stdwin_getdefwinsize
},
2513 {"getevent", stdwin_getevent
},
2514 {"getscrmm", stdwin_getscrmm
},
2515 {"getscrsize", stdwin_getscrsize
},
2516 {"getselection", stdwin_getselection
},
2517 {"listfontnames", stdwin_listfontnames
},
2518 {"menucreate", stdwin_menucreate
},
2519 {"message", stdwin_message
},
2521 {"newbitmap", stdwin_newbitmap
},
2523 {"open", stdwin_open
},
2524 {"pollevent", stdwin_pollevent
},
2525 {"resetselection", stdwin_resetselection
},
2526 {"rotatecutbuffers", stdwin_rotatecutbuffers
},
2527 {"setcutbuffer", stdwin_setcutbuffer
},
2528 {"setdefscrollbars", stdwin_setdefscrollbars
},
2529 {"setdefwinpos", stdwin_setdefwinpos
},
2530 {"setdefwinsize", stdwin_setdefwinsize
},
2532 /* Text measuring methods borrow code from drawing objects: */
2533 {"baseline", (PyCFunction
)drawing_baseline
},
2534 {"lineheight", (PyCFunction
)drawing_lineheight
},
2535 {"textbreak", (PyCFunction
)drawing_textbreak
},
2536 {"textwidth", (PyCFunction
)drawing_textwidth
},
2538 /* Same for font setting methods: */
2539 {"setfont", (PyCFunction
)drawing_setfont
},
2541 /* Same for color setting/getting methods: */
2542 {"getbgcolor", (PyCFunction
)drawing_getbgcolor
},
2543 {"getfgcolor", (PyCFunction
)drawing_getfgcolor
},
2544 {"setbgcolor", (PyCFunction
)drawing_setbgcolor
},
2545 {"setfgcolor", (PyCFunction
)drawing_setfgcolor
},
2547 {NULL
, NULL
} /* sentinel */
2552 checkstringlist(args
, ps
, pn
)
2559 if (!PyList_Check(args
)) {
2560 PyErr_SetString(PyExc_TypeError
, "list of strings expected");
2563 n
= PyList_Size(args
);
2564 s
= PyMem_NEW(char *, n
+1);
2569 for (i
= 0; i
< n
; i
++) {
2570 PyObject
*item
= PyList_GetItem(args
, i
);
2571 if (!PyString_Check(item
)) {
2572 PyErr_SetString(PyExc_TypeError
,
2573 "list of strings expected");
2576 s
[i
] = PyString_AsString(item
);
2578 s
[n
] = NULL
; /* In case caller wants a NULL-terminated list */
2585 putbackstringlist(list
, s
, n
)
2590 int oldsize
= PyList_Size(list
);
2595 newlist
= PyList_New(n
);
2596 for (i
= 0; i
< n
&& newlist
!= NULL
; i
++) {
2597 PyObject
*item
= PyString_FromString(s
[i
]);
2603 PyList_SetItem(newlist
, i
, item
);
2605 if (newlist
== NULL
)
2607 (*list
->ob_type
->tp_as_sequence
->sq_ass_slice
)
2608 (list
, 0, oldsize
, newlist
);
2612 #endif /* macintosh */
2618 static int inited
= 0;
2623 PyMac_DoYieldEnabled
= 0;
2628 PyObject
*sys_argv
= PySys_GetObject("argv");
2629 if (sys_argv
!= NULL
) {
2630 if (!checkstringlist(sys_argv
, &argv
, &argc
))
2634 /* If argv[0] has a ".py" suffix, remove the suffix */
2635 char *p
= strrchr(argv
[0], '.');
2636 if (p
!= NULL
&& strcmp(p
, ".py") == 0) {
2637 int n
= p
- argv
[0];
2638 if (n
>= sizeof(buf
))
2640 strncpy(buf
, argv
[0], n
);
2645 winitargs(&argc
, &argv
);
2647 if (!putbackstringlist(sys_argv
, argv
, argc
))
2653 m
= Py_InitModule("stdwin", stdwin_methods
);
2654 d
= PyModule_GetDict(m
);
2656 /* Initialize stdwin.error exception */
2657 StdwinError
= PyErr_NewException("stdwin.error", NULL
, NULL
);
2658 if (StdwinError
== NULL
||
2659 PyDict_SetItemString(d
, "error", StdwinError
) != 0)
2662 StdwinLock
= allocate_lock();