Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillian Padovani Germano <wpgermano@gmail.com>2005-04-16 09:25:42 +0400
committerWillian Padovani Germano <wpgermano@gmail.com>2005-04-16 09:25:42 +0400
commitd65fc84a6815673b9c4085bd4b3e4830167f59fb (patch)
treed8b083c5306ea01492f37fb92828fe4a0b42e1b4 /source/blender/python/api2_2x/Registry.c
parent8b664b924b40aeddc8bc9ac72451a0702af75afe (diff)
Note: this commit includes new functionality to save and restore scripts configure options. This is ongoing work, scripts still have to be updated to use this feature and more tests are needed, though many have been performed. The new Scripts Config Editor script is the main part of this. If anyone wants to check it, only the AC3D importer and exporter have already been updated to use it: simply open them (you can then cancel with ESC) to have the data created, then try the config editor.
Scripts: - Thanks Jean-Michel Soler (jms) for updated versions of dispaint, fixfromarmature and unweld (also renamed to remove version part). - Thanks Bart for the upgraded VRML exporter (great doc webpage!). It is available as VRML 97 and the original VRML 2 is for now still there, to help users testing the new version. For the next release the old one should be removed, of course. - New script: Scripts Config Editor (Scripts win -> Scripts -> System). Scripts with config options (simple data that is to be set according to user needs or preferences) can use this facility instead of providing a gui and writing config files to disk themselves. - Added new menu: System, available in the Scripts win. - Updated sys_info.py, help_browse.py and the AC3D importer and exporter. - Removed use of the Scrollbar and added arrow keys and mouse wheel support instead in Daniel Dunbar's old doc_browser.py. The scrollbar events handling doesn't exist, Ton suggested removing the scrollbar from the API months ago. For now its ref doc is gone and no bundled script uses it, until we get time to implement it properly. - Added module BPyRegistry.py with functions to handle reading / writing config files automatically to the scripts/bpydata/config dir. - Removing dir release/bpydata and its contents (moved earlier to release/scripts/bpydata/) - Bug #2379: made small changes to bevel_center's ui to fix a problem reported by Alexander Ewering (intrr): http://projects.blender.org/tracker/?func=detail&atid=125&aid=2379&group_id=9 BPython: - Thanks Campbell Barton for new functionality: Blender.Get() now can also return all the paths from the user prefs -> file paths win and there is a new function: Blender.sys.expandpath() to transform Blender paths (those starting with '//' and ending with '#') to absolute paths. - Added function Blender.ShowHelp(), to open the Scripts Help Browser with a given help page -- just a time saver for scripts. - Improved function Blender.Run() to also work with gui and file select scripts. - Found a (new?) crash related to NMesh.PutRaw when creating a new object while in edit mode. Leaving / entering edit mode fixes the problem, so a check for obj created, edit mode and leaving / re-entering it were added to the code for now (gdb didn't help much, no backtrace) - doc updates, including splitting intro page in two, with bpython related stuff (registering / documenting / configuring scripts and command line mode (thanks Chris Want for "use system variables to pass parameters to scripts" idea). - Registry: functions have been updated to support writing to / reading from disk, for the config editor -- only simple config data supported, for large amounts coders should write to a file themselves. This is done with a new parameter: Registry.GetKey(keyname, True) will also search for the key on the config dir, if not already loaded; equiv. for Registry.SetKey(keyname, dict, True). Data is only written to / read from disk when needed and only scripts already used (assuming they support this functionality) will have config data saved.
Diffstat (limited to 'source/blender/python/api2_2x/Registry.c')
-rw-r--r--source/blender/python/api2_2x/Registry.c85
1 files changed, 64 insertions, 21 deletions
diff --git a/source/blender/python/api2_2x/Registry.c b/source/blender/python/api2_2x/Registry.c
index e0ba81b1029..bf839630aa2 100644
--- a/source/blender/python/api2_2x/Registry.c
+++ b/source/blender/python/api2_2x/Registry.c
@@ -33,11 +33,11 @@
#include "Registry.h"
#include <stdio.h>
+#include <BKE_global.h> /* G.f & G_DEBUG */
#include "gen_utils.h"
-
/* the Registry dictionary */
PyObject *bpy_registryDict = NULL;
@@ -64,17 +64,23 @@ char M_Registry_Keys_doc[] =
Each key references another dict with saved data from a specific script.\n";
char M_Registry_GetKey_doc[] =
- "(name) - Get a specific entry (dict) from the Registry dictionary\n\
- (name) - a string that references a specific script.\n";
+ "(name, disk = False) - Get an entry (a dict) from the Registry dictionary\n\
+ (name) - a string that references a specific script;\n\
+ (disk = False) - search on the user (if available) or default scripts config\n\
+data dir.\n";
char M_Registry_SetKey_doc[] =
- "(key, dict) - Store an entry in the Registry dictionary.\n\
+ "(key, dict, disk = False) - Store an entry in the Registry dictionary.\n\
If an entry with the same 'key' already exists, it is substituted.\n\
(key) - the string to use as a key for the dict being saved.\n\
- (dict) - a dictionary with the data to be stored.\n";
+ (dict) - a dictionary with the data to be stored.\n\
+ (disk = False) - also write data as a config file inside the user (if\n\
+available) or default scripts config data dir.\n";
char M_Registry_RemoveKey_doc[] =
- "(key) - Remove the dict with key 'key' from the Registry.\n";
+ "(key, disk = False) - Remove the dict with key 'key' from the Registry.\n\
+ (key) - the name of the key to delete;\n\
+ (disk = False) - if True the respective config file is also deleted.\n";
/*****************************************************************************/
/* Python method structure definition for Blender.Registry module: */
@@ -118,25 +124,35 @@ static PyObject *M_Registry_GetKey( PyObject * self, PyObject * args )
{
PyObject *pyentry = NULL;
PyObject *pydict = NULL;
+ int disk = 0;
if( !bpy_registryDict )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "No Registry dictionary found!" );
+ "No Registry dictionary found!" );
- if( !PyArg_ParseTuple( args, "O!", &PyString_Type, &pyentry ) )
+ if( !PyArg_ParseTuple( args, "O!|i", &PyString_Type, &pyentry, &disk ) )
return EXPP_ReturnPyObjError( PyExc_AttributeError,
- "expected a string" );
+ "expected a string and optionally a bool" );
pydict = PyDict_GetItem( bpy_registryDict, pyentry ); /* borrowed ... */
- if( !pydict )
-/* return EXPP_ReturnPyObjError (PyExc_KeyError,
- "no such key in the Registry"); */
- pydict = Py_None; /* better to return None than an error */
-
- Py_INCREF( pydict ); /* ... so we incref it */
- /* should we copy the dict instead? */
- return pydict;
+ if (!pydict) {
+ if (disk > 0) {
+ /* try to get data from disk */
+ char buf[256];
+ PyOS_snprintf(buf, sizeof(buf),
+ "import Blender, BPyRegistry; BPyRegistry.LoadConfigData('%s')",
+ PyString_AsString(pyentry));
+ if (!PyRun_SimpleString(buf))
+ pydict = PyDict_GetItem(bpy_registryDict, pyentry);
+ else PyErr_Clear();
+ }
+
+ if (!pydict) /* no need to return a KeyError, since without doubt */
+ pydict = Py_None; /* Py_None means no key (all valid keys are dicts) */
+ }
+
+ return EXPP_incr_ret (pydict); /* ... so we incref it */
}
/*****************************************************************************/
@@ -147,14 +163,15 @@ static PyObject *M_Registry_SetKey( PyObject * self, PyObject * args )
{
PyObject *pystr = NULL;
PyObject *pydict = NULL;
+ int disk = 0;
if( !bpy_registryDict )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"No Registry dictionary found!" );
- if( !PyArg_ParseTuple( args, "O!O!",
+ if( !PyArg_ParseTuple( args, "O!O!|i",
&PyString_Type, &pystr, &PyDict_Type,
- &pydict ) )
+ &pydict, &disk ) )
return EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected a string and a dictionary" );
@@ -162,6 +179,19 @@ static PyObject *M_Registry_SetKey( PyObject * self, PyObject * args )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"Registry_SetKey: couldn't update the Registry dict" );
+ if (disk) {
+ /* try to save data to disk */
+ char buf[256];
+ PyOS_snprintf(buf, sizeof(buf),
+ "import Blender, BPyRegistry; BPyRegistry.SaveConfigData('%s')",
+ PyString_AsString(pystr));
+ if (PyRun_SimpleString(buf) != 0) {
+ PyErr_Clear();
+ if (G.f & G_DEBUG)
+ fprintf(stderr, "\nCan't save script configuration data!\n");
+ }
+ }
+
Py_INCREF( Py_None );
return Py_None;
}
@@ -173,18 +203,31 @@ static PyObject *M_Registry_SetKey( PyObject * self, PyObject * args )
static PyObject *M_Registry_RemoveKey( PyObject * self, PyObject * args )
{
PyObject *pystr = NULL;
+ int disk = 0;
if( !bpy_registryDict )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"No Registry dictionary found!" );
- if( !PyArg_ParseTuple( args, "O!", &PyString_Type, &pystr ) )
+ if( !PyArg_ParseTuple( args, "O!|i", &PyString_Type, &pystr, &disk ) )
return EXPP_ReturnPyObjError( PyExc_AttributeError,
- "expected a string" );
+ "expected a string and optionally a bool" );
if( PyDict_DelItem( bpy_registryDict, pystr ) ) /* returns 0 on success */
return EXPP_ReturnPyObjError( PyExc_KeyError,
"no such key in the Registry" );
+ else if (disk) {
+ /* try to delete from disk too */
+ char buf[256];
+ PyOS_snprintf(buf, sizeof(buf),
+ "import Blender, BPyRegistry; BPyRegistry.RemoveConfigData('%s')",
+ PyString_AsString(pystr));
+ if (PyRun_SimpleString(buf) != 0) {
+ PyErr_Clear();
+ if (G.f & G_DEBUG)
+ fprintf(stderr, "\nCan't remove script configuration data file!\n");
+ }
+ }
Py_INCREF( Py_None );
return Py_None;