void WizardPurgeStack(PyMOLGlobals * G) { #ifndef _PYMOL_NOPY int blocked; ov_diff a; register CWizard *I = G->Wizard; blocked = PAutoBlock(G); for(a = I->Stack; a >= 0; a--) Py_XDECREF(I->Wiz[a]); I->Stack = -1; PAutoUnblock(G, blocked); #endif }
static void ObjectCallbackRender(ObjectCallback * I, RenderInfo * info) { #ifndef _PYMOL_NOPY int state = info->state; CRay *ray = info->ray; auto pick = info->pick; int pass = info->pass; PyMOLGlobals *G = I->Obj.G; ObjectCallbackState *sobj = NULL; if(pass != 1) /* for now, the callback should be called during the first pass (opaque), so that it is possible to set positions for any object that is rendered in the opaque pass. This is still a kludge, since the callback should probably happen in a pass before this (should we add a new pass 2? this will probably need changes all over.. and will introduce some minimal overhead (another pass on the objects). For now, these callbacks need to be in the object list before any objects it tries to set (this came up on the crosshair.py screen stabilized example) We also might want to have arguments on the callback for whether it gets called at the beginning (pre-first pass) or end (post-last pass). */ return; if(ray || pick) return; if(!(G->HaveGUI && G->ValidContext)) return; if(!I->State || I->NState == 0) return; ObjectPrepareContext(&I->Obj, info); if((I->Obj.visRep & cRepCallbackBit)) { int blocked = PAutoBlock(G); for(StateIterator iter(G, I->Obj.Setting, state, I->NState); iter.next();) { sobj = I->State + iter.state; if(!sobj->is_callable) continue; Py_DecRef(PyObject_CallObject(sobj->PObj, NULL)); if(PyErr_Occurred()) PyErr_Print(); } PAutoUnblock(G, blocked); } #endif }
static void ObjectCallbackFree(ObjectCallback * I) { #ifndef _PYMOL_NOPY int a; PyMOLGlobals *G = I->Obj.G; int blocked = PAutoBlock(G); for(a = 0; a < I->NState; a++) { if(I->State[a].PObj) { Py_DECREF(I->State[a].PObj); I->State[a].PObj = NULL; } } PAutoUnblock(G, blocked); #endif VLAFreeP(I->State); ObjectPurge(&I->Obj); OOFreeP(I); }
/*========================================================================*/ void WizardSet(PyMOLGlobals * G, PyObject * wiz, int replace) { #ifndef _PYMOL_NOPY register CWizard *I = G->Wizard; int blocked; blocked = PAutoBlock(G); if(I->Wiz) { if((!wiz) || (wiz == Py_None) || ((I->Stack >= 0) && replace)) { if(I->Stack >= 0) { /* pop */ PyObject *old_wiz = I->Wiz[I->Stack]; /* remove wizard from stack first */ I->Wiz[I->Stack] = NULL; I->Stack--; if(old_wiz) { /* then call cleanup, etc. */ if(PyObject_HasAttrString(old_wiz, "cleanup")) { PXDecRef(PyObject_CallMethod(old_wiz, "cleanup", "")); if(PyErr_Occurred()) PyErr_Print(); } Py_DECREF(old_wiz); } } } if(wiz && (wiz != Py_None)) { /* push */ if(wiz) { I->Stack++; VLACheck(I->Wiz, PyObject *, I->Stack); I->Wiz[I->Stack] = wiz; if(I->Wiz[I->Stack]) Py_INCREF(I->Wiz[I->Stack]); } } } WizardRefresh(G); PAutoUnblock(G, blocked); #endif }
/*========================================================================*/ void WizardRefresh(PyMOLGlobals * G) { #ifndef _PYMOL_NOPY register CWizard *I = G->Wizard; char *vla = NULL; PyObject *P_list; ov_size ll; PyObject *i; ov_size a; int blocked; blocked = PAutoBlock(G); /* get the current prompt */ if(I->Stack >= 0) if(I->Wiz[I->Stack]) { vla = NULL; if(PyObject_HasAttrString(I->Wiz[I->Stack], "get_prompt")) { P_list = PyObject_CallMethod(I->Wiz[I->Stack], "get_prompt", ""); if(PyErr_Occurred()) PyErr_Print(); if(P_list) PConvPyListToStringVLA(P_list, &vla); Py_XDECREF(P_list); } } OrthoSetWizardPrompt(G, vla); /* get the current panel list */ I->NLine = 0; if(I->Stack >= 0) if(I->Wiz[I->Stack]) { I->EventMask = cWizEventPick + cWizEventSelect; if(PyObject_HasAttrString(I->Wiz[I->Stack], "get_event_mask")) { i = PyObject_CallMethod(I->Wiz[I->Stack], "get_event_mask", ""); if(PyErr_Occurred()) PyErr_Print(); if(!PConvPyIntToInt(i, &I->EventMask)) I->EventMask = cWizEventPick + cWizEventSelect; Py_XDECREF(i); } if(PyObject_HasAttrString(I->Wiz[I->Stack], "get_panel")) { P_list = PyObject_CallMethod(I->Wiz[I->Stack], "get_panel", ""); if(PyErr_Occurred()) PyErr_Print(); if(P_list) { if(PyList_Check(P_list)) { ll = PyList_Size(P_list); VLACheck(I->Line, WizardLine, ll); for(a = 0; a < ll; a++) { /* fallback defaults */ I->Line[a].text[0] = 0; I->Line[a].code[0] = 0; I->Line[a].type = 0; i = PyList_GetItem(P_list, a); if(PyList_Check(i)) if(PyList_Size(i) > 2) { PConvPyObjectToInt(PyList_GetItem(i, 0), &I->Line[a].type); PConvPyObjectToStrMaxLen(PyList_GetItem(i, 1), I->Line[a].text, sizeof(WordType) - 1); PConvPyObjectToStrMaxLen(PyList_GetItem(i, 2), I->Line[a].code, sizeof(OrthoLineType) - 1); } } I->NLine = ll; } } Py_XDECREF(P_list); } } if(I->NLine) { int LineHeight = SettingGetGlobal_i(G, cSetting_internal_gui_control_size); OrthoReshapeWizard(G, LineHeight * I->NLine + 4); } else { OrthoReshapeWizard(G, 0); } PAutoUnblock(G, blocked); #endif }