예제 #1
0
// @pymethod |PyAssocObject|AttachObject|Attaches a Python object for lookup of "virtual" functions.
PyObject *
ui_assoc_object::AttachObject(PyObject *self, PyObject *args)
{
	PyObject *ob;
	ui_assoc_object *pAssoc = (ui_assoc_object *)self;
	if (pAssoc==NULL) return NULL;
	if (!PyArg_ParseTuple(args, "O:AttachObject", &ob ))
		return NULL;
	// Possibility for recursion here if we re-attach the
	// same instance to the same win32ui type object.
	// decref of the instance may trigger instance delete,
	// which may trigger AttachObject(None), which will
	// attempt to decref etc.  
	// So set the instance to NULL _before_ we decref it, and only
	// do the decref after we've incref'd the new object - if it is the
	// same object we may otherwise transition it via a refcount of 0.
	PyObject *old = pAssoc->virtualInst;
	pAssoc->virtualInst = NULL;
	if (ob!=Py_None) {
		pAssoc->virtualInst = ob;
		DOINCREF(ob);
	}
	XDODECREF(old);
	RETURN_NONE;
}
예제 #2
0
PyObject *ui_assoc_object::GetGoodRet()
{
	if (this==NULL) return NULL;
	if (virtualInst) {
		PyObject *vi = virtualInst;
		DOINCREF(vi);
		DODECREF(this);
		return vi;
	} else
		return this;
}
예제 #3
0
// @pymethod |PyCPrintInfo|SetUserData|Set a user-created structure.
// @pyseemfc CPrintInfo|m_lpUserData
static PyObject *ui_set_user_data(PyObject * self, PyObject * args)
{
  PyObject *var;
  if (!PyArg_ParseTuple(args,"O:SetUserData",&var))
    return NULL;
  CPrintInfo *pInfo = ui_prinfo_object::GetPrintInfo(self);
  if (!pInfo)
    return NULL;
  if (pInfo->m_lpUserData) XDODECREF((PyObject*)pInfo->m_lpUserData);
  pInfo->m_lpUserData = var;
  DOINCREF(var);
  RETURN_NONE;
}
예제 #4
0
BOOL CVirtualHelper::call(CView *pWnd, PyObject *ob)
{
	if (!handler) return FALSE;
	CEnterLeavePython _celp;
	if (!ob)
		ob=Py_None;
	PyObject *wnd ;
	if (pWnd==NULL) {
		wnd = Py_None;
		DOINCREF(wnd);
	} else {
		wnd = PyWinObject_FromCWnd(pWnd);
		if (!wnd) return FALSE;
	}
	PyObject *arglst = Py_BuildValue("(OO)",wnd,ob);
	BOOL ret = do_call(arglst);
	DODECREF (wnd); // the reference I created.
	return ret;
}
예제 #5
0
BOOL CVirtualHelper::call(CDC *pDC, CWnd *pWnd, int i)
{
	PyObject *wnd ;
	CEnterLeavePython _celp;
	if (pWnd==NULL) {
		wnd = Py_None;
		DOINCREF(wnd);
	} else {
		wnd = PyWinObject_FromCWnd(pWnd);
		if (!wnd) return FALSE;
	}
	PyObject *dc = (PyObject *) ui_assoc_object::make (ui_dc_object::type,
												   pDC)->GetGoodRet();
	if (!dc) {
		Py_DECREF(wnd);
		return FALSE;
	}
	PyObject *arglst = Py_BuildValue("(OOi)",dc, wnd, i);
	BOOL ret = do_call(arglst);
	Py_DECREF(wnd);
	Py_DECREF(dc);
	return ret;

}