diff options
Diffstat (limited to 'source/blender/python/api2_2x/doc/Registry.py')
-rw-r--r-- | source/blender/python/api2_2x/doc/Registry.py | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/source/blender/python/api2_2x/doc/Registry.py b/source/blender/python/api2_2x/doc/Registry.py index 390669eb37d..5913505f4e4 100644 --- a/source/blender/python/api2_2x/doc/Registry.py +++ b/source/blender/python/api2_2x/doc/Registry.py @@ -3,6 +3,8 @@ """ The Blender.Registry submodule. +B{New}: L{GetKey} and L{SetKey} can respectively load and save data to disk now. + Registry ======== @@ -17,19 +19,19 @@ give script authors a way around this limitation. In Python terms, the Registry holds a dictionary of dictionaries. You should use it to save Python objects only, not BPython (Blender Python) objects -- but you can save BPython object names, since those are strings. -Also, if you need to save a considerable amount of data, please save to a -file instead. There's no need to keep huge blocks of memory around when they -can simply be read from a file. +Also, if you need to save a considerable amount of data, we recommend saving +it to a file instead. There's no need to keep huge blocks of memory around when +they can simply be read from a file. + +Examples of what this module can be used for: -Two uses for this module: +a) Saving data from a script that another script will need to access later. -a) To save data from a script that another script will need to access later. +b) Saving configuration data for a script. Users can view and edit this data +using the "Scripts Configuration Editor" script, then. -b) To save configuration data from your script's gui (button values) so that the -next time the user runs your script, the changes will still be there. Later we -can make Blender save the Registry so that its data won't be lost after users -quit the program. And also add an option to save as a Text that can be kept in -a .blend file, letting users keep script data there. +c) Saving configuration data from your script's gui (button values) so that the +next time the user runs your script, the changes will still be there. Example:: @@ -42,12 +44,12 @@ Example:: mystr = "hello" # then check if they are already at the Registry (saved on a - # previous execution of this script): - dict = Registry.GetKey('MyScript') - if dict: # if found, get the values saved there - myvar1 = dict['myvar1'] - myvar2 = dict['myvar2'] - mystr = dict['mystr'] + # previous execution of this script) or on disk: + rdict = Registry.GetKey('MyScript', True) + if rdict: # if found, get the values saved there + myvar1 = rdict['myvar1'] + myvar2 = rdict['myvar2'] + mystr = rdict['mystr'] # let's create a function to update the Registry when we need to: def update_Registry(): @@ -55,7 +57,8 @@ Example:: d['myvar1'] = myvar1 d['myvar2'] = myvar2 d['mystr'] = mystr - Blender.Registry.SetKey('MyScript', d) + # cache = True: data is also saved to a file + Blender.Registry.SetKey('MyScript', d, True) # ... # here goes the main part of the script ... @@ -72,21 +75,29 @@ def Keys (): Get all keys currently in the Registry's dictionary. """ -def GetKey (key): +def GetKey (key, cached = False): """ Get key 'key' from the Registry. @type key: string @param key: a key from the Registry dictionary. + @type cached: bool + @param cached: if True and the requested key isn't already loaded in the + Registry, it will also be searched on the user or default scripts config + data dir (config subdir in L{Blender.Get}('datadir')). @return: the dictionary called 'key'. """ -def SetKey (key, dict): +def SetKey (key, dict, cache = False): """ Store a new entry in the Registry. @type key: string @param key: the name of the new entry, tipically your script's name. @type dict: dictionary @param dict: a dict with all data you want to save in the Registry. + @type cache: bool + @param cache: if True the given key data will also be saved as a file + in the config subdir of the scripts user or default data dir (see + L{Blender.Get}. """ def RemoveKey (key): |