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

Skip to content

Commit e058189

Browse files
committed
Added Ctl.as_Control and Menu.as_Menu methods, which take a resource as
argument and return a Control or Menu object.
1 parent b068789 commit e058189

6 files changed

Lines changed: 52 additions & 0 deletions

File tree

Mac/Modules/ctl/Ctlmodule.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ extern PyObject *WinObj_WhichWindow(WindowPtr);
4444

4545
#include <Controls.h>
4646

47+
#define as_Control(h) ((ControlHandle)h)
48+
4749
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
4850

4951
extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
@@ -1333,6 +1335,22 @@ static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
13331335
return _res;
13341336
}
13351337

1338+
static PyObject *Ctl_as_Control(_self, _args)
1339+
PyObject *_self;
1340+
PyObject *_args;
1341+
{
1342+
PyObject *_res = NULL;
1343+
ControlHandle _rv;
1344+
Handle h;
1345+
if (!PyArg_ParseTuple(_args, "O&",
1346+
ResObj_Convert, &h))
1347+
return NULL;
1348+
_rv = as_Control(h);
1349+
_res = Py_BuildValue("O&",
1350+
CtlObj_New, _rv);
1351+
return _res;
1352+
}
1353+
13361354
static PyMethodDef Ctl_methods[] = {
13371355
{"NewControl", (PyCFunction)Ctl_NewControl, 1,
13381356
"(WindowPtr owningWindow, Rect boundsRect, Str255 controlTitle, Boolean initiallyVisible, SInt16 initialValue, SInt16 minimumValue, SInt16 maximumValue, SInt16 procID, SInt32 controlReference) -> (ControlHandle _rv)"},
@@ -1364,6 +1382,8 @@ static PyMethodDef Ctl_methods[] = {
13641382
"(WindowPtr inWindow) -> None"},
13651383
{"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
13661384
"(WindowPtr inWindow) -> None"},
1385+
{"as_Control", (PyCFunction)Ctl_as_Control, 1,
1386+
"(Handle h) -> (ControlHandle _rv)"},
13671387
{NULL, NULL, 0}
13681388
};
13691389

Mac/Modules/ctl/ctledit.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
f = Function(ControlHandle, 'as_Control',
2+
(Handle, 'h', InMode))
3+
functions.append(f)
4+
15
as_resource_body = """
26
return ResObj_New((Handle)_self->ob_itself);
37
"""

Mac/Modules/ctl/ctlsupport.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
includestuff = includestuff + """
4545
#include <%s>""" % MACHEADERFILE + """
4646
47+
#define as_Control(h) ((ControlHandle)h)
48+
4749
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
4850
4951
extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */

Mac/Modules/menu/Menumodule.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ extern PyObject *WinObj_WhichWindow(WindowPtr);
4747

4848
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
4949

50+
#define as_Menu(h) ((MenuHandle)h)
51+
5052
static PyObject *Menu_Error;
5153

5254
/* ------------------------ Object type Menu ------------------------ */
@@ -1455,6 +1457,22 @@ static PyObject *Menu_OpenDeskAcc(_self, _args)
14551457
return _res;
14561458
}
14571459

1460+
static PyObject *Menu_as_Menu(_self, _args)
1461+
PyObject *_self;
1462+
PyObject *_args;
1463+
{
1464+
PyObject *_res = NULL;
1465+
MenuHandle _rv;
1466+
Handle h;
1467+
if (!PyArg_ParseTuple(_args, "O&",
1468+
ResObj_Convert, &h))
1469+
return NULL;
1470+
_rv = as_Menu(h);
1471+
_res = Py_BuildValue("O&",
1472+
MenuObj_New, _rv);
1473+
return _res;
1474+
}
1475+
14581476
static PyObject *Menu_GetMenu(_self, _args)
14591477
PyObject *_self;
14601478
PyObject *_args;
@@ -1548,6 +1566,8 @@ static PyMethodDef Menu_methods[] = {
15481566
"(EventRecord inEvent) -> (UInt32 _rv)"},
15491567
{"OpenDeskAcc", (PyCFunction)Menu_OpenDeskAcc, 1,
15501568
"(Str255 name) -> None"},
1569+
{"as_Menu", (PyCFunction)Menu_as_Menu, 1,
1570+
"(Handle h) -> (MenuHandle _rv)"},
15511571
{"GetMenu", (PyCFunction)Menu_GetMenu, 1,
15521572
"(short resourceID) -> (MenuHandle _rv)"},
15531573
{"DeleteMenu", (PyCFunction)Menu_DeleteMenu, 1,

Mac/Modules/menu/menuedit.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
)
44
functions.append(f)
55

6+
f = Function(MenuHandle, 'as_Menu',
7+
(Handle, 'h', InMode))
8+
functions.append(f)
9+
610
as_resource_body = """
711
return ResObj_New((Handle)_self->ob_itself);
812
"""

Mac/Modules/menu/menusupport.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <%s>""" % MACHEADERFILE + """
3333
3434
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
35+
36+
#define as_Menu(h) ((MenuHandle)h)
3537
"""
3638

3739
class MyObjectDefinition(GlobalObjectDefinition):

0 commit comments

Comments
 (0)