Import Upstream version 2.7.18

This commit is contained in:
geos_one
2025-08-15 16:28:06 +02:00
commit ba1f69ab39
4521 changed files with 1778434 additions and 0 deletions

View File

@@ -0,0 +1,193 @@
/* ========================== Module _Help ========================== */
#include "Python.h"
#include "pymactoolbox.h"
#if APPLE_SUPPORTS_QUICKTIME
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
PyErr_SetString(PyExc_NotImplementedError, \
"Not available in this shared library/OS version"); \
return NULL; \
}} while(0)
#include <Carbon/Carbon.h>
static PyObject *Help_Error;
static PyObject *Help_HMGetHelpMenu(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
MenuRef outHelpMenu;
MenuItemIndex outFirstCustomItemIndex;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_err = HMGetHelpMenu(&outHelpMenu,
&outFirstCustomItemIndex);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("O&H",
MenuObj_New, outHelpMenu,
outFirstCustomItemIndex);
return _res;
}
static PyObject *Help_HMAreHelpTagsDisplayed(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
Boolean _rv;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = HMAreHelpTagsDisplayed();
_res = Py_BuildValue("b",
_rv);
return _res;
}
static PyObject *Help_HMSetHelpTagsDisplayed(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
Boolean inDisplayTags;
if (!PyArg_ParseTuple(_args, "b",
&inDisplayTags))
return NULL;
_err = HMSetHelpTagsDisplayed(inDisplayTags);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Help_HMSetTagDelay(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
Duration inDelay;
if (!PyArg_ParseTuple(_args, "l",
&inDelay))
return NULL;
_err = HMSetTagDelay(inDelay);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Help_HMGetTagDelay(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
Duration outDelay;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_err = HMGetTagDelay(&outDelay);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("l",
outDelay);
return _res;
}
static PyObject *Help_HMSetMenuHelpFromBalloonRsrc(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
MenuRef inMenu;
SInt16 inHmnuRsrcID;
if (!PyArg_ParseTuple(_args, "O&h",
MenuObj_Convert, &inMenu,
&inHmnuRsrcID))
return NULL;
_err = HMSetMenuHelpFromBalloonRsrc(inMenu,
inHmnuRsrcID);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Help_HMSetDialogHelpFromBalloonRsrc(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
DialogPtr inDialog;
SInt16 inHdlgRsrcID;
SInt16 inItemStart;
if (!PyArg_ParseTuple(_args, "O&hh",
DlgObj_Convert, &inDialog,
&inHdlgRsrcID,
&inItemStart))
return NULL;
_err = HMSetDialogHelpFromBalloonRsrc(inDialog,
inHdlgRsrcID,
inItemStart);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Help_HMHideTag(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSStatus _err;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_err = HMHideTag();
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
#endif /* APPLE_SUPPORTS_QUICKTIME */
static PyMethodDef Help_methods[] = {
#if APPLE_SUPPORTS_QUICKTIME
{"HMGetHelpMenu", (PyCFunction)Help_HMGetHelpMenu, 1,
PyDoc_STR("() -> (MenuRef outHelpMenu, MenuItemIndex outFirstCustomItemIndex)")},
{"HMAreHelpTagsDisplayed", (PyCFunction)Help_HMAreHelpTagsDisplayed, 1,
PyDoc_STR("() -> (Boolean _rv)")},
{"HMSetHelpTagsDisplayed", (PyCFunction)Help_HMSetHelpTagsDisplayed, 1,
PyDoc_STR("(Boolean inDisplayTags) -> None")},
{"HMSetTagDelay", (PyCFunction)Help_HMSetTagDelay, 1,
PyDoc_STR("(Duration inDelay) -> None")},
{"HMGetTagDelay", (PyCFunction)Help_HMGetTagDelay, 1,
PyDoc_STR("() -> (Duration outDelay)")},
{"HMSetMenuHelpFromBalloonRsrc", (PyCFunction)Help_HMSetMenuHelpFromBalloonRsrc, 1,
PyDoc_STR("(MenuRef inMenu, SInt16 inHmnuRsrcID) -> None")},
{"HMSetDialogHelpFromBalloonRsrc", (PyCFunction)Help_HMSetDialogHelpFromBalloonRsrc, 1,
PyDoc_STR("(DialogPtr inDialog, SInt16 inHdlgRsrcID, SInt16 inItemStart) -> None")},
{"HMHideTag", (PyCFunction)Help_HMHideTag, 1,
PyDoc_STR("() -> None")},
#endif /* APPLE_SUPPORTS_QUICKTIME */
{NULL, NULL, 0}
};
void init_Help(void)
{
PyObject *m;
#if APPLE_SUPPORTS_QUICKTIME
PyObject *d;
#endif /* APPLE_SUPPORTS_QUICKTIME */
m = Py_InitModule("_Help", Help_methods);
#if APPLE_SUPPORTS_QUICKTIME
d = PyModule_GetDict(m);
Help_Error = PyMac_GetOSErrException();
if (Help_Error == NULL ||
PyDict_SetItemString(d, "Error", Help_Error) != 0)
return;
#endif /* APPLE_SUPPORTS_QUICKTIME */
}
/* ======================== End module _Help ======================== */

View File

@@ -0,0 +1,66 @@
# Scan an Apple header file, generating a Python file of generator calls.
import sys
from bgenlocations import TOOLBOXDIR, BGENDIR
sys.path.append(BGENDIR)
from scantools import Scanner
LONG = "MacHelp"
SHORT = "help"
OBJECT = "NOTUSED"
def main():
input = LONG + ".h"
output = SHORT + "gen.py"
defsoutput = TOOLBOXDIR + LONG + ".py"
scanner = MyScanner(input, output, defsoutput)
scanner.scan()
scanner.close()
print "=== Testing definitions output code ==="
execfile(defsoutput, {}, {})
print "=== Done scanning and generating, now importing the generated code... ==="
exec "import " + SHORT + "support"
print "=== Done. It's up to you to compile it now! ==="
class MyScanner(Scanner):
def destination(self, type, name, arglist):
classname = "Function"
listname = "functions"
if arglist:
t, n, m = arglist[0]
# This is non-functional today
if t == OBJECT and m == "InMode":
classname = "Method"
listname = "methods"
return classname, listname
def writeinitialdefs(self):
self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
def makeblacklistnames(self):
return [
]
def makeblacklisttypes(self):
return [
## "TipFunctionUPP",
## "HMMessageRecord",
## "HMMessageRecord_ptr",
"HMWindowContentUPP",
"HMMenuTitleContentUPP",
"HMControlContentUPP",
"HMMenuItemContentUPP",
# For the moment
"HMHelpContentRec",
"HMHelpContentRec_ptr",
]
def makerepairinstructions(self):
return [
## ([("WindowPtr", "*", "OutMode")],
## [("ExistingWindowPtr", "*", "*")]),
]
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,78 @@
# This script generates a Python interface for an Apple Macintosh Manager.
# It uses the "bgen" package to generate C code.
# The function specifications are generated by scanning the mamager's header file,
# using the "scantools" package (customized for this particular manager).
import string
# Declarations that change for each manager
MODNAME = '_Help' # The name of the module
OBJECTNAME = 'UNUSED' # The basic name of the objects used here
KIND = 'Record' # Usually 'Ptr' or 'Handle'
# The following is *usually* unchanged but may still require tuning
MODPREFIX = 'Help' # The prefix for module-wide routines
OBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them
OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
from macsupport import *
# Create the type objects
MenuRef = OpaqueByValueType("MenuRef", "MenuObj")
MenuItemIndex = Type("MenuItemIndex", "H")
#WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
#RgnHandle = FakeType("(RgnHandle)0")
# XXXX Should be next, but this will break a lot of code...
# RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
#KeyMap = ArrayOutputBufferType("KeyMap")
##MacOSEventKind = Type("MacOSEventKind", "h") # Old-style
##MacOSEventMask = Type("MacOSEventMask", "h") # Old-style
#EventMask = Type("EventMask", "H")
#EventKind = Type("EventKind", "H")
includestuff = includestuff + """
#include <Carbon/Carbon.h>
"""
class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
def outputCheckConvertArg(self):
OutLbrace("if (DlgObj_Check(v))")
Output("*p_itself = ((WindowObject *)v)->ob_itself;")
Output("return 1;")
OutRbrace()
Out("""
if (v == Py_None) { *p_itself = NULL; return 1; }
if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
""")
# From here on it's basically all boiler plate...
# Create the generator groups and link them
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
##module.addobject(object)
# Create the generator classes used to populate the lists
Function = OSErrFunctionGenerator
##Method = OSErrMethodGenerator
# Create and populate the lists
functions = []
##methods = []
execfile(INPUTFILE)
# add the populated lists to the generator groups
# (in a different wordl the scan program would generate this)
for f in functions: module.add(f)
##for f in methods: object.add(f)
# generate output (open the output file as late as possible)
SetOutputFileName(OUTPUTFILE)
module.generate()