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