/Mac/Modules/help/_Helpmodule.c

http://unladen-swallow.googlecode.com/ · C · 196 lines · 164 code · 29 blank · 3 comment · 28 complexity · 640b87c22b757f680eb5bdc30555ea2c MD5 · raw file

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