Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c46ce9

Browse files
committed
Allow setting the auto dispose flag on window objects.
1 parent f776dee commit 8c46ce9

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

Mac/Modules/win/_Winmodule.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
/* Macro to test whether a weak-loaded CFM function exists */
1616
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17-
PyErr_SetString(PyExc_NotImplementedError, \
18-
"Not available in this shared library/OS version"); \
19-
return NULL; \
17+
PyErr_SetString(PyExc_NotImplementedError, \
18+
"Not available in this shared library/OS version"); \
19+
return NULL; \
2020
}} while(0)
2121

2222

@@ -2300,6 +2300,24 @@ static PyObject *WinObj_ShowWindow(WindowObject *_self, PyObject *_args)
23002300
return _res;
23012301
}
23022302

2303+
static PyObject *WinObj_AutoDispose(WindowObject *_self, PyObject *_args)
2304+
{
2305+
PyObject *_res = NULL;
2306+
2307+
int onoff, old = 0;
2308+
if (!PyArg_ParseTuple(_args, "i", &onoff))
2309+
return NULL;
2310+
if ( _self->ob_freeit )
2311+
old = 1;
2312+
if ( onoff )
2313+
_self->ob_freeit = PyMac_AutoDisposeWindow;
2314+
else
2315+
_self->ob_freeit = NULL;
2316+
_res = Py_BuildValue("i", old);
2317+
return _res;
2318+
2319+
}
2320+
23032321
static PyMethodDef WinObj_methods[] = {
23042322
{"GetWindowOwnerCount", (PyCFunction)WinObj_GetWindowOwnerCount, 1,
23052323
PyDoc_STR("() -> (UInt32 outCount)")},
@@ -2540,6 +2558,8 @@ static PyMethodDef WinObj_methods[] = {
25402558
PyDoc_STR("(short hGlobal, short vGlobal, Boolean front) -> None")},
25412559
{"ShowWindow", (PyCFunction)WinObj_ShowWindow, 1,
25422560
PyDoc_STR("() -> None")},
2561+
{"AutoDispose", (PyCFunction)WinObj_AutoDispose, 1,
2562+
PyDoc_STR("(int)->int. Automatically DisposeHandle the object on Python object cleanup")},
25432563
{NULL, NULL, 0}
25442564
};
25452565

Mac/Modules/win/winedit.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,24 @@
4848
)
4949
methods.append(f)
5050

51+
#
52+
# A method to set the auto-dispose flag
53+
#
54+
AutoDispose_body = """
55+
int onoff, old = 0;
56+
if (!PyArg_ParseTuple(_args, "i", &onoff))
57+
return NULL;
58+
if ( _self->ob_freeit )
59+
old = 1;
60+
if ( onoff )
61+
_self->ob_freeit = PyMac_AutoDisposeWindow;
62+
else
63+
_self->ob_freeit = NULL;
64+
_res = Py_BuildValue("i", old);
65+
return _res;
66+
"""
67+
f = ManualGenerator("AutoDispose", AutoDispose_body)
68+
f.docstring = lambda: "(int)->int. Automatically DisposeHandle the object on Python object cleanup"
69+
methods.append(f)
5170

5271

0 commit comments

Comments
 (0)