summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/ctl/ctlsupport.py
diff options
context:
space:
mode:
authorJust van Rossum <just@letterror.com>2001-12-30 21:25:26 (GMT)
committerJust van Rossum <just@letterror.com>2001-12-30 21:25:26 (GMT)
commitcae6da632a46096fc0013198c2ecef14a3e4e891 (patch)
treee403a8cd88892257415103d0ee794032a338a47e /Mac/Modules/ctl/ctlsupport.py
parent85f98143b7860dbbe791535450e5c94b67cb1bc9 (diff)
downloadcpython-cae6da632a46096fc0013198c2ecef14a3e4e891.zip
cpython-cae6da632a46096fc0013198c2ecef14a3e4e891.tar.gz
cpython-cae6da632a46096fc0013198c2ecef14a3e4e891.tar.bz2
- added support for ControlActionProcs, exposing the following calls:
- ctl.SetControlAction() - CreateScrollBarControl() - CreateSliderControl() - print traceback when callbacks fail
Diffstat (limited to 'Mac/Modules/ctl/ctlsupport.py')
-rw-r--r--Mac/Modules/ctl/ctlsupport.py46
1 files changed, 43 insertions, 3 deletions
diff --git a/Mac/Modules/ctl/ctlsupport.py b/Mac/Modules/ctl/ctlsupport.py
index 5538608..37422ed 100644
--- a/Mac/Modules/ctl/ctlsupport.py
+++ b/Mac/Modules/ctl/ctlsupport.py
@@ -94,6 +94,24 @@ ControlBevelButtonMenuBehavior = UInt16
ControlBevelButtonMenuPlacement = UInt16
ControlPushButtonIconAlignment = UInt16
+class ControlActionDefinition(Type):
+ def declare(self, name):
+ Output("%s %s;", self.typeName, name)
+ Output("UniversalProcPtr c_callback;")
+ def passInput(self, name):
+ return "myactionproc_upp"
+ def cleanup(self, name):
+ Output("setcallback((PyObject*)_self, kMyControlActionProcTag, actionProc, &c_callback);")
+
+class ControlActionDefinitionNewControl(ControlActionDefinition):
+ def cleanup(self, name):
+ Output("setcallback(_res, kMyControlActionProcTag, liveTrackingProc, &c_callback);")
+
+ControlActionUPP = ControlActionDefinition("PyObject*", "O")
+ControlActionUPPNewControl = ControlActionDefinitionNewControl("PyObject*", "O")
+ControlSliderOrientation = UInt16
+
+
includestuff = includestuff + """
#ifdef WITHOUT_FRAMEWORKS
#include <Controls.h>
@@ -203,8 +221,10 @@ DataBrowserListViewColumnDesc_Convert(PyObject *v, DataBrowserListViewColumnDesc
}
/* TrackControl and HandleControlClick callback support */
+#define kMyControlActionProcTag 'ACTN' /* not an official tag, only for internal use */
static PyObject *tracker;
static ControlActionUPP mytracker_upp;
+static ControlActionUPP myactionproc_upp;
static ControlUserPaneDrawUPP mydrawproc_upp;
static ControlUserPaneIdleUPP myidleproc_upp;
static ControlUserPaneHitTestUPP myhittestproc_upp;
@@ -279,8 +299,10 @@ mytracker(ControlHandle ctl, short part)
}
if (rv)
Py_DECREF(rv);
- else
+ else {
PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\\n");
+ PyErr_Print();
+ }
}
static int
@@ -289,7 +311,9 @@ setcallback(PyObject *myself, OSType which, PyObject *callback, UniversalProcPtr
ControlObject *self = (ControlObject *)myself;
char keybuf[9];
- if ( which == kControlUserPaneDrawProcTag )
+ if ( which == kMyControlActionProcTag )
+ *uppp = (UniversalProcPtr)myactionproc_upp;
+ else if ( which == kControlUserPaneDrawProcTag )
*uppp = (UniversalProcPtr)mydrawproc_upp;
else if ( which == kControlUserPaneIdleProcTag )
*uppp = (UniversalProcPtr)myidleproc_upp;
@@ -326,12 +350,27 @@ callcallback(ControlObject *self, OSType which, PyObject *arglist)
return NULL;
}
rv = PyEval_CallObject(func, arglist);
- if ( rv == NULL )
+ if ( rv == NULL ) {
PySys_WriteStderr("Exception in control callback %x handler\\n", (unsigned)which);
+ PyErr_Print();
+ }
return rv;
}
static pascal void
+myactionproc(ControlHandle control, SInt16 part)
+{
+ ControlObject *ctl_obj;
+ PyObject *arglist, *rv;
+
+ ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
+ arglist = Py_BuildValue("Oh", ctl_obj, part);
+ rv = callcallback(ctl_obj, kMyControlActionProcTag, arglist);
+ Py_XDECREF(arglist);
+ Py_XDECREF(rv);
+}
+
+static pascal void
mydrawproc(ControlHandle control, SInt16 part)
{
ControlObject *ctl_obj;
@@ -396,6 +435,7 @@ mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc
initstuff = initstuff + """
mytracker_upp = NewControlActionUPP(mytracker);
+myactionproc_upp = NewControlActionUPP(myactionproc);
mydrawproc_upp = NewControlUserPaneDrawUPP(mydrawproc);
myidleproc_upp = NewControlUserPaneIdleUPP(myidleproc);
myhittestproc_upp = NewControlUserPaneHitTestUPP(myhittestproc);