Make GameLogic work for python autocomplete (after running the BGE once at least)
authorCampbell Barton <ideasman42@gmail.com>
Tue, 23 Sep 2008 00:37:19 +0000 (00:37 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 23 Sep 2008 00:37:19 +0000 (00:37 +0000)
only clear newly added items from the gameLogic dictionary rather then the whole dictionary.

source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp

index 74fe6c68863a87c4c1ab1bedc3ddbf3dc46ff5ea..6a296a3e2449026d7c1aba30d326ca92262c7c84 100644 (file)
@@ -326,8 +326,10 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                        ketsjiengine->SetPythonDictionary(dictionaryobject);
                        initRasterizer(rasterizer, canvas);
                        PyObject *gameLogic = initGameLogic(ketsjiengine, startscene);
-                       PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module.
                        PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
+                       PyObject *gameLogic_keys = PyDict_Keys(PyModule_GetDict(gameLogic));
+                       PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module.
+                       
                        initGameKeys();
                        initPythonConstraintBinding();
                        initMathutils();
@@ -401,8 +403,20 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                                // inside the GameLogic dictionary when the python interpreter is finalized.
                                // which allows the scene to safely delete them :)
                                // see: (space.c)->start_game
-                               PyDict_Clear(PyModule_GetDict(gameLogic));
-                               PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict);
+                               
+                               //PyDict_Clear(PyModule_GetDict(gameLogic));
+                               
+                               // Keep original items, means python plugins will autocomplete members
+                               int listIndex;
+                               PyObject *gameLogic_keys_new = PyDict_Keys(PyModule_GetDict(gameLogic));
+                               for (listIndex=0; listIndex < PyList_Size(gameLogic_keys_new); listIndex++)  {
+                                       PyObject* item = PyList_GET_ITEM(gameLogic_keys_new, listIndex);
+                                       if (!PySequence_Contains(gameLogic_keys, item)) {
+                                               PyDict_DelItem( PyModule_GetDict(gameLogic), item);
+                                       }
+                               }
+                               Py_DECREF(gameLogic_keys_new);
+                               gameLogic_keys_new = NULL;
                                
                                ketsjiengine->StopEngine();
                                exitGamePythonScripting();
@@ -413,6 +427,9 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                                delete sceneconverter;
                                sceneconverter = NULL;
                        }
+                       
+                       Py_DECREF(gameLogic_keys);
+                       gameLogic_keys = NULL;
                }
                // set the cursor back to normal
                canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);