Added interface to the Balloon Help Manager

This commit is contained in:
Jack Jansen 1997-09-09 13:52:47 +00:00
parent 6954e34324
commit bf2f6021c5
4 changed files with 494 additions and 0 deletions

View File

@ -101,6 +101,7 @@ extern void initCtl();
extern void initDlg();
extern void initEvt();
extern void initFm();
extern void initHelp();
extern void initList();
extern void initMenu();
extern void initQd();
@ -203,6 +204,7 @@ struct _inittab _PyImport_Inittab[] = {
{"Dlg", initDlg},
{"Evt", initEvt},
{"Fm", initFm},
{"Help", initHelp},
{"Menu", initMenu},
{"List", initList},
{"Qd", initQd},

View File

@ -0,0 +1,358 @@
/* ========================== Module Help =========================== */
#include "Python.h"
#define SystemSevenOrLater 1
#include "macglue.h"
#include <Memory.h>
#include <Dialogs.h>
#include <Menus.h>
#include <Controls.h>
extern PyObject *ResObj_New(Handle);
extern int ResObj_Convert(PyObject *, Handle *);
extern PyObject *OptResObj_New(Handle);
extern int OptResObj_Convert(PyObject *, Handle *);
extern PyObject *WinObj_New(WindowPtr);
extern int WinObj_Convert(PyObject *, WindowPtr *);
extern PyTypeObject Window_Type;
#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
extern PyObject *DlgObj_New(DialogPtr);
extern int DlgObj_Convert(PyObject *, DialogPtr *);
extern PyTypeObject Dialog_Type;
#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
extern PyObject *MenuObj_New(MenuHandle);
extern int MenuObj_Convert(PyObject *, MenuHandle *);
extern PyObject *CtlObj_New(ControlHandle);
extern int CtlObj_Convert(PyObject *, ControlHandle *);
extern PyObject *GrafObj_New(GrafPtr);
extern int GrafObj_Convert(PyObject *, GrafPtr *);
extern PyObject *BMObj_New(BitMapPtr);
extern int BMObj_Convert(PyObject *, BitMapPtr *);
extern PyObject *WinObj_WhichWindow(WindowPtr);
#include <Balloons.h>
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
static PyObject *Help_Error;
static PyObject *Help_HMGetHelpMenuHandle(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
OSErr _err;
MenuRef mh;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_err = HMGetHelpMenuHandle(&mh);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("O&",
ResObj_New, mh);
return _res;
}
static PyObject *Help_HMRemoveBalloon(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
OSErr _err;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_err = HMRemoveBalloon();
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Help_HMGetBalloons(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
Boolean _rv;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = HMGetBalloons();
_res = Py_BuildValue("b",
_rv);
return _res;
}
static PyObject *Help_HMSetBalloons(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
OSErr _err;
Boolean flag;
if (!PyArg_ParseTuple(_args, "b",
&flag))
return NULL;
_err = HMSetBalloons(flag);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Help_HMIsBalloon(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
Boolean _rv;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = HMIsBalloon();
_res = Py_BuildValue("b",
_rv);
return _res;
}
static PyObject *Help_HMSetFont(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
OSErr _err;
SInt16 font;
if (!PyArg_ParseTuple(_args, "h",
&font))
return NULL;
_err = HMSetFont(font);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Help_HMSetFontSize(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
OSErr _err;
UInt16 fontSize;
if (!PyArg_ParseTuple(_args, "h",
&fontSize))
return NULL;
_err = HMSetFontSize(fontSize);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Help_HMGetFont(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
OSErr _err;
SInt16 font;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_err = HMGetFont(&font);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("h",
font);
return _res;
}
static PyObject *Help_HMGetFontSize(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
OSErr _err;
UInt16 fontSize;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_err = HMGetFontSize(&fontSize);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("h",
fontSize);
return _res;
}
static PyObject *Help_HMSetDialogResID(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
OSErr _err;
SInt16 resID;
if (!PyArg_ParseTuple(_args, "h",
&resID))
return NULL;
_err = HMSetDialogResID(resID);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Help_HMSetMenuResID(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
OSErr _err;
SInt16 menuID;
SInt16 resID;
if (!PyArg_ParseTuple(_args, "hh",
&menuID,
&resID))
return NULL;
_err = HMSetMenuResID(menuID,
resID);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Help_HMScanTemplateItems(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
OSErr _err;
SInt16 whichID;
SInt16 whichResFile;
ResType whichType;
if (!PyArg_ParseTuple(_args, "hhO&",
&whichID,
&whichResFile,
PyMac_GetOSType, &whichType))
return NULL;
_err = HMScanTemplateItems(whichID,
whichResFile,
whichType);
if (_err != noErr) return PyMac_Error(_err);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *Help_HMGetDialogResID(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
OSErr _err;
SInt16 resID;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_err = HMGetDialogResID(&resID);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("h",
resID);
return _res;
}
static PyObject *Help_HMGetMenuResID(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
OSErr _err;
SInt16 menuID;
SInt16 resID;
if (!PyArg_ParseTuple(_args, "h",
&menuID))
return NULL;
_err = HMGetMenuResID(menuID,
&resID);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("h",
resID);
return _res;
}
static PyObject *Help_HMGetBalloonWindow(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
OSErr _err;
WindowPtr window;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_err = HMGetBalloonWindow(&window);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("O&",
WinObj_New, window);
return _res;
}
static PyMethodDef Help_methods[] = {
{"HMGetHelpMenuHandle", (PyCFunction)Help_HMGetHelpMenuHandle, 1,
"() -> (MenuRef mh)"},
{"HMRemoveBalloon", (PyCFunction)Help_HMRemoveBalloon, 1,
"() -> None"},
{"HMGetBalloons", (PyCFunction)Help_HMGetBalloons, 1,
"() -> (Boolean _rv)"},
{"HMSetBalloons", (PyCFunction)Help_HMSetBalloons, 1,
"(Boolean flag) -> None"},
{"HMIsBalloon", (PyCFunction)Help_HMIsBalloon, 1,
"() -> (Boolean _rv)"},
{"HMSetFont", (PyCFunction)Help_HMSetFont, 1,
"(SInt16 font) -> None"},
{"HMSetFontSize", (PyCFunction)Help_HMSetFontSize, 1,
"(UInt16 fontSize) -> None"},
{"HMGetFont", (PyCFunction)Help_HMGetFont, 1,
"() -> (SInt16 font)"},
{"HMGetFontSize", (PyCFunction)Help_HMGetFontSize, 1,
"() -> (UInt16 fontSize)"},
{"HMSetDialogResID", (PyCFunction)Help_HMSetDialogResID, 1,
"(SInt16 resID) -> None"},
{"HMSetMenuResID", (PyCFunction)Help_HMSetMenuResID, 1,
"(SInt16 menuID, SInt16 resID) -> None"},
{"HMScanTemplateItems", (PyCFunction)Help_HMScanTemplateItems, 1,
"(SInt16 whichID, SInt16 whichResFile, ResType whichType) -> None"},
{"HMGetDialogResID", (PyCFunction)Help_HMGetDialogResID, 1,
"() -> (SInt16 resID)"},
{"HMGetMenuResID", (PyCFunction)Help_HMGetMenuResID, 1,
"(SInt16 menuID) -> (SInt16 resID)"},
{"HMGetBalloonWindow", (PyCFunction)Help_HMGetBalloonWindow, 1,
"() -> (WindowPtr window)"},
{NULL, NULL, 0}
};
void initHelp()
{
PyObject *m;
PyObject *d;
m = Py_InitModule("Help", Help_methods);
d = PyModule_GetDict(m);
Help_Error = PyMac_GetOSErrException();
if (Help_Error == NULL ||
PyDict_SetItemString(d, "Error", Help_Error) != 0)
Py_FatalError("can't initialize Help.Error");
}
/* ======================== End module Help ========================= */

View File

@ -0,0 +1,52 @@
# Scan an Apple header file, generating a Python file of generator calls.
import addpack
addpack.addpack(':tools:bgen:bgen')
from scantools import Scanner
from bgenlocations import TOOLBOXDIR
LONG = "Balloons"
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 "=== 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 makeblacklistnames(self):
return [
]
def makeblacklisttypes(self):
return [
"TipFunctionUPP",
"HMMessageRecord",
"HMMessageRecord_ptr",
]
def makerepairinstructions(self):
return [
]
if __name__ == "__main__":
main()

View File

@ -0,0 +1,82 @@
# 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
MACHEADERFILE = 'Balloons.h' # The Apple header file
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 = MODNAME # 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", "ResObj")
#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 <%s>""" % MACHEADERFILE + """
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
"""
class MyObjectDefinition(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()