/Mac/Modules/OSATerminology.c

http://unladen-swallow.googlecode.com/ · C · 98 lines · 78 code · 9 blank · 11 comment · 7 complexity · ae2a1511d6e1ca000013825b0d80d077 MD5 · raw file

  1. /*
  2. ** This module is a one-trick pony: given an FSSpec it gets the aeut
  3. ** resources. It was written by Donovan Preston and slightly modified
  4. ** by Jack.
  5. **
  6. ** It should be considered a placeholder, it will probably be replaced
  7. ** by a full interface to OpenScripting.
  8. */
  9. #include "Python.h"
  10. #include "pymactoolbox.h"
  11. #include <Carbon/Carbon.h>
  12. #ifndef __LP64__
  13. static PyObject *
  14. PyOSA_GetAppTerminology(PyObject* self, PyObject* args)
  15. {
  16. AEDesc theDesc = {0,0};
  17. FSSpec fss;
  18. ComponentInstance defaultComponent = NULL;
  19. SInt16 defaultTerminology = 0;
  20. Boolean didLaunch = 0;
  21. OSAError err;
  22. long modeFlags = 0;
  23. if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &modeFlags))
  24. return NULL;
  25. defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
  26. err = GetComponentInstanceError (defaultComponent);
  27. if (err) return PyMac_Error(err);
  28. err = OSAGetAppTerminology (
  29. defaultComponent,
  30. modeFlags,
  31. &fss,
  32. defaultTerminology,
  33. &didLaunch,
  34. &theDesc
  35. );
  36. if (err) return PyMac_Error(err);
  37. return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
  38. }
  39. static PyObject *
  40. PyOSA_GetSysTerminology(PyObject* self, PyObject* args)
  41. {
  42. AEDesc theDesc = {0,0};
  43. FSSpec fss;
  44. ComponentInstance defaultComponent = NULL;
  45. SInt16 defaultTerminology = 0;
  46. Boolean didLaunch = 0;
  47. OSAError err;
  48. long modeFlags = 0;
  49. if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &modeFlags))
  50. return NULL;
  51. defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
  52. err = GetComponentInstanceError (defaultComponent);
  53. if (err) return PyMac_Error(err);
  54. err = OSAGetAppTerminology (
  55. defaultComponent,
  56. modeFlags,
  57. &fss,
  58. defaultTerminology,
  59. &didLaunch,
  60. &theDesc
  61. );
  62. if (err) return PyMac_Error(err);
  63. return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
  64. }
  65. #endif /* !__LP64__ */
  66. /*
  67. * List of methods defined in the module
  68. */
  69. static struct PyMethodDef OSATerminology_methods[] =
  70. {
  71. #ifndef __LP64__
  72. {"GetAppTerminology",
  73. (PyCFunction) PyOSA_GetAppTerminology,
  74. METH_VARARGS,
  75. "Get an applications terminology, as an AEDesc object."},
  76. {"GetSysTerminology",
  77. (PyCFunction) PyOSA_GetSysTerminology,
  78. METH_VARARGS,
  79. "Get an applications system terminology, as an AEDesc object."},
  80. #endif /* !__LP64__ */
  81. {NULL, (PyCFunction) NULL, 0, NULL}
  82. };
  83. void
  84. initOSATerminology(void)
  85. {
  86. if (PyErr_WarnPy3k("In 3.x, OSATerminology is removed.", 1) < 0)
  87. return;
  88. Py_InitModule("OSATerminology", OSATerminology_methods);
  89. }