1991-02-19 12:39:46 +00:00
|
|
|
/***********************************************************
|
1995-01-04 19:10:35 +00:00
|
|
|
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
|
|
|
|
The Netherlands.
|
1991-02-19 12:39:46 +00:00
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
1996-10-25 14:44:06 +00:00
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
1991-02-19 12:39:46 +00:00
|
|
|
provided that the above copyright notice appear in all copies and that
|
1996-10-25 14:44:06 +00:00
|
|
|
both that copyright notice and this permission notice appear in
|
1991-02-19 12:39:46 +00:00
|
|
|
supporting documentation, and that the names of Stichting Mathematisch
|
1996-10-25 14:44:06 +00:00
|
|
|
Centrum or CWI or Corporation for National Research Initiatives or
|
|
|
|
CNRI not be used in advertising or publicity pertaining to
|
|
|
|
distribution of the software without specific, written prior
|
|
|
|
permission.
|
|
|
|
|
|
|
|
While CWI is the initial source for this software, a modified version
|
|
|
|
is made available by the Corporation for National Research Initiatives
|
|
|
|
(CNRI) at the Internet address ftp://ftp.python.org.
|
|
|
|
|
|
|
|
STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
|
|
|
|
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
|
|
|
|
CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
|
|
|
|
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
|
|
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
PERFORMANCE OF THIS SOFTWARE.
|
1991-02-19 12:39:46 +00:00
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
1990-10-14 12:07:46 +00:00
|
|
|
/* Stdwin module */
|
|
|
|
|
|
|
|
/* Stdwin itself is a module, not a separate object type.
|
|
|
|
Object types defined here:
|
|
|
|
wp: a window
|
|
|
|
dp: a drawing structure (only one can exist at a time)
|
|
|
|
mp: a menu
|
|
|
|
tp: a textedit block
|
1993-02-08 15:49:17 +00:00
|
|
|
bp: a bitmap
|
1990-10-14 12:07:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Rules for translating C stdwin function calls into Python stwin:
|
|
|
|
- All names drop their initial letter 'w'
|
|
|
|
- Functions with a window as first parameter are methods of window objects
|
|
|
|
- There is no equivalent for wclose(); just delete the window object
|
|
|
|
(all references to it!) (XXX maybe this is a bad idea)
|
|
|
|
- w.begindrawing() returns a drawing object
|
|
|
|
- There is no equivalent for wenddrawing(win); just delete the drawing
|
|
|
|
object (all references to it!) (XXX maybe this is a bad idea)
|
|
|
|
- Functions that may only be used inside wbegindrawing / wendddrawing
|
|
|
|
are methods of the drawing object; this includes the text measurement
|
|
|
|
functions (which however have doubles as module functions).
|
|
|
|
- Methods of the drawing object drop an initial 'draw' from their name
|
|
|
|
if they have it, e.g., wdrawline() --> d.line()
|
|
|
|
- The obvious type conversions: int --> intobject; string --> stringobject
|
|
|
|
- A text parameter followed by a length parameter is only a text (string)
|
|
|
|
parameter in Python
|
|
|
|
- A point or other pair of horizontal and vertical coordinates is always
|
|
|
|
a pair of integers in Python
|
|
|
|
- Two points forming a rectangle or endpoints of a line segment are a
|
|
|
|
pair of points in Python
|
|
|
|
- The arguments to d.elarc() are three points.
|
|
|
|
- The functions wgetclip() and wsetclip() are translated into
|
|
|
|
stdwin.getcutbuffer() and stdwin.setcutbuffer(); 'clip' is really
|
|
|
|
a bad word for what these functions do (clipping has a different
|
|
|
|
meaning in the drawing world), while cutbuffer is standard X jargon.
|
1990-10-30 13:39:00 +00:00
|
|
|
XXX This must change again in the light of changes to stdwin!
|
1990-10-14 12:07:46 +00:00
|
|
|
- For textedit, similar rules hold, but they are less strict.
|
|
|
|
XXX more?
|
|
|
|
*/
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
#include "Python.h"
|
|
|
|
|
1995-08-14 12:17:18 +00:00
|
|
|
#ifdef macintosh
|
|
|
|
#include "macglue.h"
|
|
|
|
#endif
|
1990-10-14 12:07:46 +00:00
|
|
|
|
1993-01-21 16:07:51 +00:00
|
|
|
#ifdef macintosh
|
1993-07-29 13:14:32 +00:00
|
|
|
#include ":::stdwin:H:stdwin.h"
|
1993-01-21 16:07:51 +00:00
|
|
|
#else /* !macintosh */
|
1990-12-20 15:06:42 +00:00
|
|
|
#include "stdwin.h"
|
1993-07-29 13:14:32 +00:00
|
|
|
#define HAVE_BITMAPS
|
1993-01-21 16:07:51 +00:00
|
|
|
#endif /* !macintosh */
|
1990-10-14 12:07:46 +00:00
|
|
|
|
1994-08-01 11:34:53 +00:00
|
|
|
#ifdef WITH_THREAD
|
1992-08-05 19:58:53 +00:00
|
|
|
|
1998-10-01 20:42:43 +00:00
|
|
|
#include "pythread.h"
|
1992-08-05 19:58:53 +00:00
|
|
|
|
1998-12-21 19:32:43 +00:00
|
|
|
static PyThread_type_lock StdwinLock; /* Lock held when interpreter not locked */
|
1992-08-05 19:58:53 +00:00
|
|
|
|
1998-12-21 19:32:43 +00:00
|
|
|
#define BGN_STDWIN Py_BEGIN_ALLOW_THREADS PyThread_acquire_lock(StdwinLock, 1);
|
|
|
|
#define RET_STDWIN PyThread_release_lock(StdwinLock); Py_BLOCK_THREADS
|
|
|
|
#define END_STDWIN PyThread_release_lock(StdwinLock); Py_END_ALLOW_THREADS
|
1992-08-05 19:58:53 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
#define BGN_STDWIN Py_BEGIN_ALLOW_THREADS
|
|
|
|
#define RET_STDWIN Py_BLOCK_THREADS
|
|
|
|
#define END_STDWIN Py_END_ALLOW_THREADS
|
1992-08-05 19:58:53 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1997-10-20 23:22:07 +00:00
|
|
|
#define getintarg(v,a) PyArg_Parse(v, "i", a)
|
|
|
|
#define getlongarg(v,a) PyArg_Parse(v, "l", a)
|
|
|
|
#define getstrarg(v,a) PyArg_Parse(v, "s", a)
|
1996-12-12 22:48:20 +00:00
|
|
|
#define getpointarg(v, a) PyArg_Parse(v, "(ii)", a, (a)+1)
|
|
|
|
#define get3pointarg(v, a) PyArg_Parse(v, "((ii)(ii)(ii))", \
|
|
|
|
a, a+1, a+2, a+3, a+4, a+5)
|
|
|
|
#define getrectarg(v, a) PyArg_Parse(v, "((ii)(ii))", a, a+1, a+2, a+3)
|
|
|
|
#define getrectintarg(v, a) PyArg_Parse(v, "(((ii)(ii))i)", \
|
|
|
|
a, a+1, a+2, a+3, a+4)
|
|
|
|
#define getpointintarg(v, a) PyArg_Parse(v, "((ii)i)", a, a+1, a+2)
|
|
|
|
#define getrectpointarg(v, a) PyArg_Parse(v, "(((ii)(ii))(ii))", \
|
|
|
|
a, a+1, a+2, a+3, a+4, a+5)
|
1993-06-17 12:35:49 +00:00
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *StdwinError; /* Exception stdwin.error */
|
1991-12-10 14:00:03 +00:00
|
|
|
|
1990-10-14 12:07:46 +00:00
|
|
|
/* Window and menu object types declared here because of forward references */
|
|
|
|
|
|
|
|
typedef struct {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject_HEAD
|
|
|
|
PyObject *w_title;
|
|
|
|
WINDOW *w_win;
|
|
|
|
PyObject *w_attr; /* Attributes dictionary */
|
1990-10-14 12:07:46 +00:00
|
|
|
} windowobject;
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
staticforward PyTypeObject Windowtype;
|
1990-10-14 12:07:46 +00:00
|
|
|
|
|
|
|
#define is_windowobject(wp) ((wp)->ob_type == &Windowtype)
|
|
|
|
|
|
|
|
typedef struct {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject_HEAD
|
|
|
|
MENU *m_menu;
|
|
|
|
int m_id;
|
|
|
|
PyObject *m_attr; /* Attributes dictionary */
|
1990-10-14 12:07:46 +00:00
|
|
|
} menuobject;
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
staticforward PyTypeObject Menutype;
|
1990-10-14 12:07:46 +00:00
|
|
|
|
|
|
|
#define is_menuobject(mp) ((mp)->ob_type == &Menutype)
|
|
|
|
|
1993-02-08 15:49:17 +00:00
|
|
|
typedef struct {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject_HEAD
|
|
|
|
BITMAP *b_bitmap;
|
|
|
|
PyObject *b_attr; /* Attributes dictionary */
|
1993-02-08 15:49:17 +00:00
|
|
|
} bitmapobject;
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
staticforward PyTypeObject Bitmaptype;
|
1993-02-08 15:49:17 +00:00
|
|
|
|
|
|
|
#define is_bitmapobject(mp) ((mp)->ob_type == &Bitmaptype)
|
|
|
|
|
1990-10-14 12:07:46 +00:00
|
|
|
|
|
|
|
/* Strongly stdwin-specific argument handlers */
|
|
|
|
|
|
|
|
static int
|
|
|
|
getmenudetail(v, ep)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *v;
|
1990-10-14 12:07:46 +00:00
|
|
|
EVENT *ep;
|
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
menuobject *mp;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_Parse(v, "(Oi)", &mp, &ep->u.m.item))
|
1992-01-27 16:45:55 +00:00
|
|
|
return 0;
|
|
|
|
if (!is_menuobject(mp))
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyErr_BadArgument();
|
1992-01-27 16:45:55 +00:00
|
|
|
ep->u.m.id = mp->m_id;
|
|
|
|
return 1;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
geteventarg(v, ep)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *v;
|
1990-10-14 12:07:46 +00:00
|
|
|
EVENT *ep;
|
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *wp, *detail;
|
1990-10-14 12:07:46 +00:00
|
|
|
int a[4];
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_Parse(v, "(iOO)", &ep->type, &wp, &detail))
|
1990-10-14 12:07:46 +00:00
|
|
|
return 0;
|
1992-01-27 16:45:55 +00:00
|
|
|
if (is_windowobject(wp))
|
|
|
|
ep->window = ((windowobject *)wp) -> w_win;
|
1996-12-12 22:48:20 +00:00
|
|
|
else if (wp == Py_None)
|
1990-10-14 12:07:46 +00:00
|
|
|
ep->window = NULL;
|
|
|
|
else
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyErr_BadArgument();
|
1992-01-27 16:45:55 +00:00
|
|
|
switch (ep->type) {
|
|
|
|
case WE_CHAR: {
|
|
|
|
char c;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_Parse(detail, "c", &c))
|
1992-01-27 16:45:55 +00:00
|
|
|
return 0;
|
|
|
|
ep->u.character = c;
|
|
|
|
return 1;
|
|
|
|
}
|
1990-10-14 12:07:46 +00:00
|
|
|
case WE_COMMAND:
|
|
|
|
return getintarg(detail, &ep->u.command);
|
|
|
|
case WE_DRAW:
|
|
|
|
if (!getrectarg(detail, a))
|
|
|
|
return 0;
|
|
|
|
ep->u.area.left = a[0];
|
|
|
|
ep->u.area.top = a[1];
|
|
|
|
ep->u.area.right = a[2];
|
|
|
|
ep->u.area.bottom = a[3];
|
|
|
|
return 1;
|
|
|
|
case WE_MOUSE_DOWN:
|
|
|
|
case WE_MOUSE_UP:
|
|
|
|
case WE_MOUSE_MOVE:
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyArg_Parse(detail, "((ii)iii)",
|
|
|
|
&ep->u.where.h, &ep->u.where.v,
|
|
|
|
&ep->u.where.clicks,
|
|
|
|
&ep->u.where.button,
|
|
|
|
&ep->u.where.mask);
|
1990-10-14 12:07:46 +00:00
|
|
|
case WE_MENU:
|
|
|
|
return getmenudetail(detail, ep);
|
1992-06-30 12:48:26 +00:00
|
|
|
case WE_KEY:
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyArg_Parse(detail, "(ii)",
|
|
|
|
&ep->u.key.code, &ep->u.key.mask);
|
1990-10-14 12:07:46 +00:00
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Return construction tools */
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
makepoint(a, b)
|
|
|
|
int a, b;
|
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
return Py_BuildValue("(ii)", a, b);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
makerect(a, b, c, d)
|
|
|
|
int a, b, c, d;
|
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
return Py_BuildValue("((ii)(ii))", a, b, c, d);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Drawing objects */
|
|
|
|
|
|
|
|
typedef struct {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject_HEAD
|
1990-10-14 12:07:46 +00:00
|
|
|
windowobject *d_ref;
|
|
|
|
} drawingobject;
|
|
|
|
|
|
|
|
static drawingobject *Drawing; /* Set to current drawing object, or NULL */
|
|
|
|
|
|
|
|
/* Drawing methods */
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-11-27 14:54:54 +00:00
|
|
|
drawing_close(dp)
|
|
|
|
drawingobject *dp;
|
|
|
|
{
|
|
|
|
if (dp->d_ref != NULL) {
|
|
|
|
wenddrawing(dp->d_ref->w_win);
|
|
|
|
Drawing = NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_DECREF(dp->d_ref);
|
1991-11-27 14:54:54 +00:00
|
|
|
dp->d_ref = NULL;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-11-27 14:54:54 +00:00
|
|
|
}
|
1992-01-14 18:41:24 +00:00
|
|
|
|
1990-10-14 12:07:46 +00:00
|
|
|
static void
|
|
|
|
drawing_dealloc(dp)
|
|
|
|
drawingobject *dp;
|
|
|
|
{
|
1991-11-27 14:54:54 +00:00
|
|
|
if (dp->d_ref != NULL) {
|
|
|
|
wenddrawing(dp->d_ref->w_win);
|
|
|
|
Drawing = NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_DECREF(dp->d_ref);
|
1991-11-27 14:54:54 +00:00
|
|
|
dp->d_ref = NULL;
|
|
|
|
}
|
1990-10-14 12:07:46 +00:00
|
|
|
free((char *)dp);
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_generic(dp, args, func)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
|
|
|
void (*func) Py_FPROTO((int, int, int, int));
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a[4];
|
|
|
|
if (!getrectarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
(*func)(a[0], a[1], a[2], a[3]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_line(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1991-03-06 13:14:12 +00:00
|
|
|
return drawing_generic(dp, args, wdrawline);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_xorline(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1991-03-06 13:14:12 +00:00
|
|
|
return drawing_generic(dp, args, wxorline);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_circle(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a[3];
|
|
|
|
if (!getpointintarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wdrawcircle(a[0], a[1], a[2]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
1991-05-14 12:09:25 +00:00
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-04-16 08:43:03 +00:00
|
|
|
drawing_fillcircle(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-04-16 08:43:03 +00:00
|
|
|
{
|
|
|
|
int a[3];
|
|
|
|
if (!getpointintarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wfillcircle(a[0], a[1], a[2]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-04-16 08:43:03 +00:00
|
|
|
}
|
1990-10-14 12:07:46 +00:00
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-05-14 12:09:25 +00:00
|
|
|
drawing_xorcircle(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-05-14 12:09:25 +00:00
|
|
|
{
|
|
|
|
int a[3];
|
|
|
|
if (!getpointintarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wxorcircle(a[0], a[1], a[2]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-05-14 12:09:25 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_elarc(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a[6];
|
|
|
|
if (!get3pointarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wdrawelarc(a[0], a[1], a[2], a[3], a[4], a[5]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-04-16 08:43:03 +00:00
|
|
|
drawing_fillelarc(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-04-16 08:43:03 +00:00
|
|
|
{
|
|
|
|
int a[6];
|
|
|
|
if (!get3pointarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wfillelarc(a[0], a[1], a[2], a[3], a[4], a[5]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-04-16 08:43:03 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-05-14 12:09:25 +00:00
|
|
|
drawing_xorelarc(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-05-14 12:09:25 +00:00
|
|
|
{
|
|
|
|
int a[6];
|
|
|
|
if (!get3pointarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wxorelarc(a[0], a[1], a[2], a[3], a[4], a[5]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-05-14 12:09:25 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_box(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1991-03-06 13:14:12 +00:00
|
|
|
return drawing_generic(dp, args, wdrawbox);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_erase(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1991-03-06 13:14:12 +00:00
|
|
|
return drawing_generic(dp, args, werase);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_paint(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1991-03-06 13:14:12 +00:00
|
|
|
return drawing_generic(dp, args, wpaint);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_invert(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1991-03-06 13:14:12 +00:00
|
|
|
return drawing_generic(dp, args, winvert);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1991-04-16 08:43:03 +00:00
|
|
|
static POINT *
|
|
|
|
getpointsarray(v, psize)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *v;
|
1991-04-16 08:43:03 +00:00
|
|
|
int *psize;
|
|
|
|
{
|
|
|
|
int n = -1;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject * (*getitem) Py_PROTO((PyObject *, int));
|
1991-04-16 08:43:03 +00:00
|
|
|
int i;
|
|
|
|
POINT *points;
|
|
|
|
|
|
|
|
if (v == NULL)
|
|
|
|
;
|
1996-12-12 22:48:20 +00:00
|
|
|
else if (PyList_Check(v)) {
|
|
|
|
n = PyList_Size(v);
|
|
|
|
getitem = PyList_GetItem;
|
1991-04-16 08:43:03 +00:00
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
else if (PyTuple_Check(v)) {
|
|
|
|
n = PyTuple_Size(v);
|
|
|
|
getitem = PyTuple_GetItem;
|
1991-04-16 08:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n <= 0) {
|
1996-12-12 22:48:20 +00:00
|
|
|
(void) PyErr_BadArgument();
|
1991-04-16 08:43:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
points = PyMem_NEW(POINT, n);
|
1991-04-16 08:43:03 +00:00
|
|
|
if (points == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
(void) PyErr_NoMemory();
|
1991-04-16 08:43:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *w = (*getitem)(v, i);
|
1991-04-16 08:43:03 +00:00
|
|
|
int a[2];
|
|
|
|
if (!getpointarg(w, a)) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyMem_DEL(points);
|
1991-04-16 08:43:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
points[i].h = a[0];
|
|
|
|
points[i].v = a[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
*psize = n;
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-04-16 08:43:03 +00:00
|
|
|
drawing_poly(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-04-16 08:43:03 +00:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
POINT *points = getpointsarray(args, &n);
|
|
|
|
if (points == NULL)
|
|
|
|
return NULL;
|
|
|
|
wdrawpoly(n, points);
|
1996-12-12 22:48:20 +00:00
|
|
|
PyMem_DEL(points);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-04-16 08:43:03 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-04-16 08:43:03 +00:00
|
|
|
drawing_fillpoly(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-04-16 08:43:03 +00:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
POINT *points = getpointsarray(args, &n);
|
|
|
|
if (points == NULL)
|
|
|
|
return NULL;
|
|
|
|
wfillpoly(n, points);
|
1996-12-12 22:48:20 +00:00
|
|
|
PyMem_DEL(points);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-04-16 08:43:03 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-05-14 12:09:25 +00:00
|
|
|
drawing_xorpoly(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-05-14 12:09:25 +00:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
POINT *points = getpointsarray(args, &n);
|
|
|
|
if (points == NULL)
|
|
|
|
return NULL;
|
|
|
|
wxorpoly(n, points);
|
1996-12-12 22:48:20 +00:00
|
|
|
PyMem_DEL(points);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-05-14 12:09:25 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_cliprect(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1991-03-06 13:14:12 +00:00
|
|
|
return drawing_generic(dp, args, wcliprect);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_noclip(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
wnoclip();
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_shade(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a[5];
|
|
|
|
if (!getrectintarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wshade(a[0], a[1], a[2], a[3], a[4]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_text(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
int h, v, size;
|
|
|
|
char *text;
|
1998-10-08 02:25:24 +00:00
|
|
|
if (!PyArg_Parse(args, "((ii)t#)", &h, &v, &text, &size))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
1992-01-27 16:45:55 +00:00
|
|
|
wdrawtext(h, v, text, size);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The following four are also used as stdwin functions */
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_lineheight(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyInt_FromLong((long)wlineheight());
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_baseline(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyInt_FromLong((long)wbaseline());
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_textwidth(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
char *text;
|
|
|
|
int size;
|
1998-10-08 02:25:24 +00:00
|
|
|
if (!PyArg_Parse(args, "t#", &text, &size))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyInt_FromLong((long)wtextwidth(text, size));
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
drawing_textbreak(dp, args)
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
char *text;
|
|
|
|
int size, width;
|
1998-10-08 02:25:24 +00:00
|
|
|
if (!PyArg_Parse(args, "(t#i)", &text, &size, &width))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyInt_FromLong((long)wtextbreak(text, size, width));
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-04-03 19:12:14 +00:00
|
|
|
drawing_setfont(self, args)
|
|
|
|
drawingobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-04-03 19:12:14 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
char *font;
|
|
|
|
char style = '\0';
|
|
|
|
int size = 0;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (args == NULL || !PyTuple_Check(args)) {
|
|
|
|
if (!PyArg_Parse(args, "z", &font))
|
1992-01-27 16:45:55 +00:00
|
|
|
return NULL;
|
1991-04-04 15:24:07 +00:00
|
|
|
}
|
1992-01-27 16:45:55 +00:00
|
|
|
else {
|
1996-12-12 22:48:20 +00:00
|
|
|
int n = PyTuple_Size(args);
|
1991-04-04 15:24:07 +00:00
|
|
|
if (n == 2) {
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_Parse(args, "(zi)", &font, &size))
|
1991-04-04 15:24:07 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
else if (!PyArg_Parse(args, "(zic)", &font, &size, &style)) {
|
|
|
|
PyErr_Clear();
|
|
|
|
if (!PyArg_Parse(args, "(zci)", &font, &style, &size))
|
1992-01-27 16:45:55 +00:00
|
|
|
return NULL;
|
1991-04-04 15:24:07 +00:00
|
|
|
}
|
|
|
|
}
|
1993-01-21 16:07:51 +00:00
|
|
|
if (font != NULL) {
|
|
|
|
if (!wsetfont(font)) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(StdwinError, "font not found");
|
1993-01-21 16:07:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
1991-04-04 15:24:07 +00:00
|
|
|
if (size != 0)
|
|
|
|
wsetsize(size);
|
1992-01-27 16:45:55 +00:00
|
|
|
switch (style) {
|
|
|
|
case 'b':
|
|
|
|
wsetbold();
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
wsetitalic();
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
wsetbolditalic();
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
wsetunderline();
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
wsetplain();
|
|
|
|
break;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-04-03 19:12:14 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-04-03 19:12:14 +00:00
|
|
|
drawing_getbgcolor(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1991-04-03 19:12:14 +00:00
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1991-04-03 19:12:14 +00:00
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyInt_FromLong((long)wgetbgcolor());
|
1991-04-03 19:12:14 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-04-03 19:12:14 +00:00
|
|
|
drawing_getfgcolor(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1991-04-03 19:12:14 +00:00
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1991-04-03 19:12:14 +00:00
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyInt_FromLong((long)wgetfgcolor());
|
1991-04-03 19:12:14 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-04-03 19:12:14 +00:00
|
|
|
drawing_setbgcolor(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1991-04-03 19:12:14 +00:00
|
|
|
{
|
|
|
|
long color;
|
|
|
|
if (!getlongarg(args, &color))
|
|
|
|
return NULL;
|
|
|
|
wsetbgcolor((COLOR)color);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-04-03 19:12:14 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-04-03 19:12:14 +00:00
|
|
|
drawing_setfgcolor(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1991-04-03 19:12:14 +00:00
|
|
|
{
|
|
|
|
long color;
|
|
|
|
if (!getlongarg(args, &color))
|
|
|
|
return NULL;
|
|
|
|
wsetfgcolor((COLOR)color);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-04-03 19:12:14 +00:00
|
|
|
}
|
|
|
|
|
1993-07-29 13:14:32 +00:00
|
|
|
#ifdef HAVE_BITMAPS
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1993-02-08 15:49:17 +00:00
|
|
|
drawing_bitmap(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1993-02-08 15:49:17 +00:00
|
|
|
{
|
|
|
|
int h, v;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *bp;
|
|
|
|
PyObject *mask = NULL;
|
|
|
|
if (!PyArg_Parse(args, "((ii)O)", &h, &v, &bp)) {
|
|
|
|
PyErr_Clear();
|
|
|
|
if (!PyArg_Parse(args, "((ii)OO)", &h, &v, &bp, &mask))
|
1993-02-08 15:49:17 +00:00
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (mask == Py_None)
|
1993-02-08 15:49:17 +00:00
|
|
|
mask = NULL;
|
|
|
|
else if (!is_bitmapobject(mask)) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_BadArgument();
|
1993-02-08 15:49:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!is_bitmapobject(bp)) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_BadArgument();
|
1993-02-08 15:49:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (((bitmapobject *)bp)->b_bitmap == NULL ||
|
|
|
|
mask != NULL && ((bitmapobject *)mask)->b_bitmap == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(StdwinError, "bitmap object already close");
|
1993-02-08 15:49:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (mask == NULL)
|
|
|
|
wdrawbitmap(h, v, ((bitmapobject *)bp)->b_bitmap, ALLBITS);
|
|
|
|
else
|
|
|
|
wdrawbitmap(h, v,
|
|
|
|
((bitmapobject *)bp)->b_bitmap,
|
|
|
|
((bitmapobject *)bp)->b_bitmap);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1993-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
1993-07-29 13:14:32 +00:00
|
|
|
#endif /* HAVE_BITMAPS */
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyMethodDef drawing_methods[] = {
|
1993-07-29 13:14:32 +00:00
|
|
|
#ifdef HAVE_BITMAPS
|
1996-12-12 22:48:20 +00:00
|
|
|
{"bitmap", (PyCFunction)drawing_bitmap},
|
1993-07-29 13:14:32 +00:00
|
|
|
#endif
|
1996-12-12 22:48:20 +00:00
|
|
|
{"box", (PyCFunction)drawing_box},
|
|
|
|
{"circle", (PyCFunction)drawing_circle},
|
|
|
|
{"cliprect", (PyCFunction)drawing_cliprect},
|
|
|
|
{"close", (PyCFunction)drawing_close},
|
|
|
|
{"elarc", (PyCFunction)drawing_elarc},
|
|
|
|
{"enddrawing", (PyCFunction)drawing_close},
|
|
|
|
{"erase", (PyCFunction)drawing_erase},
|
|
|
|
{"fillcircle", (PyCFunction)drawing_fillcircle},
|
|
|
|
{"fillelarc", (PyCFunction)drawing_fillelarc},
|
|
|
|
{"fillpoly", (PyCFunction)drawing_fillpoly},
|
|
|
|
{"invert", (PyCFunction)drawing_invert},
|
|
|
|
{"line", (PyCFunction)drawing_line},
|
|
|
|
{"noclip", (PyCFunction)drawing_noclip},
|
|
|
|
{"paint", (PyCFunction)drawing_paint},
|
|
|
|
{"poly", (PyCFunction)drawing_poly},
|
|
|
|
{"shade", (PyCFunction)drawing_shade},
|
|
|
|
{"text", (PyCFunction)drawing_text},
|
|
|
|
{"xorcircle", (PyCFunction)drawing_xorcircle},
|
|
|
|
{"xorelarc", (PyCFunction)drawing_xorelarc},
|
|
|
|
{"xorline", (PyCFunction)drawing_xorline},
|
|
|
|
{"xorpoly", (PyCFunction)drawing_xorpoly},
|
1990-10-14 12:07:46 +00:00
|
|
|
|
|
|
|
/* Text measuring methods: */
|
1996-12-12 22:48:20 +00:00
|
|
|
{"baseline", (PyCFunction)drawing_baseline},
|
|
|
|
{"lineheight", (PyCFunction)drawing_lineheight},
|
|
|
|
{"textbreak", (PyCFunction)drawing_textbreak},
|
|
|
|
{"textwidth", (PyCFunction)drawing_textwidth},
|
1991-04-03 19:12:14 +00:00
|
|
|
|
|
|
|
/* Font setting methods: */
|
1996-12-12 22:48:20 +00:00
|
|
|
{"setfont", (PyCFunction)drawing_setfont},
|
1991-04-03 19:12:14 +00:00
|
|
|
|
|
|
|
/* Color methods: */
|
1996-12-12 22:48:20 +00:00
|
|
|
{"getbgcolor", (PyCFunction)drawing_getbgcolor},
|
|
|
|
{"getfgcolor", (PyCFunction)drawing_getfgcolor},
|
|
|
|
{"setbgcolor", (PyCFunction)drawing_setbgcolor},
|
|
|
|
{"setfgcolor", (PyCFunction)drawing_setfgcolor},
|
1991-04-03 19:12:14 +00:00
|
|
|
|
1990-10-14 12:07:46 +00:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1992-01-14 18:41:24 +00:00
|
|
|
drawing_getattr(dp, name)
|
|
|
|
drawingobject *dp;
|
1990-10-14 12:07:46 +00:00
|
|
|
char *name;
|
|
|
|
{
|
1992-01-14 18:41:24 +00:00
|
|
|
if (dp->d_ref == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(StdwinError, "drawing object already closed");
|
1992-01-14 18:41:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
return Py_FindMethod(drawing_methods, (PyObject *)dp, name);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
PyTypeObject Drawingtype = {
|
|
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
1990-10-14 12:07:46 +00:00
|
|
|
0, /*ob_size*/
|
|
|
|
"drawing", /*tp_name*/
|
|
|
|
sizeof(drawingobject), /*tp_size*/
|
|
|
|
0, /*tp_itemsize*/
|
|
|
|
/* methods */
|
1994-08-01 11:34:53 +00:00
|
|
|
(destructor)drawing_dealloc, /*tp_dealloc*/
|
1990-10-14 12:07:46 +00:00
|
|
|
0, /*tp_print*/
|
1994-08-01 11:34:53 +00:00
|
|
|
(getattrfunc)drawing_getattr, /*tp_getattr*/
|
1990-10-14 12:07:46 +00:00
|
|
|
0, /*tp_setattr*/
|
|
|
|
0, /*tp_compare*/
|
|
|
|
0, /*tp_repr*/
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Text(edit) objects */
|
|
|
|
|
|
|
|
typedef struct {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject_HEAD
|
1990-10-14 12:07:46 +00:00
|
|
|
TEXTEDIT *t_text;
|
|
|
|
windowobject *t_ref;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *t_attr; /* Attributes dictionary */
|
1990-10-14 12:07:46 +00:00
|
|
|
} textobject;
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
staticforward PyTypeObject Texttype;
|
1990-10-14 12:07:46 +00:00
|
|
|
|
|
|
|
static textobject *
|
|
|
|
newtextobject(wp, left, top, right, bottom)
|
|
|
|
windowobject *wp;
|
|
|
|
int left, top, right, bottom;
|
|
|
|
{
|
|
|
|
textobject *tp;
|
1996-12-12 22:48:20 +00:00
|
|
|
tp = PyObject_NEW(textobject, &Texttype);
|
1990-10-14 12:07:46 +00:00
|
|
|
if (tp == NULL)
|
|
|
|
return NULL;
|
|
|
|
tp->t_attr = NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(wp);
|
1990-10-14 12:07:46 +00:00
|
|
|
tp->t_ref = wp;
|
|
|
|
tp->t_text = tecreate(wp->w_win, left, top, right, bottom);
|
|
|
|
if (tp->t_text == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_DECREF(tp);
|
|
|
|
return (textobject *) PyErr_NoMemory();
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
return tp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Text(edit) methods */
|
|
|
|
|
|
|
|
static void
|
|
|
|
text_dealloc(tp)
|
|
|
|
textobject *tp;
|
|
|
|
{
|
|
|
|
if (tp->t_text != NULL)
|
|
|
|
tefree(tp->t_text);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_XDECREF(tp->t_attr);
|
|
|
|
Py_XDECREF(tp->t_ref);
|
|
|
|
PyMem_DEL(tp);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-11-27 14:54:54 +00:00
|
|
|
text_close(tp, args)
|
|
|
|
textobject *tp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-11-27 14:54:54 +00:00
|
|
|
{
|
|
|
|
if (tp->t_text != NULL) {
|
|
|
|
tefree(tp->t_text);
|
|
|
|
tp->t_text = NULL;
|
|
|
|
}
|
|
|
|
if (tp->t_attr != NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_DECREF(tp->t_attr);
|
1991-11-27 14:54:54 +00:00
|
|
|
tp->t_attr = NULL;
|
|
|
|
}
|
|
|
|
if (tp->t_ref != NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_DECREF(tp->t_ref);
|
1991-11-27 14:54:54 +00:00
|
|
|
tp->t_ref = NULL;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-11-27 14:54:54 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
text_arrow(self, args)
|
|
|
|
textobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int code;
|
|
|
|
if (!getintarg(args, &code))
|
|
|
|
return NULL;
|
|
|
|
tearrow(self->t_text, code);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
text_draw(self, args)
|
|
|
|
textobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
register TEXTEDIT *tp = self->t_text;
|
|
|
|
int a[4];
|
|
|
|
int left, top, right, bottom;
|
|
|
|
if (!getrectarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
if (Drawing != NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(StdwinError, "already drawing");
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* Clip to text area and ignore if area is empty */
|
|
|
|
left = tegetleft(tp);
|
|
|
|
top = tegettop(tp);
|
|
|
|
right = tegetright(tp);
|
|
|
|
bottom = tegetbottom(tp);
|
|
|
|
if (a[0] < left) a[0] = left;
|
|
|
|
if (a[1] < top) a[1] = top;
|
|
|
|
if (a[2] > right) a[2] = right;
|
|
|
|
if (a[3] > bottom) a[3] = bottom;
|
|
|
|
if (a[0] < a[2] && a[1] < a[3]) {
|
|
|
|
wbegindrawing(self->t_ref->w_win);
|
|
|
|
tedrawnew(tp, a[0], a[1], a[2], a[3]);
|
|
|
|
wenddrawing(self->t_ref->w_win);
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
text_event(self, args)
|
|
|
|
textobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
register TEXTEDIT *tp = self->t_text;
|
|
|
|
EVENT e;
|
|
|
|
if (!geteventarg(args, &e))
|
|
|
|
return NULL;
|
|
|
|
if (e.type == WE_MOUSE_DOWN) {
|
1991-02-13 23:19:39 +00:00
|
|
|
/* Cheat at the margins */
|
|
|
|
int width, height;
|
|
|
|
wgetdocsize(e.window, &width, &height);
|
1990-10-14 12:07:46 +00:00
|
|
|
if (e.u.where.h < 0 && tegetleft(tp) == 0)
|
|
|
|
e.u.where.h = 0;
|
1991-02-13 23:19:39 +00:00
|
|
|
else if (e.u.where.h > width && tegetright(tp) == width)
|
|
|
|
e.u.where.h = width;
|
|
|
|
if (e.u.where.v < 0 && tegettop(tp) == 0)
|
|
|
|
e.u.where.v = 0;
|
|
|
|
else if (e.u.where.v > height && tegetright(tp) == height)
|
|
|
|
e.u.where.v = height;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyInt_FromLong((long) teevent(tp, &e));
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
text_getfocus(self, args)
|
|
|
|
textobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
return makepoint(tegetfoc1(self->t_text), tegetfoc2(self->t_text));
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
text_getfocustext(self, args)
|
|
|
|
textobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int f1, f2;
|
|
|
|
char *text;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
f1 = tegetfoc1(self->t_text);
|
|
|
|
f2 = tegetfoc2(self->t_text);
|
|
|
|
text = tegettext(self->t_text);
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyString_FromStringAndSize(text + f1, f2-f1);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
text_getrect(self, args)
|
|
|
|
textobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
return makerect(tegetleft(self->t_text),
|
|
|
|
tegettop(self->t_text),
|
|
|
|
tegetright(self->t_text),
|
|
|
|
tegetbottom(self->t_text));
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
text_gettext(self, args)
|
|
|
|
textobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyString_FromStringAndSize(tegettext(self->t_text),
|
|
|
|
tegetlen(self->t_text));
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
text_move(self, args)
|
|
|
|
textobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a[4];
|
|
|
|
if (!getrectarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
temovenew(self->t_text, a[0], a[1], a[2], a[3]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-05-28 21:57:04 +00:00
|
|
|
text_replace(self, args)
|
|
|
|
textobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-05-28 21:57:04 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
char *text;
|
1991-05-28 21:57:04 +00:00
|
|
|
if (!getstrarg(args, &text))
|
|
|
|
return NULL;
|
1992-01-27 16:45:55 +00:00
|
|
|
tereplace(self->t_text, text);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-05-28 21:57:04 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-05-28 21:57:04 +00:00
|
|
|
text_setactive(self, args)
|
|
|
|
textobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-05-28 21:57:04 +00:00
|
|
|
{
|
|
|
|
int flag;
|
|
|
|
if (!getintarg(args, &flag))
|
|
|
|
return NULL;
|
|
|
|
tesetactive(self->t_text, flag);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-05-28 21:57:04 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
text_setfocus(self, args)
|
|
|
|
textobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a[2];
|
|
|
|
if (!getpointarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
tesetfocus(self->t_text, a[0], a[1]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-05-05 20:13:41 +00:00
|
|
|
text_settext(self, args)
|
|
|
|
textobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-05-05 20:13:41 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
char *text;
|
1991-05-05 20:13:41 +00:00
|
|
|
char *buf;
|
|
|
|
int size;
|
1998-10-08 02:25:24 +00:00
|
|
|
if (!PyArg_Parse(args, "t#", &text, &size))
|
1991-05-05 20:13:41 +00:00
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
if ((buf = PyMem_NEW(char, size)) == NULL) {
|
|
|
|
return PyErr_NoMemory();
|
1991-05-05 20:13:41 +00:00
|
|
|
}
|
1992-01-27 16:45:55 +00:00
|
|
|
memcpy(buf, text, size);
|
1991-05-05 20:13:41 +00:00
|
|
|
tesetbuf(self->t_text, buf, size); /* Becomes owner of buffer */
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-05-05 20:13:41 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-05-28 21:57:04 +00:00
|
|
|
text_setview(self, args)
|
1990-10-14 12:07:46 +00:00
|
|
|
textobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1991-05-28 21:57:04 +00:00
|
|
|
int a[4];
|
1996-12-12 22:48:20 +00:00
|
|
|
if (args == Py_None)
|
1991-05-28 21:57:04 +00:00
|
|
|
tenoview(self->t_text);
|
|
|
|
else {
|
|
|
|
if (!getrectarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
tesetview(self->t_text, a[0], a[1], a[2], a[3]);
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyMethodDef text_methods[] = {
|
|
|
|
{"arrow", (PyCFunction)text_arrow},
|
|
|
|
{"close", (PyCFunction)text_close},
|
|
|
|
{"draw", (PyCFunction)text_draw},
|
|
|
|
{"event", (PyCFunction)text_event},
|
|
|
|
{"getfocus", (PyCFunction)text_getfocus},
|
|
|
|
{"getfocustext",(PyCFunction)text_getfocustext},
|
|
|
|
{"getrect", (PyCFunction)text_getrect},
|
|
|
|
{"gettext", (PyCFunction)text_gettext},
|
|
|
|
{"move", (PyCFunction)text_move},
|
|
|
|
{"replace", (PyCFunction)text_replace},
|
|
|
|
{"setactive", (PyCFunction)text_setactive},
|
|
|
|
{"setfocus", (PyCFunction)text_setfocus},
|
|
|
|
{"settext", (PyCFunction)text_settext},
|
|
|
|
{"setview", (PyCFunction)text_setview},
|
1990-10-14 12:07:46 +00:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
text_getattr(tp, name)
|
|
|
|
textobject *tp;
|
|
|
|
char *name;
|
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *v = NULL;
|
1992-01-14 18:41:24 +00:00
|
|
|
if (tp->t_ref == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(StdwinError, "text object already closed");
|
1992-01-14 18:41:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1991-10-20 20:22:50 +00:00
|
|
|
if (strcmp(name, "__dict__") == 0) {
|
|
|
|
v = tp->t_attr;
|
|
|
|
if (v == NULL)
|
1996-12-12 22:48:20 +00:00
|
|
|
v = Py_None;
|
1991-10-20 20:22:50 +00:00
|
|
|
}
|
|
|
|
else if (tp->t_attr != NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
v = PyDict_GetItemString(tp->t_attr, name);
|
1991-10-20 20:22:50 +00:00
|
|
|
}
|
|
|
|
if (v != NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(v);
|
1991-10-20 20:22:50 +00:00
|
|
|
return v;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
return Py_FindMethod(text_methods, (PyObject *)tp, name);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
text_setattr(tp, name, v)
|
|
|
|
textobject *tp;
|
|
|
|
char *name;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *v;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
if (tp->t_attr == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
tp->t_attr = PyDict_New();
|
1990-10-14 12:07:46 +00:00
|
|
|
if (tp->t_attr == NULL)
|
|
|
|
return -1;
|
|
|
|
}
|
1992-09-04 09:45:18 +00:00
|
|
|
if (v == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
int rv = PyDict_DelItemString(tp->t_attr, name);
|
1992-09-04 09:45:18 +00:00
|
|
|
if (rv < 0)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(PyExc_AttributeError,
|
|
|
|
"delete non-existing text object attribute");
|
1992-09-04 09:45:18 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1990-10-14 12:07:46 +00:00
|
|
|
else
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyDict_SetItemString(tp->t_attr, name, v);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
statichere PyTypeObject Texttype = {
|
|
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
1990-10-14 12:07:46 +00:00
|
|
|
0, /*ob_size*/
|
|
|
|
"textedit", /*tp_name*/
|
|
|
|
sizeof(textobject), /*tp_size*/
|
|
|
|
0, /*tp_itemsize*/
|
|
|
|
/* methods */
|
1994-08-01 11:34:53 +00:00
|
|
|
(destructor)text_dealloc, /*tp_dealloc*/
|
1990-10-14 12:07:46 +00:00
|
|
|
0, /*tp_print*/
|
1994-08-01 11:34:53 +00:00
|
|
|
(getattrfunc)text_getattr, /*tp_getattr*/
|
|
|
|
(setattrfunc)text_setattr, /*tp_setattr*/
|
1990-10-14 12:07:46 +00:00
|
|
|
0, /*tp_compare*/
|
|
|
|
0, /*tp_repr*/
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Menu objects */
|
|
|
|
|
1991-02-19 12:26:49 +00:00
|
|
|
#define IDOFFSET 10 /* Menu IDs we use start here */
|
1991-04-16 08:43:03 +00:00
|
|
|
#define MAXNMENU 200 /* Max #menus we allow */
|
1991-02-19 12:26:49 +00:00
|
|
|
static menuobject *menulist[MAXNMENU];
|
1990-10-14 12:07:46 +00:00
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static menuobject *newmenuobject Py_PROTO((char *));
|
1990-10-14 12:07:46 +00:00
|
|
|
static menuobject *
|
|
|
|
newmenuobject(title)
|
1992-01-27 16:45:55 +00:00
|
|
|
char *title;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int id;
|
|
|
|
MENU *menu;
|
|
|
|
menuobject *mp;
|
1991-02-19 12:26:49 +00:00
|
|
|
for (id = 0; id < MAXNMENU; id++) {
|
1990-10-14 12:07:46 +00:00
|
|
|
if (menulist[id] == NULL)
|
|
|
|
break;
|
|
|
|
}
|
1991-04-16 08:43:03 +00:00
|
|
|
if (id >= MAXNMENU) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(StdwinError, "creating too many menus");
|
1991-04-16 08:43:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1992-01-27 16:45:55 +00:00
|
|
|
menu = wmenucreate(id + IDOFFSET, title);
|
1990-10-14 12:07:46 +00:00
|
|
|
if (menu == NULL)
|
1996-12-12 22:48:20 +00:00
|
|
|
return (menuobject *) PyErr_NoMemory();
|
|
|
|
mp = PyObject_NEW(menuobject, &Menutype);
|
1990-10-14 12:07:46 +00:00
|
|
|
if (mp != NULL) {
|
|
|
|
mp->m_menu = menu;
|
1991-02-19 12:26:49 +00:00
|
|
|
mp->m_id = id + IDOFFSET;
|
1990-10-14 12:07:46 +00:00
|
|
|
mp->m_attr = NULL;
|
|
|
|
menulist[id] = mp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
wmenudelete(menu);
|
|
|
|
return mp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Menu methods */
|
|
|
|
|
|
|
|
static void
|
|
|
|
menu_dealloc(mp)
|
|
|
|
menuobject *mp;
|
|
|
|
{
|
|
|
|
|
1991-02-19 12:26:49 +00:00
|
|
|
int id = mp->m_id - IDOFFSET;
|
|
|
|
if (id >= 0 && id < MAXNMENU && menulist[id] == mp) {
|
1990-10-14 12:07:46 +00:00
|
|
|
menulist[id] = NULL;
|
|
|
|
}
|
1992-01-14 18:41:24 +00:00
|
|
|
if (mp->m_menu != NULL)
|
|
|
|
wmenudelete(mp->m_menu);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_XDECREF(mp->m_attr);
|
|
|
|
PyMem_DEL(mp);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1992-01-14 18:41:24 +00:00
|
|
|
menu_close(mp, args)
|
|
|
|
menuobject *mp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1992-01-14 18:41:24 +00:00
|
|
|
{
|
|
|
|
int id = mp->m_id - IDOFFSET;
|
|
|
|
if (id >= 0 && id < MAXNMENU && menulist[id] == mp) {
|
|
|
|
menulist[id] = NULL;
|
|
|
|
}
|
|
|
|
mp->m_id = -1;
|
|
|
|
if (mp->m_menu != NULL)
|
|
|
|
wmenudelete(mp->m_menu);
|
|
|
|
mp->m_menu = NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_XDECREF(mp->m_attr);
|
1992-01-14 18:41:24 +00:00
|
|
|
mp->m_attr = NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-01-14 18:41:24 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
menu_additem(self, args)
|
|
|
|
menuobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
char *text;
|
|
|
|
int shortcut = -1;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (PyTuple_Check(args)) {
|
1992-01-27 16:45:55 +00:00
|
|
|
char c;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_Parse(args, "(sc)", &text, &c))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
1992-01-27 16:45:55 +00:00
|
|
|
shortcut = c;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
1992-01-27 16:45:55 +00:00
|
|
|
else if (!getstrarg(args, &text))
|
|
|
|
return NULL;
|
|
|
|
wmenuadditem(self->m_menu, text, shortcut);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
menu_setitem(self, args)
|
|
|
|
menuobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int index;
|
1992-01-27 16:45:55 +00:00
|
|
|
char *text;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_Parse(args, "(is)", &index, &text))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
1992-01-27 16:45:55 +00:00
|
|
|
wmenusetitem(self->m_menu, index, text);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
menu_enable(self, args)
|
|
|
|
menuobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
int flag;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_Parse(args, "(ii)", &index, &flag))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
wmenuenable(self->m_menu, index, flag);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
menu_check(self, args)
|
|
|
|
menuobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
int flag;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_Parse(args, "(ii)", &index, &flag))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
wmenucheck(self->m_menu, index, flag);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyMethodDef menu_methods[] = {
|
|
|
|
{"additem", (PyCFunction)menu_additem},
|
|
|
|
{"setitem", (PyCFunction)menu_setitem},
|
|
|
|
{"enable", (PyCFunction)menu_enable},
|
|
|
|
{"check", (PyCFunction)menu_check},
|
|
|
|
{"close", (PyCFunction)menu_close},
|
1990-10-14 12:07:46 +00:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
menu_getattr(mp, name)
|
|
|
|
menuobject *mp;
|
|
|
|
char *name;
|
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *v = NULL;
|
1992-01-14 18:41:24 +00:00
|
|
|
if (mp->m_menu == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(StdwinError, "menu object already closed");
|
1992-01-14 18:41:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1991-10-20 20:22:50 +00:00
|
|
|
if (strcmp(name, "__dict__") == 0) {
|
|
|
|
v = mp->m_attr;
|
|
|
|
if (v == NULL)
|
1996-12-12 22:48:20 +00:00
|
|
|
v = Py_None;
|
1991-10-20 20:22:50 +00:00
|
|
|
}
|
|
|
|
else if (mp->m_attr != NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
v = PyDict_GetItemString(mp->m_attr, name);
|
1991-10-20 20:22:50 +00:00
|
|
|
}
|
|
|
|
if (v != NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(v);
|
1991-10-20 20:22:50 +00:00
|
|
|
return v;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
return Py_FindMethod(menu_methods, (PyObject *)mp, name);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
menu_setattr(mp, name, v)
|
|
|
|
menuobject *mp;
|
|
|
|
char *name;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *v;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
if (mp->m_attr == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
mp->m_attr = PyDict_New();
|
1990-10-14 12:07:46 +00:00
|
|
|
if (mp->m_attr == NULL)
|
|
|
|
return -1;
|
|
|
|
}
|
1992-09-04 09:45:18 +00:00
|
|
|
if (v == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
int rv = PyDict_DelItemString(mp->m_attr, name);
|
1992-09-04 09:45:18 +00:00
|
|
|
if (rv < 0)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(PyExc_AttributeError,
|
|
|
|
"delete non-existing menu object attribute");
|
1992-09-04 09:45:18 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1990-10-14 12:07:46 +00:00
|
|
|
else
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyDict_SetItemString(mp->m_attr, name, v);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
statichere PyTypeObject Menutype = {
|
|
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
1990-10-14 12:07:46 +00:00
|
|
|
0, /*ob_size*/
|
|
|
|
"menu", /*tp_name*/
|
|
|
|
sizeof(menuobject), /*tp_size*/
|
|
|
|
0, /*tp_itemsize*/
|
|
|
|
/* methods */
|
1994-08-01 11:34:53 +00:00
|
|
|
(destructor)menu_dealloc, /*tp_dealloc*/
|
1990-10-14 12:07:46 +00:00
|
|
|
0, /*tp_print*/
|
1994-08-01 11:34:53 +00:00
|
|
|
(getattrfunc)menu_getattr, /*tp_getattr*/
|
|
|
|
(setattrfunc)menu_setattr, /*tp_setattr*/
|
1990-10-14 12:07:46 +00:00
|
|
|
0, /*tp_compare*/
|
|
|
|
0, /*tp_repr*/
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1993-07-29 13:14:32 +00:00
|
|
|
#ifdef HAVE_BITMAPS
|
|
|
|
|
1993-02-08 15:49:17 +00:00
|
|
|
/* Bitmaps objects */
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static bitmapobject *newbitmapobject Py_PROTO((int, int));
|
1993-02-08 15:49:17 +00:00
|
|
|
static bitmapobject *
|
|
|
|
newbitmapobject(width, height)
|
|
|
|
int width, height;
|
|
|
|
{
|
|
|
|
BITMAP *bitmap;
|
|
|
|
bitmapobject *bp;
|
|
|
|
bitmap = wnewbitmap(width, height);
|
|
|
|
if (bitmap == NULL)
|
1996-12-12 22:48:20 +00:00
|
|
|
return (bitmapobject *) PyErr_NoMemory();
|
|
|
|
bp = PyObject_NEW(bitmapobject, &Bitmaptype);
|
1993-02-08 15:49:17 +00:00
|
|
|
if (bp != NULL) {
|
|
|
|
bp->b_bitmap = bitmap;
|
|
|
|
bp->b_attr = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
wfreebitmap(bitmap);
|
|
|
|
return bp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bitmap methods */
|
|
|
|
|
|
|
|
static void
|
|
|
|
bitmap_dealloc(bp)
|
|
|
|
bitmapobject *bp;
|
|
|
|
{
|
|
|
|
if (bp->b_bitmap != NULL)
|
|
|
|
wfreebitmap(bp->b_bitmap);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_XDECREF(bp->b_attr);
|
|
|
|
PyMem_DEL(bp);
|
1993-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1993-02-08 15:49:17 +00:00
|
|
|
bitmap_close(bp, args)
|
|
|
|
bitmapobject *bp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1993-02-08 15:49:17 +00:00
|
|
|
{
|
|
|
|
if (bp->b_bitmap != NULL)
|
|
|
|
wfreebitmap(bp->b_bitmap);
|
|
|
|
bp->b_bitmap = NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_XDECREF(bp->b_attr);
|
1993-02-08 15:49:17 +00:00
|
|
|
bp->b_attr = NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1993-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1993-02-08 15:49:17 +00:00
|
|
|
bitmap_setbit(self, args)
|
|
|
|
bitmapobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1993-02-08 15:49:17 +00:00
|
|
|
{
|
|
|
|
int a[3];
|
|
|
|
if (!getpointintarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wsetbit(self->b_bitmap, a[0], a[1], a[2]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1993-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1993-02-08 15:49:17 +00:00
|
|
|
bitmap_getbit(self, args)
|
|
|
|
bitmapobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1993-02-08 15:49:17 +00:00
|
|
|
{
|
|
|
|
int a[2];
|
|
|
|
if (!getpointarg(args, a))
|
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyInt_FromLong((long) wgetbit(self->b_bitmap, a[0], a[1]));
|
1993-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1993-02-08 15:49:17 +00:00
|
|
|
bitmap_getsize(self, args)
|
|
|
|
bitmapobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1993-02-08 15:49:17 +00:00
|
|
|
{
|
|
|
|
int width, height;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1993-02-08 15:49:17 +00:00
|
|
|
return NULL;
|
|
|
|
wgetbitmapsize(self->b_bitmap, &width, &height);
|
1996-12-12 22:48:20 +00:00
|
|
|
return Py_BuildValue("(ii)", width, height);
|
1993-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyMethodDef bitmap_methods[] = {
|
|
|
|
{"close", (PyCFunction)bitmap_close},
|
|
|
|
{"getsize", (PyCFunction)bitmap_getsize},
|
|
|
|
{"getbit", (PyCFunction)bitmap_getbit},
|
|
|
|
{"setbit", (PyCFunction)bitmap_setbit},
|
1993-02-08 15:49:17 +00:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1993-02-08 15:49:17 +00:00
|
|
|
bitmap_getattr(bp, name)
|
|
|
|
bitmapobject *bp;
|
|
|
|
char *name;
|
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *v = NULL;
|
1993-02-08 15:49:17 +00:00
|
|
|
if (bp->b_bitmap == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(StdwinError, "bitmap object already closed");
|
1993-02-08 15:49:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (strcmp(name, "__dict__") == 0) {
|
|
|
|
v = bp->b_attr;
|
|
|
|
if (v == NULL)
|
1996-12-12 22:48:20 +00:00
|
|
|
v = Py_None;
|
1993-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
else if (bp->b_attr != NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
v = PyDict_GetItemString(bp->b_attr, name);
|
1993-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
if (v != NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(v);
|
1993-02-08 15:49:17 +00:00
|
|
|
return v;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
return Py_FindMethod(bitmap_methods, (PyObject *)bp, name);
|
1993-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bitmap_setattr(bp, name, v)
|
|
|
|
bitmapobject *bp;
|
|
|
|
char *name;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *v;
|
1993-02-08 15:49:17 +00:00
|
|
|
{
|
|
|
|
if (bp->b_attr == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
bp->b_attr = PyDict_New();
|
1993-02-08 15:49:17 +00:00
|
|
|
if (bp->b_attr == NULL)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (v == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
int rv = PyDict_DelItemString(bp->b_attr, name);
|
1993-02-08 15:49:17 +00:00
|
|
|
if (rv < 0)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(PyExc_AttributeError,
|
1993-02-08 15:49:17 +00:00
|
|
|
"delete non-existing bitmap object attribute");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
else
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyDict_SetItemString(bp->b_attr, name, v);
|
1993-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
statichere PyTypeObject Bitmaptype = {
|
|
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
1993-02-08 15:49:17 +00:00
|
|
|
0, /*ob_size*/
|
|
|
|
"bitmap", /*tp_name*/
|
|
|
|
sizeof(bitmapobject), /*tp_size*/
|
|
|
|
0, /*tp_itemsize*/
|
|
|
|
/* methods */
|
1994-08-01 11:34:53 +00:00
|
|
|
(destructor)bitmap_dealloc, /*tp_dealloc*/
|
1993-02-08 15:49:17 +00:00
|
|
|
0, /*tp_print*/
|
1994-08-01 11:34:53 +00:00
|
|
|
(getattrfunc)bitmap_getattr, /*tp_getattr*/
|
|
|
|
(setattrfunc)bitmap_setattr, /*tp_setattr*/
|
1993-02-08 15:49:17 +00:00
|
|
|
0, /*tp_compare*/
|
|
|
|
0, /*tp_repr*/
|
|
|
|
};
|
|
|
|
|
1993-07-29 13:14:32 +00:00
|
|
|
#endif /* HAVE_BITMAPS */
|
|
|
|
|
1993-02-08 15:49:17 +00:00
|
|
|
|
1990-10-14 12:07:46 +00:00
|
|
|
/* Windows */
|
|
|
|
|
|
|
|
#define MAXNWIN 50
|
|
|
|
static windowobject *windowlist[MAXNWIN];
|
|
|
|
|
|
|
|
/* Window methods */
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_dealloc(wp)
|
|
|
|
windowobject *wp;
|
|
|
|
{
|
|
|
|
if (wp->w_win != NULL) {
|
|
|
|
int tag = wgettag(wp->w_win);
|
|
|
|
if (tag >= 0 && tag < MAXNWIN)
|
|
|
|
windowlist[tag] = NULL;
|
|
|
|
else
|
|
|
|
fprintf(stderr, "XXX help! tag %d in window_dealloc\n",
|
|
|
|
tag);
|
|
|
|
wclose(wp->w_win);
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_DECREF(wp->w_title);
|
1990-10-14 12:07:46 +00:00
|
|
|
if (wp->w_attr != NULL)
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_DECREF(wp->w_attr);
|
1990-10-14 12:07:46 +00:00
|
|
|
free((char *)wp);
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-11-27 14:54:54 +00:00
|
|
|
window_close(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-11-27 14:54:54 +00:00
|
|
|
{
|
|
|
|
if (wp->w_win != NULL) {
|
|
|
|
int tag = wgettag(wp->w_win);
|
|
|
|
if (tag >= 0 && tag < MAXNWIN)
|
|
|
|
windowlist[tag] = NULL;
|
|
|
|
wclose(wp->w_win);
|
|
|
|
wp->w_win = NULL;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-11-27 14:54:54 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_begindrawing(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
drawingobject *dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
if (Drawing != NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(StdwinError, "already drawing");
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
dp = PyObject_NEW(drawingobject, &Drawingtype);
|
1990-10-14 12:07:46 +00:00
|
|
|
if (dp == NULL)
|
|
|
|
return NULL;
|
|
|
|
Drawing = dp;
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(wp);
|
1990-10-14 12:07:46 +00:00
|
|
|
dp->d_ref = wp;
|
|
|
|
wbegindrawing(wp->w_win);
|
1996-12-12 22:48:20 +00:00
|
|
|
return (PyObject *)dp;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_change(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a[4];
|
|
|
|
if (!getrectarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wchange(wp->w_win, a[0], a[1], a[2], a[3]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_gettitle(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(wp->w_title);
|
1990-10-14 12:07:46 +00:00
|
|
|
return wp->w_title;
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-05-05 20:13:41 +00:00
|
|
|
window_getwinpos(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-05-05 20:13:41 +00:00
|
|
|
{
|
|
|
|
int h, v;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1991-05-05 20:13:41 +00:00
|
|
|
return NULL;
|
|
|
|
wgetwinpos(wp->w_win, &h, &v);
|
|
|
|
return makepoint(h, v);
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_getwinsize(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int width, height;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
wgetwinsize(wp->w_win, &width, &height);
|
|
|
|
return makepoint(width, height);
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1993-02-08 15:49:17 +00:00
|
|
|
window_setwinpos(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1993-02-08 15:49:17 +00:00
|
|
|
{
|
|
|
|
int a[2];
|
|
|
|
if (!getpointarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wsetwinpos(wp->w_win, a[0], a[1]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1993-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1993-02-08 15:49:17 +00:00
|
|
|
window_setwinsize(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1993-02-08 15:49:17 +00:00
|
|
|
{
|
|
|
|
int a[2];
|
|
|
|
if (!getpointarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wsetwinsize(wp->w_win, a[0], a[1]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1993-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_getdocsize(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int width, height;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
wgetdocsize(wp->w_win, &width, &height);
|
|
|
|
return makepoint(width, height);
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_getorigin(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int width, height;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
wgetorigin(wp->w_win, &width, &height);
|
|
|
|
return makepoint(width, height);
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_scroll(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a[6];
|
|
|
|
if (!getrectpointarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wscroll(wp->w_win, a[0], a[1], a[2], a[3], a[4], a[5]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_setdocsize(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a[2];
|
|
|
|
if (!getpointarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wsetdocsize(wp->w_win, a[0], a[1]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_setorigin(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a[2];
|
|
|
|
if (!getpointarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wsetorigin(wp->w_win, a[0], a[1]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_settitle(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *title;
|
|
|
|
if (!PyArg_Parse(args, "S", &title))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_DECREF(wp->w_title);
|
|
|
|
Py_INCREF(title);
|
1990-10-14 12:07:46 +00:00
|
|
|
wp->w_title = title;
|
1996-12-12 22:48:20 +00:00
|
|
|
wsettitle(wp->w_win, PyString_AsString(title));
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_show(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a[4];
|
|
|
|
if (!getrectarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wshow(wp->w_win, a[0], a[1], a[2], a[3]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_settimer(wp, args)
|
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a;
|
|
|
|
if (!getintarg(args, &a))
|
|
|
|
return NULL;
|
|
|
|
wsettimer(wp->w_win, a);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_menucreate(self, args)
|
|
|
|
windowobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
menuobject *mp;
|
1992-01-27 16:45:55 +00:00
|
|
|
char *title;
|
1990-10-14 12:07:46 +00:00
|
|
|
if (!getstrarg(args, &title))
|
|
|
|
return NULL;
|
|
|
|
wmenusetdeflocal(1);
|
|
|
|
mp = newmenuobject(title);
|
|
|
|
if (mp == NULL)
|
|
|
|
return NULL;
|
|
|
|
wmenuattach(self->w_win, mp->m_menu);
|
1996-12-12 22:48:20 +00:00
|
|
|
return (PyObject *)mp;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_textcreate(self, args)
|
|
|
|
windowobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a[4];
|
|
|
|
if (!getrectarg(args, a))
|
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
return (PyObject *)newtextobject(self, a[0], a[1], a[2], a[3]);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-30 16:01:48 +00:00
|
|
|
window_setselection(self, args)
|
|
|
|
windowobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-30 16:01:48 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
int sel, size, ok;
|
|
|
|
char *text;
|
1998-10-08 02:25:24 +00:00
|
|
|
if (!PyArg_Parse(args, "(it#)", &sel, &text, &size))
|
1990-10-30 16:01:48 +00:00
|
|
|
return NULL;
|
1992-01-27 16:45:55 +00:00
|
|
|
ok = wsetselection(self->w_win, sel, text, size);
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyInt_FromLong(ok);
|
1990-10-30 16:01:48 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-30 16:01:48 +00:00
|
|
|
window_setwincursor(self, args)
|
|
|
|
windowobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-30 16:01:48 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
char *name;
|
1990-10-30 16:01:48 +00:00
|
|
|
CURSOR *c;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_Parse(args, "z", &name))
|
1990-10-30 16:01:48 +00:00
|
|
|
return NULL;
|
1992-02-05 11:15:00 +00:00
|
|
|
if (name == NULL)
|
|
|
|
c = NULL;
|
|
|
|
else {
|
|
|
|
c = wfetchcursor(name);
|
|
|
|
if (c == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(StdwinError, "no such cursor");
|
1992-02-05 11:15:00 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1990-10-30 16:01:48 +00:00
|
|
|
}
|
|
|
|
wsetwincursor(self->w_win, c);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-30 16:01:48 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1992-01-27 16:45:55 +00:00
|
|
|
window_setactive(self, args)
|
|
|
|
windowobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1992-01-27 16:45:55 +00:00
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1992-01-27 16:45:55 +00:00
|
|
|
return NULL;
|
|
|
|
wsetactive(self->w_win);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-01-27 16:45:55 +00:00
|
|
|
}
|
|
|
|
|
1991-07-27 21:42:24 +00:00
|
|
|
#ifdef CWI_HACKS
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-07-27 21:42:24 +00:00
|
|
|
window_getxwindowid(self, args)
|
|
|
|
windowobject *self;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1991-07-27 21:42:24 +00:00
|
|
|
{
|
|
|
|
long wid = wgetxwindowid(self->w_win);
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyInt_FromLong(wid);
|
1991-07-27 21:42:24 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyMethodDef window_methods[] = {
|
|
|
|
{"begindrawing",(PyCFunction)window_begindrawing},
|
|
|
|
{"change", (PyCFunction)window_change},
|
|
|
|
{"close", (PyCFunction)window_close},
|
|
|
|
{"getdocsize", (PyCFunction)window_getdocsize},
|
|
|
|
{"getorigin", (PyCFunction)window_getorigin},
|
|
|
|
{"gettitle", (PyCFunction)window_gettitle},
|
|
|
|
{"getwinpos", (PyCFunction)window_getwinpos},
|
|
|
|
{"getwinsize", (PyCFunction)window_getwinsize},
|
|
|
|
{"menucreate", (PyCFunction)window_menucreate},
|
|
|
|
{"scroll", (PyCFunction)window_scroll},
|
|
|
|
{"setactive", (PyCFunction)window_setactive},
|
|
|
|
{"setdocsize", (PyCFunction)window_setdocsize},
|
|
|
|
{"setorigin", (PyCFunction)window_setorigin},
|
|
|
|
{"setselection",(PyCFunction)window_setselection},
|
|
|
|
{"settimer", (PyCFunction)window_settimer},
|
|
|
|
{"settitle", (PyCFunction)window_settitle},
|
|
|
|
{"setwincursor",(PyCFunction)window_setwincursor},
|
|
|
|
{"setwinpos", (PyCFunction)window_setwinpos},
|
|
|
|
{"setwinsize", (PyCFunction)window_setwinsize},
|
|
|
|
{"show", (PyCFunction)window_show},
|
|
|
|
{"textcreate", (PyCFunction)window_textcreate},
|
1991-07-27 21:42:24 +00:00
|
|
|
#ifdef CWI_HACKS
|
1996-12-12 22:48:20 +00:00
|
|
|
{"getxwindowid",(PyCFunction)window_getxwindowid},
|
1991-07-27 21:42:24 +00:00
|
|
|
#endif
|
1990-10-14 12:07:46 +00:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
window_getattr(wp, name)
|
|
|
|
windowobject *wp;
|
|
|
|
char *name;
|
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *v = NULL;
|
1992-01-14 18:41:24 +00:00
|
|
|
if (wp->w_win == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(StdwinError, "window already closed");
|
1992-01-14 18:41:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1991-10-20 20:22:50 +00:00
|
|
|
if (strcmp(name, "__dict__") == 0) {
|
|
|
|
v = wp->w_attr;
|
|
|
|
if (v == NULL)
|
1996-12-12 22:48:20 +00:00
|
|
|
v = Py_None;
|
1991-10-20 20:22:50 +00:00
|
|
|
}
|
|
|
|
else if (wp->w_attr != NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
v = PyDict_GetItemString(wp->w_attr, name);
|
1991-10-20 20:22:50 +00:00
|
|
|
}
|
|
|
|
if (v != NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(v);
|
1991-10-20 20:22:50 +00:00
|
|
|
return v;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
return Py_FindMethod(window_methods, (PyObject *)wp, name);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
window_setattr(wp, name, v)
|
|
|
|
windowobject *wp;
|
|
|
|
char *name;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *v;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
if (wp->w_attr == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
wp->w_attr = PyDict_New();
|
1990-10-14 12:07:46 +00:00
|
|
|
if (wp->w_attr == NULL)
|
|
|
|
return -1;
|
|
|
|
}
|
1992-09-04 09:45:18 +00:00
|
|
|
if (v == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
int rv = PyDict_DelItemString(wp->w_attr, name);
|
1992-09-04 09:45:18 +00:00
|
|
|
if (rv < 0)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(PyExc_AttributeError,
|
|
|
|
"delete non-existing menu object attribute");
|
1992-09-04 09:45:18 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1990-10-14 12:07:46 +00:00
|
|
|
else
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyDict_SetItemString(wp->w_attr, name, v);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
statichere PyTypeObject Windowtype = {
|
|
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
1990-10-14 12:07:46 +00:00
|
|
|
0, /*ob_size*/
|
|
|
|
"window", /*tp_name*/
|
|
|
|
sizeof(windowobject), /*tp_size*/
|
|
|
|
0, /*tp_itemsize*/
|
|
|
|
/* methods */
|
1994-08-01 11:34:53 +00:00
|
|
|
(destructor)window_dealloc, /*tp_dealloc*/
|
1992-09-17 17:54:56 +00:00
|
|
|
0, /*tp_print*/
|
1994-08-01 11:34:53 +00:00
|
|
|
(getattrfunc)window_getattr, /*tp_getattr*/
|
|
|
|
(setattrfunc)window_setattr, /*tp_setattr*/
|
1990-10-14 12:07:46 +00:00
|
|
|
0, /*tp_compare*/
|
|
|
|
0, /*tp_repr*/
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Stdwin methods */
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1993-10-18 11:44:47 +00:00
|
|
|
stdwin_done(sw, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *sw;
|
|
|
|
PyObject *args;
|
1993-10-18 11:44:47 +00:00
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1993-10-18 11:44:47 +00:00
|
|
|
return NULL;
|
|
|
|
wdone();
|
|
|
|
/* XXX There is no protection against continued use of
|
|
|
|
XXX stdwin functions or objects after this call is made.
|
|
|
|
XXX Use at own risk */
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1993-10-18 11:44:47 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
stdwin_open(sw, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *sw;
|
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int tag;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *title;
|
1990-10-14 12:07:46 +00:00
|
|
|
windowobject *wp;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_Parse(args, "S", &title))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
for (tag = 0; tag < MAXNWIN; tag++) {
|
|
|
|
if (windowlist[tag] == NULL)
|
|
|
|
break;
|
|
|
|
}
|
1991-04-16 08:43:03 +00:00
|
|
|
if (tag >= MAXNWIN) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(StdwinError, "creating too many windows");
|
1991-04-16 08:43:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
wp = PyObject_NEW(windowobject, &Windowtype);
|
1990-10-14 12:07:46 +00:00
|
|
|
if (wp == NULL)
|
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(title);
|
1990-10-14 12:07:46 +00:00
|
|
|
wp->w_title = title;
|
1996-12-12 22:48:20 +00:00
|
|
|
wp->w_win = wopen(PyString_AsString(title), (void (*)()) NULL);
|
1990-10-14 12:07:46 +00:00
|
|
|
wp->w_attr = NULL;
|
|
|
|
if (wp->w_win == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_DECREF(wp);
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
windowlist[tag] = wp;
|
|
|
|
wsettag(wp->w_win, tag);
|
1996-12-12 22:48:20 +00:00
|
|
|
return (PyObject *)wp;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-06-03 10:55:14 +00:00
|
|
|
window2object(win)
|
|
|
|
WINDOW *win;
|
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *w;
|
1991-06-03 10:55:14 +00:00
|
|
|
if (win == NULL)
|
1996-12-12 22:48:20 +00:00
|
|
|
w = Py_None;
|
1991-06-03 10:55:14 +00:00
|
|
|
else {
|
|
|
|
int tag = wgettag(win);
|
|
|
|
if (tag < 0 || tag >= MAXNWIN || windowlist[tag] == NULL ||
|
|
|
|
windowlist[tag]->w_win != win)
|
1996-12-12 22:48:20 +00:00
|
|
|
w = Py_None;
|
1991-06-03 10:55:14 +00:00
|
|
|
else
|
1996-12-12 22:48:20 +00:00
|
|
|
w = (PyObject *)windowlist[tag];
|
1991-06-03 10:55:14 +00:00
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(w);
|
1991-06-03 10:55:14 +00:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-01-16 14:06:18 +00:00
|
|
|
stdwin_get_poll_event(poll, args)
|
|
|
|
int poll;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
EVENT e;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *u, *v, *w;
|
|
|
|
if (!PyArg_NoArgs(args))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
if (Drawing != NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(StdwinError,
|
|
|
|
"cannot getevent() while drawing");
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1991-06-03 10:55:14 +00:00
|
|
|
again:
|
1992-08-05 19:58:53 +00:00
|
|
|
BGN_STDWIN
|
1991-01-16 14:06:18 +00:00
|
|
|
if (poll) {
|
|
|
|
if (!wpollevent(&e)) {
|
1992-08-05 19:58:53 +00:00
|
|
|
RET_STDWIN
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-01-16 14:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
wgetevent(&e);
|
1992-08-05 19:58:53 +00:00
|
|
|
END_STDWIN
|
1990-10-14 12:07:46 +00:00
|
|
|
if (e.type == WE_COMMAND && e.u.command == WC_CANCEL) {
|
|
|
|
/* Turn keyboard interrupts into exceptions */
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetNone(PyExc_KeyboardInterrupt);
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1990-11-06 15:17:35 +00:00
|
|
|
if (e.type == WE_COMMAND && e.u.command == WC_CLOSE) {
|
|
|
|
/* Turn WC_CLOSE commands into WE_CLOSE events */
|
|
|
|
e.type = WE_CLOSE;
|
|
|
|
}
|
1992-04-13 15:54:35 +00:00
|
|
|
v = window2object(e.window);
|
1990-10-14 12:07:46 +00:00
|
|
|
switch (e.type) {
|
|
|
|
case WE_CHAR:
|
|
|
|
{
|
|
|
|
char c[1];
|
|
|
|
c[0] = e.u.character;
|
1996-12-12 22:48:20 +00:00
|
|
|
w = PyString_FromStringAndSize(c, 1);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WE_COMMAND:
|
1996-12-12 22:48:20 +00:00
|
|
|
w = PyInt_FromLong((long)e.u.command);
|
1990-10-14 12:07:46 +00:00
|
|
|
break;
|
|
|
|
case WE_DRAW:
|
|
|
|
w = makerect(e.u.area.left, e.u.area.top,
|
|
|
|
e.u.area.right, e.u.area.bottom);
|
|
|
|
break;
|
|
|
|
case WE_MOUSE_DOWN:
|
|
|
|
case WE_MOUSE_MOVE:
|
|
|
|
case WE_MOUSE_UP:
|
1996-12-12 22:48:20 +00:00
|
|
|
w = Py_BuildValue("((ii)iii)",
|
|
|
|
e.u.where.h, e.u.where.v,
|
|
|
|
e.u.where.clicks,
|
|
|
|
e.u.where.button,
|
|
|
|
e.u.where.mask);
|
1990-10-14 12:07:46 +00:00
|
|
|
break;
|
|
|
|
case WE_MENU:
|
1996-12-12 22:48:20 +00:00
|
|
|
if (e.u.m.id >= IDOFFSET &&
|
|
|
|
e.u.m.id < IDOFFSET+MAXNMENU &&
|
|
|
|
menulist[e.u.m.id - IDOFFSET] != NULL)
|
|
|
|
{
|
|
|
|
w = Py_BuildValue("(Oi)",
|
|
|
|
menulist[e.u.m.id - IDOFFSET],
|
|
|
|
e.u.m.item);
|
|
|
|
}
|
1991-06-03 10:55:14 +00:00
|
|
|
else {
|
|
|
|
/* Ghost menu event.
|
|
|
|
Can occur only on the Mac if another part
|
|
|
|
of the aplication has installed a menu;
|
|
|
|
like the THINK C console library. */
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_DECREF(v);
|
1991-06-03 10:55:14 +00:00
|
|
|
goto again;
|
|
|
|
}
|
1990-10-14 12:07:46 +00:00
|
|
|
break;
|
1992-06-30 12:48:26 +00:00
|
|
|
case WE_KEY:
|
1996-12-12 22:48:20 +00:00
|
|
|
w = Py_BuildValue("(ii)", e.u.key.code, e.u.key.mask);
|
1992-06-30 12:48:26 +00:00
|
|
|
break;
|
1990-10-30 16:01:48 +00:00
|
|
|
case WE_LOST_SEL:
|
1996-12-12 22:48:20 +00:00
|
|
|
w = PyInt_FromLong((long)e.u.sel);
|
1990-10-30 16:01:48 +00:00
|
|
|
break;
|
1990-10-14 12:07:46 +00:00
|
|
|
default:
|
1996-12-12 22:48:20 +00:00
|
|
|
w = Py_None;
|
|
|
|
Py_INCREF(w);
|
1990-10-14 12:07:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (w == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_DECREF(v);
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
u = Py_BuildValue("(iOO)", e.type, v, w);
|
|
|
|
Py_XDECREF(v);
|
|
|
|
Py_XDECREF(w);
|
1992-04-13 15:54:35 +00:00
|
|
|
return u;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-01-16 14:06:18 +00:00
|
|
|
stdwin_getevent(sw, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *sw;
|
|
|
|
PyObject *args;
|
1991-01-16 14:06:18 +00:00
|
|
|
{
|
|
|
|
return stdwin_get_poll_event(0, args);
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-01-16 14:06:18 +00:00
|
|
|
stdwin_pollevent(sw, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *sw;
|
|
|
|
PyObject *args;
|
1991-01-16 14:06:18 +00:00
|
|
|
{
|
|
|
|
return stdwin_get_poll_event(1, args);
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
stdwin_setdefwinpos(sw, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *sw;
|
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a[2];
|
|
|
|
if (!getpointarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wsetdefwinpos(a[0], a[1]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
stdwin_setdefwinsize(sw, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *sw;
|
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
|
|
|
int a[2];
|
|
|
|
if (!getpointarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wsetdefwinsize(a[0], a[1]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-04-03 19:12:14 +00:00
|
|
|
stdwin_setdefscrollbars(sw, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *sw;
|
|
|
|
PyObject *args;
|
1991-04-03 19:12:14 +00:00
|
|
|
{
|
|
|
|
int a[2];
|
|
|
|
if (!getpointarg(args, a))
|
|
|
|
return NULL;
|
|
|
|
wsetdefscrollbars(a[0], a[1]);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-04-03 19:12:14 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-05-05 20:13:41 +00:00
|
|
|
stdwin_getdefwinpos(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1991-02-13 23:19:39 +00:00
|
|
|
{
|
|
|
|
int h, v;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1991-02-13 23:19:39 +00:00
|
|
|
return NULL;
|
|
|
|
wgetdefwinpos(&h, &v);
|
|
|
|
return makepoint(h, v);
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-05-05 20:13:41 +00:00
|
|
|
stdwin_getdefwinsize(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1991-02-13 23:19:39 +00:00
|
|
|
{
|
|
|
|
int width, height;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1991-02-13 23:19:39 +00:00
|
|
|
return NULL;
|
|
|
|
wgetdefwinsize(&width, &height);
|
|
|
|
return makepoint(width, height);
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-05-05 20:13:41 +00:00
|
|
|
stdwin_getdefscrollbars(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1991-04-03 19:12:14 +00:00
|
|
|
{
|
|
|
|
int h, v;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1991-04-03 19:12:14 +00:00
|
|
|
return NULL;
|
|
|
|
wgetdefscrollbars(&h, &v);
|
|
|
|
return makepoint(h, v);
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
stdwin_menucreate(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
char *title;
|
1990-10-14 12:07:46 +00:00
|
|
|
if (!getstrarg(args, &title))
|
|
|
|
return NULL;
|
|
|
|
wmenusetdeflocal(0);
|
1996-12-12 22:48:20 +00:00
|
|
|
return (PyObject *)newmenuobject(title);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
stdwin_askfile(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
char *prompt, *dflt;
|
1990-10-14 12:07:46 +00:00
|
|
|
int new, ret;
|
|
|
|
char buf[256];
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_Parse(args, "(ssi)", &prompt, &dflt, &new))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
1992-01-27 16:45:55 +00:00
|
|
|
strncpy(buf, dflt, sizeof buf);
|
1990-10-14 12:07:46 +00:00
|
|
|
buf[sizeof buf - 1] = '\0';
|
1992-08-05 19:58:53 +00:00
|
|
|
BGN_STDWIN
|
1992-01-27 16:45:55 +00:00
|
|
|
ret = waskfile(prompt, buf, sizeof buf, new);
|
1992-08-05 19:58:53 +00:00
|
|
|
END_STDWIN
|
1990-10-14 12:07:46 +00:00
|
|
|
if (!ret) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetNone(PyExc_KeyboardInterrupt);
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyString_FromString(buf);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
stdwin_askync(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
char *prompt;
|
1990-10-14 12:07:46 +00:00
|
|
|
int new, ret;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_Parse(args, "(si)", &prompt, &new))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
1992-08-05 19:58:53 +00:00
|
|
|
BGN_STDWIN
|
1992-01-27 16:45:55 +00:00
|
|
|
ret = waskync(prompt, new);
|
1992-08-05 19:58:53 +00:00
|
|
|
END_STDWIN
|
1990-10-14 12:07:46 +00:00
|
|
|
if (ret < 0) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetNone(PyExc_KeyboardInterrupt);
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyInt_FromLong((long)ret);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
stdwin_askstr(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
char *prompt, *dflt;
|
1990-10-14 12:07:46 +00:00
|
|
|
int ret;
|
|
|
|
char buf[256];
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_Parse(args, "(ss)", &prompt, &dflt))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
1992-01-27 16:45:55 +00:00
|
|
|
strncpy(buf, dflt, sizeof buf);
|
1990-10-14 12:07:46 +00:00
|
|
|
buf[sizeof buf - 1] = '\0';
|
1992-08-05 19:58:53 +00:00
|
|
|
BGN_STDWIN
|
1992-01-27 16:45:55 +00:00
|
|
|
ret = waskstr(prompt, buf, sizeof buf);
|
1992-08-05 19:58:53 +00:00
|
|
|
END_STDWIN
|
1990-10-14 12:07:46 +00:00
|
|
|
if (!ret) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetNone(PyExc_KeyboardInterrupt);
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyString_FromString(buf);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
stdwin_message(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
char *msg;
|
1990-10-14 12:07:46 +00:00
|
|
|
if (!getstrarg(args, &msg))
|
|
|
|
return NULL;
|
1992-08-05 19:58:53 +00:00
|
|
|
BGN_STDWIN
|
1992-01-27 16:45:55 +00:00
|
|
|
wmessage(msg);
|
1992-08-05 19:58:53 +00:00
|
|
|
END_STDWIN
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
stdwin_fleep(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
wfleep();
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
stdwin_setcutbuffer(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
int i, size;
|
|
|
|
char *str;
|
1998-10-08 02:25:24 +00:00
|
|
|
if (!PyArg_Parse(args, "(it#)", &i, &str, &size))
|
1990-11-06 15:17:35 +00:00
|
|
|
return NULL;
|
1992-01-27 16:45:55 +00:00
|
|
|
wsetcutbuffer(i, str, size);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-06-03 10:55:14 +00:00
|
|
|
stdwin_getactive(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1991-06-03 10:55:14 +00:00
|
|
|
{
|
|
|
|
return window2object(wgetactive());
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-14 12:07:46 +00:00
|
|
|
stdwin_getcutbuffer(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
1990-10-30 16:01:48 +00:00
|
|
|
int i;
|
1990-10-14 12:07:46 +00:00
|
|
|
char *str;
|
1990-10-30 13:39:00 +00:00
|
|
|
int len;
|
1990-11-06 15:17:35 +00:00
|
|
|
if (!getintarg(args, &i))
|
1990-10-14 12:07:46 +00:00
|
|
|
return NULL;
|
1990-10-30 16:01:48 +00:00
|
|
|
str = wgetcutbuffer(i, &len);
|
1990-10-30 13:39:00 +00:00
|
|
|
if (str == NULL) {
|
1990-10-14 12:07:46 +00:00
|
|
|
str = "";
|
1990-10-30 13:39:00 +00:00
|
|
|
len = 0;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyString_FromStringAndSize(str, len);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-30 16:01:48 +00:00
|
|
|
stdwin_rotatecutbuffers(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1990-10-30 16:01:48 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (!getintarg(args, &i))
|
|
|
|
return NULL;
|
|
|
|
wrotatecutbuffers(i);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-30 16:01:48 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-30 16:01:48 +00:00
|
|
|
stdwin_getselection(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1990-10-30 16:01:48 +00:00
|
|
|
{
|
|
|
|
int sel;
|
|
|
|
char *data;
|
|
|
|
int len;
|
|
|
|
if (!getintarg(args, &sel))
|
|
|
|
return NULL;
|
|
|
|
data = wgetselection(sel, &len);
|
|
|
|
if (data == NULL) {
|
|
|
|
data = "";
|
|
|
|
len = 0;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyString_FromStringAndSize(data, len);
|
1990-10-30 16:01:48 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1990-10-30 16:01:48 +00:00
|
|
|
stdwin_resetselection(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1990-10-30 16:01:48 +00:00
|
|
|
{
|
|
|
|
int sel;
|
|
|
|
if (!getintarg(args, &sel))
|
|
|
|
return NULL;
|
|
|
|
wresetselection(sel);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1990-10-30 16:01:48 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-04-03 19:12:14 +00:00
|
|
|
stdwin_fetchcolor(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1991-04-03 19:12:14 +00:00
|
|
|
{
|
1992-01-27 16:45:55 +00:00
|
|
|
char *colorname;
|
1993-01-26 13:33:44 +00:00
|
|
|
COLOR color;
|
1991-04-03 19:12:14 +00:00
|
|
|
if (!getstrarg(args, &colorname))
|
|
|
|
return NULL;
|
1993-01-26 13:33:44 +00:00
|
|
|
color = wfetchcolor(colorname);
|
|
|
|
#ifdef BADCOLOR
|
|
|
|
if (color == BADCOLOR) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_SetString(StdwinError, "color name not found");
|
1993-01-26 13:33:44 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyInt_FromLong((long)color);
|
1991-04-03 19:12:14 +00:00
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-05-05 20:13:41 +00:00
|
|
|
stdwin_getscrsize(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1991-05-05 20:13:41 +00:00
|
|
|
{
|
|
|
|
int width, height;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1991-05-05 20:13:41 +00:00
|
|
|
return NULL;
|
|
|
|
wgetscrsize(&width, &height);
|
|
|
|
return makepoint(width, height);
|
|
|
|
}
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1991-05-05 20:13:41 +00:00
|
|
|
stdwin_getscrmm(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1991-05-05 20:13:41 +00:00
|
|
|
{
|
|
|
|
int width, height;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1991-05-05 20:13:41 +00:00
|
|
|
return NULL;
|
|
|
|
wgetscrmm(&width, &height);
|
|
|
|
return makepoint(width, height);
|
|
|
|
}
|
|
|
|
|
1992-06-23 09:07:03 +00:00
|
|
|
#ifdef unix
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1992-06-23 09:07:03 +00:00
|
|
|
stdwin_connectionnumber(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1992-06-23 09:07:03 +00:00
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1992-06-23 09:07:03 +00:00
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
return PyInt_FromLong((long) wconnectionnumber());
|
1992-06-23 09:07:03 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1993-02-08 15:49:17 +00:00
|
|
|
stdwin_listfontnames(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1993-02-08 15:49:17 +00:00
|
|
|
{
|
|
|
|
char *pattern;
|
|
|
|
char **fontnames;
|
|
|
|
int count;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *list;
|
|
|
|
if (!PyArg_Parse(args, "z", &pattern))
|
1993-02-08 15:49:17 +00:00
|
|
|
return NULL;
|
|
|
|
fontnames = wlistfontnames(pattern, &count);
|
1996-12-12 22:48:20 +00:00
|
|
|
list = PyList_New(count);
|
1993-02-08 15:49:17 +00:00
|
|
|
if (list != NULL) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < count; i++) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *v = PyString_FromString(fontnames[i]);
|
1993-02-08 15:49:17 +00:00
|
|
|
if (v == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_DECREF(list);
|
1993-02-08 15:49:17 +00:00
|
|
|
list = NULL;
|
|
|
|
break;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
PyList_SetItem(list, i, v);
|
1993-02-08 15:49:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
1993-07-29 13:14:32 +00:00
|
|
|
#ifdef HAVE_BITMAPS
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyObject *
|
1993-02-08 15:49:17 +00:00
|
|
|
stdwin_newbitmap(self, args)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1993-02-08 15:49:17 +00:00
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
bitmapobject *bp;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyArg_Parse(args, "(ii)", &width, &height))
|
1993-02-08 15:49:17 +00:00
|
|
|
return NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
return (PyObject *)newbitmapobject(width, height);
|
1993-02-08 15:49:17 +00:00
|
|
|
}
|
1993-07-29 13:14:32 +00:00
|
|
|
#endif
|
1993-02-08 15:49:17 +00:00
|
|
|
|
1996-12-12 22:48:20 +00:00
|
|
|
static PyMethodDef stdwin_methods[] = {
|
1990-10-14 12:07:46 +00:00
|
|
|
{"askfile", stdwin_askfile},
|
|
|
|
{"askstr", stdwin_askstr},
|
|
|
|
{"askync", stdwin_askync},
|
1993-10-18 11:44:47 +00:00
|
|
|
{"done", stdwin_done},
|
1991-04-16 08:43:03 +00:00
|
|
|
{"fetchcolor", stdwin_fetchcolor},
|
1992-06-23 09:07:03 +00:00
|
|
|
#ifdef unix
|
|
|
|
{"fileno", stdwin_connectionnumber},
|
|
|
|
{"connectionnumber", stdwin_connectionnumber},
|
|
|
|
#endif
|
1990-10-14 12:07:46 +00:00
|
|
|
{"fleep", stdwin_fleep},
|
1991-06-03 10:55:14 +00:00
|
|
|
{"getactive", stdwin_getactive},
|
1990-10-14 12:07:46 +00:00
|
|
|
{"getcutbuffer", stdwin_getcutbuffer},
|
1991-04-03 19:12:14 +00:00
|
|
|
{"getdefscrollbars", stdwin_getdefscrollbars},
|
1991-02-13 23:19:39 +00:00
|
|
|
{"getdefwinpos", stdwin_getdefwinpos},
|
|
|
|
{"getdefwinsize", stdwin_getdefwinsize},
|
1990-10-14 12:07:46 +00:00
|
|
|
{"getevent", stdwin_getevent},
|
1991-05-05 20:13:41 +00:00
|
|
|
{"getscrmm", stdwin_getscrmm},
|
|
|
|
{"getscrsize", stdwin_getscrsize},
|
1991-04-16 08:43:03 +00:00
|
|
|
{"getselection", stdwin_getselection},
|
1993-02-08 15:49:17 +00:00
|
|
|
{"listfontnames", stdwin_listfontnames},
|
1990-10-14 12:07:46 +00:00
|
|
|
{"menucreate", stdwin_menucreate},
|
|
|
|
{"message", stdwin_message},
|
1993-07-29 13:14:32 +00:00
|
|
|
#ifdef HAVE_BITMAPS
|
1993-02-08 15:49:17 +00:00
|
|
|
{"newbitmap", stdwin_newbitmap},
|
1993-07-29 13:14:32 +00:00
|
|
|
#endif
|
1990-10-14 12:07:46 +00:00
|
|
|
{"open", stdwin_open},
|
1991-01-16 14:06:18 +00:00
|
|
|
{"pollevent", stdwin_pollevent},
|
1990-10-30 16:01:48 +00:00
|
|
|
{"resetselection", stdwin_resetselection},
|
|
|
|
{"rotatecutbuffers", stdwin_rotatecutbuffers},
|
1990-10-14 12:07:46 +00:00
|
|
|
{"setcutbuffer", stdwin_setcutbuffer},
|
1991-04-03 19:12:14 +00:00
|
|
|
{"setdefscrollbars", stdwin_setdefscrollbars},
|
1990-10-14 12:07:46 +00:00
|
|
|
{"setdefwinpos", stdwin_setdefwinpos},
|
|
|
|
{"setdefwinsize", stdwin_setdefwinsize},
|
|
|
|
|
|
|
|
/* Text measuring methods borrow code from drawing objects: */
|
1996-12-12 22:48:20 +00:00
|
|
|
{"baseline", (PyCFunction)drawing_baseline},
|
|
|
|
{"lineheight", (PyCFunction)drawing_lineheight},
|
|
|
|
{"textbreak", (PyCFunction)drawing_textbreak},
|
|
|
|
{"textwidth", (PyCFunction)drawing_textwidth},
|
1991-04-03 19:12:14 +00:00
|
|
|
|
|
|
|
/* Same for font setting methods: */
|
1996-12-12 22:48:20 +00:00
|
|
|
{"setfont", (PyCFunction)drawing_setfont},
|
1991-04-03 19:12:14 +00:00
|
|
|
|
|
|
|
/* Same for color setting/getting methods: */
|
1996-12-12 22:48:20 +00:00
|
|
|
{"getbgcolor", (PyCFunction)drawing_getbgcolor},
|
|
|
|
{"getfgcolor", (PyCFunction)drawing_getfgcolor},
|
|
|
|
{"setbgcolor", (PyCFunction)drawing_setbgcolor},
|
|
|
|
{"setfgcolor", (PyCFunction)drawing_setfgcolor},
|
1991-04-03 19:12:14 +00:00
|
|
|
|
1990-10-14 12:07:46 +00:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
1994-08-01 11:34:53 +00:00
|
|
|
#ifndef macintosh
|
1993-10-18 11:44:47 +00:00
|
|
|
static int
|
|
|
|
checkstringlist(args, ps, pn)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *args;
|
1993-10-18 11:44:47 +00:00
|
|
|
char ***ps;
|
|
|
|
int *pn;
|
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
char **s;
|
1996-12-12 22:48:20 +00:00
|
|
|
if (!PyList_Check(args)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "list of strings expected");
|
1993-10-18 11:44:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
n = PyList_Size(args);
|
|
|
|
s = PyMem_NEW(char *, n+1);
|
1993-10-18 11:44:47 +00:00
|
|
|
if (s == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_NoMemory();
|
1993-10-18 11:44:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < n; i++) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *item = PyList_GetItem(args, i);
|
|
|
|
if (!PyString_Check(item)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"list of strings expected");
|
1993-10-18 11:44:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
s[i] = PyString_AsString(item);
|
1993-10-18 11:44:47 +00:00
|
|
|
}
|
|
|
|
s[n] = NULL; /* In case caller wants a NULL-terminated list */
|
|
|
|
*ps = s;
|
|
|
|
*pn = n;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
putbackstringlist(list, s, n)
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *list;
|
1993-10-18 11:44:47 +00:00
|
|
|
char **s;
|
|
|
|
int n;
|
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
int oldsize = PyList_Size(list);
|
|
|
|
PyObject *newlist;
|
1993-10-18 11:44:47 +00:00
|
|
|
int i;
|
|
|
|
if (n == oldsize)
|
|
|
|
return 1;
|
1996-12-12 22:48:20 +00:00
|
|
|
newlist = PyList_New(n);
|
1993-10-18 11:44:47 +00:00
|
|
|
for (i = 0; i < n && newlist != NULL; i++) {
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *item = PyString_FromString(s[i]);
|
1993-10-18 11:44:47 +00:00
|
|
|
if (item == NULL) {
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_DECREF(newlist);
|
1993-10-18 11:44:47 +00:00
|
|
|
newlist = NULL;
|
|
|
|
}
|
|
|
|
else
|
1996-12-12 22:48:20 +00:00
|
|
|
PyList_SetItem(newlist, i, item);
|
1993-10-18 11:44:47 +00:00
|
|
|
}
|
|
|
|
if (newlist == NULL)
|
|
|
|
return 0;
|
|
|
|
(*list->ob_type->tp_as_sequence->sq_ass_slice)
|
|
|
|
(list, 0, oldsize, newlist);
|
1996-12-12 22:48:20 +00:00
|
|
|
Py_DECREF(newlist);
|
1993-10-18 11:44:47 +00:00
|
|
|
return 1;
|
|
|
|
}
|
1994-08-01 11:34:53 +00:00
|
|
|
#endif /* macintosh */
|
1993-10-18 11:44:47 +00:00
|
|
|
|
1998-12-04 18:50:17 +00:00
|
|
|
DL_EXPORT(void)
|
1990-10-14 12:07:46 +00:00
|
|
|
initstdwin()
|
|
|
|
{
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *m, *d;
|
1991-12-16 15:44:53 +00:00
|
|
|
static int inited = 0;
|
|
|
|
|
1991-02-19 12:26:49 +00:00
|
|
|
if (!inited) {
|
1994-08-01 11:34:53 +00:00
|
|
|
#ifdef macintosh
|
|
|
|
winit();
|
1995-01-27 14:44:16 +00:00
|
|
|
PyMac_DoYieldEnabled = 0;
|
1994-08-01 11:34:53 +00:00
|
|
|
#else
|
1995-01-26 00:37:10 +00:00
|
|
|
char buf[1000];
|
1993-10-18 11:44:47 +00:00
|
|
|
int argc = 0;
|
|
|
|
char **argv = NULL;
|
1996-12-12 22:48:20 +00:00
|
|
|
PyObject *sys_argv = PySys_GetObject("argv");
|
1993-10-18 11:44:47 +00:00
|
|
|
if (sys_argv != NULL) {
|
|
|
|
if (!checkstringlist(sys_argv, &argv, &argc))
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_Clear();
|
1993-10-18 11:44:47 +00:00
|
|
|
}
|
1993-11-17 22:58:56 +00:00
|
|
|
if (argc > 0) {
|
|
|
|
/* If argv[0] has a ".py" suffix, remove the suffix */
|
|
|
|
char *p = strrchr(argv[0], '.');
|
|
|
|
if (p != NULL && strcmp(p, ".py") == 0) {
|
|
|
|
int n = p - argv[0];
|
|
|
|
if (n >= sizeof(buf))
|
|
|
|
n = sizeof(buf)-1;
|
|
|
|
strncpy(buf, argv[0], n);
|
|
|
|
buf[n] = '\0';
|
|
|
|
argv[0] = buf;
|
|
|
|
}
|
|
|
|
}
|
1993-10-18 11:44:47 +00:00
|
|
|
winitargs(&argc, &argv);
|
|
|
|
if (argv != NULL) {
|
|
|
|
if (!putbackstringlist(sys_argv, argv, argc))
|
1996-12-12 22:48:20 +00:00
|
|
|
PyErr_Clear();
|
1993-10-18 11:44:47 +00:00
|
|
|
}
|
1994-08-01 11:34:53 +00:00
|
|
|
#endif
|
1991-02-19 12:26:49 +00:00
|
|
|
inited = 1;
|
|
|
|
}
|
1996-12-12 22:48:20 +00:00
|
|
|
m = Py_InitModule("stdwin", stdwin_methods);
|
|
|
|
d = PyModule_GetDict(m);
|
1991-12-16 15:44:53 +00:00
|
|
|
|
|
|
|
/* Initialize stdwin.error exception */
|
1997-10-01 04:29:29 +00:00
|
|
|
StdwinError = PyErr_NewException("stdwin.error", NULL, NULL);
|
1996-12-12 22:48:20 +00:00
|
|
|
if (StdwinError == NULL ||
|
|
|
|
PyDict_SetItemString(d, "error", StdwinError) != 0)
|
1997-10-01 04:29:29 +00:00
|
|
|
return;
|
1994-08-01 11:34:53 +00:00
|
|
|
#ifdef WITH_THREAD
|
1998-12-21 19:32:43 +00:00
|
|
|
StdwinLock = PyThread_allocate_lock();
|
1992-08-05 19:58:53 +00:00
|
|
|
#endif
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|