PageRenderTime 474ms CodeModel.GetById 161ms app.highlight 176ms RepoModel.GetById 127ms app.codeStats 0ms

/Mac/Modules/help/_Helpmodule.c

http://unladen-swallow.googlecode.com/
C | 196 lines | 164 code | 29 blank | 3 comment | 27 complexity | 640b87c22b757f680eb5bdc30555ea2c MD5 | raw file
  1
  2/* ========================== Module _Help ========================== */
  3
  4#include "Python.h"
  5
  6#ifndef __LP64__
  7
  8
  9#include "pymactoolbox.h"
 10
 11/* Macro to test whether a weak-loaded CFM function exists */
 12#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL )  {\
 13        PyErr_SetString(PyExc_NotImplementedError, \
 14        "Not available in this shared library/OS version"); \
 15        return NULL; \
 16    }} while(0)
 17
 18
 19#include <Carbon/Carbon.h>
 20
 21static PyObject *Help_Error;
 22
 23static PyObject *Help_HMGetHelpMenu(PyObject *_self, PyObject *_args)
 24{
 25	PyObject *_res = NULL;
 26	OSStatus _err;
 27	MenuRef outHelpMenu;
 28	MenuItemIndex outFirstCustomItemIndex;
 29	if (!PyArg_ParseTuple(_args, ""))
 30		return NULL;
 31	_err = HMGetHelpMenu(&outHelpMenu,
 32	                     &outFirstCustomItemIndex);
 33	if (_err != noErr) return PyMac_Error(_err);
 34	_res = Py_BuildValue("O&H",
 35	                     MenuObj_New, outHelpMenu,
 36	                     outFirstCustomItemIndex);
 37	return _res;
 38}
 39
 40static PyObject *Help_HMAreHelpTagsDisplayed(PyObject *_self, PyObject *_args)
 41{
 42	PyObject *_res = NULL;
 43	Boolean _rv;
 44	if (!PyArg_ParseTuple(_args, ""))
 45		return NULL;
 46	_rv = HMAreHelpTagsDisplayed();
 47	_res = Py_BuildValue("b",
 48	                     _rv);
 49	return _res;
 50}
 51
 52static PyObject *Help_HMSetHelpTagsDisplayed(PyObject *_self, PyObject *_args)
 53{
 54	PyObject *_res = NULL;
 55	OSStatus _err;
 56	Boolean inDisplayTags;
 57	if (!PyArg_ParseTuple(_args, "b",
 58	                      &inDisplayTags))
 59		return NULL;
 60	_err = HMSetHelpTagsDisplayed(inDisplayTags);
 61	if (_err != noErr) return PyMac_Error(_err);
 62	Py_INCREF(Py_None);
 63	_res = Py_None;
 64	return _res;
 65}
 66
 67static PyObject *Help_HMSetTagDelay(PyObject *_self, PyObject *_args)
 68{
 69	PyObject *_res = NULL;
 70	OSStatus _err;
 71	Duration inDelay;
 72	if (!PyArg_ParseTuple(_args, "l",
 73	                      &inDelay))
 74		return NULL;
 75	_err = HMSetTagDelay(inDelay);
 76	if (_err != noErr) return PyMac_Error(_err);
 77	Py_INCREF(Py_None);
 78	_res = Py_None;
 79	return _res;
 80}
 81
 82static PyObject *Help_HMGetTagDelay(PyObject *_self, PyObject *_args)
 83{
 84	PyObject *_res = NULL;
 85	OSStatus _err;
 86	Duration outDelay;
 87	if (!PyArg_ParseTuple(_args, ""))
 88		return NULL;
 89	_err = HMGetTagDelay(&outDelay);
 90	if (_err != noErr) return PyMac_Error(_err);
 91	_res = Py_BuildValue("l",
 92	                     outDelay);
 93	return _res;
 94}
 95
 96static PyObject *Help_HMSetMenuHelpFromBalloonRsrc(PyObject *_self, PyObject *_args)
 97{
 98	PyObject *_res = NULL;
 99	OSStatus _err;
100	MenuRef inMenu;
101	SInt16 inHmnuRsrcID;
102	if (!PyArg_ParseTuple(_args, "O&h",
103	                      MenuObj_Convert, &inMenu,
104	                      &inHmnuRsrcID))
105		return NULL;
106	_err = HMSetMenuHelpFromBalloonRsrc(inMenu,
107	                                    inHmnuRsrcID);
108	if (_err != noErr) return PyMac_Error(_err);
109	Py_INCREF(Py_None);
110	_res = Py_None;
111	return _res;
112}
113
114static PyObject *Help_HMSetDialogHelpFromBalloonRsrc(PyObject *_self, PyObject *_args)
115{
116	PyObject *_res = NULL;
117	OSStatus _err;
118	DialogPtr inDialog;
119	SInt16 inHdlgRsrcID;
120	SInt16 inItemStart;
121	if (!PyArg_ParseTuple(_args, "O&hh",
122	                      DlgObj_Convert, &inDialog,
123	                      &inHdlgRsrcID,
124	                      &inItemStart))
125		return NULL;
126	_err = HMSetDialogHelpFromBalloonRsrc(inDialog,
127	                                      inHdlgRsrcID,
128	                                      inItemStart);
129	if (_err != noErr) return PyMac_Error(_err);
130	Py_INCREF(Py_None);
131	_res = Py_None;
132	return _res;
133}
134
135static PyObject *Help_HMHideTag(PyObject *_self, PyObject *_args)
136{
137	PyObject *_res = NULL;
138	OSStatus _err;
139	if (!PyArg_ParseTuple(_args, ""))
140		return NULL;
141	_err = HMHideTag();
142	if (_err != noErr) return PyMac_Error(_err);
143	Py_INCREF(Py_None);
144	_res = Py_None;
145	return _res;
146}
147
148#endif /* __LP64__ */
149
150static PyMethodDef Help_methods[] = {
151#ifndef __LP64__
152	{"HMGetHelpMenu", (PyCFunction)Help_HMGetHelpMenu, 1,
153	 PyDoc_STR("() -> (MenuRef outHelpMenu, MenuItemIndex outFirstCustomItemIndex)")},
154	{"HMAreHelpTagsDisplayed", (PyCFunction)Help_HMAreHelpTagsDisplayed, 1,
155	 PyDoc_STR("() -> (Boolean _rv)")},
156	{"HMSetHelpTagsDisplayed", (PyCFunction)Help_HMSetHelpTagsDisplayed, 1,
157	 PyDoc_STR("(Boolean inDisplayTags) -> None")},
158	{"HMSetTagDelay", (PyCFunction)Help_HMSetTagDelay, 1,
159	 PyDoc_STR("(Duration inDelay) -> None")},
160	{"HMGetTagDelay", (PyCFunction)Help_HMGetTagDelay, 1,
161	 PyDoc_STR("() -> (Duration outDelay)")},
162	{"HMSetMenuHelpFromBalloonRsrc", (PyCFunction)Help_HMSetMenuHelpFromBalloonRsrc, 1,
163	 PyDoc_STR("(MenuRef inMenu, SInt16 inHmnuRsrcID) -> None")},
164	{"HMSetDialogHelpFromBalloonRsrc", (PyCFunction)Help_HMSetDialogHelpFromBalloonRsrc, 1,
165	 PyDoc_STR("(DialogPtr inDialog, SInt16 inHdlgRsrcID, SInt16 inItemStart) -> None")},
166	{"HMHideTag", (PyCFunction)Help_HMHideTag, 1,
167	 PyDoc_STR("() -> None")},
168#endif /* __LP64__ */
169	{NULL, NULL, 0}
170};
171
172
173
174
175void init_Help(void)
176{
177	PyObject *m;
178#ifndef __LP64__
179	PyObject *d;
180#endif /* __LP64__ */
181
182
183
184
185	m = Py_InitModule("_Help", Help_methods);
186#ifndef __LP64__
187	d = PyModule_GetDict(m);
188	Help_Error = PyMac_GetOSErrException();
189	if (Help_Error == NULL ||
190	    PyDict_SetItemString(d, "Error", Help_Error) != 0)
191		return;
192#endif /* __LP64__ */
193}
194
195/* ======================== End module _Help ======================== */
196